Shaders: keep buffer offsets below 2 GiB (NVIDIA + vkd3d-proton world device loss) #542

Open
github-bot wants to merge 2 commits from github-bot/gh-542 into main AGit
Owner

@⁠gingertonik on GitHub · 2026-11-24 04:41 UTC · original
gingertonik:fix/oob-buffer-bounds → main · +484 −34 · 2 files · 2 commits · open

What

Translated buffer loads, stores and atomics are kept below 2 GiB, so 32-bit offset arithmetic cannot wrap past 4 GiB:

  • raw buffers: offset < 0x7FFF_FFC0
  • structured buffers: index < 0x7000_0000 / stride and offset < 0x0FFF_FFE0
  • typed buffers: index < 0x1000_0000

An out-of-range load reads at 0 and its result is replaced by 0. An out-of-range store or atomic is skipped (the bound is folded into the existing lane guard). Two commits: synthetic GPU tests first, then the fix.

Why

Under Wine + vkd3d-proton on NVIDIA, every world run here lost the device 20-75 s in (Xid 13 MMU fault, then Xid 109). vkd3d-proton's fault report (VKD3D_CONFIG=fault) gave a ReadInvalid address equal to the host address of one 90 MiB title buffer plus exactly 0x1_0000_0000 in 9 of 9 runs that logged host addresses.

The tests in this PR reproduce that shape with no game data: a four-word raw load at byte offset 0xFFFFFFFC (index -1 times 4). dxil-spirv lowers it to OpRawAccessChainNV ... RobustnessPerComponentNV and a 16-byte OpLoad. Component 0 is out of range. Component 1's offset wraps to 0 in 32 bits and passes the check, and the load faults 4 GiB above the buffer. The console's buffer descriptors bound such a read. Structured loads where index * stride reaches 2^32 do not fault but return element 0 where 0 is correct.

We did not isolate the game shader or its runtime offset; the link to the game is the fault address shape plus the two A/B runs below.

Workaround with no code change, for NVIDIA under Proton: VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains.

Tested

RTX 4080 16 GB, driver 620.73.04, Linux 7.3.5, Proton Experimental's vkd3d-proton (2576c0b4a). Unattended runs, scripted input, no network.

Synthetic tests (emit::valu_tests::oob_*, one process per test):

Test Tests commit alone With the fix
oob_raw_dword_high_offsets pass pass
oob_raw_dwordx4_at_0xfffffffc device lost, Xid 31 MMU fault at 0x1_0bd00000 pass
oob_structured_stride4_at_0x40000000 fail: returns element 0 pass
oob_structured_stride16_at_0x10000000 fail: returns element 0 pass
oob_structured_stride32_at_0x08000000 fail: returns element 0 pass
oob_raw_store_does_not_corrupt_element_zero not run (added with the fix) pass

In the game, opening cutscene, d2a4bae + #177 as the base:

Build vkd3d-proton Time in the world Result
base, and diagnostic variants of it stock 20-75 s device lost in every run (about 10)
base VK_NV_raw_access_chains disabled 6 min 11 s, ended by timeout no device loss, 0 Xid (1 run)
base + this PR stock 9 min no device loss, 0 Xid (1 run)

The run with this PR ended on the title's own breakpoint (0x80000003), not on the GPU. The scene is still dark.

Gates: cargo test -p victory-shader --lib 56 passed; rustfmt --check clean on both files; clippy adds no warnings; cargo xtask policy: asset policy: 151 files ok.

Not tested: Windows (any vendor), AMD, Intel, WARP. Typed buffers on NVIDIA (their bound is defensive). Frame-time cost: each load gains a compare and a select, each store a branch; no controlled A/B was run.

Limits: this is a cannot-wrap guard, not a per-view length check. Below 2 GiB it relies on the host view's own bounds, which the single-word test shows working on this driver for a heap view. A root SRV has no view length (#493 covers that case).

AI-assisted (Hermes): the +4 GiB match, the tests and the fix were produced by AI agents under my direction; I ran everything above on my hardware.

**@⁠gingertonik** on GitHub · 2026-11-24 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/542) `gingertonik:fix/oob-buffer-bounds` → `main` · +484 −34 · 2 files · 2 commits · open ## What Translated buffer loads, stores and atomics are kept below 2 GiB, so 32-bit offset arithmetic cannot wrap past 4 GiB: - raw buffers: `offset < 0x7FFF_FFC0` - structured buffers: `index < 0x7000_0000 / stride` and `offset < 0x0FFF_FFE0` - typed buffers: `index < 0x1000_0000` An out-of-range load reads at 0 and its result is replaced by 0. An out-of-range store or atomic is skipped (the bound is folded into the existing lane guard). Two commits: synthetic GPU tests first, then the fix. ## Why Under Wine + vkd3d-proton on NVIDIA, every world run here lost the device 20-75 s in (Xid 13 MMU fault, then Xid 109). vkd3d-proton's fault report (`VKD3D_CONFIG=fault`) gave a `ReadInvalid` address equal to the host address of one 90 MiB title buffer **plus exactly `0x1_0000_0000`** in 9 of 9 runs that logged host addresses. The tests in this PR reproduce that shape with no game data: a four-word raw load at byte offset `0xFFFFFFFC` (index -1 times 4). dxil-spirv lowers it to `OpRawAccessChainNV ... RobustnessPerComponentNV` and a 16-byte `OpLoad`. Component 0 is out of range. Component 1's offset wraps to 0 in 32 bits and passes the check, and the load faults 4 GiB above the buffer. The console's buffer descriptors bound such a read. Structured loads where `index * stride` reaches 2^32 do not fault but return element 0 where 0 is correct. We did not isolate the game shader or its runtime offset; the link to the game is the fault address shape plus the two A/B runs below. **Workaround with no code change**, for NVIDIA under Proton: `VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains`. ## Tested RTX 4080 16 GB, driver 620.73.04, Linux 7.3.5, Proton Experimental's vkd3d-proton (2576c0b4a). Unattended runs, scripted input, no network. Synthetic tests (`emit::valu_tests::oob_*`, one process per test): | Test | Tests commit alone | With the fix | | --- | --- | --- | | `oob_raw_dword_high_offsets` | pass | pass | | `oob_raw_dwordx4_at_0xfffffffc` | **device lost**, Xid 31 MMU fault at `0x1_0bd00000` | pass | | `oob_structured_stride4_at_0x40000000` | fail: returns element 0 | pass | | `oob_structured_stride16_at_0x10000000` | fail: returns element 0 | pass | | `oob_structured_stride32_at_0x08000000` | fail: returns element 0 | pass | | `oob_raw_store_does_not_corrupt_element_zero` | not run (added with the fix) | pass | In the game, opening cutscene, `d2a4bae` + #177 as the base: | Build | vkd3d-proton | Time in the world | Result | | --- | --- | --- | --- | | base, and diagnostic variants of it | stock | 20-75 s | device lost in every run (about 10) | | base | `VK_NV_raw_access_chains` disabled | 6 min 11 s, ended by timeout | no device loss, 0 Xid (1 run) | | base + this PR | stock | 9 min | no device loss, 0 Xid (1 run) | The run with this PR ended on the title's own breakpoint (`0x80000003`), not on the GPU. The scene is still dark. Gates: `cargo test -p victory-shader --lib` 56 passed; `rustfmt --check` clean on both files; clippy adds no warnings; `cargo xtask policy`: `asset policy: 151 files ok`. **Not tested:** Windows (any vendor), AMD, Intel, WARP. Typed buffers on NVIDIA (their bound is defensive). Frame-time cost: each load gains a compare and a select, each store a branch; no controlled A/B was run. **Limits:** this is a cannot-wrap guard, not a per-view length check. Below 2 GiB it relies on the host view's own bounds, which the single-word test shows working on this driver for a heap view. A root SRV has no view length (#493 covers that case). AI-assisted (Hermes): the +4 GiB match, the tests and the fix were produced by AI agents under my direction; I ran everything above on my hardware.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:45 +00:00
Author
Owner

@⁠desplmfao on GitHub · 2026-11-24 04:58 UTC · original

Another NVIDIA / Linux data point, with the workaround only (no code change), in case it helps place this next to #493.

RTX 5080, driver 615.71.09, CachyOS, proton-cachyos (vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of main d2a4bae + #185, #436, #462, #440, #259, #177, #151, story mode by VICTORY_KEYS, no other input.

build Xid 109 (CTX SWITCH TIMEOUT), then the title's crash at +0x23cf683
as above 4 of 5 runs, 3.5–5.3 min after start
as above, VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains (vkd3d confirmed Extension "VK_NV_raw_access_chains" is disabled.) 1 of 1 run, 6.5 min after start
with #493 (+#336) added, extension enabled 0 of 4 runs, 7.5–10 min each

So on this card the hang I see is the one #493 removes, and disabling raw access chains alone did not stop it. That does not say anything against the fault this PR's synthetic tests show; it may just not be what ends these runs here, or both may be present. I did not run with VKD3D_CONFIG=fault, so I cannot tell whether a +0x1_0000_0000 read happened.

AI-assisted (Claude Code); numbers from the runs' logs and the kernel log.

**@⁠desplmfao** on GitHub · 2026-11-24 04:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7122501236) Another NVIDIA / Linux data point, with the workaround only (no code change), in case it helps place this next to #493. RTX 5080, driver 615.71.09, CachyOS, proton-cachyos (vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build of `main` `d2a4bae` + #185, #436, #462, #440, #259, #177, #151, story mode by `VICTORY_KEYS`, no other input. | build | `Xid 109` (CTX SWITCH TIMEOUT), then the title's crash at `+0x23cf683` | |---|---| | as above | 4 of 5 runs, 3.5–5.3 min after start | | as above, `VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains` (vkd3d confirmed `Extension "VK_NV_raw_access_chains" is disabled.`) | 1 of 1 run, 6.5 min after start | | with #493 (+#336) added, extension enabled | 0 of 4 runs, 7.5–10 min each | So on this card the hang I see is the one #493 removes, and disabling raw access chains alone did not stop it. That does not say anything against the fault this PR's synthetic tests show; it may just not be what ends these runs here, or both may be present. I did not run with `VKD3D_CONFIG=fault`, so I cannot tell whether a `+0x1_0000_0000` read happened. AI-assisted (Claude Code); numbers from the runs' logs and the kernel log.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 05:11 UTC · original

Tested 31a4692 on main d2a4bae, native Windows 11, RTX 4070 SUPER (driver 621.24), rustc 1.98.1.

  • cargo test --workspace --locked: 270 passed, 0 failed, 4 ignored (main: 264 / 0 / 4). No new clippy warnings; cargo xtask policy ok. The oob_* tests pass 6/6 on the hardware device and with VICTORY_WARP=1.
  • Tests commit d033e6c alone (fix reverted, one process per test): oob_raw_dword_high_offsets, oob_raw_dwordx4_at_0xfffffffc and the raw store pass on the 4070 SUPER with no device loss, while oob_structured_stride{4,16,32} fail by returning element 0, and WARP does the same for stride 4. So on native D3D12 the +4 GiB fault looks like a vkd3d-proton-only path, while the structured wrap is vendor-neutral and this PR fixes it.
  • valu_tests.rs:821,1004: Host::new(false).expect(...) panics on machines without an SM 6.6 GPU, where run_cases skips. lower.rs:1798 also zeroes in-range elements between 1.75 and 2 GiB. Conflicts with #437 / #136 in the SRV scalar-load path.

No game data used.

AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

