Skip to content

Shaders: query a descriptor's level count only when word 3 is read - #259

Open
desplmfao wants to merge 2 commits into
Marvisak:mainfrom
desplmfao:fix/nvidia-level-query
Open

desplmfao wants to merge 2 commits into
Marvisak:mainfrom
desplmfao:fix/nvidia-level-query

Conversation

@desplmfao

@desplmfao desplmfao commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

On NVIDIA under Wine with vkd3d-proton (#144), loading into the world ends the process inside the driver: vkCreateComputePipelines Exception 0xc0000005 in Unix call, with no crashes.log entry. On current vkd3d-proton (3.2.0) and with #177 applied, the remaining crashing compute shaders here were 9938c251a313fe28, ef05293f6107fc99, a3d1a26ad0c8c2cd and b80cd30e37e3fa05.

When a program reads an image descriptor as data, descriptor_data rebuilds the descriptor words from getDimensions and always extracts the level count for word 3. vkd3d-proton turns that into OpImageQueryLevels. On a 3D image inside a loop, NVIDIA's Vulkan compiler crashes on it. These shaders load the whole descriptor (s_load_dwordx8) in a loop but never read word 3 as data.

How it was found

  • Dumped the SPIR-V vkd3d-proton generates for these shaders (VKD3D_SHADER_DUMP_PATH). It passes spirv-val. Creating a pipeline from it in a small native Linux Vulkan program (no Wine, no vkd3d-proton) segfaults the NVIDIA driver too.
  • spirv-reduce against that native crash leaves a module of a few blocks. It crashes only with all three: OpImageQueryLevels, a 3D image, and the query inside a loop. OpImageQuerySizeLod instead, a 2D image, or the query moved out of the loop all build.
  • In all four crashing shaders, every 3D-image query sits inside a loop. In 25 compute shaders that build fine, none does.

Change

descriptor_data extracts the level count only when some instruction or phi reads word 3's register as data, not as the resource operand of a memory instruction, which takes the descriptor whole. Otherwise the level count is not queried; word 3's value is then unused. Programs that do read word 3 are unchanged.

Testing

  • RTX 5080, driver 615.71.09, CachyOS, proton-cachyos 11.0 (20260703), Series X 1.0.2.1, release build cross-compiled from Linux.
  • victory translate <dir> --pipelines on the four shaders: all crashed before, all create their pipeline after.
  • In game: all four now create their host pipelines and loading continues past the point where it crashed before.
  • cargo test -p victory-shader passes.
  • Not tested on Windows or on AMD; the change only skips a query whose result was unused.

What else this was run with

These are separate, and this PR does not include them:

Related: #144.

🤖 Generated with Claude Code

@desplmfao
desplmfao force-pushed the fix/nvidia-level-query branch from 71da6c4 to 47e61bd Compare November 24, 2026 01:54
When a program reads an image descriptor as data, descriptor_data
rebuilt word 3 from getDimensions' level count even when nothing reads
that word. vkd3d-proton turns the query into OpImageQueryLevels, and on
a 3D image inside a loop NVIDIA's Vulkan compiler crashes on it
(vkCreateComputePipelines, 0xc0000005 under Wine). Query the level
count only when word 3's register is read as data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao
desplmfao force-pushed the fix/nvidia-level-query branch from 47e61bd to e232d3d Compare November 24, 2026 01:54
@MisaXz

MisaXz commented Nov 24, 2026

Copy link
Copy Markdown

Test report on Windows, which the description lists as not tested.

Tested

  • NVIDIA GeForce RTX 5080, driver 621.14; Ryzen 7 9800X3D; Windows 11 Pro 26300 (native D3D12, no Wine); Rust 1.98.1; debug
  • This PR at e232d3d (base d2a4bae): cargo test --workspace --no-fail-fast: 264 passed, 0 failed, 4 ignored. Same counts as main d2a4bae on this machine.

Not tested

  • The title itself (no game files used), so not the world load this fixes under vkd3d-proton; this only shows the suite is unchanged on native Windows.
  • The GPU diff tests skip here (no VICTORY_CONSOLE_DXC). Release build, AMD.

AI use

  • Claude Code (Claude Fable 5.2) ran the tests and wrote this report from their output.

muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…rd 3 is read

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

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

Tested e232d3d on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. Not tested under Wine or vkd3d-proton.

  • The rebuilt word 3 is only observable when some SGPR written by this load at descriptor word 3 is read as data. When nothing reads it, putting one there instead of querying the level count can't change any result, and it removes the getDimensions level query that vkd3d-proton turns into OpImageQueryLevels.
  • read_as_data errs the safe way. A phi use counts as a data read, so a word that flows through a loop still gets the real level count, and only direct resource operands of image, buffer and SMEM instructions are exempt. The worst case is the old behaviour.
  • The reduction story (3D image, query inside a loop, and OpImageQueryLevels all needed for the crash) is well isolated. This narrows the trigger without changing the semantics of shaders that do read word 3. Those can still hit the driver bug, which is outside our control.

No issues found.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…ount only when word 3 is read

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mercuryVM pushed a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
A direct eight-word scalar load can supply the resource of an image atomic without exposing any descriptor words as values. Avoid emitting a float-annotated dimension query in that case while retaining reconstruction for scalar reads, PHIs, and other consumers.

Refs: Marvisak#48, Marvisak#177, Marvisak#259
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request 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>

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. In Lower::descriptor_data (crates/victory-shader/src/emit/lower.rs), an image descriptor rebuilt from getDimensions now extracts the level count (field 3) only when the program reads word 3's register as data, through the new Lower::read_as_data. Phis count as data reads; image, buffer and scalar-memory operands, which take the whole descriptor, do not. Otherwise word 3 is built with one level. I checked that levels feeds only d3, so when no instruction or phi reads word 3 the generated value is never used, and programs that do read it are unchanged. The evidence for the driver crash is concrete (a spirv-reduce reduction to OpImageQueryLevels on a 3D image in a loop, reproduced natively and on several driver versions in the comments). The merge commit keeps main's new scalar-load functions unchanged.

Thanks for the merge with main. It now merges cleanly against 940d32f, and the conflict resolution in lower.rs keeps both sides as you describe.

CI: passing (check).


Generated by Claude Code

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
@desplmfao

Copy link
Copy Markdown
Author

Rebased for the triage's "needs rebase": 31a6137 merges current main (940d32f) into the branch as a new commit, so the history above stays as it was. The only conflict was in emit/lower.rs, where main added new scalar-load functions (user_data_smem, memory_smem, add64 and others) next to this PR's read_as_data. Both are kept unchanged. GitHub shows the PR as mergeable again.

Checked on an RTX 5080 (Linux, proton-cachyos 11.0, vkd3d-proton 3.2.0), victory-shader tests with --test-threads 1: 241 passed, 6 failed. Plain main gives exactly the same result, with the same six tests failing, so the merge adds no failures. The six are NVIDIA/Wine issues covered elsewhere (#2037, #1994, #1777/#1779), or they only happen under Wine.

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>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
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>
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
… when word 3 is read) into the integration

The descriptor words are placed by the load's skew on our side, so word 3 is found through the skew instead of the PR's first dword; read_as_data sits next to load_skew.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
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.

8 participants