gpu: implement RenderPassColorAttachment
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
510c7de9f2
commit
f5a5c7eaa7
3 changed files with 61 additions and 20 deletions
|
|
@ -998,25 +998,66 @@ const command_encoder_vtable = CommandEncoder.VTable{
|
||||||
}).setLabel,
|
}).setLabel,
|
||||||
.beginRenderPass = (struct {
|
.beginRenderPass = (struct {
|
||||||
pub fn beginRenderPass(ptr: *anyopaque, d: *const RenderPassEncoder.Descriptor) RenderPassEncoder {
|
pub fn beginRenderPass(ptr: *anyopaque, d: *const RenderPassEncoder.Descriptor) RenderPassEncoder {
|
||||||
|
var few_color_attachments: [8]c.WGPURenderPassColorAttachment = undefined;
|
||||||
|
const color_attachments = if (d.color_attachments.len <= 8) blk: {
|
||||||
|
for (d.color_attachments) |v, i| {
|
||||||
|
few_color_attachments[i] = c.WGPURenderPassColorAttachment{
|
||||||
|
.view = @ptrCast(c.WGPUTextureView, v.view.ptr),
|
||||||
|
.resolveTarget = if (v.resolve_target) |t| @ptrCast(c.WGPUTextureView, t.ptr) else null,
|
||||||
|
.loadOp = @enumToInt(v.load_op),
|
||||||
|
.storeOp = @enumToInt(v.load_op),
|
||||||
|
.clearValue = @bitCast(c.WGPUColor, v.clear_value),
|
||||||
|
// deprecated:
|
||||||
|
.clearColor = c.WGPUColor{
|
||||||
|
.r = std.math.nan(f32),
|
||||||
|
.g = std.math.nan(f32),
|
||||||
|
.b = std.math.nan(f32),
|
||||||
|
.a = std.math.nan(f32),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break :blk few_color_attachments[0..d.color_attachments.len];
|
||||||
|
} else blk: {
|
||||||
|
const mem = std.heap.page_allocator.alloc(c.WGPURenderPassColorAttachment, d.color_attachments.len) catch unreachable;
|
||||||
|
for (d.color_attachments) |v, i| {
|
||||||
|
mem[i] = c.WGPURenderPassColorAttachment{
|
||||||
|
.view = @ptrCast(c.WGPUTextureView, v.view.ptr),
|
||||||
|
.resolveTarget = if (v.resolve_target) |t| @ptrCast(c.WGPUTextureView, t.ptr) else null,
|
||||||
|
.loadOp = @enumToInt(v.load_op),
|
||||||
|
.storeOp = @enumToInt(v.load_op),
|
||||||
|
.clearValue = @bitCast(c.WGPUColor, v.clear_value),
|
||||||
|
// deprecated:
|
||||||
|
.clearColor = c.WGPUColor{
|
||||||
|
.r = std.math.nan(f32),
|
||||||
|
.g = std.math.nan(f32),
|
||||||
|
.b = std.math.nan(f32),
|
||||||
|
.a = std.math.nan(f32),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break :blk mem;
|
||||||
|
};
|
||||||
|
defer if (d.color_attachments.len > 8) std.heap.page_allocator.free(color_attachments);
|
||||||
|
|
||||||
const desc = c.WGPURenderPassDescriptor{
|
const desc = c.WGPURenderPassDescriptor{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.label = if (d.label) |l| l else null,
|
.label = if (d.label) |l| l else null,
|
||||||
.colorAttachmentCount = 0, // TODO
|
.colorAttachmentCount = @intCast(u32, color_attachments.len),
|
||||||
.colorAttachments = null, // TODO
|
.colorAttachments = &color_attachments[0],
|
||||||
.depthStencilAttachment = &c.WGPURenderPassDepthStencilAttachment{
|
.depthStencilAttachment = if (d.depth_stencil_attachment) |v| &c.WGPURenderPassDepthStencilAttachment{
|
||||||
.view = @ptrCast(c.WGPUTextureView, d.depth_stencil_attachment.view.ptr),
|
.view = @ptrCast(c.WGPUTextureView, v.view.ptr),
|
||||||
.depthLoadOp = @enumToInt(d.depth_stencil_attachment.depth_load_op),
|
.depthLoadOp = @enumToInt(v.depth_load_op),
|
||||||
.depthStoreOp = @enumToInt(d.depth_stencil_attachment.depth_store_op),
|
.depthStoreOp = @enumToInt(v.depth_store_op),
|
||||||
.clearDepth = d.depth_stencil_attachment.clear_depth,
|
.clearDepth = v.clear_depth,
|
||||||
.depthClearValue = d.depth_stencil_attachment.depth_clear_value,
|
.depthClearValue = v.depth_clear_value,
|
||||||
.depthReadOnly = d.depth_stencil_attachment.depth_read_only,
|
.depthReadOnly = v.depth_read_only,
|
||||||
.stencilLoadOp = @enumToInt(d.depth_stencil_attachment.stencil_load_op),
|
.stencilLoadOp = @enumToInt(v.stencil_load_op),
|
||||||
.stencilStoreOp = @enumToInt(d.depth_stencil_attachment.stencil_store_op),
|
.stencilStoreOp = @enumToInt(v.stencil_store_op),
|
||||||
.clearStencil = d.depth_stencil_attachment.clear_stencil,
|
.clearStencil = v.clear_stencil,
|
||||||
.stencilClearValue = d.depth_stencil_attachment.stencil_clear_value,
|
.stencilClearValue = v.stencil_clear_value,
|
||||||
.stencilReadOnly = d.depth_stencil_attachment.stencil_read_only,
|
.stencilReadOnly = v.stencil_read_only,
|
||||||
},
|
} else null,
|
||||||
.occlusionQuerySet = @ptrCast(c.WGPUQuerySet, d.occlusion_query_set.ptr),
|
.occlusionQuerySet = if (d.occlusion_query_set) |v| @ptrCast(c.WGPUQuerySet, v.ptr) else null,
|
||||||
.timestampWriteCount = 0, // TODO
|
.timestampWriteCount = 0, // TODO
|
||||||
.timestampWrites = null, // TODO
|
.timestampWrites = null, // TODO
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,9 @@ pub inline fn setLabel(pass: RenderPassEncoder, label: [:0]const u8) void {
|
||||||
pub const Descriptor = struct {
|
pub const Descriptor = struct {
|
||||||
label: ?[*:0]const u8 = null,
|
label: ?[*:0]const u8 = null,
|
||||||
color_attachments: []const RenderPassColorAttachment,
|
color_attachments: []const RenderPassColorAttachment,
|
||||||
depth_stencil_attachment: *const RenderPassDepthStencilAttachment,
|
depth_stencil_attachment: ?*const RenderPassDepthStencilAttachment,
|
||||||
occlusion_query_set: QuerySet,
|
occlusion_query_set: ?QuerySet = null,
|
||||||
timestamp_writes: []RenderPassTimestampWrite,
|
timestamp_writes: ?[]RenderPassTimestampWrite = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
test "syntax" {
|
test "syntax" {
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ pub const RenderPassDepthStencilAttachment = struct {
|
||||||
|
|
||||||
pub const RenderPassColorAttachment = struct {
|
pub const RenderPassColorAttachment = struct {
|
||||||
view: TextureView,
|
view: TextureView,
|
||||||
resolve_target: TextureView,
|
resolve_target: ?TextureView,
|
||||||
load_op: LoadOp,
|
load_op: LoadOp,
|
||||||
store_op: StoreOp,
|
store_op: StoreOp,
|
||||||
clear_value: Color,
|
clear_value: Color,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue