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.
This commit is contained in:
Dean Galvin
2026-09-29 13:26:41 +13:00
parent fe1935ef68
commit 2b0fa0bb74
2 changed files with 19 additions and 1 deletions
@@ -515,7 +515,8 @@ std::set<std::uint32_t> ValidateShaders(std::span<const CompiledShader> shaders,
const auto attachments = std::max<std::size_t>(state.colors.size(), 1u);
std::set<std::uint32_t> 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;
@@ -12,6 +12,7 @@
#include <initializer_list>
#include <iostream>
#include <map>
#include <set>
#include <string_view>
#include <type_traits>
#include <vector>
@@ -771,6 +772,7 @@ struct ModuleShape {
std::uint32_t perVertexLength = 3;
bool parameterOutput = false;
bool rectParameters = false;
bool secondTarget = false;
};
void emit(std::vector<std::uint32_t>& out, spv::Op op, std::initializer_list<std::uint32_t> operands) {
@@ -809,6 +811,12 @@ std::vector<std::uint32_t> 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<AgcDriver::Graphics::CompiledShader, 2> 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<std::uint32_t>{0u}, "an export past the attachments was not dropped");
}
{
ShaderRecompiler::RecompileResult vertex;
vertex.spirv = makeModule({.vertexInput = true});