Skip to content

Shaders: key heap handles by element type (atomic on a float-read UAV) - #177

Open
Ortomanic wants to merge 2 commits into
Marvisak:mainfrom
Ortomanic:pr/shader-handle-element-type
Open

Ortomanic wants to merge 2 commits into
Marvisak:mainfrom
Ortomanic:pr/shader-handle-element-type

Conversation

@Ortomanic

Copy link
Copy Markdown

What

handle() in emit/lower.rs cached heap handles by (block, load, first, sampler, props.0). When a program reads a texture UAV as float and uses it atomically, both annotations share props.0 (RWTexture2D), so the atomic got the cached float handle. dxil-spirv then emits OpAtomicOr %float on a float texel pointer, which is invalid SPIR-V (spirv-val: "AtomicOr: expected Result Type to be integer scalar type").

On NVIDIA (RTX 5080, driver 620.73, vkd3d-proton under Wine) the driver's compiler crashes in vkCreateComputePipelines on that SPIR-V as GTA VI enters its world (programs c12c1f7296419a5b, 8358f9eef7931421).

Change

The element type (props.1) is part of the cache key, so the atomic gets its own u32 handle as the texture-atomics note in emit/mod.rs intends.

Testing

  • cargo test -p victory-shader: 56 passed.
  • Dumped every SPIR-V vkd3d-proton produced in a world run (VKD3D_SHADER_DUMP_PATH) and ran spirv-val --target-env vulkan1.3: 2 invalid before, 0 after.
  • World runs on RTX 5080 / Wine 11.22: the vkCreateComputePipelines driver crash no longer occurs (it reproduced in 3 of 3 runs before).

@DaviTostes

Copy link
Copy Markdown

Tested e55eb69 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 56 passed, 0 failed (2 test binaries).
  • The diff adds no test for the heap-handle element-type key; this run only shows nothing else broke.
  • The full workspace still needs Build: Linux workspace, contributor setup and CI #112 for the victory-gpu E0425.

No game data used.

@gingertonik

Copy link
Copy Markdown

Independent confirmation on an RTX 4080 (Linux, vkd3d-proton), a whole-package check, and a test

I hit the same crash on a second NVIDIA card and traced it to the same cache key independently, so here is what I can add.

Environment: Arch-based Linux, kernel 7.3; Core i5-13600K; GeForce RTX 4080 16 GB, driver 620.73.04; GE-Proton11-12's Wine with vkd3d-proton 2576c0b4a (from Proton Experimental 11.0-20261112) in the prefix; Series X 1.0.2.1; release build cross-compiled on Linux.

In the game (one run each):

  • 9aef3d9, unchanged: err:vulkan:vkCreateComputePipelines Exception 0xc0000005 in Unix call at world entry, exit code 3. Of 211 SPIR-V modules vkd3d-proton dumped, 2 fail spirv-val, both an atomic with a %float result type, and one of them is the last compute module dumped before the crash.
  • 9aef3d9 with the same key change applied locally: no trap, 577 shaders translated, and the run reaches the opening cutscene. It stops later on a separate GPU fault (kernel Xid 13 ... MMU Fault), which looks like the world hang in NVIDIA RTX 5070 Ti: world hang (DEVICE_HUNG) on 97c78d1 is not one program, not loops, not barriers; 77 compute pipelines refused #71 and not like this bug.

Across the whole package (no GPU involved): victory translate --list with VICTORY_EMIT_DUMP, then every emitted DXIL converted with dxil-spirv 114e664e (the commit vkd3d-proton 2576c0b4a carries) and checked with spirv-val --target-env vulkan1.3 --scalar-block-layout.

Build DXIL emitted Invalid SPIR-V
main d2a4bae 22,151 39
this PR e55eb69 22,151 0

The 39 are 26 pixel and 13 compute programs: 22 AtomicUMin, 11 AtomicOr, 3 AtomicUMax, 3 AtomicIAdd, all "expected Result Type to be integer scalar type". This PR changes the emitted DXIL of exactly those 39 programs and of no other. So the bug reaches well past the two programs seen in a world run, and the fix covers all of them.

One caveat: the dxil-spirv command line (--ssbo-uav --ssbo-srv --bindless) is not the exact option set vkd3d-proton uses in the game. It did reproduce the two in-game failures exactly.

This looks like the remaining 0xc0000005 crash in #144; I have put the numbers there too.

A test. DaviTostes noted the diff has none. I wrote one in the style of the existing synthetic programs: a compute program that loads a 2D image UAV and then runs image_atomic_umin on it in the same block, asserting that the image is annotated once as four floats and once as one u32. On d2a4bae it fails with the atomic's annotation: [(d, ffffffff), (1002, 409)]; on e55eb69 it passes. It is one commit on top of this PR's head: #226. Take it into this PR or separately, whichever is easier.

No game data is attached; the dumps stay on my disk.

AI-assisted (Hermes).

@tanishq-dubey

Copy link
Copy Markdown

Independent reproduction on RTX 5090 / NVIDIA 620.70.06, Wine 11.22 and vkd3d-proton 3.2.0: before an equivalent local cache-key fix, the captured c12c1f7296419a5b SPIR-V failed spirv-val --target-env vulkan1.3 with OpAtomicOr %float and an isolated D3D12 pipeline probe exited with Wine reporting vkCreateComputePipelines / 0xc0000005.

After keying by both resource-property words, the corresponding generated SPIR-V passed spirv-val and the title successfully created that host pipeline. A synthetic same-descriptor regression also fails before the fix (float annotation returned for an integer atomic) and passes after. The title later hit a separate null-write termination during world rendering; that run used one pipeline worker and shader dumps, so it is not a normal-performance comparison. No game files attached. AI-assisted.

@ItsYusei99

Copy link
Copy Markdown

Tested on a third card: RTX 4070, driver 620.70.06 (nvidia-open), Wine 11.22, vkd3d-proton 3.2.0 (Proton Experimental 11.0-20261112), Ryzen 7 9800X3D. Build: main 9aef3d9 with this PR applied as a diff, Series X mode.

  • Before: every world load died in the driver with vkCreateComputePipelines Exception 0xc0000005 in Unix call (5d113aa6830760b6, with one pipeline worker). Skipping hashes with VICTORY_SKIP_PIPELINES only moved the crash to vkCreateGraphicsPipelines (5ad3a82b1c3cc63a, then 15c34c906ac8b908). That matches the 26 pixel programs in the analysis on Wine + vkd3d-proton on NVIDIA: the driver crashes in vkCreateComputePipelines while the world loads (0xc000001d / 0xc0000005, earlier stack overflows) #144.
  • After: with no skip list, the load translated 706 shaders with no driver exception. The opening cutscene ran for about 3 minutes, then the title entered the first mission (~600 draws/frame, mission audio playing).
  • It then stopped on a GPU fault, the same one reported on the RTX 4080: NVRM: Xid 13 ... Graphics SM Warp Exception ... MMU Fault (class c9c0). The screen stays on the last frame, audio continues, and VIctory logs nothing after it. That is a separate problem from this PR.

So this fixes the driver crash for me too. Related: #144.

@Ortomanic

Copy link
Copy Markdown
Author

Thanks all for the independent reproductions on the RTX 4070/4080/5090 and for the package-wide numbers. I've added @gingertonik's regression test from #226 to this PR (cherry-picked with attribution as ce945d6). cargo test -p victory-shader: 57 passed. Note that #48 contains the same key change, so whichever lands first, the other can drop it.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
spidercraft added a commit to spidercraft/VIctory that referenced this pull request Nov 24, 2026
…x runtime

Replaces this branch's own fix of the same bug (reverted above): main
already annotates an atomic's handle as U32, and Marvisak#177 keys the handle
cache by the element type too, which is the whole fix for the float
OpAtomicUMax that crashed NVIDIA's compiler on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@spidercraft

Copy link
Copy Markdown

Confirmed on a native Linux build (no Wine; vkd3d-proton, RTX 5090, NVIDIA 620.73): with this change victory translate --pipelines over the title's shader archive completes; without it the driver's compiler crashed on the float OpAtomicUMax. #526 includes this PR's commits as they are.

