gpu: add CommandBuffer, Queue.submit

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-08 00:54:56 -07:00 committed by Stephen Gutekanst
parent ad6cfbb0c9
commit bf93ae0f81
4 changed files with 46 additions and 2 deletions

25
gpu/src/CommandBuffer.zig Normal file
View file

@ -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;
}

View file

@ -17,6 +17,7 @@ const Device = @import("Device.zig");
const Surface = @import("Surface.zig"); const Surface = @import("Surface.zig");
const Limits = @import("Limits.zig"); const Limits = @import("Limits.zig");
const Queue = @import("Queue.zig"); const Queue = @import("Queue.zig");
const CommandBuffer = @import("CommandBuffer.zig");
const NativeInstance = @This(); const NativeInstance = @This();
@ -352,6 +353,15 @@ const queue_vtable = Queue.VTable{
c.wgpuQueueRelease(@ptrCast(c.WGPUQueue, ptr)); c.wgpuQueueRelease(@ptrCast(c.WGPUQueue, ptr));
} }
}).release, }).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" { test "syntax" {

View file

@ -1,3 +1,5 @@
const CommandBuffer = @import("CommandBuffer.zig");
const Queue = @This(); const Queue = @This();
/// The type erased pointer to the Queue implementation /// The type erased pointer to the Queue implementation
@ -10,7 +12,7 @@ pub const VTable = struct {
release: fn (ptr: *anyopaque) void, 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 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 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 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); // 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); 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 void (*WGPUQueueWorkDoneCallback)(WGPUQueueWorkDoneStatus status, void * userdata);
// typedef enum WGPUQueueWorkDoneStatus { // typedef enum WGPUQueueWorkDoneStatus {
@ -37,4 +43,5 @@ test "syntax" {
_ = VTable; _ = VTable;
_ = reference; _ = reference;
_ = release; _ = release;
} _ = submit;
}

View file

@ -32,6 +32,7 @@ pub const Device = @import("Device.zig");
pub const Surface = @import("Surface.zig"); pub const Surface = @import("Surface.zig");
pub const Limits = @import("Limits.zig"); pub const Limits = @import("Limits.zig");
pub const Queue = @import("Queue.zig"); pub const Queue = @import("Queue.zig");
pub const CommandBuffer = @import("CommandBuffer.zig");
pub const FeatureName = @import("feature_name.zig").FeatureName; pub const FeatureName = @import("feature_name.zig").FeatureName;
@ -44,6 +45,7 @@ test "syntax" {
_ = Surface; _ = Surface;
_ = Limits; _ = Limits;
_ = Queue; _ = Queue;
_ = CommandBuffer;
_ = FeatureName; _ = FeatureName;
} }