Start shader constant tables after instructions #408

Closed
github-bot wants to merge 660 commits from github-bot/gh-408 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-28 13:25 UTC · original
safesearch77:fix/shader-code-table-start → main · +61 −5 · 3 files · 1 commits · closed without merging

When a shader reads its embedded CODE constant table through a computed offset, the resource pass records an address at offset 0. Lower::code_dword previously took the minimum CODE offset across all loads and descriptors, which turned the entire program (instructions plus constants, up to 64 KiB) into an internal DXIL constant array.

Under vkd3d-proton on NVIDIA Vulkan, that internal constant array lowers to per-thread local memory reserved across the GPU, so a large table consumes substantial VRAM. Even on native D3D12, keeping instruction bytes out of the constant array avoids emitting unneeded constant data.

code_table_start now starts the constant table where the program's instructions end (code_end & !3), unless a load at a fixed offset reads below code_end, in which case it falls back to lowest. Trade-off (same as upstream #2143): a computed load that actually reads instruction bytes clamps to the last entry (rel underflows and over clamps). TRANSLATOR_VERSION is bumped from 15 to 16 because the emitted DXIL constant array changes for shaders with computed CODE table offsets.

Ported from Marvisak/VIctory#2143 (e04c0781, by desp).

Verification

  • cargo +1.98.1 test --locked -p victory-shader --lib (native Linux): 230 passed; 0 failed; 2 ignored, including the_code_table_starts_after_the_instructions (covers computed offset at 0, computed + fixed after code_end, computed + fixed inside instructions, and fixed-only past code_end).
  • cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-shader --lib -- --skip paired_fp32 (Wine, no GPU/D3D12 host): all 300 CPU-side tests pass including the_code_table_starts_after_the_instructions; 40 GPU/WARP SM 6.6 shader-execution tests fail under sandboxed Wine because no GPU device is exposed.
  • cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib -- shader_cache (Wine): 4 passed; 0 failed (pure CPU/disk tests; no host() guard).
  • cargo +1.98.1 clippy --locked --target x86_64-pc-windows-msvc -p victory-shader --all-targets -- -D warnings: clean (0 warnings).
  • cargo +1.98.1 xtask policy: asset policy: 322 files ok.
  • Live smoke test under Proton + vkd3d-proton (RTX 4070 Laptop 8 GB, CachyOS, GE-Proton11-14-viewtree, Wayland, Series S, DLSS Quality, VICTORY_VRAM_HEADROOM_MB=1024, VICTORY_POOL_STATS=1): 25,792 shader files pre-translated cleanly under TRANSLATOR_VERSION = 16 (2,530 active translations / 105 MB in-run), zero visual regressions, steady 13.7–16.6 fps at 5,390–5,863 draws/frame (matching 13.4–16.8 fps on the same heavy scene without this change), clean shutdown (DLSS: NGX shut down result="Success").
**@⁠safesearch77** on GitHub · 2026-11-28 13:25 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408) `safesearch77:fix/shader-code-table-start` → `main` · +61 −5 · 3 files · 1 commits · closed without merging When a shader reads its embedded `CODE` constant table through a computed offset, the resource pass records an address at offset `0`. `Lower::code_dword` previously took the minimum `CODE` offset across all loads and descriptors, which turned the entire program (instructions plus constants, up to 64 KiB) into an internal DXIL constant array. Under `vkd3d-proton` on NVIDIA Vulkan, that internal constant array lowers to per-thread local memory reserved across the GPU, so a large table consumes substantial VRAM. Even on native D3D12, keeping instruction bytes out of the constant array avoids emitting unneeded constant data. `code_table_start` now starts the constant table where the program's instructions end (`code_end & !3`), unless a load at a fixed offset reads below `code_end`, in which case it falls back to `lowest`. Trade-off (same as upstream `#2143`): a computed load that actually reads instruction bytes clamps to the last entry (`rel` underflows and `over` clamps). `TRANSLATOR_VERSION` is bumped from `15` to `16` because the emitted DXIL constant array changes for shaders with computed `CODE` table offsets. Ported from `Marvisak/VIctory#2143` (`e04c0781`, by `desp`). ### Verification - `cargo +1.98.1 test --locked -p victory-shader --lib` (native Linux): `230 passed; 0 failed; 2 ignored`, including `the_code_table_starts_after_the_instructions` (covers computed offset at `0`, computed + fixed after `code_end`, computed + fixed inside instructions, and fixed-only past `code_end`). - `cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-shader --lib -- --skip paired_fp32` (Wine, no GPU/D3D12 host): all `300` CPU-side tests pass including `the_code_table_starts_after_the_instructions`; `40` GPU/WARP SM 6.6 shader-execution tests fail under sandboxed Wine because no GPU device is exposed. - `cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib -- shader_cache` (Wine): `4 passed; 0 failed` (pure CPU/disk tests; no `host()` guard). - `cargo +1.98.1 clippy --locked --target x86_64-pc-windows-msvc -p victory-shader --all-targets -- -D warnings`: clean (`0` warnings). - `cargo +1.98.1 xtask policy`: `asset policy: 322 files ok`. - Live smoke test under Proton + `vkd3d-proton` (RTX 4070 Laptop 8 GB, CachyOS, `GE-Proton11-14-viewtree`, Wayland, Series S, DLSS Quality, `VICTORY_VRAM_HEADROOM_MB=1024`, `VICTORY_POOL_STATS=1`): `25,792` shader files pre-translated cleanly under `TRANSLATOR_VERSION = 16` (`2,530` active translations / `105 MB` in-run), zero visual regressions, steady `13.7–16.6 fps` at `5,390–5,863` draws/frame (matching `13.4–16.8 fps` on the same heavy scene without this change), clean shutdown (`DLSS: NGX shut down result="Success"`).
Start the embedded CODE constant table after the program's instructions
unless a fixed-offset load reads below code_end, avoiding emitting
instruction bytes into DXIL constant arrays on computed-offset loads.
A computed load that actually reads instruction bytes now clamps to
the last entry (same trade-off as upstream #2143). Bump
TRANSLATOR_VERSION from 15 to 16.

Ported from Marvisak/VIctory#2143 (e04c0781, desp).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 13:36:38 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-28 13:34 UTC · original

Ran the code-table placement test at 06aaf1b on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.

cargo test -p victory-shader --lib the_code_table_starts_after_the_instructions -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 361 filtered out      (exit 0)

The test passes on a real 32-lane NVIDIA host, covering a computed CODE offset at 0, computed and fixed reads before and after the instruction end, and fixed-only reads past it. It is a translation-level test; no Vulkan/VKD3D VRAM measurement was made here. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti.

Not tested: a retail title, the VRAM saving under vkd3d-proton, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-28 13:34 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7240033150) Ran the code-table placement test at `06aaf1b` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build. ``` cargo test -p victory-shader --lib the_code_table_starts_after_the_instructions -- --test-threads=1 1 passed; 0 failed; 0 ignored; 0 measured; 361 filtered out (exit 0) ``` The test passes on a real 32-lane NVIDIA host, covering a computed `CODE` offset at 0, computed and fixed reads before and after the instruction end, and fixed-only reads past it. It is a translation-level test; no Vulkan/VKD3D VRAM measurement was made here. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti. Not tested: a retail title, the VRAM saving under vkd3d-proton, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-28 19:14 UTC · original

The description says the 40 GPU shader-execution tests couldn't run under Wine, so I ran the whole victory-shader lib suite natively on Windows (NVIDIA card, debug build):

Result
main (fe7c6e5) 343 passed, 0 failed, 18 ignored
this PR (06aaf1b) 344 passed, 0 failed, 18 ignored (the new the_code_table_starts_after_the_instructions)

It merges cleanly on current main.

On the trade-off: code_end comes from ir::build, and gfx10::decode only follows reachable control flow, so it's the end of the last instruction that can actually run, never constant data decoded as code. A computed load can only clamp to the wrong entry if the title puts constants before its last reachable instruction (between two code regions, say). The upstream port has the same assumption, so I'm only noting it here.

One practical point: the TRANSLATOR_VERSION 15 → 16 bump makes everyone translate again and rebuild pipelines on their next launch, which is the slow first launch from #422/#423. If other translator changes are close to landing, merging them in the same window would save users one of those launches.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-28 19:14 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7244397581) The description says the 40 GPU shader-execution tests couldn't run under Wine, so I ran the whole `victory-shader` lib suite natively on Windows (NVIDIA card, debug build): | | Result | | --- | --- | | `main` (`fe7c6e5`) | 343 passed, 0 failed, 18 ignored | | this PR (`06aaf1b`) | 344 passed, 0 failed, 18 ignored (the new `the_code_table_starts_after_the_instructions`) | It merges cleanly on current `main`. On the trade-off: `code_end` comes from `ir::build`, and `gfx10::decode` only follows reachable control flow, so it's the end of the last instruction that can actually run, never constant data decoded as code. A computed load can only clamp to the wrong entry if the title puts constants before its last reachable instruction (between two code regions, say). The upstream port has the same assumption, so I'm only noting it here. One practical point: the `TRANSLATOR_VERSION` 15 → 16 bump makes everyone translate again and rebuild pipelines on their next launch, which is the slow first launch from #422/#423. If other translator changes are close to landing, merging them in the same window would save users one of those launches. AI-assisted: yes
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