dieharddillon1 pushed a commit to dieharddillon1/VIctory that referenced this pull request Nov 24, 2026
Adapt the validated lowering from flapwarp78 (VIctory Marvisak#48) and Tarcisio (VIctory Marvisak#305), and key typed handles by both resource properties from Ortomanic (VIctory Marvisak#177). Gate the runtime on the typed and descriptor-heap capabilities and test both dwords against hardware.

(cherry picked from commit 26cc0b15c12e6ac6339929754b01c4ce4660c26b)
suirentakamura pushed a commit to suirentakamura/victory-suiren that referenced this pull request Nov 24, 2026
handle() keys its cache by resource kind only, so an image atomic that
followed a size query of the same view (getDimensions on a float4
handle) reused that handle: the i64 atomic ran on a RWTexture2D<float4>
annotation ({4098, 1033}) instead of DXC's {4098, 261}. Reported by
jeremygold02 on #539. The 64-bit path now makes its own heap handle; the
general fix of the cache key is #177.

translate --validate on shaders.rpf unchanged (vertex/pixel 12690,
compute 1672).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
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>
@brunofgmag

Copy link
Copy Markdown

This is still needed on the new main (70564ae). There it now conflicts, and without it the title dies about 2 s after launch on an RTX 4080 under Proton Experimental (driver 620.73.04, CachyOS).

The log shows nothing at default Wine debug settings. With WINEDEBUG=+seh,+process the cause is the one this PR describes: an access violation in libnvidia-gpucomp.so +0x55a954 inside vkCreateComputePipelines, then vkCreateComputePipelines Exception 0xc0000005 in Unix call and NtTerminateProcess with exit code 3 on every thread.

I ported the change by hand onto 70564ae. The handle cache key in Lower gets the element type as its sixth element, and the test from b7300eb comes along, with resource::track now taking the structure as its fourth argument. The test fails with the old key and passes with the new one, and cargo test -p victory-shader --lib passes (124 passed, 1 ignored). With the port, a 60 s run gets past the crash: frames are presented, and there are no err:vulkan lines or libnvidia faults.

Thanks to @Ortomanic for finding this and for the fix. A rebase onto the new main would let it go in as it is.

1bugproof pushed a commit to 1984742628/VIctory that referenced this pull request Nov 24, 2026
…(port of fork Marvisak#177)

A block the query does not report resident is still probed with a one-byte read.

Co-Authored-By: Claude Opus 5.5 <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.

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


Generated by Claude Code

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
A title buffer object's copy is, with VICTORY_IN_PLACE=1, the title's
memory too: placed from the 64 KiB boundary at or below the buffer
(views find their bytes by address), past its end by 256 bytes where the
allocation has them. A placed buffer's end only needs to be committed
pages, not 64 KiB. A remap drops in-place title buffers over it as well.

Buffers over many separately mapped 64 KiB views (MEM_MAPPED, one
allocation each) are still copied: one heap cannot span them, and tile
mappings into heaps opened over process memory were not reliable under
vkd3d-proton here.

Measured (RTX 5080, proton-cachyos 11.0, the title loading its world,
with Marvisak#259, Marvisak#177 and Marvisak#1849 on top for NVIDIA under Wine): 3,335 title
buffers and 2,117 loose windows in place, none refused, no device
errors; 8 large buffers (378 MB) over separate views still copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ruvenesh

ruvenesh commented Nov 25, 2026 •

Copy link
Copy Markdown

Test report: Linux + Proton on an RTX 3060 (Ampere, 32-lane), where this fixes 704 pixel and 6 compute pipelines the driver refuses on main, with no regressions in a whole-archive census.

Setup: Ubuntu-based host, NVIDIA RTX 3060 12 GB (Linux driver), GE-Proton11-14 (vkd3d-proton 3.2.x), VIctory diag builds cross-compiled for x86_64-pc-windows-msvc. This PR's change merged onto main (two small conflicts in lower.rs, resolved by keeping both sides).

What fails on main: victory translate shaders.rpf --list --pipelines --jobs 1 on main 7ae5e17 refuses 704 pixel pipelines with Out of memory and 6 compute pipelines with Call failed; stderr has NVVM compilation failed: 1 for each. The cause is the one this PR names: a shader that reads a heap UAV texture (here, its dimensions) and does an image atomic on it in the same block gets the cached float-annotated handle for the atomic. dxil-spirv then emits OpAtomicUMin / OpAtomicOr / OpAtomicIAdd with a float result type. Of the SPIR-V modules vkd3d-proton dumped for these programs, 618 fail spirv-val --target-env vulkan1.3 with "expected Result Type to be integer scalar type" (611 UMin, 5 IAdd, 2 Or), and NVIDIA's compiler rejects them, which vkd3d-proton reports as E_OUTOFMEMORY. (So on this path it is not the worker-stack problem of #966/#1129: a 64 MiB worker stack changes nothing here, A/B tested in the title.)

With this PR:

  • Offline census, same archive, per program against main: all 704 pixel and all 6 compute pipelines are created; 0 programs changed for the worse (25,889 programs joined). The WaveSize-64 refusals (32-lane device) and the geometry-program refusals are unchanged, as expected.
  • In the title (same scripted input, ~5 min each): host pipelines refused with Out of memory 13 → 0, Call failed 2 → 0, vkd3d Failed to create Vulkan graphics pipeline, vr -13 13 → 0. (The two runs are on slightly different main commits, 940d32f and ccfb029; I compared counts and the failure type, not program by program.)

Not done here: cargo test on the merged tree (the PR's own test covers the key), and a Windows NVIDIA check — Windows compiles the DXIL directly, so this failure may not show there.

No game data attached. AI-assisted (Claude Code).

@neonbyte1

Copy link
Copy Markdown

Confirmed on an RTX 5090 under Wine + vkd3d-proton (GE-Proton11-14), main 940d32f: this is the crash at world load. Compute 76c35de1c2444e67 gets a R32f handle ([4100, 1033]) that its image_atomic_add reuses. dxil-spirv then emits OpAtomicIAdd %float, spirv-val rejects it, and NVIDIA's driver faults in vkCreateComputePipelines (0xc0000005). With an R32ui handle ([4100, 261]) the SPIR-V validates and the pipeline is created. Details and numbers are in #144.

This branch conflicts with current main (the page-table merge rewrote descriptor_data). I have the same fix rebuilt on 940d32f if a fresh PR is easier.

AI-assisted (Claude); measured on my machine.

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