gpu: add CommandBuffer, Queue.submit
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
ad6cfbb0c9
commit
bf93ae0f81
4 changed files with 46 additions and 2 deletions
25
gpu/src/CommandBuffer.zig
Normal file
25
gpu/src/CommandBuffer.zig
Normal 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;
|
||||
}
|
||||
|
|
@ -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" {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
_ = submit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue