Skip to content

Shaders: the code table can start after the instructions (VICTORY_CODE_TABLE_AFTER=1, off by default: RTX 5090 Xid 13, GBs of VRAM) - #550

Open
kibagami-nc wants to merge 2 commits into
trustno1-coder:mainfrom
kibagami-nc:fix/code-table-after-instructions
Open

kibagami-nc wants to merge 2 commits into
trustno1-coder:mainfrom
kibagami-nc:fix/code-table-after-instructions

Conversation

@kibagami-nc

@kibagami-nc kibagami-nc commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Rebased on main (923e38c). The only conflict was the shader cache key: VICTORY_CODE_TABLE_AFTER sits beside main's new VICTORY_LDS_BOUNDS_EXEMPT. cargo test -p victory-shader --locked: 349 passed, 8 ignored, the code table tests included.

Update: off by default (VICTORY_CODE_TABLE_AFTER=1)

Machad3x measured a regression with the first commit, A/B in a batch on an RTX 3080 Ti (1440p, DLSS Quality, title ray tracing on), 240 s runs into the prison cell. Thanks for that.

  • Series X profile: the card time per frame went from 18-19 ms to 76-224 ms, and the picture looked the same.
  • The A/B: the same batch with only this PR reverted was back to 18-19 ms.
  • Series S profile: it stayed fast.

A computed load below the new start reads the table's last dword instead of the code's bytes, and a program may use such a value as a count.

So the second commit (1ae101b) makes the shorter table a switch, VICTORY_CODE_TABLE_AFTER=1, off by default. dkdknight's port of this PR to their fork uses the same name and the same default.

  • Without the switch: the table starts at the lowest offset any load names, exactly as on main.
  • With it: the table starts after the instructions, as in the first commit.
  • It is for the cards the whole-program table hurts: Xid 13 on an RTX 5090, and gigabytes of video memory reserved on an RTX 5080.
  • The cache follows it: the switch is in the shader cache's key (shader_cache.rs), so turning it on or off translates again.

The problem

code_dword (crates/victory-shader/src/emit/lower.rs) 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: 4,160 to 4,596 dwords (16 to 18 KiB) in the lighting computes reached at world entry.

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:

The change, with the switch on

A program's constants follow its instructions, and a load at a computed offset reads them. So the table starts where the instructions end, unless a load at a fixed offset reads below that. A computed index below the start is clamped to the table's last dword, like one past the end.

Upstream logged 1,149 code-table reads in 114 programs. None of them falls below the new start, and the tables that were 3,200 to 4,600 dwords are now 154 to 177. The regression above says that some program, at the Series X settings, does read below it.

This is a port of desplmfao's fix (Marvisak/VIctory#2143, commits 524e2834 and a68ae559), as carried to fxceless/victory-fork#1006. The regression test is in emit's own test module, with code_table_start made pub(super) for it.

Tests

  • The code-table tests pass (3), with the switch unset and with VICTORY_CODE_TABLE_AFTER=1.
  • cargo test -p victory-shader --locked: 290 passed, 4 ignored.
  • cargo clippy -p victory-shader --all-targets -- -D warnings, with and without --all-features: no warnings. Nothing in shader_cache.rs either.

