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

Closed
kibagami-nc wants to merge 0 commits from upstream-pr/550 into main
kibagami-nc commented 2026-11-28 00:39:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T00:39:45Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5535012386 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T00:39:45Z. --- **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://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7232026583), 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://github.com/trustno1-coder/VIctory-NVIDIA/issues/721#issuecomment-7240458843)). 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.
Machad3x commented 2026-11-28 01:57:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Machad3x on 2026-11-28T01:57:07Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232026583 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7232026583). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-28T01:57:07Z. --- 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 commented 2026-11-28 02:07:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T02:07:19Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232145279 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7232145279). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T02:07:19Z. --- 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.
trustno1-coder commented 2026-11-29 08:27:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-29T08:27:55Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253121495 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7253121495). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-29T08:27:55Z. --- 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.
kibagami-nc commented 2026-11-29 20:34:53 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-29T20:34:53Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7262194397 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/550#issuecomment-7262194397). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-29T20:34:53Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

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