From d2b073554011bd66733bf754852ceea127d822ef Mon Sep 17 00:00:00 2001 From: adrien Date: Mon, 18 May 2026 15:35:38 +0200 Subject: [PATCH] Moved all f32 out of GpuXxxx to all be in Vec --- src/GpuBuffer.zig | 5 +++-- src/GpuProcess.zig | 6 +++++- src/Vec.zig | 4 ++-- src/lib.zig | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/GpuBuffer.zig b/src/GpuBuffer.zig index 970a2ba..906eda9 100644 --- a/src/GpuBuffer.zig +++ b/src/GpuBuffer.zig @@ -66,12 +66,13 @@ pub fn unmap(self: @This()) void { /// CPU to GPU. pub fn load( self: @This(), - data: []const f16, + T: type, + data: []const T, ) !void { c.wgpuQueueWriteBuffer(self.gloc.device.queue, self.raw, 0, data.ptr, self.size); } -pub fn read(self: @This(), alloc: std.mem.Allocator, T: type) ![]f16 { +pub fn read(self: @This(), alloc: std.mem.Allocator, T: type) ![]T { const out = try alloc.alloc(T, @divExact(self.size, @sizeOf(T))); const staging = try init( diff --git a/src/GpuProcess.zig b/src/GpuProcess.zig index 1b5a5c9..e03e7be 100644 --- a/src/GpuProcess.zig +++ b/src/GpuProcess.zig @@ -1,3 +1,6 @@ +/// GpuProcess is just a pipeline with 2 inpout and 1 output +/// for now, to see if I make it a bit more generic +/// const std = @import("std"); const c = @import("utils.zig").c; const sv = @import("utils.zig").sv; @@ -40,6 +43,7 @@ fn onMapped( pub fn run( self: @This(), gloc: GpuAllocator, + T: type, buf_a: GpuBuffer, buf_b: GpuBuffer, buf_out: GpuBuffer, @@ -50,7 +54,7 @@ pub fn run( var offset: u64 = 0; while (offset < bytes) { const current_chunk_bytes = @min(max_chunk_bytes, bytes - offset); - const current_chunk_elements: u32 = @intCast(current_chunk_bytes / @sizeOf(f16)); + const current_chunk_elements: u32 = @intCast(current_chunk_bytes / @sizeOf(T)); const info_buf = try GpuBuffer.init( gloc, diff --git a/src/Vec.zig b/src/Vec.zig index e624f12..e69971c 100644 --- a/src/Vec.zig +++ b/src/Vec.zig @@ -34,7 +34,7 @@ pub fn deinit(self: Vec) void { /// CPU to GPU. pub fn load(self: Vec, data: []const f16) !void { - try self.buf.load(data); + try self.buf.load(f16, data); } pub fn byteSize(self: Vec) u64 { @@ -48,7 +48,7 @@ pub fn run(self: Vec, gloc: GpuAllocator, other: Vec, process: GpuProcess) !Vec const result = try Vec.initZero(gloc, self.len); errdefer result.deinit(); - try process.run(gloc, self.buf, other.buf, result.buf); + try process.run(gloc, f32, self.buf, other.buf, result.buf); return result; } diff --git a/src/lib.zig b/src/lib.zig index 6560570..0ae3081 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -2,4 +2,4 @@ pub const GpuAllocator = @import("GpuAllocator.zig"); pub const GpuArena = @import("GpuArena.zig"); pub const GpuBuffer = @import("GpuBuffer.zig"); pub const GpuDevice = @import("GpuDevice.zig"); -pub const GpuPipeline = @import("GpuPipeline.zig"); +pub const GpuProcess = @import("GpuProcess.zig");