Shaders: keep buffer offsets below 2 GiB (NVIDIA + vkd3d-proton world device loss) #542
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!542
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-542"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@gingertonik on GitHub · 2026-11-24 04:41 UTC · original
gingertonik:fix/oob-buffer-bounds→main· +484 −34 · 2 files · 2 commits · openWhat
Translated buffer loads, stores and atomics are kept below 2 GiB, so 32-bit offset arithmetic cannot wrap past 4 GiB:
offset < 0x7FFF_FFC0index < 0x7000_0000 / strideandoffset < 0x0FFF_FFE0index < 0x1000_0000An 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 aReadInvalidaddress equal to the host address of one 90 MiB title buffer plus exactly0x1_0000_0000in 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 toOpRawAccessChainNV ... RobustnessPerComponentNVand a 16-byteOpLoad. 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 whereindex * stridereaches 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):oob_raw_dword_high_offsetsoob_raw_dwordx4_at_0xfffffffc0x1_0bd00000oob_structured_stride4_at_0x40000000oob_structured_stride16_at_0x10000000oob_structured_stride32_at_0x08000000oob_raw_store_does_not_corrupt_element_zeroIn the game, opening cutscene,
d2a4bae+ #177 as the base:VK_NV_raw_access_chainsdisabledThe 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 --lib56 passed;rustfmt --checkclean 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 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
maind2a4bae+ #185, #436, #462, #440, #259, #177, #151, story mode byVICTORY_KEYS, no other input.Xid 109(CTX SWITCH TIMEOUT), then the title's crash at+0x23cf683VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains(vkd3d confirmedExtension "VK_NV_raw_access_chains" is disabled.)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_0000read happened.AI-assisted (Claude Code); numbers from the runs' logs and the kernel log.
@QemmHD on GitHub · 2026-11-24 05:11 UTC · original
Tested
31a4692onmaind2a4bae, 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 policyok. Theoob_*tests pass 6/6 on the hardware device and withVICTORY_WARP=1.d033e6calone (fix reverted, one process per test):oob_raw_dword_high_offsets,oob_raw_dwordx4_at_0xfffffffcand the raw store pass on the 4070 SUPER with no device loss, whileoob_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, whererun_casesskips.lower.rs:1798also 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.
@KoLolX3 on GitHub · 2026-11-24 05:33 UTC · original
Check on Linux, not Windows: pass. Head
31a4692a1merged ontomaind2a4bae1f(clean merge).core,formats,game,loader,pe,pipeline,shader): PR92 passed, 7 failed,main92 passed, 7 failed.cargo xwin check --workspace --target x86_64-pc-windows-msvc, coversvictory-gpu,victory-hleand the app): PR ok,mainok.cfg(windows)modules, thevictory-gpuandvictory-hlecrates, or ignored tests), and were not run.main168.mainhere as well (not this PR): 7 tests invictory-loaderandvictory-pethat parse their own test binary as a PE image, which is an ELF file on Linux.victory-gpu/victory-hletests 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 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
wineserverview-tree patch from #340, title 1.0.2.1. The stack was Marvisak/VIctory#185 merged with currentmain(aycow/VIctory#4) plus #493, #489, #178, #638, #259, #177, #151, withVICTORY_SHADER_LOOP_LIMIT=256. In that stack, with #493 but without this PR and with nothing skipped, 4 of 8 runs hung onXid 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 noXidand 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 noXid 13in the kernel log before those earlier hangs, onlyXid 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 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 --pipelinescompletes, with VS/PS 12272 / 12172, CS 1693 / 1670, MS 8191 / 8129).victory translate shaders.rpf --validate --pipelinescrashes 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 --pipelineswould narrow it down).@MamaLeVrai on GitHub · 2026-11-24 20:08 UTC · original
For reference: the test helper this adds (
lower_compute_oobinvalu_tests.rs) callsresource::trackwith three arguments, butmaintakes the structured program as a fourth one since6638098(see #801), and itsHostShaderliteral needsroot_uavsonce #1077 is in. It also overlaps the stack's raw-view branch inlower.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.@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
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.Merge
Merge the changes and update on Forgejo.