shader: initialize NGG vertex count from active native invocations

This commit is contained in:
nmzik
2026-10-11 00:52:21 +02:00
parent 7e4e142aae
commit cf77fb4353
2 changed files with 66 additions and 5 deletions
+54
View File
@@ -16439,6 +16439,60 @@ public:
wave_ids[0] != wave_ids[1] && wave_keys[0] != wave_keys[1],
"wave32 and wave64 pixel programs shared a cache key");
static const auto waterfall_vertex = [&] {
std::vector<u32> code;
AppendVMovU32(&code, 9, 0);
// d3e1ae284c4dea3b reconstructs EXEC twice from packed NGG s3.
code.insert(code.end(), {0xbefe04c1u, 0x906a8803u, 0x81ea6a80u,
0x90fe6ac1u, 0x81ea0380u, 0x90fe6ac1u,
EncodeSop1(0x04, 10, 126)});
const auto loop = code.size();
code.push_back(EncodeSop1(0x14, 4, 10));
AppendVop3(&code, 0x360, 6, Vgpr(5), 4);
code.push_back(EncodeVopc(0xc2, 6, 5));
code.push_back(EncodeSop1(0x24, 18, 106));
AppendVMovLiteral(&code, 9, 0x3f800000u);
code.push_back(EncodeSop2(0x15, 10, 10, 106));
code.push_back(EncodeSop1(0x04, 126, 18));
code.push_back(EncodeSopp(0x05, static_cast<int16_t>(loop - code.size() - 1u)));
const auto base = code.size();
code.insert(code.end(), native_vertex.begin(), native_vertex.end());
const auto position = std::find(code.begin() + base, code.end(), EncodeExp0(0x0c, 0xf));
// Unprocessed vertices keep W=0, making waterfall progress observable.
*(position + 1) = EncodeExp1(3, 4, 0, 9);
return code;
}();
native_vertex_regs.es_regs.data_addr = reinterpret_cast<uint64_t>(waterfall_vertex.data());
ShaderMapUserData(native_vertex_regs.es_regs.data_addr,
{.type = Prospero::ShaderBinaryType::kGs, .user_data = &native_user_data,
.code_size_bytes = static_cast<u32>(waterfall_vertex.size() * sizeof(u32))});
registers.SetPsInControl(0x8008);
const auto saved_stages = registers.GetShaderStages();
for (const u32 wave : {32u, 64u}) {
registers.SetShaderStages((saved_stages & ~0x00400000u) |
(wave == 32u ? 0x00400000u : 0u));
const auto programs = context.GetPipelineCache().GetGraphicsPrograms(
native_vertex_regs, native_pixel_regs, registers.GetShaderRegisters(),
registers, user_config, export_mapping, true, native_vertex_info, pixel);
vertex_shader = programs.vertex[0];
pixel_shader = programs.pixel;
vertex = native_vertex_info[0];
Require(name, "native NGG waterfall wave",
vertex.stage.program->stage == ShaderType::Vertex &&
vertex.stage.program->wave_size == wave,
"NGG waterfall bypassed the native vertex path or lost its guest wave width");
for (const u32 count : {3u, 6u, 33u}) {
draw(pipeline(true, 2, 2), count);
const auto pixels = read_color();
for (size_t component = 0; component < pixels.size(); ++component)
Require(name, "NGG partial-wave waterfall output",
pixels[component] == (component % 4 == 3 ? 0x3f800000u : 0x3e800000u),
"native vertex waterfall did not terminate with every input vertex processed");
}
}
registers.SetShaderStages(saved_stages);
native_vertex_regs.es_regs.data_addr = vertex_address;
// Reversed RGBA targets must use logical Sa for RGB, with a separate
// zero or unit source factor for separate alpha attenuation or accumulation.
static const auto blend_pixel = [] {