gpu: implement CommandEncoder.beginRenderPass
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
12462d42aa
commit
510c7de9f2
4 changed files with 41 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
|||
const RenderPassEncoder = @import("RenderPassEncoder.zig");
|
||||
|
||||
const CommandEncoder = @This();
|
||||
|
||||
/// The type erased pointer to the CommandEncoder implementation
|
||||
|
|
@ -10,7 +12,7 @@ pub const VTable = struct {
|
|||
release: fn (ptr: *anyopaque) void,
|
||||
// TODO:
|
||||
// WGPU_EXPORT WGPUComputePassEncoder wgpuCommandEncoderBeginComputePass(WGPUCommandEncoder commandEncoder, WGPUComputePassDescriptor const * descriptor);
|
||||
// WGPU_EXPORT WGPURenderPassEncoder wgpuCommandEncoderBeginRenderPass(WGPUCommandEncoder commandEncoder, WGPURenderPassDescriptor const * descriptor);
|
||||
beginRenderPass: fn (ptr: *anyopaque, descriptor: *const RenderPassEncoder.Descriptor) RenderPassEncoder,
|
||||
// WGPU_EXPORT void wgpuCommandEncoderClearBuffer(WGPUCommandEncoder commandEncoder, WGPUBuffer buffer, uint64_t offset, uint64_t size);
|
||||
// WGPU_EXPORT void wgpuCommandEncoderCopyBufferToBuffer(WGPUCommandEncoder commandEncoder, WGPUBuffer source, uint64_t sourceOffset, WGPUBuffer destination, uint64_t destinationOffset, uint64_t size);
|
||||
// WGPU_EXPORT void wgpuCommandEncoderCopyBufferToTexture(WGPUCommandEncoder commandEncoder, WGPUImageCopyBuffer const * source, WGPUImageCopyTexture const * destination, WGPUExtent3D const * copySize);
|
||||
|
|
@ -40,6 +42,10 @@ pub inline fn setLabel(enc: CommandEncoder, label: [:0]const u8) void {
|
|||
enc.vtable.setLabel(enc.ptr, label);
|
||||
}
|
||||
|
||||
pub inline fn beginRenderPass(enc: CommandEncoder, descriptor: *const RenderPassEncoder.Descriptor) RenderPassEncoder {
|
||||
return enc.vtable.beginRenderPass(enc.ptr, descriptor);
|
||||
}
|
||||
|
||||
pub const Descriptor = struct {
|
||||
label: ?[*:0]const u8 = null,
|
||||
};
|
||||
|
|
@ -48,5 +54,6 @@ test "syntax" {
|
|||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
_ = beginRenderPass;
|
||||
_ = Descriptor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ test "syntax" {
|
|||
_ = createShaderModule;
|
||||
_ = nativeCreateSwapChain;
|
||||
_ = destroy;
|
||||
_ = createCommandEncoder;
|
||||
_ = createRenderPipeline;
|
||||
_ = Descriptor;
|
||||
_ = LostReason;
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ const device_vtable = Device.VTable{
|
|||
pub fn createCommandEncoder(ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder {
|
||||
const desc: ?*c.WGPUCommandEncoderDescriptor = if (descriptor) |d| &.{
|
||||
.nextInChain = null,
|
||||
.label = d.label,
|
||||
.label = if (d.label) |l| l else "",
|
||||
} else null;
|
||||
return wrapCommandEncoder(c.wgpuDeviceCreateCommandEncoder(@ptrCast(c.WGPUDevice, ptr), desc));
|
||||
}
|
||||
|
|
@ -430,7 +430,7 @@ inline fn convertRenderPipelineDescriptor(
|
|||
|
||||
return c.WGPURenderPipelineDescriptor{
|
||||
.nextInChain = null,
|
||||
.label = d.label,
|
||||
.label = if (d.label) |l| l else null,
|
||||
.layout = if (d.layout) |v| @ptrCast(c.WGPUPipelineLayout, v.ptr) else null,
|
||||
.vertex = c.WGPUVertexState{
|
||||
.nextInChain = null,
|
||||
|
|
@ -996,6 +996,33 @@ const command_encoder_vtable = CommandEncoder.VTable{
|
|||
c.wgpuCommandEncoderSetLabel(@ptrCast(c.WGPUCommandEncoder, ptr), label);
|
||||
}
|
||||
}).setLabel,
|
||||
.beginRenderPass = (struct {
|
||||
pub fn beginRenderPass(ptr: *anyopaque, d: *const RenderPassEncoder.Descriptor) RenderPassEncoder {
|
||||
const desc = c.WGPURenderPassDescriptor{
|
||||
.nextInChain = null,
|
||||
.label = if (d.label) |l| l else null,
|
||||
.colorAttachmentCount = 0, // TODO
|
||||
.colorAttachments = null, // TODO
|
||||
.depthStencilAttachment = &c.WGPURenderPassDepthStencilAttachment{
|
||||
.view = @ptrCast(c.WGPUTextureView, d.depth_stencil_attachment.view.ptr),
|
||||
.depthLoadOp = @enumToInt(d.depth_stencil_attachment.depth_load_op),
|
||||
.depthStoreOp = @enumToInt(d.depth_stencil_attachment.depth_store_op),
|
||||
.clearDepth = d.depth_stencil_attachment.clear_depth,
|
||||
.depthClearValue = d.depth_stencil_attachment.depth_clear_value,
|
||||
.depthReadOnly = d.depth_stencil_attachment.depth_read_only,
|
||||
.stencilLoadOp = @enumToInt(d.depth_stencil_attachment.stencil_load_op),
|
||||
.stencilStoreOp = @enumToInt(d.depth_stencil_attachment.stencil_store_op),
|
||||
.clearStencil = d.depth_stencil_attachment.clear_stencil,
|
||||
.stencilClearValue = d.depth_stencil_attachment.stencil_clear_value,
|
||||
.stencilReadOnly = d.depth_stencil_attachment.stencil_read_only,
|
||||
},
|
||||
.occlusionQuerySet = @ptrCast(c.WGPUQuerySet, d.occlusion_query_set.ptr),
|
||||
.timestampWriteCount = 0, // TODO
|
||||
.timestampWrites = null, // TODO
|
||||
};
|
||||
return wrapRenderPassEncoder(c.wgpuCommandEncoderBeginRenderPass(@ptrCast(c.WGPUCommandEncoder, ptr), &desc));
|
||||
}
|
||||
}).beginRenderPass,
|
||||
};
|
||||
|
||||
fn wrapComputePassEncoder(enc: c.WGPUComputePassEncoder) ComputePassEncoder {
|
||||
|
|
|
|||
|
|
@ -71,5 +71,8 @@ test "syntax" {
|
|||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
_ = configure;
|
||||
_ = getCurrentTextureView;
|
||||
_ = present;
|
||||
_ = Descriptor;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue