Shaders: the constant table after the instructions can be turned off (VICTORY_CODE_TABLE_AFTER=0) #550

Closed
github-bot wants to merge 0 commits from github-bot/gh-550 into main AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 00:39 UTC · original
kibagami-nc:fix/code-table-after-instructions → main · +0 −0 · 0 files · 0 commits · closed without merging

Rebuilt on main (568c5e5d), after #1880. #1880 (brunofgmag) merged the change this PR carried, on by default: a program's constant table starts after its instructions. Both are ports of desplmfao's Marvisak/VIctory#2143. So this PR is now only the way back:

  • The switch: VICTORY_CODE_TABLE_AFTER=0 starts the table at the lowest offset any load or descriptor names, as before #1880.
  • The default: unset, or any other value, keeps main's behaviour. The default does not change.
  • The cache: the switch is in the shader cache's key (KEYED in shader_cache.rs, now 34 entries), so turning it on or off translates again. #807's test that every translator switch is keyed passes.

Why a way back

@⁠Machad3x measured the change in an A/B on an RTX 3080 Ti (comment below, 2026-11-28). Setup: 1440p, DLSS Quality, title ray tracing on, 240 s runs into the prison cell.

  • Series X profile: the card time per frame was 18-19 ms without the change and 76-224 ms with it. The picture was the same.
  • The A/B: the same batch with only this change reverted was back to 18-19 ms.
  • Series S profile: fast either way (1-5 ms).

That was on the main of 2026-11-28, in a batch with other PRs, so it may not hold on today's main. With the switch, anyone who sees a slow card time can check in one run, without a rebuild.

On the other side, the change got DuckersMcQuack's RTX 5090 under Proton past its Xid 13 (#721). Upstream also measured the VRAM peak fall from 15.9 GB to 12.7 GB on an NVIDIA card (#1880).

One candidate for the extra card time: a computed load below the new start reads the table's last dword (the clamp in code_dword) instead of the code's bytes. A program that uses such a value as a count would loop longer.

Change

crates/victory-shader/src/emit/lower.rs:

  • code_table_after() reads the switch.
  • code_dword takes main's code_table_start when the switch is on, and lowest when it's off.

This PR's earlier copy of the code_table_start test is gone: main has the same test (the_code_table_starts_after_the_instructions) from #1880.

Tests

  • cargo test -p victory-shader --locked: 395 passed, 8 ignored, on 568c5e5d.
  • cargo test -p victory-gpu --locked --lib shader_cache: 4 passed, including every_switch_of_the_translator_is_in_the_key.
  • cargo clippy -p victory-shader -p victory-gpu --all-targets: nothing in the changed lines.

Tested by others (earlier form, switch on)

  • DuckersMcQuack, RTX 5090, Linux/Proton: past the Xid 13 with VICTORY_CODE_TABLE_AFTER=1. The picture stayed black, which is #721's other problem.
**@⁠kibagami-nc** on GitHub · 2026-11-28 00:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550) `kibagami-nc:fix/code-table-after-instructions` → `main` · +0 −0 · 0 files · 0 commits · closed without merging **Rebuilt on main (568c5e5d), after #1880.** #1880 (brunofgmag) merged the change this PR carried, on by default: a program's constant table starts after its instructions. Both are ports of desplmfao's Marvisak/VIctory#2143. So this PR is now only the way back: - **The switch:** `VICTORY_CODE_TABLE_AFTER=0` starts the table at the lowest offset any load or descriptor names, as before #1880. - **The default:** unset, or any other value, keeps main's behaviour. The default does not change. - **The cache:** the switch is in the shader cache's key (`KEYED` in `shader_cache.rs`, now 34 entries), so turning it on or off translates again. #807's test that every translator switch is keyed passes. ## Why a way back @⁠Machad3x measured the change in an A/B on an RTX 3080 Ti ([comment below](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/550), 2026-11-28). Setup: 1440p, DLSS Quality, title ray tracing on, 240 s runs into the prison cell. - **Series X profile:** the card time per frame was 18-19 ms without the change and 76-224 ms with it. The picture was the same. - **The A/B:** the same batch with only this change reverted was back to 18-19 ms. - **Series S profile:** fast either way (1-5 ms). That was on the main of 2026-11-28, in a batch with other PRs, so it may not hold on today's main. With the switch, anyone who sees a slow card time can check in one run, without a rebuild. On the other side, the change got DuckersMcQuack's RTX 5090 under Proton past its Xid 13 ([#721](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/721)). Upstream also measured the VRAM peak fall from 15.9 GB to 12.7 GB on an NVIDIA card (#1880). One candidate for the extra card time: a computed load below the new start reads the table's last dword (the clamp in `code_dword`) instead of the code's bytes. A program that uses such a value as a count would loop longer. ## Change `crates/victory-shader/src/emit/lower.rs`: - `code_table_after()` reads the switch. - `code_dword` takes main's `code_table_start` when the switch is on, and `lowest` when it's off. This PR's earlier copy of the `code_table_start` test is gone: main has the same test (`the_code_table_starts_after_the_instructions`) from #1880. ## Tests - `cargo test -p victory-shader --locked`: 395 passed, 8 ignored, on 568c5e5d. - `cargo test -p victory-gpu --locked --lib shader_cache`: 4 passed, including `every_switch_of_the_translator_is_in_the_key`. - `cargo clippy -p victory-shader -p victory-gpu --all-targets`: nothing in the changed lines. ## Tested by others (earlier form, switch on) - DuckersMcQuack, RTX 5090, Linux/Proton: past the Xid 13 with `VICTORY_CODE_TABLE_AFTER=1`. The picture stayed black, which is #721's other problem.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:41:19 +00:00
Author
Owner

