diff --git a/src/GpuBuffer.zig b/src/GpuBuffer.zig index 094507e..56588b6 100644 --- a/src/GpuBuffer.zig +++ b/src/GpuBuffer.zig @@ -68,3 +68,11 @@ pub fn getConstMappedRange(self: @This(), offset: u64, size: u64) ?*const anyopa pub fn unmap(self: @This()) void { c.wgpuBufferUnmap(self.raw); } + +/// CPU to GPU. +pub fn load( + self: @This(), + data: []const f16, +) !void { + c.wgpuQueueWriteBuffer(self.gloc.device.queue, self.raw, 0, data.ptr, self.size); +} diff --git a/src/Vec.zig b/src/Vec.zig index 4b725b0..a6f09e0 100644 --- a/src/Vec.zig +++ b/src/Vec.zig @@ -26,7 +26,7 @@ pub fn initZero(gloc: GpuAllocator, len: usize) !Vec { // Changed: gloc is passed by value pub fn initLoad(gloc: GpuAllocator, data: []const f16) !Vec { var self = try initZero(gloc, data.len); - try self.load(gloc.device, data); // Direct access via the interface copy + try self.load(data); // Direct access via the interface copy return self; } @@ -37,12 +37,9 @@ pub fn deinit(self: Vec) void { /// CPU to GPU. pub fn load( self: Vec, - device: GpuDevice, data: []const f16, ) !void { - std.debug.assert(data.len == self.len); - const bytes = self.byteSize(); - c.wgpuQueueWriteBuffer(device.queue, self.buf.raw, 0, data.ptr, bytes); + try self.buf.load(data); } pub fn byteSize(self: Vec) u64 {