cargo clippy --workspace -- -D warnings already stops on lints main has (see #425, #265 and #86). This change adds no warning.

Tested by others

DuckersMcQuack (#721): RTX 5090 (GB202), CachyOS, NVIDIA 620.70.06, Proton Experimental. A build of this PR on 63b902f, run with VICTORY_CODE_TABLE_AFTER=1:

  • the VK_ERROR_DEVICE_LOST with NVIDIA's Xid 13 (MMU fault), which had stopped every start, is gone;
  • the game now gets to the opening ("Vice City, two years ago").

A black picture with sound there is followed separately in #721, from the layer's play log.

This is the case the switch is for: the whole-program table faulting on GB202.

No game files, dumps or extracted data are included.

dkdknight added a commit to dkdknight/Victory-Knight-HD that referenced this pull request Nov 28, 2026
…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>
@Machad3x

Copy link
Copy Markdown

Tested in a batch on an RTX 3080 Ti + Ryzen 7 5700X, 1440p, DLSS Quality, title ray tracing on (VICTORY_BVH_BUILDER=1), 240 s runs into the prison cell scene. Batch: #552, #550, #548, #547, #544.

Regression with this PR on the Series X profile: the card time per frame went from 18-19 ms to 76-224 ms (frame 67-70 ms to 153-308 ms). The picture looked the same. A/B: the same batch with only this PR reverted is back to 18-19 ms. The Series S profile with this PR stayed fast (1-5 ms card time), so the cost seems to depend on the resolution or the shaders used at the Series X settings.
One thing a review noticed: a load at a computed offset that reaches into the instructions now reads the clamped last dword instead of the instruction bytes. If a shader uses such a value as a loop count or a size, that could explain the extra card time.

kibagami-nc added a commit to kibagami-nc/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
…fault

Machad3x measured a regression with the previous commit on trustno1-coder#550, A/B on an
RTX 3080 Ti (1440p, DLSS Quality, title ray tracing on, Series X profile):
the card time per frame went from 18-19 ms to 76-224 ms, with the picture
unchanged; with only this change reverted it was back to 18-19 ms. The
Series S profile stayed fast. A computed load below the new start reads the
table's last dword, not the code's bytes, which a program may use as a
count.

The shorter table is now taken only with VICTORY_CODE_TABLE_AFTER=1, as
dkdknight's port of it to their fork does (same name, off by default).
Without it the table starts at the lowest offset any load names, as on
main. The switch joins the shader cache's key, so flipping it translates
again. It is for the cards the whole-program table hurts: Xid 13 on an
RTX 5090, gigabytes of video memory reserved on an RTX 5080.
@kibagami-nc kibagami-nc changed the title Shaders: the code table starts after the instructions (RTX 5090 Xid 13, GBs of VRAM on other NVIDIA cards) Shaders: the code table can start after the instructions (VICTORY_CODE_TABLE_AFTER=1, off by default: RTX 5090 Xid 13, GBs of VRAM) Nov 28, 2026
@kibagami-nc

Copy link
Copy Markdown
Contributor Author

Thanks @Machad3x for the A/B, that settles it.

With 1ae101b the shorter table is a switch, VICTORY_CODE_TABLE_AFTER=1, off by default (the same name and default as dkdknight's port). Without it the translation is the same as on main, so your batch should be back to 18-19 ms on the Series X profile. The switch is in the shader cache's key, so turning it on or off translates again.

It stays for the cards the whole-program table hurts (Xid 13 on an RTX 5090, gigabytes of video memory reserved on an RTX 5080). If you find a moment, a Series X run with the switch on and the frame line would tell which part of the frame takes the extra time.

whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…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>
whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…fter the instructions only with VICTORY_CODE_TABLE_AFTER=1

From trustno1-coder#550 (1ae101b). Upstream measured the shorter table
slowing the card 4-10x on the Series X profile (RTX 3080 Ti, 18-19 ms to 76-224 ms a
frame), and a computed load below the new start reads the table's last dword instead
of the code's bytes, which a program may use as a count. Off by default: the table
starts at the lowest offset any load names, as before f36d7d6. The switch is in the
shader cache's key. Conflict in shader_cache.rs: the two other names the upstream
side carries (VICTORY_LDS_LOOP_ATOMICS, VICTORY_LDS_BOUNDS) are not in this branch.

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.
…fault

Machad3x measured a regression with the previous commit on trustno1-coder#550, A/B on an
RTX 3080 Ti (1440p, DLSS Quality, title ray tracing on, Series X profile):
the card time per frame went from 18-19 ms to 76-224 ms, with the picture
unchanged; with only this change reverted it was back to 18-19 ms. The
Series S profile stayed fast. A computed load below the new start reads the
table's last dword, not the code's bytes, which a program may use as a
count.

The shorter table is now taken only with VICTORY_CODE_TABLE_AFTER=1, as
dkdknight's port of it to their fork does (same name, off by default).
Without it the table starts at the lowest offset any load names, as on
main. The switch joins the shader cache's key, so flipping it translates
again. It is for the cards the whole-program table hurts: Xid 13 on an
RTX 5090, gigabytes of video memory reserved on an RTX 5080.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants