Skip to content

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

Open
gingertonik wants to merge 2 commits into
Marvisak:mainfrom
gingertonik:fix/oob-buffer-bounds
Open

gingertonik wants to merge 2 commits into
Marvisak:mainfrom
gingertonik:fix/oob-buffer-bounds

Conversation

@gingertonik

Copy link
Copy Markdown

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.

@desplmfao

Copy link
Copy Markdown
Contributor

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.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

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 Shaders: preserve raw scalar buffer loads on NVIDIA #437 / Shaders: s_buffer descriptor reads, signature/PSV0 fixes, gather4_l, a16 samples (+479 VS/PS, +200 mesh validated) #136 in the SRV scalar-load path.

No game data used.

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

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Windows 11 D3D12 (WARP):

  • All 75 tests in \�ictory-shader\ pass, specifically confirming the 6 new \oob_*\ tests on Windows:
    • \oob_raw_store_does_not_corrupt_element_zero\ (ok)
    • \oob_structured_stride16_at_0x10000000\ (ok)
    • \oob_structured_stride4_at_0x40000000\ (ok)
    • \oob_raw_dwordx4_at_0xfffffffc\ (ok)
    • \oob_structured_stride32_at_0x08000000\ (ok)
    • \oob_raw_dword_high_offsets\ (ok)
  • \cargo clippy -p victory-shader -- -D warnings\ is completely clean.
  • \cargo xtask policy\ passes (151 files checked, zero violations).

@KoLolX3

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@desplmfao

desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 #185 merged with current main (aycow#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).

@slint6614-dev

Copy link
Copy Markdown

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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-merge with current main (ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touched lower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.

@MamaLeVrai

Copy link
Copy Markdown

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.

x3ero0 added a commit to x3ero0/VIctory that referenced this pull request Nov 24, 2026
…stalls

Host::execute waited for each submission with no end. A host that loses
its device need not signal the fences of the work it dropped:
vkd3d-proton after a GPU fault does not, and by default does not report
the device removed either. The title's submit thread then stays in our
wait, its render thread blocks on its full submission ring, and 30 s
later the title's own watchdog ends the run at image+0x23cf683 (Marvisak#1118),
with nothing of ours in crashes.log to say that the GPU faulted.

The wait now goes in 250 ms slices:

* between slices the device is asked whether it was removed; if so the
  wait ends and the existing check after the submission reports it;
* a submission still running is said so at 10 s and 20 s;
* at 25 s it is given up with a report of its own ("has not finished a
  submission ... and reports no removal"). The limit is below the
  title's 30 s so the run ends with the cause, not with the title's
  null write. vkd3d-proton's own source calls a wait of over 5 s a lost
  device; Windows resets a device after about 2 s.

A fence that comes is taken as before; a device that is removed and
signals (Windows) is reported by the check after the wait, as before.

Tested on Linux only (RTX 5080, driver 620.70, GE-Proton11-6's Wine,
vkd3d-proton 30b0eb9), on main + Marvisak#177 + Marvisak#259, where the world faults the
GPU in every run (Xid 13, fixed by Marvisak#542):
* without this, with or without VKD3D_CONFIG=fault: the title's crash at
  +0x23cf683 24 to 30 s after the Xid, in 9 of 9 runs, and no report;
* with this and VKD3D_CONFIG=fault: "device removed: 0x887A0005" 4 s
  after the Xid;
* with this and vkd3d-proton's defaults: the two warnings, then the
  stall report 25 s after the submission began.
New unit test of the wait (no GPU); cargo test --workspace under Proton:
333 passed, the same ten environmental failures as main; clippy
-D warnings with and without --all-features; cargo xtask policy. Not run
on Windows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner

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

x3ero0 added a commit to x3ero0/VIctory that referenced this pull request Nov 25, 2026
…stalls

Host::execute waited for each submission with no end. A host that loses
its device need not signal the fences of the work it dropped:
vkd3d-proton after a GPU fault does not, and by default does not report
the device removed either. The title's submit thread then stays in our
wait, its render thread blocks on its full submission ring, and 30 s
later the title's own watchdog ends the run at image+0x23cf683 (Marvisak#1118),
with nothing of ours in crashes.log to say that the GPU faulted.

The wait now goes in 250 ms slices:

* between slices the device is asked whether it was removed; if so the
  wait ends and the existing check after the submission reports it;
* a submission still running is said so at 10 s and 20 s;
* at 25 s it is given up with a report of its own ("has not finished a
  submission ... and reports no removal"). The limit is below the
  title's 30 s so the run ends with the cause, not with the title's
  null write. vkd3d-proton's own source calls a wait of over 5 s a lost
  device; Windows resets a device after about 2 s.

A fence that comes is taken as before; a device that is removed and
signals (Windows) is reported by the check after the wait, as before.

Tested on Linux only (RTX 5080, driver 620.70, GE-Proton11-6's Wine,
vkd3d-proton 30b0eb9), on main + Marvisak#177 + Marvisak#259, where the world faults the
GPU in every run (Xid 13, fixed by Marvisak#542):
* without this, with or without VKD3D_CONFIG=fault: the title's crash at
  +0x23cf683 24 to 30 s after the Xid, in 9 of 9 runs, and no report;
* with this and VKD3D_CONFIG=fault: "device removed: 0x887A0005" 4 s
  after the Xid;
* with this and vkd3d-proton's defaults: the two warnings, then the
  stall report 25 s after the submission began.
New unit test of the wait (no GPU); cargo test --workspace under Proton:
333 passed, the same ten environmental failures as main; clippy
-D warnings with and without --all-features; cargo xtask policy. Not run
on Windows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ThatMaddLadd added a commit to ThatMaddLadd/VIctory that referenced this pull request Nov 25, 2026
Upstream superseded Marvisak#635 and Marvisak#568 (reverted just before this merge); Marvisak#189,
Marvisak#334, Marvisak#437, Marvisak#542, Marvisak#587 and Marvisak#1529 are still open upstream and are kept.

Resolutions:
- emit::Options is upstream's struct with Marvisak#189's `wave64` added;
  TranslateOptions stays as its alias. lower::Parts carries both `options`
  and upstream's `view_marks`.
- Shader cache: upstream's cached refusals and hit flag, keyed by Marvisak#189's
  Wave64 mode byte as before.
- lower.rs: Marvisak#542's 2 GiB bound applies to raw and structured views; title
  memory (upstream's MEMORY path and root views read as memory) is not
  bounded again, being checked where it is looked up. Scalar loads take
  upstream's raw views plus Marvisak#437's UAVs. The descriptor-kind use keeps
  Marvisak#437's preference for image/vector uses inside upstream's fallback.
  image() is upstream's (its own a16 bias/compare, gather4_l and _cl
  grads), replacing Marvisak#437's parallel version.
- Marvisak#189: AddH (upstream's f16 wave sum) in apply_wave_op; 16-bit
  reductions are refused in an emulated 64-lane wave. mask_dword checks
  Marvisak#189's deferred ballot errors before upstream's mask_number.
- Marvisak#334: indirect arguments keep the per-list buffer states (no
  indirect::done); upstream's single-group clamp dispatch is taken, and
  its diagnostics readback copies from the read state without barriers.
- GPU adapter: upstream still creates its device on the default adapter,
  so host_adapter() stays. The shader test host keeps the high-performance
  adapter pick and adds upstream's dedicated-memory requirement.
- Marvisak#1529: gameinput.rs as the PR's own merge of main (scripted keys first,
  then keyboard and mouse); run.rs configures controls and FidelityFX.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants