Added optional label in definitions and added logs when alloc, free and device info

This commit is contained in:
AdrienBouvais
2026-05-21 10:26:20 +02:00
parent 69f9cad2c1
commit d503ce7dea
11 changed files with 203 additions and 73 deletions
+6 -5
View File
@@ -6,6 +6,8 @@ const GpuAllocator = gpu.GpuAllocator;
const GpuBuffer = gpu.GpuBuffer;
const GpuCompute = gpu.GpuCompute;
pub const std_options = std.Options{ .log_level = .info };
/// Minimal implementation of a f16 Vector
const Vec = struct {
buf: GpuBuffer,
@@ -14,11 +16,10 @@ const Vec = struct {
// Changed: gloc is passed by value (const)
pub fn initZero(gloc: GpuAllocator, len: usize) !Vec {
return .{
.buf = try GpuBuffer.init(
gloc,
len * @sizeOf(f16),
.initMany(&.{ .Storage, .CopyDst, .CopySrc }),
),
.buf = try GpuBuffer.init(gloc, .{
.size = len * @sizeOf(f16),
.usage = .initMany(&.{ .Storage, .CopyDst, .CopySrc }),
}),
.len = len,
};
}
+3 -1
View File
@@ -18,7 +18,9 @@ pub fn main(init: std.process.Init) !void {
defer device.deinit();
// 2. Init VRAM Arena
const gloc = device.gpuAllocator();
var grena = GpuArenaAllocator.init(allocator, device.gpuAllocator());
defer grena.deinit();
const gloc = grena.gpuAllocator();
// 3. Load Render Pipeline
const circle_rp = try GpuRender.init(
+11 -8
View File
@@ -21,11 +21,14 @@ pub fn main(init: std.process.Init) !void {
const add_cp = try GpuCompute.init(
gloc,
@embedFile("shaders/add.wgsl"),
.{ .bindings = &.{
.{ .element_size = @sizeOf(f16) },
.{ .element_size = @sizeOf(f16) },
.{ .element_size = @sizeOf(f16) },
} },
.{
.label = "add",
.bindings = &.{
.{ .element_size = @sizeOf(f16) },
.{ .element_size = @sizeOf(f16) },
.{ .element_size = @sizeOf(f16) },
},
},
);
// 4. Setup CPU data
@@ -42,9 +45,9 @@ pub fn main(init: std.process.Init) !void {
// 5. Initialize raw GPU Buffers
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 }));
const buf_out = try GpuBuffer.init(gloc, byte_size, .initMany(&.{ .Storage, .CopyDst, .CopySrc }));
const buf_a = try GpuBuffer.init(gloc, .{ .label = "a", .size = byte_size, .usage = .initMany(&.{ .Storage, .CopyDst, .CopySrc }) });
const buf_b = try GpuBuffer.init(gloc, .{ .label = "b", .size = byte_size, .usage = .initMany(&.{ .Storage, .CopyDst, .CopySrc }) });
const buf_out = try GpuBuffer.init(gloc, .{ .label = "out", .size = byte_size, .usage = .initMany(&.{ .Storage, .CopyDst, .CopySrc }) });
// Note: Buffers are safely tied to the GpuArenaAllocator which will automatically
// release them at the end. You can also manually call buf_x.deinit() if desired.