gpu: fix Queue.submit commands parameter
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e26a2858ed
commit
1c5c23f101
3 changed files with 24 additions and 10 deletions
|
|
@ -211,12 +211,11 @@ fn frame(params: FrameParams) !void {
|
||||||
pass.end();
|
pass.end();
|
||||||
pass.release();
|
pass.release();
|
||||||
|
|
||||||
var commands = encoder.finish(null);
|
var command = encoder.finish(null);
|
||||||
encoder.release();
|
encoder.release();
|
||||||
|
|
||||||
const buf = gpu.CommandBuffer{ .ptr = &commands, .vtable = undefined };
|
params.queue.submit(&.{command});
|
||||||
params.queue.submit(1, &buf);
|
command.release();
|
||||||
commands.release();
|
|
||||||
pl.swap_chain.?.present();
|
pl.swap_chain.?.present();
|
||||||
back_buffer_view.release();
|
back_buffer_view.release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -510,7 +510,7 @@ const queue_vtable = Queue.VTable{
|
||||||
}
|
}
|
||||||
}).release,
|
}).release,
|
||||||
.submit = (struct {
|
.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);
|
const wgpu_queue = @ptrCast(c.WGPUQueue, queue.ptr);
|
||||||
|
|
||||||
if (queue.on_submitted_work_done) |on_submitted_work_done| {
|
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);
|
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(
|
c.wgpuQueueSubmit(
|
||||||
wgpu_queue,
|
wgpu_queue,
|
||||||
command_count,
|
@intCast(u32, commands.len),
|
||||||
@ptrCast(*c.WGPUCommandBuffer, @alignCast(@alignOf(*c.WGPUCommandBuffer), commands.ptr)),
|
@ptrCast(*c.WGPUCommandBuffer, &commands[0]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}).submit,
|
}).submit,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub const VTable = struct {
|
||||||
release: fn (ptr: *anyopaque) void,
|
release: fn (ptr: *anyopaque) void,
|
||||||
// TODO: dawn specific?
|
// TODO: dawn specific?
|
||||||
// copyTextureForBrowser: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D, options: *const CopyTextureForBrowserOptions) void,
|
// 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:
|
// TODO:
|
||||||
// writeBuffer: fn (ptr: *anyopaque, buffer: Buffer, buffer_offset: u64, data: *const anyopaque, size: usize);
|
// 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);
|
// 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);
|
queue.vtable.release(queue.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn submit(queue: Queue, command_count: u32, commands: *const CommandBuffer) void {
|
pub inline fn submit(queue: Queue, commands: []const CommandBuffer) void {
|
||||||
queue.vtable.submit(queue, command_count, commands);
|
queue.vtable.submit(queue, commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const OnSubmittedWorkDone = struct {
|
pub const OnSubmittedWorkDone = struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue