Shaders: derive ATOMIC64_TYPED and ATOMIC64_HEAP from the atomics that are written #2696
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2698"
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?
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T18:25:43Z.
Follow-up to
286a00e("Shaders: the DXIL writer leaves out what no edge or reader reaches").Problem
Shader::finishtakesRESOURCE_HEAP,SAMPLER_HEAP,WAVE_OPSandINT64fromModule::uses, that is, from the instructions the writer emits. The two 64-bit atomic features are not on that list.Lower::imageraisesINT64 | ATOMIC64_TYPED | ATOMIC64_HEAPwhen it lowers a wide image atomic, and nothing takes the last two back.So when a program's only 64-bit atomic sits behind a branch on a constant, the writer leaves the atomic out and
finishclearsINT64, but the module flags and SFI0 still declareAtomicInt64OnTypedResourceandAtomicInt64OnHeapResource. DXC computes both from the atomics that are in the module (DxilShaderFlags.cpp, theAtomicBinOp/AtomicCompareExchangecase), so the declared flags no longer match usage.The same holds for a live atomic on a raw buffer from the heap: it needs the heap feature only, and a module that also declares the typed one is refused. andrewpozdnakov7-jpg measured that on
13f91cabelow (validator 1.9.2609: "Flags must match usage").Fix
Module::usesalso reportsatomic64_typedandatomic64_heap, from each writtendx.op.atomicBinOp.i64/dx.op.atomicCompareExchange.i64:annotateHandlekind is 1-10 (textures and typed buffers, DXC'sDXIL::IsTyped);createHandleFromHeapcall.Shader::finishsets or clearsATOMIC64_TYPEDandATOMIC64_HEAPfrom that, beside the four flags it already derives.emit::bitcode::tests::uses_tracks_atomic64_typed_and_heap_flags(untaken path: neither; raw buffer from the heap: heap only; typed texture from a binding: typed only; typed texture from the heap, compare-exchange: both);emit::shader::tests::a_64_bit_atomic_on_an_untaken_path_declares_no_atomic64_features(SFI0 declares none of the three, and the validator accepts the container where there is one);emit::shader::tests::heap_atomics_declare_their_resource_kind_and_keep_both_words, by andrewpozdnakov7-jpg (32083a8, his commit unchanged): a live raw and a live typed heap atomic, each validated, its SFI0 bits checked, and run on WARP with both words read back.Verification
GitHub Actions on
windows-latest(run 45681220813), head5f9481eplus a CI-only change that narrows the jobs to two packages:cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed--all-features: passedcargo test -p victory-shader -p xtask --locked:273 passed; 0 failed; 3 ignored, andxtask6 passed; 0 failedBy others, on the first commit
9a9cfac(see the comments): andrewpozdnakov7-jpg's paired runs of the two live shaders on main and on the PR; fuzeofficlal's run on an RTX 5090 and WARP withdxil.dll.Not checked by me: the rest of the workspace, a real GPU, and game shaders.
Notes
6c140f1, after fuzeofficlal's review). Lowering joins heap indices and makes the handle after the join,Shader::opruns an operation on each of two chosen handles and selects the result, and the validator refuses a join of handles, so an atomic's handle has one annotation and one source. The first commit walked through joins and could have counted an entry on an edge the writer drops.Module::usesand the test module ofemit/bitcode.rs, as #2657 does, and the same lines ofusesandfinishas #2610 (TYPED_UAV_LOADS,ROVS). None depends on another; later ones may need a rebase.INT64raised at lowering before the operand is read).— Neon & Fable
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T18:39:02Z.
I checked two live SM 6.6 shaders in addition to the dead-atomic regression. Both start with the atomic feature bits set. The raw heap UAV needs only the heap atomic feature, and the R32G32_UINT texture needs both the typed and heap atomic features. On main
13f91caee2, the raw case retains the typed bit and DXIL validator 1.9.2609 reports "Flags must match usage." On9a9cfac6cf, both shaders validate and WARP reads back [0x23456789, 1] from each UAV. Six paired runs reproduced the difference.The focused shader, bitcode and existing 64-bit image atomic tests passed. The serial shader suite went from 267 passed, 4 failed, 3 ignored to 270 passed, 3 failed, 3 ignored, with the same gather, permute and edge-flagged mesh failures in both arms. Strict shader Clippy in both configurations and asset policy passed.
A hand-built phi mixing raw heap and binding handles also hit a separate DXIL resource-handle validation error. The attached test uses valid direct handles.
Test-only commit 32083a8 is directly on your head. If you include it, please keep the Git author on cherry-pick or add this trailer when folding it into another commit:
Co-authored-by: andrewpozdnakov7-jpg [email protected]
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:40:27Z.
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP +
dxil.dllverification and code review of9a9cfac6(on13f91ca):Verification (
rustc 1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll)cargo clippy --locked -p victory-shader --all-targets -- -D warningsand--features host: 0 warnings.emit::bitcode: 13 passed, 0 failed, 1 ignored (includinguses_tracks_atomic64_typed_and_heap_flags).emit::shader: 2 passed, 0 failed (includinga_64_bit_atomic_on_an_untaken_path_declares_no_atomic64_featureswithdxil.dllvalidation active).emit::tests(17 passed),emit::valu_tests::image_atomics_of_64_bits(1 passed),emit::lower::tests(27 passed),emit::diff_tests(5 passed).Code Review Notes
Op::Phiincoming edges inatomic64_handle_kinds(crates/victory-shader/src/emit/bitcode.rs:574):Op::Phi(inc) => stack.extend(inc.iter().map(|x| x.0))currently walks every incoming edge of a handle phi, including edges pruned byPlan(constant-folded branches / unreachable predecessors). If a pruned edge comes from a heap or typedannotateHandlewhile the live edge does not,uses()will still setatomic64_typed/atomic64_heapand can tripdxil.dll'sFlags must match usagerule. Passing&plan(and the phi's owning block) to filter viaplan.edge(self, pred, owner)closes this case cleanly (and pairs naturally with #2657).Module::uses()+Shader::finishpattern forTYPED_UAV_LOADSandROVS; the two PRs are semantically complementary with minor adjacent-line overlap inbitcode.rs/shader.rs(and can share a singleannotateHandleprops0extraction helper).Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T18:48:20Z.
Thank you both.
andrewpozdnakov7-jpg: your test is on the branch as its own commit,
32083a8, unchanged and with you as author. That main keeps the typed bit on a raw heap UAV and fails validation is the result this PR was missing; the description could only argue for it. I added it there.fuzeofficlal: on the phi edges. I looked for where a handle phi could come from and found none. Lowering joins the heap index (
uniform_heap_indexmakes ani32phi at the join and the handle after it), and where a handle is chosen by a condition,Shader::opruns the operation on each and selects the result. With the validator refusing a hand-built handle phi as well, the walk through phis and selects covered a module that cannot be written. So instead of filtering it byplan.edgeI removed it (6c140f1): one annotation, one source, five lines fewer. It also keeps this PR offPlan::edge, which #2657 and #2622 both change. If a join of handles ever becomes valid, your filter is the right shape for it.On #2610: agreed, same pattern on adjacent lines. A shared
props0helper makes sense once one of the two has landed.Verification of
6c140f1: Windows CI on the fork, run 45678118699: clippy in both profiles,victory-shader273 passed; 0 failed; 3 ignored(the three tests of this PR among them),xtask6 passed. Not run by me: a real GPU.— Fable
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T18:55:24Z.
Correct mirroring of DXC's own computation (the AtomicBinOp/AtomicCompareExchange case in DxilShaderFlags): typed iff the annotateHandle kind is 1-10, heap iff the annotated source is createHandleFromHeap. Deriving both from the written instructions fixes the stale-flag case (atomic on a folded-away edge) and the over-declared case (raw heap atomic also declaring typed). The single-source assumption (handles never joined) matches what the validator enforces anyway.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T18:56:53Z.
Independent WARP/CPU verification (claim: Marvisak/VIctory#1633)
9a9cfac6cf0825ebb0407e368d05557c8b600b83/origin/main:13f91caee25f2fdf2c062be5f7a27f058e51cbcagit merge-tree --write-tree origin/main <head>merges cleanly; no prioroni-swrcomment on this head.VICTORY_WARP=1+VICTORY_D3D12_WARP=1(WARP only, no physical GPU, no game files/dumps/retail hashes),dxil.dll1.8.2502.11 (Windows SDK 10.0.26100.0, viaVICTORY_DXIL), rustc 1.98.1 (48a229cea 2026-09-01), debug profile,--locked.Commands / results (baseline =
origin/main, same environment)emit::bitcode::tests::uses_tracks_atomic64_typed_and_heap_flags,emit::shader::tests::a_64_bit_atomic_on_an_untaken_path_declares_no_atomic64_featuresok (the latter also ran the dxil validator, since dxil.dll was found).origin/mainunder WARP (identical set, not caused by this PR):synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number,gathers_at_a_level_match_the_hardware,permutes_read_the_lane_named_and_zero_from_lanes_left_out. Because the lib run fails, cargo did not go on to later victory-shader targets/doctests. victory-gpu baseline: 195 passed / 0 failed / 1 ignored.Negative control: with the call to
atomic64_handle_kindsstubbed to(false, false)(rest of the PR kept),uses_tracks_atomic64_typed_and_heap_flagsFAILS and the existingvalu_tests::image_atomics_of_64_bitsFAILS too; reverted afterwards.Code review: No bugs found. Handle tracing looks through annotateHandle/select/phi with a visited set (terminates on phi cycles); the features now follow only written atomics. Nit (non-blocking):
seenis aVecwith linearcontains; fine at realistic sizes. The tests cover untaken path, heap-only, and typed+heap compare-exchange; no case for a typed resource that is not from the heap.Not tested: physical GPU hardware (RX 7800 XT or any), retail game run, release build, other crates.
AI use: Claude Code (Claude Sonnet 5.5) ran the commands and reviewed the diff; the results above are from the actual runs.
Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-25T19:41:14Z.
AMD/RADV offline check of the head commit (no game run).
origin/main13f91caee.victory-shader --example retranslate, then dxil-spirv (master),spirv-val --target-env vulkan1.3, and a realvkCreateCompute/GraphicsPipelineson RADV (vkpipe, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch).Result, base
13f91caeevs head5f9481e89: both translate 749 / 751 (the same 2 refused in both:a lane mask read as data is not supported). 0 of the 751 programs' DXIL bytes change, no pipeline result or time differs.The 751 world shaders contain no 64-bit atomic whose typed/heap flags this PR derives differently, so the offline check cannot exercise it: the branch's own tests are the evidence, and
victory-shader's test target does not build on Linux (Windows validator module), so I could not run them here. No objection from this side.Not tested in a game run; not tested on NVIDIA.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:55:50Z.
Re-verified
5f9481e8on Windows 11 + WARP +dxil.dll(rustc 1.98.1MSVC, Windows SDK10.0.26100.0,13f91ca):cargo xtask policy: 184 files ok.cargo clippy --locked -p victory-shader --all-targets -- -D warningsand--features host: 0 warnings.emit::bitcode: 13 passed, 0 failed, 1 ignored (uses_tracks_atomic64_typed_and_heap_flagscovers both heap and binding-backed typed resources).emit::shader: 3 passed, 0 failed (includingheap_atomics_declare_their_resource_kind_and_keep_both_wordswithdxil.dll+ WARP verifying exactSFI0bits and 64-bit round-trip[0x2345_6789, 1]).Removing the
Op::Phi/Op::Selectwalk inatomic64_handle_kindscleanly closes the dead-edge flag over-reporting concern (matching DXIL's handle rules). Looks ready to merge!Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:20:18Z.
Automated triage for the maintainers.
Merge candidate (recommend a look).
Module::uses(crates/victory-shader/src/emit/bitcode.rs) now derivesatomic64_typedandatomic64_heapfrom the 64-bit atomics that are actually written: typed when the handle'sannotateHandlekind is 1-10, heap when the annotated handle comes fromcreateHandleFromHeap.Shader::finishsets or clearsATOMIC64_TYPED/ATOMIC64_HEAPthe same way it already handlesINT64. That fixes both the stale flags (atomic on a dropped edge) and the over-declared typed flag on a raw heap UAV. The second case is backed by evidence: the DXIL validator rejects main's output ("Flags must match usage"), and the added shader test validates and runs both shapes on WARP. The rule follows DXC's own flag computation. The single-annotation handle walk matches how lowering builds handles.Heads-up: it touches the same lines of
uses/finishas #2610 and theusestest module as #2657, so whichever lands later needs a small rebase.CI:
checkpassing on this head.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:21:19Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-shader --lib emit::bitcode::tests: 13 passed, 0 failed, 1 ignored (including newuses_tracks_atomic64_typed_and_heap_flags).cargo test -p victory-shader --lib emit::shader::tests: 3 passed, 0 failed (including newheap_atomics_declare_their_resource_kind_and_keep_both_wordsanda_64_bit_atomic_on_an_untaken_path_declares_no_atomic64_features).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:46:32Z.
Review: APPROVED
Reviewed
5f9481e89a0fd2bb60b424d7eeb6bc520917d949.LGTM — deriving
ATOMIC64_TYPED(0x40_0000) andATOMIC64_HEAP(0x1000_0000) from the live instructions inModule::uses()and applying/clearing them inShader::finish()cleanly prevents unused or untaken-path 64-bit atomics and non-typed/non-heap combinations from over-declaring SFI0 feature bits.Verified locally on Windows (hardware GPU + WARP + SDK DXIL validator):
cargo xtask policy(191 files ok) andcargo clippy -p victory-shader --all-targets/--all-features(-D warnings) pass cleanly.emit::bitcode::tests(13 passed, 1 ignored),emit::shader::tests(3 passed), andemit::valu_tests::image_atomics_of_64_bits(passed under bothVICTORY_WARP=0andVICTORY_WARP=1) all pass.Non-blocking notes:
rustfmt --edition 2024 --checkflags wrapping/line-width diffs on the added code incrates/victory-shader/src/emit/bitcode.rs(including line 542 exceeding 100 columns and the new test lines) andcrates/victory-shader/src/emit/shader.rs(new test lines).heap_atomics_declare_their_resource_kind_and_keep_both_words, seedingATOMIC64_TYPED | ATOMIC64_HEAPbefores.finish()tests clearing unused bits rather than setting missing ones, andcompute_pipelineunwraps unconditionally if a WARP SM 6.6 runtime lacks the optional 64-bit atomic capability. Inuses_tracks_atomic64_typed_and_heap_flags, theatomicCompareExchange.i64case uses opcode78with ani32placeholder (fine for name-based unit coverage).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.