Skip to content

Shaders: a vertex program writing through views declares UAVs at every stage - #1989

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/uavs-at-every-stage
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/uavs-at-every-stage

Conversation

@BastienRodz

@BastienRodz BastienRodz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What's wrong

Since cd94d35 ("GPU: shaders mark the pages they write through views; copy-backs compare only those"), translated shaders built with emit::Options::view_marks declare the view-write bitmap (u1 in MEMORY_SPACE, a raw root UAV in dx.resources) whenever they store or perform atomics through unordered buffer views. That includes vertex programs.

DXIL requires any non-pixel, non-compute shader that declares UAVs to set the UAVsAtEveryStage shader flag and the matching SFI0 feature bit. Because victory-shader did not set either bit, the DXIL validator recomputed the flags from the module and rejected those vertex modules with Flags must match usage. (#1973, 867 vertex programs in the reporter's offline check with dxil.dll 1.8.2502).

What the fix does

  • Adds flags::UAVS_AT_EVERY_STAGE = 1 << 16 in crates/victory-shader/src/emit/shader.rs, matching m_UAVsAtEveryStage at bit 16 in DXC's include/dxc/DXIL/DxilShaderFlags.h (lines 264-265).
  • In Shader::finish, sets flags::UAVS_AT_EVERY_STAGE whenever the stage is neither pixel nor compute (graphics && !self.pixel, covering vertex, geometry, and mesh shaders) and dx.resources declares any UAV (!self.root_uavs.is_empty() || self.memory_dirty.is_some() || self.view_writes.is_some()). This matches DXC's DxilModule::CollectShaderFlagsForModule in lib/DXIL/DxilModule.cpp (lines 318-350): because victory-shader declares dx.valver (1, 6) (< 1.8), DXC sets UAVsAtEveryStage whenever NumUAVs && !(SM->IsCS() || SM->IsPS()).
  • Maps flags::UAVS_AT_EVERY_STAGE to 0x4 in the SFI0 feature word, matching ShaderFeatureInfo_UAVsAtEveryStage = 0x0004 in DXC's include/dxc/DXIL/DxilConstants.h (line 2276) and ShaderFlags::GetFeatureInfo in lib/DXIL/DxilShaderFlags.cpp (lines 85-86).
  • Adds a synthetic unit test (emit::tests::vertex_uav_writes_declare_uavs_at_every_stage) checking SFI0, the serialized dx.entryPoints shader flags, and dxil.dll validation (when available) for vertex and mesh programs with view_marks, vertex programs without declared UAVs, and pixel and compute programs with view_marks.

Tests

  • Failure on origin/main (940d32f): the new unit test failed before the fix with:
    assertion left != right failed: VS SFI0 0x2000000: missing UAVsAtEveryStage
  • Local (Linux cross-compiling to x86_64-pc-windows-msvc, tests under Wine, no SM 6.6 device / no dxil.dll):
    • cargo xwin test -p victory-shader --target x86_64-pc-windows-msvc -- --test-threads=1: 173 passed, 75 failed, 3 ignored (vs 172 passed, 75 failed, 3 ignored on origin/main; only difference is the new test passing, and all 75 failures are the same SM 6.6 device tests under Wine).
    • cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: pass.
    • cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings: pass.
    • cargo xtask policy: pass (182 files ok).
  • Windows CI run: On GitHub's windows-latest (which has dxil.dll) with the upstream CI's commands, everything passes; victory-shader 248 passed, 0 failed, including the new test: https://github.com/BastienRodz/VIctory/actions/runs/45532795156

On the title's shaders (@zed6000, comment): translate --validate over the retail shader pack with dxil.dll 1.8.2502 gives 23,918 validated on main 940d32f and 24,785 with this PR, +867 and 0 lost. That is identical, program by program, to ccfb029 before cd94d35, and no program is left with "Flags must match usage".

Fixes #1973. Same report: #1987.

No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and verified with Claude Code.

🤖 Generated with Claude Code

…y stage

Commit cd94d35 emits a raw root UAV for the view-write bitmap whenever
a shader built with Options::view_marks writes through an unordered
buffer view, including vertex programs. DXIL requires any non-pixel,
non-compute shader with declared UAVs to set the UAVsAtEveryStage
shader flag (bit 16) and the matching SFI0 feature bit (0x4); without
them, dxil.dll rejects the module with 'Flags must match usage.'
(Marvisak#1973).

Add flags::UAVS_AT_EVERY_STAGE (1 << 16), set it in Shader::finish for
non-pixel, non-compute stages (vertex, geometry, and mesh, matching
DXC's valver < 1.8 rule since we emit dx.valver 1.6) when dx.resources
declares any UAV, map it to SFI0 bit 0x4, and add a synthetic unit test
covering vertex, mesh, pixel, and compute stages.

Fixes Marvisak#1973.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DesertGamer

Copy link
Copy Markdown

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

Confirmed on the title's shaders, as asked in #1973. Head 0f11320, merged onto main 940d32f (a clean merge), measured with victory translate --validate --list over shaders.rpf (1.0.2.1, dxil.dll 1.8.2502) and compared program by program:

Build Validated Change
main 940d32f 23,918
940d32f + this PR 24,785 +867, 0 lost
compared with ccfb029, before cd94d35 0 gained, 0 lost: identical

No program is left with "Flags must match usage". cargo test -p victory-shader --lib gives 248 passed and 0 failed on an RX 7900 XTX (RDNA3). Your version also flags mesh programs with UAVs, which my patch in #1973 didn't; on this data both give the same result. Offline counts only; no program names or data.

@Calvix2k

Copy link
Copy Markdown
Contributor

Confirming this as the one to merge for #1973 (I closed my #1977 in its favour after @Dathinel's mesh fixture showed my stage predicate still failed the mesh case and yours passes it).

The corpus result applies to this head too: zed6000 and @sinan-cmyk both measured main 940d32f 23,918 → 24,785 validated (+867, 0 lost) on 25,889 programs with the same two bits. I ran this branch's test locally on Windows 10 / RX 7800 XT: vertex_uav_writes_declare_uavs_at_every_stage passes, and the mesh finding above is the reason to prefer it over mine.

zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Restore validator compatibility after the marked-write copy-back update.
Keep the original fix and regression coverage. Verified the expected
pre-fix failure, Linux shader tests, and Windows MSVC test compilation.
@BaggyALPHA

Copy link
Copy Markdown
Contributor

Independent native Windows validation of 0f11320 on upstream 940d32f. I made validator loading mandatory in the local synthetic test so a skipped validator could not produce a pass.

  • With the PR, all five cases in vertex_uav_writes_declare_uavs_at_every_stage validated with both official DXC 1.7 and 1.8. The SFI0 and dx.entryPoints assertions passed as well.
  • With upstream metadata generation restored and the same test run on DXC 1.8, the vertex program with view marking failed with Flags must match usage. It passed again with the PR's metadata.

This verifies the focused synthetic cases, including mesh and the pixel/compute controls. No game files or title corpus were used. AI-assisted (OpenAI Codex).

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

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. Vertex program writing through views declares UAVs at every stage (+1 test). Duplicate/overlap with #1977 — maintainer should pick one; this one covers the 'writing through views' case explicitly.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 0f11320. victory-shader: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on main (the two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

@AgneyaK

AgneyaK commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

An independent full-corpus run of this PR: offline victory translate --validate over the title 1.0.2.1's shader pack, release builds, Windows 11 26300. The validator is the SDK 10.0.26100.0\x64\dxil.dll, which on this machine is DXC 1.9.2602 (serviced; IDxcVersionInfo reports 1.9). This PR (0f11320) is a fast-forward of main 940d32f.

vertex + pixel validated compute validated mesh validated Flags must match usage
main 940d32f 13,350 of 14,217 emitted 1,961 of 2,696 8,694 of 8,765 867
this PR 14,217 of 14,217 1,961 of 2,696 8,694 of 8,765 0

So it clears exactly the 867 that cd94d35 broke (#1973, #1987). Nothing moves elsewhere: the remaining compute (735, "incompatible with the shader stage", the derivative case of #1065) and mesh (71, output size over 32,768) refusals are the same programs on both builds. This also confirms the result with a 1.9 validator; the numbers in #1987 were from 1.8.

cargo test -p victory-shader --lib --locked: 240 passed, 8 failed. The 8 are the same hardware-only ones that fail on plain main on the Intel Iris Xe the tests use here (BVH 1-ULP, dot products, 64-bit image atomics, wave size, heap cap).

Not tested: the title on the GPU with these programs (this laptop can't reach the world).

AI use: Claude Code (Claude Opus 5.5) built both trees, ran the corpus and wrote this; the results are from the runs described. No game data: counts only.

@Calvix2k

Copy link
Copy Markdown
Contributor

Independent corpus run on AMD / Windows 10, same archive as the other reports (shaders.rpf, 1.0.2.1, 411,695,600 bytes), victory translate … --validate --list --jobs 10, release builds:

build translated validated Flags must match usage
main 940d32f 26,084 23,918 868 (867 programs + the summary line)
this PR 0f11320 26,084 24,785 0

+867 validated, 0 lost — the same delta zed6000 measured on an RX 7900 XTX and @sinan-cmyk on a retail NVIDIA machine, now reproduced on an RX 7800 XT with the SDK 10.0.26100.0 validator (dxil.dll 1.7, i.e. the one default_path picks on this machine). The 1.7 PSV false failures (#1945) are in both runs at the same rate, so they do not affect the delta.

The mesh case Dathinel found is also covered: the corpus has 71 mesh programs failing vertex plus primitive output size is greater than 32768 in both runs — unrelated — and no mesh program appears among the 867.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…s, in every stage, head 0f11320)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…842 programs gained offline; known NVIDIA risks

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate.

This fixes #1973 and #1987, a regression from cd94d35. Vertex programs that now declare the view-write bitmap UAV were rejected with "Flags must match usage". The fix is in Shader::finish (emit/shader.rs). It sets shader flag bit 16 (UAVS_AT_EVERY_STAGE) and SFI0 feature 0x4 for non-pixel, non-compute stages that declare a UAV.

I checked that the PR's has_uavs condition is the same one that finish uses on main to build the UAV list in dx.resources (root_uavs / memory_dirty / view_writes), so the flag follows exactly what is declared. Including mesh stages matches DXC's pre-1.8 rule, which the PR cites with source references. Several independent corpus runs in the thread report +867 validated programs and 0 lost, with validators 1.7, 1.8 and 1.9, with no program left with the error. CI (check) passes. The competing #1977 was closed in favour of this PR.


Generated by Claude Code

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.

main: 867 vertex programs fail validation ("Flags must match usage") since cd94d35

9 participants