mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(agc): accept a fragment SampleMask output
Pixel shaders that export a coverage mask write gl_SampleMask, an int[1] (or uint[1]) output. The validator rejected array interface types; it now spells them elem[N] and accepts SampleMask as int[1] or uint[1]. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,11 @@ struct Module {
|
||||
if (op == spv::OpTypeInt && type.size() == 4 && type[2] == 32 && type[3] <= 1) return type[3] != 0 ? "i32" : "u32";
|
||||
if (op == spv::OpTypeBool && type.size() == 2) return "bool";
|
||||
if (op == spv::OpTypeVector && type.size() == 4 && type[3] >= 2 && type[3] <= 4) return Signature(type[2], depth + 1) + "x" + std::to_string(type[3]);
|
||||
if (op == spv::OpTypeArray && type.size() == 4) {
|
||||
const auto length = constants.find(type[3]);
|
||||
Require(length != constants.end(), "SPIR-V interface array length is not a constant");
|
||||
return Signature(type[2], depth + 1) + "[" + std::to_string(length->second) + "]";
|
||||
}
|
||||
throw std::runtime_error("AGC graphics: unsupported SPIR-V interface type");
|
||||
}
|
||||
|
||||
@@ -118,7 +123,7 @@ struct Module {
|
||||
Require(value == spv::BuiltInPosition && signature == "f32x4" && !position, "unsupported or duplicate vertex built-in output");
|
||||
position = true;
|
||||
} else {
|
||||
Require((storage == spv::StorageClassInput && ((value == spv::BuiltInFragCoord && signature == "f32x4") || ((value == spv::BuiltInFrontFacing || value == spv::BuiltInHelperInvocation) && signature == "bool") || ((value == spv::BuiltInSampleId || value == spv::BuiltInLayer) && signature == "i32"))) || (storage == spv::StorageClassOutput && value == spv::BuiltInFragDepth && signature == "f32"), "unsupported fragment built-in");
|
||||
Require((storage == spv::StorageClassInput && ((value == spv::BuiltInFragCoord && signature == "f32x4") || ((value == spv::BuiltInFrontFacing || value == spv::BuiltInHelperInvocation) && signature == "bool") || ((value == spv::BuiltInSampleId || value == spv::BuiltInLayer) && signature == "i32"))) || (storage == spv::StorageClassOutput && ((value == spv::BuiltInFragDepth && signature == "f32") || (value == spv::BuiltInSampleMask && (signature == "i32[1]" || signature == "u32[1]")))), "unsupported fragment built-in");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1387,6 +1387,7 @@ struct ModuleShape {
|
||||
bool sampleId = false;
|
||||
bool layer = false;
|
||||
bool fragDepth = false;
|
||||
std::uint32_t sampleMaskLength = 0;
|
||||
};
|
||||
|
||||
void emit(std::vector<std::uint32_t>& out, spv::Op op, std::initializer_list<std::uint32_t> operands) {
|
||||
@@ -1474,6 +1475,18 @@ std::vector<std::uint32_t> makeModule(const ModuleShape& shape) {
|
||||
emit(annotations, spv::OpDecorate, {variable, spv::DecorationBuiltIn, spv::BuiltInFragDepth});
|
||||
extraInterface.push_back(variable);
|
||||
}
|
||||
if (shape.sampleMaskLength != 0) {
|
||||
const auto length = id();
|
||||
const auto array = id();
|
||||
const auto pointer = id();
|
||||
const auto variable = id();
|
||||
emit(declarations, spv::OpConstant, {uintType, length, shape.sampleMaskLength});
|
||||
emit(declarations, spv::OpTypeArray, {array, uintType, length});
|
||||
emit(declarations, spv::OpTypePointer, {pointer, spv::StorageClassOutput, array});
|
||||
emit(declarations, spv::OpVariable, {pointer, variable, spv::StorageClassOutput});
|
||||
emit(annotations, spv::OpDecorate, {variable, spv::DecorationBuiltIn, spv::BuiltInSampleMask});
|
||||
extraInterface.push_back(variable);
|
||||
}
|
||||
if (shape.perVertex) {
|
||||
const auto length = id();
|
||||
const auto array = id();
|
||||
@@ -1810,8 +1823,10 @@ void validationTests() {
|
||||
AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, true);
|
||||
expectFailure([&] { AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false); }, "fragmentShaderBarycentric");
|
||||
}
|
||||
pixel.spirv = makeModule({.fragment = true, .sampleId = true, .layer = true, .fragDepth = true});
|
||||
pixel.spirv = makeModule({.fragment = true, .sampleId = true, .layer = true, .fragDepth = true, .sampleMaskLength = 1});
|
||||
AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false);
|
||||
pixel.spirv = makeModule({.fragment = true, .sampleMaskLength = 2});
|
||||
expectFailure([&] { AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false); }, "unsupported fragment built-in");
|
||||
vertex.spirv = makeModule({.parameterOutput = true, .sampleId = true});
|
||||
expectFailure([&] { AgcDriver::Graphics::ValidateShaders(shaders, state, subgroup, false); }, "unsupported device capability 35");
|
||||
vertex.spirv = makeModule({.parameterOutput = true});
|
||||
|
||||
Reference in New Issue
Block a user