From 42619616cc34025b96c91b447929f5e7d01c2435 Mon Sep 17 00:00:00 2001 From: copygirl Date: Wed, 27 Mar 2024 12:09:04 +0100 Subject: [PATCH] Add labels to GPU objects --- src/renderer.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/renderer.zig b/src/renderer.zig index 67b3263..adaa092 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -37,12 +37,16 @@ primitive_data: []PrimitiveData, object_data: []ObjectData, pub fn init(app: *App) !*Renderer { + // A string buffer used to format objects' labels. + var label_buffer: [256]u8 = undefined; + const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); defer shader_module.release(); // Define layouts for our bind groups and pipeline. // This helps find errors with missing or mismatching shader properties. var camera_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ + .label = "Camera Bind Group Layout", .entries = &.{ gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), }, @@ -50,6 +54,7 @@ pub fn init(app: *App) !*Renderer { defer camera_bind_group_layout.release(); var model_bind_group_layout = core.device.createBindGroupLayout(&gpu.BindGroupLayout.Descriptor.init(.{ + .label = "Model Bind Group Layout", .entries = &.{ gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, false, 0), gpu.BindGroupLayout.Entry.buffer(1, .{ .vertex = true }, .uniform, false, 0), @@ -104,6 +109,7 @@ pub fn init(app: *App) !*Renderer { // "Bind groups" are used to associate data from buffers with shader parameters. // So for example the `camera_bind_group` is accessible via `@group(0)` in our shader. const camera_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ + .label = "Camera Bind Group", .layout = camera_bind_group_layout, .entries = &.{ gpu.BindGroup.Entry.buffer(0, view_proj_buffer, 0, @sizeOf(zm.Mat)), @@ -160,7 +166,9 @@ pub fn init(app: *App) !*Renderer { const model_color_buffer = createAndWriteBuffer([3]f32, &.{model_color}, .{ .copy_dst = true, .uniform = true }); defer model_color_buffer.release(); + const model_bind_group_label = try std.fmt.bufPrintZ(&label_buffer, "Model Bind Group {d}", .{i}); const model_bind_group = core.device.createBindGroup(&gpu.BindGroup.Descriptor.init(.{ + .label = model_bind_group_label, .layout = model_bind_group_layout, .entries = &.{ gpu.BindGroup.Entry.buffer(0, model_matrix_buffer, 0, @sizeOf(zm.Mat)), @@ -319,6 +327,7 @@ pub fn recreateDepthTexture(self: *Renderer) void { if (self.depth_texture_view) |v| v.release(); self.depth_texture = core.device.createTexture(&.{ + .label = "Depth Texture", .usage = .{ .render_attachment = true }, .size = .{ .width = core.descriptor.width, .height = core.descriptor.height }, .format = .depth24_plus,