From 09e62cf667f04961455282b96bf8d9528450b5b6 Mon Sep 17 00:00:00 2001 From: AdrienBouvais Date: Tue, 19 May 2026 08:00:42 +0200 Subject: [PATCH] Update README and comment for new GpuProcess --- README.md | 15 +++++++++++---- examples/add.zig | 14 +++++--------- src/GpuProcess.zig | 3 +-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2742e61..807d3fb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ The library exports five primary components: Below is a complete, self-contained example demonstrating how to initialize the GPU, load data, run a compute shader, and read the results back to the CPU: ```zig - const std = @import("std"); const gpu = @import("gpu"); const GpuDevice = gpu.GpuDevice; @@ -38,7 +37,15 @@ pub fn main(init: std.process.Init) !void { const gloc = grena.gpuAllocator(); // 3. Load the WGSL compute pipeline - const add_process = try GpuProcess.init(device, @embedFile("shaders/add.wgsl")); + const add_process = try GpuProcess.init( + device, + @embedFile("shaders/add.wgsl"), + .{ .bindings = &.{ + .{ .element_size = @sizeOf(f16) }, + .{ .element_size = @sizeOf(f16) }, + .{ .element_size = @sizeOf(f16) }, + } }, + ); defer add_process.deinit(); // 4. Setup CPU data @@ -67,8 +74,7 @@ pub fn main(init: std.process.Init) !void { try buf_b.load(f16, data_b); // 7. Dispatch the Compute Process - // We pass the data type (f16) to allow GpuProcess to calculate chunks correctly - try add_process.run(gloc, f16, buf_a, buf_b, buf_out); + try add_process.run(gloc, .{ buf_a, buf_b, buf_out }); // 8. Map and copy the resulting buffer back to the CPU const out = try buf_out.read(allocator, f16); @@ -76,6 +82,7 @@ pub fn main(init: std.process.Init) !void { std.debug.print("Result: {any}\n", .{out}); } + ``` ## Dependencies diff --git a/examples/add.zig b/examples/add.zig index c611ac3..6d78b74 100644 --- a/examples/add.zig +++ b/examples/add.zig @@ -21,13 +21,11 @@ pub fn main(init: std.process.Init) !void { const add_process = try GpuProcess.init( device, @embedFile("shaders/add.wgsl"), - .{ - .bindings = &.{ - .{ .element_size = @sizeOf(f16) }, - .{ .element_size = @sizeOf(f16) }, - .{ .element_size = @sizeOf(f16) }, - }, - }, + .{ .bindings = &.{ + .{ .element_size = @sizeOf(f16) }, + .{ .element_size = @sizeOf(f16) }, + .{ .element_size = @sizeOf(f16) }, + } }, ); defer add_process.deinit(); @@ -44,7 +42,6 @@ pub fn main(init: std.process.Init) !void { } // 5. Initialize raw GPU Buffers - // We pass the EnumSet inline using `.initMany` since the Enum itself isn't exported const byte_size = len * @sizeOf(f16); const buf_a = try GpuBuffer.init(gloc, byte_size, .initMany(&.{ .Storage, .CopyDst, .CopySrc })); const buf_b = try GpuBuffer.init(gloc, byte_size, .initMany(&.{ .Storage, .CopyDst, .CopySrc })); @@ -58,7 +55,6 @@ pub fn main(init: std.process.Init) !void { try buf_b.load(f16, data_b); // 7. Dispatch the Compute Process - // We pass the data type (f16) to allow GpuProcess to calculate chunks correctly try add_process.run(gloc, .{ buf_a, buf_b, buf_out }); // 8. Map and copy the resulting buffer back to the CPU diff --git a/src/GpuProcess.zig b/src/GpuProcess.zig index 0bad385..2046c0c 100644 --- a/src/GpuProcess.zig +++ b/src/GpuProcess.zig @@ -48,8 +48,7 @@ pub fn deinit(self: @This()) void { } /// Execute the compute pass with arbitrary buffer bindings via a tuple. -/// `override_elements_count` can be `null` to infer the dispatch count from the first checked buffer. -/// Example: `try proc.run(gloc, null, .{ buf_a, buf_b, buf_out });` +/// Example: `try proc.run(gloc, .{ buf_a, buf_b, buf_out });` pub fn run( self: @This(), gloc: GpuAllocator,