adding base depth buffers
This commit is contained in:
@@ -59,12 +59,25 @@ pub const DrawCall = struct {
|
||||
viewport: vk.Viewport,
|
||||
scissor: vk.Rect2D,
|
||||
|
||||
color_attachments: []*base.ImageView,
|
||||
depth_attachment: ?*base.ImageView,
|
||||
|
||||
render_pass: *SoftRenderPass,
|
||||
framebuffer: *SoftFramebuffer,
|
||||
|
||||
fn init(allocator: std.mem.Allocator, vertex_count: usize, instance_count: usize, renderer: *Self) VkError!@This() {
|
||||
const framebuffer = renderer.framebuffer orelse return VkError.InvalidHandleDrv;
|
||||
const render_pass = renderer.render_pass orelse return VkError.InvalidHandleDrv;
|
||||
|
||||
const self: @This() = .{
|
||||
.vertices = allocator.alloc(Vertex, vertex_count * instance_count) catch return VkError.OutOfDeviceMemory,
|
||||
.renderer = renderer,
|
||||
.viewport = undefined,
|
||||
.scissor = undefined,
|
||||
.color_attachments = framebuffer.interface.attachments[0..],
|
||||
.depth_attachment = if (render_pass.interface.subpasses[0].depth_stencil_attachments) |desc| framebuffer.interface.attachments[desc.attachment] else null,
|
||||
.render_pass = render_pass,
|
||||
.framebuffer = framebuffer,
|
||||
};
|
||||
|
||||
for (self.vertices) |*vertex| {
|
||||
|
||||
@@ -577,7 +577,9 @@ pub fn readFloat4(map: []const u8, src_format: vk.Format) F32x4 {
|
||||
.r32_uint,
|
||||
=> c[0] = @floatFromInt(std.mem.bytesToValue(u32, map)),
|
||||
|
||||
.r32_sfloat => c[0] = std.mem.bytesToValue(f32, map),
|
||||
.d32_sfloat,
|
||||
.r32_sfloat,
|
||||
=> c[0] = std.mem.bytesToValue(f32, map),
|
||||
|
||||
.r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map),
|
||||
|
||||
|
||||
@@ -119,7 +119,8 @@ fn runWrapper(data: RunData) void {
|
||||
}
|
||||
|
||||
inline fn run(data: RunData) !void {
|
||||
const render_target_view: *base.ImageView = (data.draw_call.renderer.framebuffer orelse return).interface.attachments[0];
|
||||
const color_attachment = if (data.draw_call.render_pass.interface.subpasses[0].color_attachments) |attachments| attachments[0].attachment else return VkError.InvalidAttachmentDrv;
|
||||
const render_target_view: *base.ImageView = data.draw_call.color_attachments[color_attachment];
|
||||
const render_target: *SoftImage = @alignCast(@fieldParentPtr("interface", render_target_view.image));
|
||||
|
||||
var step = data.start_step;
|
||||
|
||||
@@ -108,9 +108,13 @@ fn runWrapper(data: RunData) void {
|
||||
}
|
||||
|
||||
inline fn run(data: RunData) !void {
|
||||
const render_target_view: *base.ImageView = (data.draw_call.renderer.framebuffer orelse return).interface.attachments[0];
|
||||
const color_attachment = if (data.draw_call.render_pass.interface.subpasses[0].color_attachments) |attachments| attachments[0].attachment else return VkError.InvalidAttachmentDrv;
|
||||
const render_target_view: *base.ImageView = data.draw_call.color_attachments[color_attachment];
|
||||
const render_target: *SoftImage = @alignCast(@fieldParentPtr("interface", render_target_view.image));
|
||||
|
||||
const depth_attachment_view: ?*base.ImageView = if (data.draw_call.depth_attachment) |view| view else null;
|
||||
const depth_attachment: ?*SoftImage = if (depth_attachment_view) |view| @alignCast(@fieldParentPtr("interface", view.image)) else null;
|
||||
|
||||
var y = data.min_y;
|
||||
while (y <= data.max_y) : (y += 1) {
|
||||
var x = data.min_x;
|
||||
@@ -138,6 +142,40 @@ inline fn run(data: RunData) !void {
|
||||
const b2 = w2 / data.area;
|
||||
const z = (b0 * data.v0.position[2]) + (b1 * data.v1.position[2]) + (b2 * data.v2.position[2]);
|
||||
|
||||
if (depth_attachment) |depth| {
|
||||
const depth_value = try depth.readFloat4(
|
||||
.{
|
||||
.x = x,
|
||||
.y = y,
|
||||
.z = 0,
|
||||
},
|
||||
.{
|
||||
.aspect_mask = depth_attachment_view.?.subresource_range.aspect_mask,
|
||||
.mip_level = depth_attachment_view.?.subresource_range.base_mip_level,
|
||||
.array_layer = depth_attachment_view.?.subresource_range.base_array_layer,
|
||||
},
|
||||
depth_attachment_view.?.format,
|
||||
);
|
||||
|
||||
if (z >= depth_value[0])
|
||||
continue;
|
||||
|
||||
try depth.writeFloat4(
|
||||
.{
|
||||
.x = x,
|
||||
.y = y,
|
||||
.z = 0,
|
||||
},
|
||||
.{
|
||||
.aspect_mask = depth_attachment_view.?.subresource_range.aspect_mask,
|
||||
.mip_level = depth_attachment_view.?.subresource_range.base_mip_level,
|
||||
.array_layer = depth_attachment_view.?.subresource_range.base_array_layer,
|
||||
},
|
||||
depth_attachment_view.?.format,
|
||||
zm.f32x4s(z),
|
||||
);
|
||||
}
|
||||
|
||||
const pixel = fragment.shaderInvocation(
|
||||
data.allocator,
|
||||
data.draw_call,
|
||||
@@ -156,7 +194,7 @@ inline fn run(data: RunData) !void {
|
||||
.{
|
||||
.x = x,
|
||||
.y = y,
|
||||
.z = 0, // FIXME
|
||||
.z = 0,
|
||||
},
|
||||
.{
|
||||
.aspect_mask = render_target_view.subresource_range.aspect_mask,
|
||||
|
||||
Reference in New Issue
Block a user