Shaders: the code table starts after the instructions (fixes RTX 5090 Xid 13; port of Marvisak/VIctory#2143) #1006

Open
github-bot wants to merge 1 commit from github-bot/gh-1006 into main AGit
Owner

@⁠OctoAlgo on GitHub · 2026-11-25 15:53 UTC · original
OctoAlgo:fix/code-table-after-instructions → main · +49 −7 · 1 files · 1 commits · open

Fixes #861.

Problem

On an RTX 5090 (GB202), this fork faults at every world entry (Linux, Proton, vkd3d-proton, NVIDIA 620.73.04): NVRM Xid 13, "SM Warp Exception: MMU Fault", shader writes to unmapped GPU addresses. The same build runs clean on an RTX 5070 Ti in the same PC. On other NVIDIA cards the same cause costs video memory instead: Marvisak/VIctory#2143 reports GBs of VRAM reserved on an RTX 5080.

Cause

code_dword (crates/victory-shader/src/emit/lower.rs) turns the program's code, starting at the lowest offset any load or descriptor names, into a constant array. A load at a computed offset names offset 0, so the array is the whole program. In 12 lighting computes reached at world entry, that is 4160–4596 dwords (16.3–18 KiB).

Under vkd3d-proton the array becomes a private one. NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a bigger one into each thread's local memory: 16–18 KB per thread in those 12 shaders. On GB202 this local memory faults.

Change

This is a port of Marvisak/VIctory#2143 by @⁠desplmfao: its two commits squashed into one, with desplmfao kept as the author. The only difference from upstream is the test module's import list.

The table now starts where the instructions end, because the program's constants follow its instructions and a computed load reads them. It keeps the old start if a load at a fixed offset reads below the end. A computed index below the start is clamped like one past the end, as before.

No follow-up change was needed. A 15-minute run logged all 1149 code-table reads in 114 programs:

  • None is a fixed-offset load inside the instructions.
  • Every s_getpc_b64 + literal table base, as the translator computes it, sits at or after the instructions' end.
  • So no real read falls below the new start. The 9 programs whose tables were 3200–4600 dwords now have 154–177 dwords.

Evidence (RTX 5090 + RTX 5070 Ti, one PC)

  • Nsight Aftermath dumps of the 5090 faults always named a shader whose NVIDIA compile uses local memory.
  • Refusing every shader with local memory gave a clean 15-minute run, twice.
  • Refusing only the 12 computes with 16–18 KB of local memory also gave a clean run, so they are the trigger. The other ~1000 shaders with 16–240 B of local memory are fine.
  • A local switch with the same rule (table from the end of the instructions; it also kept a 256 B margin and a cap) gave two clean 15-minute 5090 runs with all shaders on and the world lit. It reached frames 3232 and 3272 with 0 Xid.
    • The executables' local memory, as reported by the driver, no longer reaches 16 KB anywhere (the largest compute uses 128 B, the largest pixel shader 192 B; before: 16–18 KB in 12 executables).
    • An A/B on the 5070 Ti, switch on vs. off, lit alike: mean luminance 0.161 vs. 0.162, and the per-frame difference is within run-to-run noise.
  • This branch on the 5090: clean: full 15 minutes (frame 3059), 0 Xid, lit. The window scene's mean luminance is 0.141, vs. 0.143 with the local switch and 0.003 with the 12 computes refused. Local memory per the driver: at most 128 B (compute) and 192 B (pixel), over 997 compute and 782 pixel executables.

Testing

  • cargo test -p victory-shader --lib (Linux host): 172 passed, 2 ignored, including #2143's the_code_table_starts_after_the_instructions.
  • cargo build --locked --target x86_64-pc-windows-msvc --release -p victory (cross-built with xwin): OK. Also --profile diag --features diagnostics.
  • One 15-minute RTX 5090 run of this branch, built with --profile diag --features diagnostics, with this PC's Linux-only additions on top (not part of this PR): the DXC fallback from #20 and the VICTORY_NO_WATCHDOG loader hook.

Credit for the fix goes to @⁠desplmfao (Marvisak/VIctory#2143).

(Investigated and prepared with an AI coding assistant; all numbers are from runs on this PC.)

🤖 Generated with Claude Code

**@⁠OctoAlgo** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/1006) `OctoAlgo:fix/code-table-after-instructions` → `main` · +49 −7 · 1 files · 1 commits · open Fixes #861. ## Problem On an **RTX 5090 (GB202)**, this fork faults at every world entry (Linux, Proton, vkd3d-proton, NVIDIA 620.73.04): NVRM Xid 13, "SM Warp Exception: MMU Fault", shader writes to unmapped GPU addresses. The same build runs clean on an RTX 5070 Ti in the same PC. On other NVIDIA cards the same cause costs video memory instead: Marvisak/VIctory#2143 reports GBs of VRAM reserved on an RTX 5080. ## Cause `code_dword` (`crates/victory-shader/src/emit/lower.rs`) turns the program's code, starting at the lowest offset any load or descriptor names, into a constant array. A load at a computed offset names offset 0, so the array is the whole program. In 12 lighting computes reached at world entry, that is 4160–4596 dwords (16.3–18 KiB). Under vkd3d-proton the array becomes a private one. NVIDIA's compiler keeps up to 16 KiB of such arrays in constant memory and copies a bigger one into each thread's **local memory**: 16–18 KB per thread in those 12 shaders. On GB202 this local memory faults. ## Change This is a port of Marvisak/VIctory#2143 by @⁠desplmfao: its two commits squashed into one, with desplmfao kept as the author. The only difference from upstream is the test module's import list. The table now starts where the instructions end, because the program's constants follow its instructions and a computed load reads them. It keeps the old start if a load at a fixed offset reads below the end. A computed index below the start is clamped like one past the end, as before. No follow-up change was needed. A 15-minute run logged all 1149 code-table reads in 114 programs: - None is a fixed-offset load inside the instructions. - Every `s_getpc_b64` + literal table base, as the translator computes it, sits at or after the instructions' end. - So no real read falls below the new start. The 9 programs whose tables were 3200–4600 dwords now have 154–177 dwords. ## Evidence (RTX 5090 + RTX 5070 Ti, one PC) - Nsight Aftermath dumps of the 5090 faults always named a shader whose NVIDIA compile uses local memory. - Refusing every shader with local memory gave a clean 15-minute run, twice. - Refusing only the 12 computes with 16–18 KB of local memory also gave a clean run, so they are the trigger. The other ~1000 shaders with 16–240 B of local memory are fine. - A local switch with the same rule (table from the end of the instructions; it also kept a 256 B margin and a cap) gave two clean 15-minute 5090 runs with all shaders on and the world lit. It reached frames 3232 and 3272 with 0 Xid. - The executables' local memory, as reported by the driver, no longer reaches 16 KB anywhere (the largest compute uses 128 B, the largest pixel shader 192 B; before: 16–18 KB in 12 executables). - An A/B on the 5070 Ti, switch on vs. off, lit alike: mean luminance 0.161 vs. 0.162, and the per-frame difference is within run-to-run noise. - **This branch** on the 5090: clean: full 15 minutes (frame 3059), 0 Xid, lit. The window scene's mean luminance is 0.141, vs. 0.143 with the local switch and 0.003 with the 12 computes refused. Local memory per the driver: at most 128 B (compute) and 192 B (pixel), over 997 compute and 782 pixel executables. ## Testing - `cargo test -p victory-shader --lib` (Linux host): 172 passed, 2 ignored, including #2143's `the_code_table_starts_after_the_instructions`. - `cargo build --locked --target x86_64-pc-windows-msvc --release -p victory` (cross-built with xwin): OK. Also `--profile diag --features diagnostics`. - One 15-minute RTX 5090 run of this branch, built with `--profile diag --features diagnostics`, with this PC's Linux-only additions on top (not part of this PR): the DXC fallback from #20 and the `VICTORY_NO_WATCHDOG` loader hook. Credit for the fix goes to @⁠desplmfao (Marvisak/VIctory#2143). (Investigated and prepared with an AI coding assistant; all numbers are from runs on this PC.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:55:42 +00:00
Author
Owner

@⁠Ym1r1710 on GitHub · 2026-11-25 16:04 UTC · original

Ran this on an RTX 5080 16 GB, Windows 11 (native D3D12, not Proton), on top of current main plus a few open PRs.

No faults before or after on this card, so I can't say anything about the Xid itself. What I can say: the picture in the first cell is the same as without it (lit the same, window and walls unchanged), frame time is within run to run noise (~155-170 ms either way), and video memory in use was the same in both runs, 12.4 GB per the memory line. So at least on Windows I don't see the multi-GB reservation from #2143 going away or coming back, it just doesn't show up here.

Keeping it in my build since it removes the 16-18 KB local arrays and costs nothing that I can measure.

**@⁠Ym1r1710** on GitHub · 2026-11-25 16:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/1006#issuecomment-7167568240) Ran this on an RTX 5080 16 GB, Windows 11 (native D3D12, not Proton), on top of current main plus a few open PRs. No faults before or after on this card, so I can't say anything about the Xid itself. What I can say: the picture in the first cell is the same as without it (lit the same, window and walls unchanged), frame time is within run to run noise (~155-170 ms either way), and video memory in use was the same in both runs, 12.4 GB per the memory line. So at least on Windows I don't see the multi-GB reservation from #2143 going away or coming back, it just doesn't show up here. Keeping it in my build since it removes the 16-18 KB local arrays and costs nothing that I can measure.
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-25 16:40 UTC · original · edited 2026-11-25 16:52 UTC

Independent positive result on CachyOS, RTX 5090, NVIDIA 620.73.04 and GE-Proton 11-14, testing the exact change at 4e7af7b013.

Before this change, the immediately preceding build hit Xid 13 at world entry after 131 seconds. With this change, the run lasted 583.74 seconds with no NVIDIA Xid and produced textured in-world characters, floor geometry and lighting for the first time in this investigation. It eventually exited with a title breakpoint (0x80000003), so this is not a claim of complete stability or playable performance. Frame times remained highly variable.

The captured production SPIR-V confirms two private tables shrinking from 18,368 to 632 bytes and from 16,640 to 616 bytes. Each new initializer matches the corresponding old table's trailing data exactly.

Checks: native shader suite 179 passed / 2 ignored; Windows shader suite 225 passed / 1 existing stub-pipeline failure / 3 ignored; diagnostic cross-build and Clippy passed. Restoring the old table-start rule makes the new regression fail.

Context: this is atop existing Linux descriptor/subresource corrections. Runtime is vkd3d-proton cae8353e with local allocator/null-CBV fixes and a patched DXIL converter. Those fixes were also present in the preceding failing run. Normal shaders and default loop limits; watchdog disabled; Vulkan core/synchronization validation enabled. A repeat with the same executable/runtime and validation disabled lasted 534.58 seconds, again rendered world scenes without Xid, then hit the same title breakpoint. Memory/swap-limit and OOM counters remained zero; memory pressure was substantial, but allocation failure is not established as the assertion's cause.

**@⁠ThomasHFWright** on GitHub · 2026-11-25 16:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/1006#issuecomment-7168360845) · edited 2026-11-25 16:52 UTC Independent positive result on CachyOS, RTX 5090, NVIDIA 620.73.04 and GE-Proton 11-14, testing the exact change at 4e7af7b01356417864b935bd1fffc7d0dece266f. Before this change, the immediately preceding build hit Xid 13 at world entry after 131 seconds. With this change, the run lasted 583.74 seconds with **no NVIDIA Xid** and produced textured in-world characters, floor geometry and lighting for the first time in this investigation. It eventually exited with a title breakpoint (0x80000003), so this is not a claim of complete stability or playable performance. Frame times remained highly variable. The captured production SPIR-V confirms two private tables shrinking from 18,368 to 632 bytes and from 16,640 to 616 bytes. Each new initializer matches the corresponding old table's trailing data exactly. Checks: native shader suite 179 passed / 2 ignored; Windows shader suite 225 passed / 1 existing stub-pipeline failure / 3 ignored; diagnostic cross-build and Clippy passed. Restoring the old table-start rule makes the new regression fail. Context: this is atop existing Linux descriptor/subresource corrections. Runtime is vkd3d-proton cae8353e with local allocator/null-CBV fixes and a patched DXIL converter. Those fixes were also present in the preceding failing run. Normal shaders and default loop limits; watchdog disabled; Vulkan core/synchronization validation enabled. A repeat with the same executable/runtime and validation disabled lasted 534.58 seconds, again rendered world scenes without Xid, then hit the same title breakpoint. Memory/swap-limit and OOM counters remained zero; memory pressure was substantial, but allocation failure is not established as the assertion's cause.
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-25 19:02 UTC · original · edited 2026-11-25 19:08 UTC

Incremental asset-free regression on the receiving fork, before attempting another physical-GPU run: c5820acd4fc24a387396dc6ccef051115cbe9813 (#1056) with the exact delta from this PR at 4e7af7b01356417864b935bd1fffc7d0dece266f. The delta applies cleanly. Credit to @⁠desplmfao (Marvisak/VIctory#2143) and @⁠OctoAlgo for the port.

In addition to this PR's table-start helper test, I exercised the actual Lower::code_dword allocation path with a synthetic 4,251-dword instruction prefix, 160 dwords of trailing constants, and controlled CODE resource addresses. No title assets, driver pipeline creation, or GPU dispatch involved.

Case Before With #1006
Computed address (offset 0) base 0, 4,411 dwords base 17,004, 160 dwords
Computed address plus fixed instruction read at byte 4 — base 0, 4,411 dwords

The baseline regression failed at the expected table extent assertion (17,644 bytes vs expected 640). Patched full native cargo test --locked --offline -p victory-shader --lib: 173 passed, 0 failed, 2 ignored, including the upstream test and this additional witness. Rust 1.98.1 on Linux. This tests the emitter's table extent, not driver local-memory allocation or correctness of executed loads. The fixed-read case is deliberately preserved.

The motivation is our separate Linux/Proton DXC integration test on #20. This makes #1006 a candidate for that integration, but it does not establish that the RTX 4060 host hang reported on #20 shares the RTX 5090 Xid mechanism. No new gameplay, FPS or hardware stability claim.

Integration follow-up: this exact #1006 delta also cross-builds cleanly on c5820ac + #830 (951dc00) + #20 (d4a36b1, manifest-only context adaptation). Rust 1.98.1, locked/offline GNU/LLVM Windows diagnostics release. On a separately linked victory-gpu --lib test executable from the integrated tree, the strict production argument-clamp witness still behaves as expected under GE-Proton11-14 / llvmpipe 26.3.1: with the Wine builtin compiler forced and no DXC DLLs, actual FL11_0 device creation succeeds but clamp construction fails (0x8007007E, test exit 101); with DXC DLLs, the production root signature and PSO are created (1 passed, exit 0). Separate copies of the same software-only prefix, identical test executable; no physical GPU or title files exposed. This is integration compatibility evidence only. Marvisak/VIctory#144 and #2723 describe another converter/handle-typing problem that still deserves separate testing before a physical NVIDIA run.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High)

**@⁠ArturoWolff** on GitHub · 2026-11-25 19:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/1006#issuecomment-7171742284) · edited 2026-11-25 19:08 UTC Incremental asset-free regression on the receiving fork, before attempting another physical-GPU run: `c5820acd4fc24a387396dc6ccef051115cbe9813` (#1056) with the exact delta from this PR at `4e7af7b01356417864b935bd1fffc7d0dece266f`. The delta applies cleanly. Credit to @⁠desplmfao (Marvisak/VIctory#2143) and @⁠OctoAlgo for the port. In addition to this PR's table-start helper test, I exercised the actual `Lower::code_dword` allocation path with a synthetic 4,251-dword instruction prefix, 160 dwords of trailing constants, and controlled CODE resource addresses. No title assets, driver pipeline creation, or GPU dispatch involved. | Case | Before | With #1006 | |---|---:|---:| | Computed address (offset 0) | base 0, 4,411 dwords | base 17,004, 160 dwords | | Computed address plus fixed instruction read at byte 4 | — | base 0, 4,411 dwords | The baseline regression failed at the expected table extent assertion (17,644 bytes vs expected 640). Patched full native `cargo test --locked --offline -p victory-shader --lib`: **173 passed, 0 failed, 2 ignored**, including the upstream test and this additional witness. Rust 1.98.1 on Linux. This tests the emitter's table extent, not driver local-memory allocation or correctness of executed loads. The fixed-read case is deliberately preserved. The motivation is our separate Linux/Proton DXC integration [test on #20](https://git.gtahub.st/github/fxceless--victory-fork/pulls/20). This makes #1006 a candidate for that integration, but it does not establish that the RTX 4060 host hang reported on #20 shares the RTX 5090 Xid mechanism. No new gameplay, FPS or hardware stability claim. **Integration follow-up:** this exact #1006 delta also cross-builds cleanly on `c5820ac` + #830 (`951dc00`) + #20 (`d4a36b1`, manifest-only context adaptation). Rust 1.98.1, locked/offline GNU/LLVM Windows diagnostics release. On a separately linked `victory-gpu --lib` test executable from the integrated tree, the strict production argument-clamp witness still behaves as expected under GE-Proton11-14 / llvmpipe 26.3.1: with the Wine builtin compiler forced and no DXC DLLs, actual FL11_0 device creation succeeds but clamp construction fails (`0x8007007E`, test exit 101); with DXC DLLs, the production root signature and PSO are created (1 passed, exit 0). Separate copies of the same software-only prefix, identical test executable; no physical GPU or title files exposed. This is integration compatibility evidence only. Marvisak/VIctory#144 and #2723 describe another converter/handle-typing problem that still deserves separate testing before a physical NVIDIA run. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol High)
Author
Owner

@⁠tylerstraub on GitHub · 2026-11-26 06:55 UTC · original

Confirming on a second RTX 5090, on a different fork (trustno1-coder/VIctory-NVIDIA, 0a43566 line), Linux/Proton Experimental, NVIDIA 595.99.02: without this change the world entry hung every time, showing as Xid 109 only rather than Xid 13. With a hand port of this fix plus VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains, there were no GPU errors through 20+ minutes of gameplay. (Applied together, not yet A/B'd.)

**@⁠tylerstraub** on GitHub · 2026-11-26 06:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/1006#issuecomment-7184922701) Confirming on a second RTX 5090, on a different fork (trustno1-coder/VIctory-NVIDIA, 0a43566 line), Linux/Proton Experimental, NVIDIA 595.99.02: without this change the world entry hung every time, showing as **Xid 109 only** rather than Xid 13. With a hand port of this fix plus `VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains`, there were no GPU errors through 20+ minutes of gameplay. (Applied together, not yet A/B'd.)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1006/head:github-bot/gh-1006'
git switch 'github-bot/gh-1006'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1006'
git switch 'github-bot/gh-1006'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1006'
git switch 'github-bot/gh-1006'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1006'
git switch 'main'
git merge --squash 'github-bot/gh-1006'
git switch 'main'
git merge --ff-only 'github-bot/gh-1006'
git switch 'main'
git merge 'github-bot/gh-1006'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.