Update README and comment for new GpuProcess
This commit is contained in:
parent
62b5224e6e
commit
09e62cf667
15
README.md
15
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user