Give NVN2 compute programs the local memory their control section asks for, and put spills after it.

An NVN2 compute program's control section gives its local memory in bytes a thread at +0x68, beside the shared memory
size at +0x64 that the job already carried. Without it the translator declared its default of 0x1000 bytes: one of the
game's compute programs needs 4,752 bytes a thread, and its translation declared a 1,024-word local array that it
indexed up to word 1,187, outside the array. The job now carries "local_mem" from +0x68, and the lowering starts a
compute program's spill area after its own local memory (at least 0x1000 bytes) instead of always at 0x1000, where a
larger program's own memory would have overlapped it.

Checked: that program's translation now declares 1,188 words (indices up to 1,187) and passes spirv-val; two programs
of 3,456 bytes a thread translate as before. All 266 compute programs whose stored input id starts with 0 in an
installed shader cache translate and pass spirv-val (vulkan1.3), and tools/xlate_smoke.py passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 17:09:43 -05:00
parent b5c9a9b38e
commit d02220f578
3 changed files with 18 additions and 5 deletions

View File

@@ -199,8 +199,13 @@ static class SwshXlate
}
else
{
code = AmpereLowering.Lower(code, size, (string)job["stage"] != "cs", out int local, table);
// A compute program's own local memory: "local_mem" from its control section, at least the
// translator's default of 0x1000 bytes; the lowering's spill area goes after it.
bool cs = (string)job["stage"] == "cs";
int own = cs ? (Math.Max(job["local_mem"] is JsonNode lm ? (int)lm : 0, 0x1000) + 15) & ~15 : 0;
code = AmpereLowering.Lower(code, size, !cs, out int local, table, null, own);
if (local != 0) job["local_mem"] = local;
else if (cs) job["local_mem"] = own;
}
if (job["lowered_out"] is JsonNode lo) File.WriteAllBytes((string)lo, code);
}