Repository navigation
Shaders: a program's constant table starts after its instructions (GBs of NVIDIA video memory) - #2143
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 Thanks for 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 |
…ter its instructions
|
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
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 (Investigated with an AI coding assistant; all numbers are from runs on this PC.) |
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous main (old upstream base) is the first parent; the second is upstream main with the current heads of our pull requests merged in: Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491, Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's element-type key on main's three handle maps, and the README. Marvisak#2112 (opt-in, in place) stays in the renderer branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…visak#2143 added Marvisak#2143 (merged today) reads `i.machine.words.len()` in `code_table_start`, and this branch made `words` an inline array behind an accessor, so the two textually disjoint hunks do not build together. The accessor returns the slice, so `.len()` is the same number; no behaviour change.
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erged) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # README.md # crates/victory-gpu/src/descriptor.rs # crates/victory-gpu/src/pipeline.rs # crates/victory-gpu/src/pipeline/library.rs # crates/victory-hle/src/modules/gameinput.rs
…s of NVIDIA video memory) (Marvisak#2143) * Shaders: a program's constant table starts after its instructions 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. * Shaders: code_table_start's comment says only what it does As suggested in the triage: the vkd3d-proton/NVIDIA background stays in the pull request's description. (cherry picked from commit e04c078)
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's code is kept for those. - emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its and_guard dropped); title-memory marks: main's straddling-write lookup (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in lower/mark_tests.rs; the old Marvisak#2167 head taken out first. - emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's adapter list and Host::on (create_device takes an optional adapter). - descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept. - gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy. - pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides. - Tests main added since get Marvisak#439's Parts fields and emit's Target. - README: base 63bcca4; rows of PRs merged upstream, superseded or closed taken out, with a note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous renderer (old upstream base 940d32f) is the first parent and is also kept as the branch renderer-2026-11-25-oldbase; the second parent is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with the renderer stack merged on it: Marvisak#439 (on main: update/439-main's resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292, Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes. Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by main: Marvisak#1769, Marvisak#1763, Marvisak#2366. The picture on this base still shows the overlay that plain upstream main shows too; that is being looked into. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 90b529f with 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
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). |
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 then the whole program. NVIDIA's compiler keeps a dynamically indexed constant array of more than 16 KiB in every thread's local memory rather than its constant memory (upstream measured 16-18 KB of local memory per thread in twelve lighting compute programs, a page fault on an RTX 5090 at every entry into the world, and GBs of video memory on other cards). 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. Over the title's archive (translate, 32-lane host): 20 tables of more than 4,096 dwords (up to 5,328) before, none after (the largest 2,348); the six heaviest passes of the first room are not among them (their tables are 3 to 131 dwords). Port of Marvisak/VIctory e04c078 (Marvisak#2143, desp; also fxceless/victory-fork Marvisak#1006), with its test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported by hand from upstream VIctory e04c078 (Marvisak#2143, by desp); the file was restructured here, so the cherry-pick did not apply. The table code_dword reads started at the lowest offset any load names, and a load at a computed offset names 0, so the table was the whole program (up to 64 KiB). Upstream measured GBs of NVIDIA video memory reserved for it under vkd3d-proton. (ported from commit e04c078) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…table after its instructions (off by default) Hand port of upstream e04c078 (Marvisak#2143), behind a switch: it saved GBs of reserved video memory under vkd3d-proton on NVIDIA; the effect on D3D12 is unmeasured. The switch is part of the shader cache key. AI-assisted (Claude)
…uctions code_dword built the program's constant 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 and constants, up to 64 KiB. On NVIDIA such a large runtime-indexed constant array goes to local memory, and the driver reserves that for every resident thread (gigabytes of video memory for a handful of compute shaders). 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 (code_table_start). A computed index below the start is clamped as one past the end already was. This changes translated shaders; the disk shader cache is keyed on the translator source fingerprint, so old translations are not reused. Source: Marvisak/VIctory pull request #2143 (merged, GPL-3.0) Marvisak/VIctory#2143 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Ported from Marvisak/VIctory#2143 (524e2834 and a68ae559, squashed; only the test module's import list differs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ak/VIctory#2143) 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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. The fix is desplmfao's (Marvisak/VIctory#2143, 524e2834 and a68ae559, squashed), re-ported onto this tree. This tree has no lower_tests.rs, so the regression test is in emit's own test module and code_table_start is pub(super) for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the instructions (fixes RTX 5090 Xid 13; port of Marvisak/VIctory#2143) Taken from fxceless/victory-fork#1006 (GPL-3.0-or-later), as victory-linux-av b32932d carried it. This tree's code table started at the lowest code-relative load, so a load at a computed offset from the code's start indexed instruction bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011E3imKzjNhFo4qDM5vuLSv (cherry picked from commit 1b0c2d15c799d701b53557fee31f7c7d1d571a58)
…E_TABLE_AFTER=1; off) Port of trustno1-coder/VIctory-NVIDIA#550 (kibagami-nc, d5a6e96f), itself desplmfao's fix (Marvisak/VIctory#2143, 524e2834 and a68ae559). code_dword turns the program's code into a constant table starting at the lowest offset any load or descriptor names. A load at a computed offset names offset 0, so the table is the whole program: 16 to 18 KiB in the lighting computes. NVIDIA's compiler copies such an array into every thread's local memory (Xid 13 on an RTX 5090, gigabytes of VRAM reserved on an RTX 5080). With the switch the table starts where the instructions end, unless a load at a fixed offset reads below that; upstream logged 1,149 code-table reads in 114 programs and none falls below the new start. Read at translation time; the switch's value joins the shader cache key (translation_fingerprint), so flipping it translates again. Not A/B-able while the title runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Port of desplmfao's fix (Marvisak/VIctory#2143, 524e2834 and a68ae559), as carried to fxceless/victory-fork#1006. The regression test is in emit's own test module, with code_table_start pub(super) for it.
|
A measured A/B from another tree, where this same change is now off by default (read from their reports; not run here). trustno1-coder/VIctory-NVIDIA ported this change as its #550 (kibagami-nc). Machad3x ran the A/B there: RTX 3080 Ti, Windows, 1440p, DLSS Quality, the title's ray tracing on, 240 s into the prison cell scene.
Their reading is that a computed load reaching below the new start now gets the table's last dword instead of the instruction bytes it read before. If a program uses that value as a loop count or a size, that would add card time without changing the picture. So the tree now has it behind On AI-assisted (Claude Code, Claude Opus 5.5 read main's |
…instructions Cherry-picked from trustno1-coder#550 (Manley.B, d5a6e96; a port of desplmfao's Marvisak/VIctory#2143 524e2834 and a68ae559). A load at a computed offset named offset 0, so the constant table of the lighting computes was the whole program (4,160 to 4,596 dwords, 16-18 KiB). NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory: gigabytes of video memory on a 12 GB card. The table now starts where the instructions end unless a fixed-offset load reads below that; a computed index below the start is clamped as one past the end was. Test: the_code_table_starts_after_the_instructions (3 code-table tests pass). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. Under vkd3d-proton that constant array becomes a private one; NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a larger one into every thread's local memory. On the RTX 5090 (GB202) the lighting computes with 16-18 KiB tables fault (Xid 13, writes to unmapped addresses); on other cards they make the driver reserve GBs of VRAM. 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. Port of desplmfao's fix (Marvisak/VIctory#2143, 524e2834 and a68ae559), as carried to fxceless/victory-fork#1006. The regression test is in emit's own test module, with code_table_start pub(super) for it.
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