From 2b0fa0bb7465492d3c06541076d3570251bd69bd Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Tue, 29 Sep 2026 13:26:41 +1300 Subject: [PATCH] fix(agc): drop pixel shader exports past the draw's attachments An MRT export to a slot past the draw's color attachments (outside CB_TARGET_MASK & CB_SHADER_MASK, e.g. MRT1 with only slot 0 enabled) is dropped by the color backend. Vulkan discards a fragment output without an attachment the same way, but validation rejected the draw ("fragment shader must export float4 colors at locations below the attachment count"). Such outputs are now left out of the written locations, and only the exports that reach an attachment must be float4. --- .../Graphics/src/ShaderValidation.cpp | 3 ++- .../libs/prx/libSceAgcDriver/tests/Graphics.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp index 08f549522..6d53bc06c 100644 --- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp +++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp @@ -515,7 +515,8 @@ std::set ValidateShaders(std::span shaders, const auto attachments = std::max(state.colors.size(), 1u); std::set locations; for (const auto& [location, signature] : previous.outputs) { - Require(location < attachments && signature == "vertex:f32x4", "fragment shader must export float4 colors at locations below the attachment count"); + if (location >= attachments) continue; + Require(signature == "vertex:f32x4", "fragment shader must export float4 colors to its attachments"); locations.insert(location); } return locations; diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index dacf921c2..aa028756f 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -771,6 +772,7 @@ struct ModuleShape { std::uint32_t perVertexLength = 3; bool parameterOutput = false; bool rectParameters = false; + bool secondTarget = false; }; void emit(std::vector& out, spv::Op op, std::initializer_list operands) { @@ -809,6 +811,12 @@ std::vector makeModule(const ModuleShape& shape) { emit(annotations, spv::OpDecorate, {parameter, spv::DecorationLocation, 0}); extraInterface.push_back(parameter); } + if (shape.secondTarget) { + const auto target = id(); + emit(declarations, spv::OpVariable, {outputPointer, target, spv::StorageClassOutput}); + emit(annotations, spv::OpDecorate, {target, spv::DecorationLocation, 1}); + extraInterface.push_back(target); + } if (shape.rectParameters) { const auto pointer = id(); emit(declarations, spv::OpTypePointer, {pointer, spv::StorageClassInput, vectorType}); @@ -1003,6 +1011,15 @@ void validationTests() { pixel.spirv = makeModule({.fragment = true}); expectFailure([&] { AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, true); }, "requires a fragment shader"); } + { + ShaderRecompiler::RecompileResult vertex; + vertex.spirv = makeModule({}); + ShaderRecompiler::RecompileResult pixel; + pixel.spirv = makeModule({.fragment = true, .secondTarget = true}); + const std::array shaders{{{ShaderRecompiler::ShaderStage::Vertex, &vertex, 0}, {ShaderRecompiler::ShaderStage::Fragment, &pixel, 0}}}; + const VkPhysicalDeviceSubgroupProperties subgroup{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES}; + Require(state.colors.empty() && AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false) == std::set{0u}, "an export past the attachments was not dropped"); + } { ShaderRecompiler::RecompileResult vertex; vertex.spirv = makeModule({.vertexInput = true});