shader: initialize perspective sample barycentrics at SampleId

This commit is contained in:
Claxten
2026-10-07 18:22:36 +04:00
committed by nmzik
parent fbf6ae400c
commit 3ba6ebae81
8 changed files with 99 additions and 6 deletions
+43
View File
@@ -6539,6 +6539,7 @@ void TestPerspectiveCentroidInputs() {
ShaderMapUserData(regs.ps_regs.data_addr, mapped);
HW::ShaderRegisters sh{};
sh.ps_input_ena = sh.ps_input_addr = inputs;
sh.m_cbShaderMask = 0xf;
const std::array<Prospero::ColorComponentMapping, 8> mappings{};
ShaderPixelInputInfo pixel{};
(void)PrepareProgram(regs, sh, mappings, pixel);
@@ -6570,6 +6571,47 @@ void TestPerspectiveCentroidInputs() {
}
}
void TestPerspectiveSampleInputs() {
for (const uint32_t inputs : {1u, 3u, 5u, 7u}) {
const std::vector<uint32_t> shader = {
EncodeExp0(0x00, 0xf),
EncodeExp1(0, 1, inputs == 1 ? 0 : 2, inputs == 1 ? 1 : 3),
EncodeSopp(0x01)};
HW::PixelShaderInfo regs{};
regs.ps_regs.data_addr = reinterpret_cast<uint64_t>(shader.data());
ShaderMappedData mapped{};
mapped.code_size_bytes = shader.size() * sizeof(uint32_t);
ShaderMapUserData(regs.ps_regs.data_addr, mapped);
HW::ShaderRegisters sh{};
sh.ps_input_ena = sh.ps_input_addr = inputs;
sh.m_cbShaderMask = 0xf;
const std::array<Prospero::ColorComponentMapping, 8> mappings{};
ShaderPixelInputInfo pixel{};
(void)PrepareProgram(regs, sh, mappings, pixel);
Check(pixel.ps_perspective_sample_vgpr == 0 &&
pixel.ps_system_input_base == 2u * std::popcount(inputs),
"perspective sample pair did not occupy the first enabled VGPRs");
const auto key = MakeStageStaticKey(pixel);
pixel.ps_perspective_sample_vgpr = UINT32_MAX;
Check(key != MakeStageStaticKey(pixel), "sample input is missing from shader key");
pixel.ps_perspective_sample_vgpr = 0;
auto options = MakeCompileOptions(ShaderType::Pixel);
options.input_info.pixel = &pixel;
const auto result = RecompileForTest(shader, options);
const auto source = DisassembleSpirvBinary(result.spirv);
Check(SpirvContainsCapability(result.spirv, 52u) &&
SpirvHasDecorationValue(result.spirv, 11u, 18u) &&
source.find("InterpolateAtSample %gl_BaryCoordKHR") != std::string::npos &&
SpirvSourceHasInstructionUsing(source, "OpLoad", "%int %gl_SampleID") &&
SpirvSourceHasInstructionUsing(source, "OpCompositeExtract", " 1") &&
SpirvSourceHasInstructionUsing(source, "OpCompositeExtract", " 2"),
"sample I/J did not evaluate BaryCoordKHR Y/Z at SampleId");
Check(!SpirvHasDecorationValueWithDecoration(result.spirv, 11u, 5286u, 17u),
"sample interpolation changed the shared barycentric input location");
CheckSpirvBinaryValidates(result.spirv);
}
}
void TestPsInputCountRegisterDecode() {
HW::Context context;
// NUM_INTERP is 3 while bit 14 is an independent control flag that must be
@@ -15054,6 +15096,7 @@ int main() {
TestNewShaderRecompilerStageInputInfo();
TestCustomVintrpMovTranslation();
TestPerspectiveCentroidInputs();
TestPerspectiveSampleInputs();
TestGraphicsCreateInterpolantMapping();
TestNewShaderRecompilerPixelPipelineEntry();
TestComputeLdsAllocationIdentity();