gpu: fix Queue.submit commands parameter

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-11 22:40:18 -07:00 committed by Stephen Gutekanst
parent e26a2858ed
commit 1c5c23f101
3 changed files with 24 additions and 10 deletions

View file

@ -211,12 +211,11 @@ fn frame(params: FrameParams) !void {
pass.end();
pass.release();
var commands = encoder.finish(null);
var command = encoder.finish(null);
encoder.release();
const buf = gpu.CommandBuffer{ .ptr = &commands, .vtable = undefined };
params.queue.submit(1, &buf);
commands.release();
params.queue.submit(&.{command});
command.release();
pl.swap_chain.?.present();
back_buffer_view.release();
}

View file

@ -510,7 +510,7 @@ const queue_vtable = Queue.VTable{
}
}).release,
.submit = (struct {
pub fn submit(queue: Queue, command_count: u32, commands: *const CommandBuffer) void {
pub fn submit(queue: Queue, cmds: []const CommandBuffer) void {
const wgpu_queue = @ptrCast(c.WGPUQueue, queue.ptr);
if (queue.on_submitted_work_done) |on_submitted_work_done| {
@ -533,10 +533,25 @@ const queue_vtable = Queue.VTable{
c.wgpuQueueOnSubmittedWorkDone(wgpu_queue, signal_value, callback, &mut_on_submitted_work_done);
}
var few_commands: [16]c.WGPUCommandBuffer = undefined;
const commands = if (cmds.len <= 8) blk: {
for (cmds) |cmd, i| {
few_commands[i] = @ptrCast(c.WGPUCommandBuffer, cmd.ptr);
}
break :blk few_commands[0..cmds.len];
} else blk: {
const mem = std.heap.page_allocator.alloc(c.WGPUCommandBuffer, cmds.len) catch unreachable;
for (cmds) |cmd, i| {
mem[i] = @ptrCast(c.WGPUCommandBuffer, cmd.ptr);
}
break :blk mem;
};
defer if (cmds.len > 8) std.heap.page_allocator.free(cmds);
c.wgpuQueueSubmit(
wgpu_queue,
command_count,
@ptrCast(*c.WGPUCommandBuffer, @alignCast(@alignOf(*c.WGPUCommandBuffer), commands.ptr)),
@intCast(u32, commands.len),
@ptrCast(*c.WGPUCommandBuffer, &commands[0]),
);
}
}).submit,

View file

@ -14,7 +14,7 @@ pub const VTable = struct {
release: fn (ptr: *anyopaque) void,
// TODO: dawn specific?
// copyTextureForBrowser: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D, options: *const CopyTextureForBrowserOptions) void,
submit: fn (queue: Queue, command_count: u32, commands: *const CommandBuffer) void,
submit: fn (queue: Queue, commands: []const CommandBuffer) void,
// TODO:
// writeBuffer: fn (ptr: *anyopaque, buffer: Buffer, buffer_offset: u64, data: *const anyopaque, size: usize);
// writeTexture: fn (ptr: *anyopaque, destination: *const ImageCopyTexture, data: *const anyopaque, data_size: usize, data_layout: *const TextureDataLayout, write_size: *const Extent3D);
@ -28,8 +28,8 @@ pub inline fn release(queue: Queue) void {
queue.vtable.release(queue.ptr);
}
pub inline fn submit(queue: Queue, command_count: u32, commands: *const CommandBuffer) void {
queue.vtable.submit(queue, command_count, commands);
pub inline fn submit(queue: Queue, commands: []const CommandBuffer) void {
queue.vtable.submit(queue, commands);
}
pub const OnSubmittedWorkDone = struct {