improving fragment outputs management
Build / build (push) Successful in 2m15s
Test / build_and_test (push) Successful in 1m31s

This commit is contained in:
2026-05-30 01:45:15 +02:00
parent 0ab6581fe9
commit 13d53abbdf
4 changed files with 38 additions and 24 deletions
+3
View File
@@ -673,8 +673,11 @@ pub fn readFloat4(map: []const u8, src_format: vk.Format) F32x4 {
}, },
.r16g16b16a16_sfloat => c = std.mem.bytesToValue(@Vector(4, f16), map), .r16g16b16a16_sfloat => c = std.mem.bytesToValue(@Vector(4, f16), map),
.r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map), .r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map),
.r32g32b32a32_uint => c = @floatFromInt(std.mem.bytesToValue(U32x4, map)),
.s8_uint => c[0] = @floatFromInt(map[0]), .s8_uint => c[0] = @floatFromInt(map[0]),
.b8g8r8a8_srgb, .b8g8r8a8_srgb,
+7 -6
View File
@@ -18,13 +18,13 @@ pub fn shaderInvocation(
batch_id: usize, batch_id: usize,
position: zm.F32x4, position: zm.F32x4,
inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolation, inputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS]VertexInterpolation,
) SpvRuntimeError!zm.F32x4 { ) SpvRuntimeError![spv.SPIRV_MAX_OUTPUT_LOCATIONS][@sizeOf(zm.F32x4)]u8 {
const io = draw_call.renderer.device.interface.io(); const io = draw_call.renderer.device.interface.io();
_ = position; _ = position;
const pipeline = draw_call.renderer.state.pipeline orelse return zm.f32x4s(0.0); const pipeline = draw_call.renderer.state.pipeline orelse return undefined;
const shader = pipeline.stages.getPtrAssertContains(.fragment); const shader = pipeline.stages.getPtr(.fragment) orelse return undefined;
const runtime = &shader.runtimes[batch_id]; const runtime = &shader.runtimes[batch_id];
const mutex = &runtime.mutex; const mutex = &runtime.mutex;
const rt = &runtime.rt; const rt = &runtime.rt;
@@ -53,10 +53,11 @@ pub fn shaderInvocation(
else => return err, else => return err,
}; };
var color = zm.f32x4s(0.0); var outputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS][@sizeOf(zm.F32x4)]u8 = undefined;
try rt.readOutput(std.mem.asBytes(&color), output_result);
try rt.readOutput(std.mem.asBytes(&outputs), output_result);
try rt.flushDescriptorSets(allocator); try rt.flushDescriptorSets(allocator);
return std.math.clamp(color, zm.f32x4s(0.0), zm.f32x4s(1.0)); return outputs;
} }
+17 -14
View File
@@ -157,19 +157,22 @@ inline fn run(data: RunData) !void {
return; return;
}; };
try render_target.writeFloat4( _ = pixel;
.{ _ = render_target;
.x = pixel_x,
.y = pixel_y, //try render_target.writeFloat4(
.z = 0, // FIXME // .{
}, // .x = pixel_x,
.{ // .y = pixel_y,
.aspect_mask = render_target_view.subresource_range.aspect_mask, // .z = 0, // FIXME
.mip_level = render_target_view.subresource_range.base_mip_level, // },
.array_layer = render_target_view.subresource_range.base_array_layer, // .{
}, // .aspect_mask = render_target_view.subresource_range.aspect_mask,
render_target_view.format, // .mip_level = render_target_view.subresource_range.base_mip_level,
pixel, // .array_layer = render_target_view.subresource_range.base_array_layer,
); // },
// render_target_view.format,
// pixel,
//);
} }
} }
+11 -4
View File
@@ -162,7 +162,7 @@ inline fn run(data: RunData) !void {
continue; continue;
} }
const pixel = fragment.shaderInvocation( const outputs = fragment.shaderInvocation(
data.allocator, data.allocator,
data.draw_call, data.draw_call,
data.batch_id, data.batch_id,
@@ -175,7 +175,6 @@ inline fn run(data: RunData) !void {
std.debug.dumpErrorReturnTrace(trace); std.debug.dumpErrorReturnTrace(trace);
} }
} }
return; return;
}; };
@@ -192,9 +191,17 @@ inline fn run(data: RunData) !void {
if (z >= depth_value[0]) if (z >= depth_value[0])
continue; continue;
blitter.writeFloat4(zm.f32x4s(z), depth.base[depth_offset..], depth.format); blitter.writeFloat4(zm.f32x4s(z), depth.base[depth_offset..], depth.format);
blitter.writeFloat4(pixel, data.color_attachment_access.base[color_offset..], data.color_attachment_access.format);
// Doubled line to stay inside the critical section
if (base.format.isUnnormalizedInteger(data.color_attachment_access.format))
blitter.writeInt4(std.mem.bytesToValue(@Vector(4, u32), &outputs[0]), data.color_attachment_access.base[color_offset..], data.color_attachment_access.format)
else
blitter.writeFloat4(std.mem.bytesToValue(@Vector(4, f32), &outputs[0]), data.color_attachment_access.base[color_offset..], data.color_attachment_access.format);
} else { } else {
blitter.writeFloat4(pixel, data.color_attachment_access.base[color_offset..], data.color_attachment_access.format); if (base.format.isUnnormalizedInteger(data.color_attachment_access.format))
blitter.writeInt4(std.mem.bytesToValue(@Vector(4, u32), &outputs[0]), data.color_attachment_access.base[color_offset..], data.color_attachment_access.format)
else
blitter.writeFloat4(std.mem.bytesToValue(@Vector(4, f32), &outputs[0]), data.color_attachment_access.base[color_offset..], data.color_attachment_access.format);
} }
} }
} }