improving draw line
Test / build_and_test (push) Successful in 30s
Build / build (push) Successful in 1m3s

This commit is contained in:
2026-05-30 13:10:34 +02:00
parent 13d53abbdf
commit 19c8d84e05
6 changed files with 177 additions and 66 deletions
+42
View File
@@ -4,10 +4,12 @@ const base = @import("base");
const zm = base.zm;
const spv = @import("spv");
const blitter = @import("../blitter.zig");
const Renderer = @import("../Renderer.zig");
const VkError = base.VkError;
const F32x4 = zm.F32x4;
const U32x4 = @Vector(4, u32);
pub const RenderTargetAccess = struct {
mutex: std.Io.Mutex,
@@ -98,3 +100,43 @@ pub fn interpolateLineOutputs(
inline fn interpolateF32x4(value0: F32x4, value1: F32x4, value2: F32x4, b0: f32, b1: f32, b2: f32) F32x4 {
return (value0 * zm.f32x4s(b0)) + (value1 * zm.f32x4s(b1)) + (value2 * zm.f32x4s(b2));
}
pub fn writeToTargets(
outputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS][@sizeOf(F32x4)]u8,
draw_call: *Renderer.DrawCall,
color_attachment_access: *const RenderTargetAccess,
depth_attachment_access: ?*RenderTargetAccess,
x: usize,
y: usize,
z: f32,
) VkError!void {
const io = draw_call.renderer.device.interface.io();
const color_offset = @as(usize, @intCast(x)) * color_attachment_access.texel_size + @as(usize, @intCast(y)) * color_attachment_access.row_pitch;
// After work depth test to avoid overwritten depth pixels during fragment invocations
if (depth_attachment_access) |depth| {
const depth_offset = @as(usize, @intCast(x)) * depth.texel_size + @as(usize, @intCast(y)) * depth.row_pitch;
depth.mutex.lock(io) catch return VkError.DeviceLost;
defer depth.mutex.unlock(io);
const depth_value = blitter.readFloat4(depth.base[depth_offset..], depth.format);
if (z >= depth_value[0])
return;
blitter.writeFloat4(zm.f32x4s(z), depth.base[depth_offset..], depth.format);
// Doubled line to stay inside the critical section
if (base.format.isUnnormalizedInteger(color_attachment_access.format)) {
blitter.writeInt4(std.mem.bytesToValue(U32x4, &outputs[0]), color_attachment_access.base[color_offset..], color_attachment_access.format);
} else {
blitter.writeFloat4(std.mem.bytesToValue(F32x4, &outputs[0]), color_attachment_access.base[color_offset..], color_attachment_access.format);
}
} else {
if (base.format.isUnnormalizedInteger(color_attachment_access.format)) {
blitter.writeInt4(std.mem.bytesToValue(U32x4, &outputs[0]), color_attachment_access.base[color_offset..], color_attachment_access.format);
} else {
blitter.writeFloat4(std.mem.bytesToValue(F32x4, &outputs[0]), color_attachment_access.base[color_offset..], color_attachment_access.format);
}
}
}