**@⁠QemmHD** on GitHub · 2026-11-24 05:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7122709907) Tested `31a4692` on `main` `d2a4bae`, native Windows 11, RTX 4070 SUPER (driver 621.24), rustc 1.98.1. - `cargo test --workspace --locked`: 270 passed, 0 failed, 4 ignored (main: 264 / 0 / 4). No new clippy warnings; `cargo xtask policy` ok. The `oob_*` tests pass 6/6 on the hardware device and with `VICTORY_WARP=1`. - Tests commit `d033e6c` alone (fix reverted, one process per test): `oob_raw_dword_high_offsets`, `oob_raw_dwordx4_at_0xfffffffc` and the raw store pass on the 4070 SUPER with no device loss, while `oob_structured_stride{4,16,32}` fail by returning element 0, and WARP does the same for stride 4. So on native D3D12 the +4 GiB fault looks like a vkd3d-proton-only path, while the structured wrap is vendor-neutral and this PR fixes it. - `valu_tests.rs:821,1004`: `Host::new(false).expect(...)` panics on machines without an SM 6.6 GPU, where `run_cases` skips. `lower.rs:1798` also zeroes in-range elements between 1.75 and 2 GiB. Conflicts with #437 / #136 in the SRV scalar-load path. No game data used. AI-assisted (Claude Code, Claude Opus 5.5). Discord: bigpeppa.
Author
Owner

@⁠KoLolX3 on GitHub · 2026-11-24 05:33 UTC · original

Check on Linux, not Windows: pass. Head 31a4692a1 merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 92 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 6, of which 0 ran in the native run (the pass count rose by 0); the other 6 are in code this run does not execute (cfg(windows) modules, the victory-gpu and victory-hle crates, or ignored tests), and were not run.
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

**@⁠KoLolX3** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7123061269) Check on Linux, not Windows: **pass**. Head `31a4692a1` merged onto `main` `d2a4bae1f` (clean merge). - Native tests of the seven crates that build on Linux (`core`, `formats`, `game`, `loader`, `pe`, `pipeline`, `shader`): PR `92 passed, 7 failed`, `main` `92 passed, 7 failed`. - Windows cross type-check of the whole workspace (`cargo xwin check --workspace --target x86_64-pc-windows-msvc`, covers `victory-gpu`, `victory-hle` and the app): PR ok, `main` ok. - Tests this PR adds: 6, of which 0 ran in the native run (the pass count rose by 0); the other 6 are in code this run does not execute (`cfg(windows)` modules, the `victory-gpu` and `victory-hle` crates, or ignored tests), and were **not run**. - rustfmt: unformatted hunks, PR 168, `main` 168. - Failing on `main` here as well (not this PR): 7 tests in `victory-loader` and `victory-pe` that parse their own test binary as a PE image, which is an ELF file on Linux. - Not run: `victory-gpu` / `victory-hle` tests and the game itself. On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.
Author
Owner

@⁠desplmfao on GitHub · 2026-11-24 10:42 UTC · original

Tested this PR's code (not just the extension workaround) on an RTX 5080 under Linux: AMD Ryzen 9 9950X3D, CachyOS, proton-cachyos 11.0 with vkd3d-proton and the wineserver view-tree patch from #340, title 1.0.2.1. The stack was Marvisak/VIctory#185 merged with current main (aycow/VIctory#4) plus #493, #489, #178, #638, #259, #177, #151, with VICTORY_SHADER_LOOP_LIMIT=256. In that stack, with #493 but without this PR and with nothing skipped, 4 of 8 runs hung on Xid 109 (CTX SWITCH TIMEOUT) between 10 s and 2 minutes into the world, followed by +0x23cf683; the other 4 ran 3 to 6 minutes clean. With this PR added, 2 of 2 runs reached the first prologue mission and stayed there for 3.5 and 3.75 minutes, with no Xid and no device loss, until I closed them. With a hang rate of about half before, two clean runs are encouraging but not proof, so I'll keep running with it. I saw no Xid 13 in the kernel log before those earlier hangs, only Xid 109, so on this machine the stall shows as a context-switch timeout rather than an MMU fault. The conflict with this PR on top of that stack was test-only (valu_tests.rs).

AI-assisted (Claude Code).

**@⁠desplmfao** on GitHub · 2026-11-24 10:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7129133014) Tested this PR's code (not just the extension workaround) on an RTX 5080 under Linux: AMD Ryzen 9 9950X3D, CachyOS, proton-cachyos 11.0 with vkd3d-proton and the `wineserver` view-tree patch from #340, title 1.0.2.1. The stack was Marvisak/VIctory#185 merged with current `main` (aycow/VIctory#4) plus #493, #489, #178, #638, #259, #177, #151, with `VICTORY_SHADER_LOOP_LIMIT=256`. In that stack, with #493 but without this PR and with nothing skipped, 4 of 8 runs hung on `Xid 109` (CTX SWITCH TIMEOUT) between 10 s and 2 minutes into the world, followed by `+0x23cf683`; the other 4 ran 3 to 6 minutes clean. With this PR added, 2 of 2 runs reached the first prologue mission and stayed there for 3.5 and 3.75 minutes, with no `Xid` and no device loss, until I closed them. With a hang rate of about half before, two clean runs are encouraging but not proof, so I'll keep running with it. I saw no `Xid 13` in the kernel log before those earlier hangs, only `Xid 109`, so on this machine the stall shows as a context-switch timeout rather than an MMU fault. The conflict with this PR on top of that stack was test-only (`valu_tests.rs`). AI-assisted (Claude Code).
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 10:54 UTC · original

Corpus run on the full retail shader pack (26,503 containers), Windows 11, AMD RX 9070 (Adrenalin), dxil.dll from SDK 10.0.26100. This PR conflicts with current main, so it was built at its own base (main before #612; there translate --validate --pipelines completes, with VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).

  • victory translate shaders.rpf --validate --pipelines crashes with an access violation (exit code 0xC0000005) right after loading the validator, with no Rust panic message. It reproduced twice, on two separate builds.
  • victory translate shaders.rpf --validate --jobs 1 (no host pipelines) completes, with counts identical to its base (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).

So one of the modules this PR emits seems to crash the host pipeline path (the driver or our D3D12 calls) on AMD, even though it does not change the translation counts. I have not isolated the module yet (--jobs 1 --pipelines would narrow it down).

**@⁠slint6614-dev** on GitHub · 2026-11-24 10:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7129412520) Corpus run on the full retail shader pack (26,503 containers), Windows 11, AMD RX 9070 (Adrenalin), dxil.dll from SDK 10.0.26100. This PR conflicts with current main, so it was built at its own base (main before #612; there `translate --validate --pipelines` completes, with VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129). - `victory translate shaders.rpf --validate --pipelines` **crashes with an access violation (exit code 0xC0000005)** right after loading the validator, with no Rust panic message. It reproduced twice, on two separate builds. - `victory translate shaders.rpf --validate --jobs 1` (no host pipelines) completes, with counts identical to its base (VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129). So one of the modules this PR emits seems to crash the host pipeline path (the driver or our D3D12 calls) on AMD, even though it does not change the translation counts. I have not isolated the module yet (`--jobs 1 --pipelines` would narrow it down).
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-24 20:08 UTC · original

For reference: the test helper this adds (lower_compute_oob in valu_tests.rs) calls resource::track with three arguments, but main takes the structured program as a fourth one since 6638098 (see #801), and its HostShader literal needs root_uavs once #1077 is in. It also overlaps the stack's raw-view branch in lower.rs (#1015, #1055): the bound applies to the SRV, UAV and heap-buffer cases there. All three are handled in #1632. AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-24 20:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7143090596) For reference: the test helper this adds (`lower_compute_oob` in `valu_tests.rs`) calls `resource::track` with three arguments, but `main` takes the structured program as a fourth one since `6638098` (see #801), and its `HostShader` literal needs `root_uavs` once #1077 is in. It also overlaps the stack's raw-view branch in `lower.rs` (#1015, #1055): the bound applies to the SRV, UAV and heap-buffer cases there. All three are handled in #1632. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:24 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/542#issuecomment-7148479233) <!-- victory-triage v1 head=31a4692a1581a4ed20d33cd22b5164a0ce240ce8 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-542'
git switch 'github-bot/gh-542'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-542'
git switch 'github-bot/gh-542'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-542'
git switch 'main'
git merge --squash 'github-bot/gh-542'
git switch 'main'
git merge --ff-only 'github-bot/gh-542'
git switch 'main'
git merge 'github-bot/gh-542'
git push origin 'main'
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/Marvisak--VIctory!542
No description provided.