Thanks for running the native shader execution suite. The 344 vs 343 test result adds useful coverage beyond Wine. #428 carries the same constant-table change; we'll keep one implementation and coordinate the translator version and regression test.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7255220573) Thanks for running the native shader execution suite. The 344 vs 343 test result adds useful coverage beyond Wine. #428 carries the same constant-table change; we'll keep one implementation and coordinate the translator version and regression test.
Author
Owner

@⁠safesearch77 on GitHub · 2026-11-29 13:18 UTC · original

Thanks. I compared this PR with #428 (85a3ebf). The code is identical: emit/lower.rs, the regression test the_code_table_starts_after_the_instructions, and the TRANSLATOR_VERSION bump. The only difference is one extra doc-comment line on the test in #428 that names #221.

Since #428 is already in #439 and #439 has moved TRANSLATOR_VERSION on to 19, I'll close this PR in favor of #428 so there's one implementation to keep. If you'd rather keep this one, tell me and I'll rebase it instead.

Thanks to @⁠Aniseto and @⁠Kal0s-design for the native Windows runs (RTX 5070 Ti, plus the full victory-shader suite: 344 passed against 343 on main). Those apply to #428's code too.

AI-assisted: yes (Claude), reviewed locally before posting.

**@⁠safesearch77** on GitHub · 2026-11-29 13:18 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7256437539) Thanks. I compared this PR with #428 (85a3ebf). The code is identical: `emit/lower.rs`, the regression test `the_code_table_starts_after_the_instructions`, and the `TRANSLATOR_VERSION` bump. The only difference is one extra doc-comment line on the test in #428 that names #221. Since #428 is already in #439 and #439 has moved `TRANSLATOR_VERSION` on to 19, I'll close this PR in favor of #428 so there's one implementation to keep. If you'd rather keep this one, tell me and I'll rebase it instead. Thanks to @⁠Aniseto and @⁠Kal0s-design for the native Windows runs (RTX 5070 Ti, plus the full `victory-shader` suite: 344 passed against 343 on `main`). Those apply to #428's code too. AI-assisted: yes (Claude), reviewed locally before posting.
github-bot closed this pull request 2026-11-29 13:23:48 +00:00
Author
Owner

@⁠zmelumian972 on GitHub · 2026-11-29 17:23 UTC · original · edited 2026-11-29 17:24 UTC

Hey @⁠safesearch77

thanks for 408, I think both of them are identical tbh so it doens't really matter, once I realized the problem I asked claude how come Victory doesn't have it and he told me it was solved there, so I asked him to port it... I think we both did the same thing

can you take a look at #221 ?

on both 428 and 408 I still have those artifacts, I want to make sure it's not something specific to the 5090

**@⁠zmelumian972** on GitHub · 2026-11-29 17:23 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7259649813) · edited 2026-11-29 17:24 UTC Hey @⁠safesearch77 thanks for 408, I think both of them are identical tbh so it doens't really matter, once I realized the problem I asked claude how come Victory doesn't have it and he told me it was solved there, so I asked him to port it... I think we both did the same thing can you take a look at https://git.gtahub.st/github/TaynanGT--Vice-Tay/issues/221 ? on both 428 and 408 I still have those artifacts, I want to make sure it's not something specific to the 5090
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 19:02 UTC · original

Thanks for checking both branches. Let's keep #428 as the single constant-table implementation and track the remaining rendering artifacts in #221 rather than duplicate the fix. A matched Windows/Proton comparison would help establish whether this is specific to the RTX 5090.

**@⁠TaynanGT** on GitHub · 2026-11-29 19:02 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/408#issuecomment-7260953188) Thanks for checking both branches. Let's keep #428 as the single constant-table implementation and track the remaining rendering artifacts in #221 rather than duplicate the fix. A matched Windows/Proton comparison would help establish whether this is specific to the RTX 5090.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.