{gfx,examples}: add labels to gpu objects

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-21 19:47:08 -07:00
parent 2b8bfcaa3e
commit bffc668005
10 changed files with 78 additions and 34 deletions

View file

@ -35,7 +35,9 @@ fn init(game: *Mod) !void {
});
// Create our render pipeline that will ultimately get pixels onto the screen.
const label = @tagName(name) ++ ".init";
const pipeline_descriptor = gpu.RenderPipeline.Descriptor{
.label = label,
.fragment = &fragment,
.vertex = gpu.VertexState{
.module = shader_module,
@ -75,7 +77,8 @@ fn tick(
defer back_buffer_view.release();
// Create a command encoder
const encoder = mach.core.device.createCommandEncoder(null);
const label = @tagName(name) ++ ".tick";
const encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
defer encoder.release();
// Begin render pass
@ -87,7 +90,7 @@ fn tick(
.store_op = .store,
}};
const render_pass = encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
.label = "main render pass",
.label = label,
.color_attachments = &color_attachments,
}));
@ -99,7 +102,7 @@ fn tick(
render_pass.end();
// Submit our commands to the queue
var command = encoder.finish(null);
var command = encoder.finish(&.{ .label = label });
defer command.release();
mach.core.queue.submit(&[_]*gpu.CommandBuffer{command});

View file

@ -58,7 +58,9 @@ fn init(
.targets = &.{color_target},
});
const label = @tagName(name) ++ ".init";
const uniform_buffer = device.createBuffer(&.{
.label = label ++ " uniform buffer",
.usage = .{ .copy_dst = true, .uniform = true },
.size = @sizeOf(UniformBufferObject) * uniform_offset * num_bind_groups,
.mapped_at_creation = .false,
@ -66,6 +68,7 @@ fn init(
const bind_group_layout_entry = gpu.BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0);
const bind_group_layout = device.createBindGroupLayout(
&gpu.BindGroupLayout.Descriptor.init(.{
.label = label,
.entries = &.{bind_group_layout_entry},
}),
);
@ -73,6 +76,7 @@ fn init(
for (bind_groups, 0..) |_, i| {
bind_groups[i] = device.createBindGroup(
&gpu.BindGroup.Descriptor.init(.{
.label = label,
.layout = bind_group_layout,
.entries = &.{
gpu.BindGroup.Entry.buffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject)),
@ -83,9 +87,11 @@ fn init(
const bind_group_layouts = [_]*gpu.BindGroupLayout{bind_group_layout};
const pipeline_layout = device.createPipelineLayout(&gpu.PipelineLayout.Descriptor.init(.{
.label = label,
.bind_group_layouts = &bind_group_layouts,
}));
const pipeline_descriptor = gpu.RenderPipeline.Descriptor{
.label = label,
.fragment = &fragment,
.layout = pipeline_layout,
.vertex = gpu.VertexState{
@ -127,8 +133,10 @@ fn tick(
.store_op = .store,
};
const encoder = device.createCommandEncoder(null);
const label = @tagName(name) ++ ".tick";
const encoder = device.createCommandEncoder(&.{ .label = label });
const render_pass_info = gpu.RenderPassDescriptor.init(.{
.label = label,
.color_attachments = &.{color_attachment},
});
@ -162,7 +170,7 @@ fn tick(
pass.end();
pass.release();
var command = encoder.finish(null);
var command = encoder.finish(&.{ .label = label });
encoder.release();
renderer.state().queue.submit(&[_]*gpu.CommandBuffer{command});

View file

@ -202,7 +202,8 @@ fn tick(
sprite_pipeline.send(.pre_render, .{});
// Create a command encoder for this frame
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
const label = @tagName(name) ++ ".tick";
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
// Grab the back buffer of the swapchain
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
@ -216,9 +217,10 @@ fn tick(
.load_op = .clear,
.store_op = .store,
}};
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
// TODO: can we eliminate this assignment
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
.label = "main render pass",
.label = label,
.color_attachments = &color_attachments,
}));
@ -235,7 +237,8 @@ fn tick(
fn endFrame(game: *Mod) !void {
// Finish render pass
game.state().frame_render_pass.end();
var command = game.state().frame_encoder.finish(null);
const label = @tagName(name) ++ ".endFrame";
var command = game.state().frame_encoder.finish(&.{ .label = label });
game.state().frame_encoder.release();
defer command.release();
mach.core.queue.submit(&[_]*gpu.CommandBuffer{command});

View file

@ -48,7 +48,9 @@ fn init(
const img_size = gpu.Extent3D{ .width = 1024, .height = 1024 };
// Create a GPU texture
const label = @tagName(name) ++ ".init";
const texture = device.createTexture(&.{
.label = label,
.size = img_size,
.format = .rgba8_unorm,
.usage = .{

View file

@ -183,7 +183,8 @@ fn tick(
sprite_pipeline.send(.pre_render, .{});
// Create a command encoder for this frame
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
const label = @tagName(name) ++ ".tick";
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
// Grab the back buffer of the swapchain
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
@ -197,9 +198,10 @@ fn tick(
.load_op = .clear,
.store_op = .store,
}};
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
// TODO: can we eliminate this assignment
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
.label = "main render pass",
.label = label,
.color_attachments = &color_attachments,
}));
@ -216,7 +218,8 @@ fn tick(
fn endFrame(game: *Mod) !void {
// Finish render pass
game.state().frame_render_pass.end();
var command = game.state().frame_encoder.finish(null);
const label = @tagName(name) ++ ".endFrame";
var command = game.state().frame_encoder.finish(&.{ .label = label });
game.state().frame_encoder.release();
defer command.release();
mach.core.queue.submit(&[_]*gpu.CommandBuffer{command});
@ -244,7 +247,9 @@ fn loadTexture(core: *mach.Core.Mod, allocator: std.mem.Allocator) !*gpu.Texture
const img_size = gpu.Extent3D{ .width = @as(u32, @intCast(img.width)), .height = @as(u32, @intCast(img.height)) };
// Create a GPU texture
const label = @tagName(name) ++ ".loadTexture";
const texture = device.createTexture(&.{
.label = label,
.size = img_size,
.format = .rgba8_unorm,
.usage = .{

View file

@ -227,7 +227,8 @@ fn tick(
text_pipeline.send(.pre_render, .{});
// Create a command encoder for this frame
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
const label = @tagName(name) ++ ".tick";
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
// Grab the back buffer of the swapchain
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
@ -241,9 +242,9 @@ fn tick(
.load_op = .clear,
.store_op = .store,
}};
game.state().frame_encoder = mach.core.device.createCommandEncoder(null);
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
.label = "main render pass",
.label = label,
.color_attachments = &color_attachments,
}));
@ -260,7 +261,8 @@ fn tick(
fn endFrame(game: *Mod, text: *gfx.Text.Mod) !void {
// Finish render pass
game.state().frame_render_pass.end();
var command = game.state().frame_encoder.finish(null);
const label = @tagName(name) ++ ".tick";
var command = game.state().frame_encoder.finish(&.{ .label = label });
game.state().frame_encoder.release();
defer command.release();
mach.core.queue.submit(&[_]*gpu.CommandBuffer{command});