Shaders: a program's constant table starts after its instructions (GBs of NVIDIA video memory) #2143
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2143
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2143/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@desplmfao on GitHub · 2026-11-25 05:58 UTC · original
desplmfao:fix/code-table-after-instructions→main· +49 −7 · 1 files · 2 commits · merged 2026-11-25 21:54 UTCProblem
On NVIDIA under Wine (vkd3d-proton), several GB of video memory went to the driver as soon as pipelines were created, and runs filled the 16 GB of an RTX 5080 while the world loaded. With all of a run's shaders dumped as SPIR-V and compiled natively with
VK_KHR_pipeline_executable_properties, six compute shaders stood out by their local memory per thread:0b341b15…(SPIR-V name)c4c847ce…Each holds one large constant
uint[]array indexed at runtime. That's the program's constant table fromcode_dword. vkd3d-proton turns it into a private array, NVIDIA keeps it in local memory, and the driver reserves local memory for the worst shader times all resident threads. Tables of 5–14 KB stayed out of local memory (0–16 B), so the cut-off seems to be around 16 KB. That's from the driver's statistics, not from a documented limit.Why the tables were that big:
code_dwordbuilt the table from the lowest code offset any load or descriptor names. A load at a computed offset names offset 0, so the table was the whole program: instructions plus constants, up to 64 KiB.Change
The program's constants follow its instructions, and a load at a computed offset reads them, not instruction bytes. So the table now starts where the instructions end, unless a load at a fixed offset reads below that, in which case it starts where it did before. A computed index below the table's start is clamped like one past its end. The start is computed in
code_table_start.Measured
Grand Theft Auto VI, Series X 1.0.2.1:
The run used some other open PRs to get that far on NVIDIA under Wine (#259, #1849, and #177's handle key), but none of them touches this.
Not covered / limits
Tested
the_code_table_starts_after_the_instructions.cargo test -p victory-shader --lib -- --test-threads 1on the RTX 5080 under Proton: 242 passed, 6 failed. Plainmaingives 241 passed with the same 6 failures (NVIDIA/Wine, see #2037).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Related
code_dword. Its tables get the same, smaller start.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@sinan-cmyk on GitHub · 2026-11-25 08:22 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
524e2834ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 11:24 UTC · original · edited 2026-11-25 12:30 UTC
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/lower.rs,code_dwordused to start the program's constant table at the lowestCODEoffset any load or descriptor names. A computed load names offset 0, so the table was the whole program. The newcode_table_startstarts it at the end of the instructions (the highestmachine.offset + 4·wordsin the IR), unless a fixed-offset load reads below that, in which case the old start is kept.I checked the edge cases in
code_dword. A computed byte below the new start makesbyte - basewrap, so it is clamped to the last dword by the existingIUGTselect. Fixed-offset reads inside the instructions keep the old behaviour.the_code_table_starts_after_the_instructionscovers these cases. The offline count on the title's shaders (no change in emitted programs, 23,918 validated before and after) supports that nothing regresses.Thanks for
a68ae55, which is comment-only:code_table_start's doc comment now says only what the function does. CI: passing on the previous head.Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 11:30 UTC · original
Thanks. I took the optional point in
a68ae55:code_table_start's comment now only says what the function does, and the vkd3d-proton/NVIDIA background stays in the description. No code change. Clippy is clean.@OctoAlgo on GitHub · 2026-11-25 15:55 UTC · original
This also fixes NVIDIA RTX 5090 (GB202) GPU faults, so +1 for merging it.
On a 5090 (Linux, Proton, vkd3d-proton, driver 620.73.04) a fork of VIctory with the same
code_dwordcode faulted at every world entry: NVRM Xid 13, "SM Warp Exception: MMU Fault", shader writes to unmapped addresses. The same build ran clean on an RTX 5070 Ti in the same PC. What we found:On the edge case of a table base just below the instructions' end: we logged every code-table read in a 15-minute run (1149 reads in 114 programs). None of them is a fixed-offset load inside the instructions. Every
s_getpc_b64+ literal base, as the translator computes it, sits at or after the instructions' end (e.g. 16032/16064/16336 for an end at 16024). Socode_table_startnever clamps a real read there, and every table that was big drops to 154–177 dwords. No extra margin is needed.(Investigated with an AI coding assistant; all numbers are from runs on this PC.)
@Alm0stSurely on GitHub · 2026-11-26 05:14 UTC · original
Independent RTX 5080 measurement under GE-Proton 11-6, NVIDIA 620.73.04. I applied the shader change from #2143 to a ZTRX build based on
90b529f8with local Wine adaptations.I captured two compute shader translations before and after the change. For each one I replayed the exact DXIL and root-signature metadata from the title in a fresh process, called
CreateComputePipelineStateonce, and held the returned PSO for four seconds. No shader dispatch was issued. The serialized root signature matched across each pair.The values are differences between the median of four process GPU-memory samples before creation and four with the PSO held. One run per case. A control that held only the root signature and a third compute shader without this table both measured 0 MiB change before and after.
In my title run the patched build reached the opening credits and exited after about 5 min 15 s with 8,766 MiB of VRAM still free at the last sample with the game process present. The same exception had occurred on the earlier fork. I can confirm the pipeline memory improvement independently. I did not reproduce the in-world result on this run.
AI-assisted with OpenAI Codex (gpt-6.2-astra).