Repository navigation
Conversation
The table code_dword reads was the program's code from the lowest offset any load or descriptor names, and a load at a computed offset names offset 0: the table was the whole program, up to 64 KiB. Under vkd3d-proton that constant array becomes a private one, which NVIDIA's Vulkan driver keeps in every thread's local memory, and the driver reserves that per thread for the whole GPU: one 57 KiB table made it reserve GBs of video memory. The program's constants follow its instructions, and a load at a computed offset reads them, so the table now starts where the instructions end, unless a load at a fixed offset reads below that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-shader --lib the_code_table_starts_after_the_instructions— passedcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean fix starting the emitted code constant table after the program's instructions rather than at offset 0, avoiding huge wasted constant-buffer/VRAM allocations on NVIDIA. Looks great.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.
145 passed / 0 failed / 2 ignored. Program constant table starts after its instructions — constant-table layout fix.
…s of NVIDIA video memory) Upstream: Marvisak/VIctory#2143 (import list and test section merged by hand) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkAEvF29hMbrBJw8os (cherry picked from commit 9c6a651)
…s of NVIDIA video memory) Upstream: Marvisak/VIctory#2143 (import list and test section merged by hand) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkAEvF29hMbrBJw8os (cherry picked from commit 9c6a651) (cherry picked from commit 8aaf44a)
Offline measurement on a retail dumpResult: no count change against I merged head 524e283 onto 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). |
|
Automated triage for the maintainers. Merge candidate. In I checked the edge cases in A small optional point: the doc comment on Generated by Claude Code |
As suggested in the triage: the vkd3d-proton/NVIDIA background stays in the pull request's description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. I took the optional point in |
Problem
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 Shaders: byte and half format loads at a constant offset load the aligned dword directly (NVIDIA) #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