@⁠Machad3x on GitHub · 2026-11-28 01:57 UTC · original

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.

**@⁠Machad3x** on GitHub · 2026-11-28 01:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7232026583) 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.
github-bot changed title from Shaders: the code table starts after the instructions (RTX 5090 Xid 13, GBs of VRAM on other NVIDIA cards) to Shaders: the code table can start after the instructions (VICTORY_CODE_TABLE_AFTER=1, off by default: RTX 5090 Xid 13, GBs of VRAM) 2026-11-28 02:09:30 +00:00
Machad3x measured a regression with the previous commit on #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.
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 02:07 UTC · original

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.

**@⁠kibagami-nc** on GitHub · 2026-11-28 02:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7232145279) 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.
github-bot force-pushed github-bot/gh-550 from 1ae101b44f to 8c75b9bdfb 2026-11-28 20:11:39 +00:00 Compare
github-bot force-pushed github-bot/gh-550 from 8c75b9bdfb to 005d06c0e0 2026-11-29 00:39:26 +00:00 Compare
github-bot force-pushed github-bot/gh-550 from 005d06c0e0 to a15140a957 2026-11-29 01:40:25 +00:00 Compare
github-bot changed title from Shaders: the code table can start after the instructions (VICTORY_CODE_TABLE_AFTER=1, off by default: RTX 5090 Xid 13, GBs of VRAM) to Shaders: the constant table after the instructions can be turned off (VICTORY_CODE_TABLE_AFTER=0) 2026-11-29 02:51:06 +00:00
github-bot force-pushed github-bot/gh-550 from a15140a957 to a86b0512ff 2026-11-29 02:51:07 +00:00 Compare
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-29 08:27 UTC · original

Thank you! An earlier version of this pull request was merged into main with its original commits and is part of v2026.11.29.01, where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.

**@⁠trustno1-coder** on GitHub · 2026-11-29 08:27 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7253121495) Thank you! An earlier version of this pull request was merged into main with its original commits and is part of [v2026.11.29.01](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.29.01), where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.
github-bot force-pushed github-bot/gh-550 from a86b0512ff to a15140a957 2026-11-29 20:34:56 +00:00 Compare
github-bot closed this pull request 2026-11-29 20:34:57 +00:00
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-29 20:34 UTC · original

Closed by GitHub because the branch now points at a15140a9, which main already has: that earlier head of this PR came in with last night's merges.

So main is back to the opt-in form:

  • The default: the short constant table is off.
  • The switch: VICTORY_CODE_TABLE_AFTER=1 turns it on.
  • The cache: the switch is in the shader cache's key.

The later head (a86b0512, an opt-out on top of #1880's default) no longer applies, so there's nothing left to merge here.

For the cards that need it, the switch has to be set:

  • RTX 5090: past Xid 13 (#721).
  • Cards where the driver reserves gigabytes per pipeline: #1922.

The v2026.11.29.0x releases have it off by default.

**@⁠kibagami-nc** on GitHub · 2026-11-29 20:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7262194397) Closed by GitHub because the branch now points at a15140a9, which main already has: that earlier head of this PR came in with last night's merges. So main is back to the opt-in form: - **The default:** the short constant table is off. - **The switch:** `VICTORY_CODE_TABLE_AFTER=1` turns it on. - **The cache:** the switch is in the shader cache's key. The later head (a86b0512, an opt-out on top of #1880's default) no longer applies, so there's nothing left to merge here. For the cards that need it, the switch has to be set: - **RTX 5090:** past Xid 13 (#721). - **Cards where the driver reserves gigabytes per pipeline:** #1922. The v2026.11.29.0x releases have it off by default.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!550
No description provided.