improving fragment outputs management
This commit is contained in:
@@ -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),
|
||||
|
||||
.r32g32b32a32_sfloat => c = std.mem.bytesToValue(F32x4, map),
|
||||
|
||||
.r32g32b32a32_uint => c = @floatFromInt(std.mem.bytesToValue(U32x4, map)),
|
||||
|
||||
.s8_uint => c[0] = @floatFromInt(map[0]),
|
||||
|
||||
.b8g8r8a8_srgb,
|
||||
|
||||
@@ -18,13 +18,13 @@ pub fn shaderInvocation(
|
||||
batch_id: usize,
|
||||
position: zm.F32x4,
|
||||
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();
|
||||
|
||||
_ = 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 mutex = &runtime.mutex;
|
||||
const rt = &runtime.rt;
|
||||
@@ -53,10 +53,11 @@ pub fn shaderInvocation(
|
||||
else => return err,
|
||||
};
|
||||
|
||||
var color = zm.f32x4s(0.0);
|
||||
try rt.readOutput(std.mem.asBytes(&color), output_result);
|
||||
var outputs: [spv.SPIRV_MAX_OUTPUT_LOCATIONS][@sizeOf(zm.F32x4)]u8 = undefined;
|
||||
|
||||
try rt.readOutput(std.mem.asBytes(&outputs), output_result);
|
||||
|
||||
try rt.flushDescriptorSets(allocator);
|
||||
|
||||
return std.math.clamp(color, zm.f32x4s(0.0), zm.f32x4s(1.0));
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@@ -157,19 +157,22 @@ inline fn run(data: RunData) !void {
|
||||
return;
|
||||
};
|
||||
|
||||
try render_target.writeFloat4(
|
||||
.{
|
||||
.x = pixel_x,
|
||||
.y = pixel_y,
|
||||
.z = 0, // FIXME
|
||||
},
|
||||
.{
|
||||
.aspect_mask = render_target_view.subresource_range.aspect_mask,
|
||||
.mip_level = render_target_view.subresource_range.base_mip_level,
|
||||
.array_layer = render_target_view.subresource_range.base_array_layer,
|
||||
},
|
||||
render_target_view.format,
|
||||
pixel,
|
||||
);
|
||||
_ = pixel;
|
||||
_ = render_target;
|
||||
|
||||
//try render_target.writeFloat4(
|
||||
// .{
|
||||
// .x = pixel_x,
|
||||
// .y = pixel_y,
|
||||
// .z = 0, // FIXME
|
||||
// },
|
||||
// .{
|
||||
// .aspect_mask = render_target_view.subresource_range.aspect_mask,
|
||||
// .mip_level = render_target_view.subresource_range.base_mip_level,
|
||||
// .array_layer = render_target_view.subresource_range.base_array_layer,
|
||||
// },
|
||||
// render_target_view.format,
|
||||
// pixel,
|
||||
//);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ inline fn run(data: RunData) !void {
|
||||
continue;
|
||||
}
|
||||
|
||||
const pixel = fragment.shaderInvocation(
|
||||
const outputs = fragment.shaderInvocation(
|
||||
data.allocator,
|
||||
data.draw_call,
|
||||
data.batch_id,
|
||||
@@ -175,7 +175,6 @@ inline fn run(data: RunData) !void {
|
||||
std.debug.dumpErrorReturnTrace(trace);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -192,9 +191,17 @@ inline fn run(data: RunData) !void {
|
||||
if (z >= depth_value[0])
|
||||
continue;
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user