diff --git a/gpu/src/CommandBuffer.zig b/gpu/src/CommandBuffer.zig new file mode 100644 index 00000000..3615f6ab --- /dev/null +++ b/gpu/src/CommandBuffer.zig @@ -0,0 +1,25 @@ +const CommandBuffer = @This(); + +/// The type erased pointer to the CommandBuffer implementation +/// Equal to c.WGPUCommandBuffer for NativeInstance. +ptr: *anyopaque, +vtable: *const VTable, + +pub const VTable = struct { + reference: fn (ptr: *anyopaque) void, + release: fn (ptr: *anyopaque) void, +}; + +pub inline fn reference(buf: CommandBuffer) void { + buf.vtable.reference(buf.ptr); +} + +pub inline fn release(buf: CommandBuffer) void { + buf.vtable.release(buf.ptr); +} + +test "syntax" { + _ = VTable; + _ = reference; + _ = release; +} \ No newline at end of file diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 86c0dd7b..6f4ee26c 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -17,6 +17,7 @@ const Device = @import("Device.zig"); const Surface = @import("Surface.zig"); const Limits = @import("Limits.zig"); const Queue = @import("Queue.zig"); +const CommandBuffer = @import("CommandBuffer.zig"); const NativeInstance = @This(); @@ -352,6 +353,15 @@ const queue_vtable = Queue.VTable{ c.wgpuQueueRelease(@ptrCast(c.WGPUQueue, ptr)); } }).release, + .submit = (struct { + pub fn submit(ptr: *anyopaque, command_count: u32, commands: *const CommandBuffer) void { + c.wgpuQueueSubmit( + @ptrCast(c.WGPUQueue, ptr), + command_count, + @ptrCast(*c.WGPUCommandBuffer, @alignCast(@alignOf(*c.WGPUCommandBuffer), commands.ptr)), + ); + } + }).submit, }; test "syntax" { diff --git a/gpu/src/Queue.zig b/gpu/src/Queue.zig index 287aa9c5..df8765e2 100644 --- a/gpu/src/Queue.zig +++ b/gpu/src/Queue.zig @@ -1,3 +1,5 @@ +const CommandBuffer = @import("CommandBuffer.zig"); + const Queue = @This(); /// The type erased pointer to the Queue implementation @@ -10,7 +12,7 @@ pub const VTable = struct { release: fn (ptr: *anyopaque) void, // WGPU_EXPORT void wgpuQueueCopyTextureForBrowser(WGPUQueue queue, WGPUImageCopyTexture const * source, WGPUImageCopyTexture const * destination, WGPUExtent3D const * copySize, WGPUCopyTextureForBrowserOptions const * options); // WGPU_EXPORT void wgpuQueueOnSubmittedWorkDone(WGPUQueue queue, uint64_t signalValue, WGPUQueueWorkDoneCallback callback, void * userdata); - // WGPU_EXPORT void wgpuQueueSubmit(WGPUQueue queue, uint32_t commandCount, WGPUCommandBuffer const * commands); + submit: fn (ptr: *anyopaque, command_count: u32, commands: *const CommandBuffer) void, // WGPU_EXPORT void wgpuQueueWriteBuffer(WGPUQueue queue, WGPUBuffer buffer, uint64_t bufferOffset, void const * data, size_t size); // WGPU_EXPORT void wgpuQueueWriteTexture(WGPUQueue queue, WGPUImageCopyTexture const * destination, void const * data, size_t dataSize, WGPUTextureDataLayout const * dataLayout, WGPUExtent3D const * writeSize); }; @@ -23,6 +25,10 @@ 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.ptr, command_count, commands); +} + // typedef void (*WGPUQueueWorkDoneCallback)(WGPUQueueWorkDoneStatus status, void * userdata); // typedef enum WGPUQueueWorkDoneStatus { @@ -37,4 +43,5 @@ test "syntax" { _ = VTable; _ = reference; _ = release; -} \ No newline at end of file + _ = submit; +} diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 89185de7..ab3c0944 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -32,6 +32,7 @@ pub const Device = @import("Device.zig"); pub const Surface = @import("Surface.zig"); pub const Limits = @import("Limits.zig"); pub const Queue = @import("Queue.zig"); +pub const CommandBuffer = @import("CommandBuffer.zig"); pub const FeatureName = @import("feature_name.zig").FeatureName; @@ -44,6 +45,7 @@ test "syntax" { _ = Surface; _ = Limits; _ = Queue; + _ = CommandBuffer; _ = FeatureName; }