Shaders: 64-bit image atomics lowering to dx.op.atomicBinOp.i64 and a… #1127
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!1127
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1127/head"
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?
@ashrafsdrop on GitHub · 2026-11-24 16:00 UTC · original
ashrafsdrop:shader/image-atomic-64→main· +669 −49 · 6 files · 3 commits · closed without mergingSummary
Implements 64-bit image atomic operations in
victory-shader::emit::lower.dmask(dmask == 3for standard atomics,dmask == 0xFforcmpswap).i64integers.atomicBinOp.i64(opcode 78) andatomicCompareExchange.i64(opcode 79).props1 = 0x107, 1 component of U64).glcis active.INT64shader model feature flag in DXIL SFI0 metadata.image_atomic_64_bit_lowers_with_int64_featureto verify lowering and SFI0 metadata.Verification
cargo test -p victory-shader: 121 tests passed, 0 failed.cargo test --workspace: all workspace crates passing cleanly.cargo run -p xtask -- policy: asset policy passes (154 files ok).@shortselow-byte on GitHub · 2026-11-24 16:41 UTC · original
This PR has no CI run yet, so I ran the CI's checks at head
52a5381(onmainffe310e): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT. Workspace tests 343 passed, 0 failed; both clippy runs (default and--all-features) clean.But the DXIL validator rejects the program from
image_atomic_64_bit_lowers_with_int64_feature. With a temporary call toValidator::load(Validator::default_path())(dxil.dll from SDK 10.0.26100.0) onl.dxilin that test:Declared
0x40100000, required0x148100000: the missing bits are1 << 27and1 << 32, i.e.ATOMIC_INT64_ON_TYPED_RESOURCEandATOMIC_INT64_ON_HEAP_RESOURCE. The test passes because it only checks theINT64bit (0x8000). In the title these programs would still fail validation.This is also the fourth open PR for 64-bit image atomics, after #305, #539 and #705. On #305, h0useadv measured that those three give the same +520 validated programs (
a 64-bit image atomic653 → 0), and #305 sets exactly the two flags above.@adamdotpy on GitHub · 2026-11-24 16:43 UTC · original
This is the second open PR for 64-bit image atomics (the other is #539), so I reviewed it against that one directly. Windows 11 / Rust 1.98.1,
52a5381on currentmain(ffe310e, merges as it stands), isolated target dir. Verified here:cargo test -p victory-shader --lib121 passed / 1 ignored including the newimage_atomic_64_bit_lowers_with_int64_feature; clippy--all-targets --all-features --locked -D warningsclean;cargo build --release -p victorybuilds.1. The handle cache collides between the two widths — this is the one real defect.
handle's cache key is(cur, load, first, sampler, props.0)(lower.rs:3311) — onlyprops.0. This PR calls it withprops.0 = kind | 0x1000for both paths butprops.1 = 0x105for 32-bit and0x107for 64-bit. So a 32-bit and a 64-bit atomic on the same view in the same block produce the same key, and the second call is served the first call's handle, annotated for the other width. #539 does not have this: it keeps0x105for both widths and, forSource::Loaded, makes the handle without going through the cache at all. Either the two annotations must be the same value (then0x107is wrong) or the key must includeprops.1; as written, one of the two widths gets a handle the validator sees as the other. Whichever PR lands, this needs deciding first, because both call sites sharehandle.2. The SFI0 feature declaration is thinner than #539's, and that is the difference most likely to show up as a validator rejection. This PR sets only
INT64(0x8000) and its test asserts just that. #539 also sets0x40_0000for a typed 64-bit atomic and0x1000_0000whenever the handle comes from the descriptor heap — which is the common case for UAV tables, i.e. exactly theSource::Loadedpath here. Ifdxil.dllrequires those flags foratomicBinOp.i64/atomicCompareExchange.i64, this branch's containers are rejected where #539's pass. The decisive check neither PR has is validating an emitted 64-bit atomic (not just reading SFI0):Validator::load(...)on a lowered container with admask:0x3atomic, the same waynormalized_mtbuf_loads_need_no_int64validates formats. Until one of the two PRs carries that, the flag set is unverified against the validator, only against each other.3. What checked out line by line against the 32-bit path and against #539. The
dmaskmapping ((false,1)|(true,3)→ 32-bit,(false,3)|(true,0xF)→ 64-bit, anything else refused) is identical to #539'swide, and the new refusal message is the better one. cmpswap packsnew = (vals[0], vals[1]),cmp = (vals[2], vals[3])and passes[cmp, new], matching the 32-bit path's[vals[1], vals[0]];subnegates the packed value the same way; the guard's restore value follows the 32-bit convention (oldfrom the registers only whenglc, else 0), where #539 restores the real pair — both fine, this one is more consistent with its sibling. The handle is made beforebegin_guarded, as onmain, and per-lane waterfall handles come for free throughhandle()(per_laneis computed inside it), which is simpler than #539's duplicatedLoadedarm. The README row dropping "64-bit image atomics" from the missing list is correct.4. Shared gap with #539: no GPU fixture — the
waterfall_testsstyle synthetic program is what would pin the emitted op and the per-lane handle — and no live-title measurement on this branch; #539 at least has one (zeroa 64-bit image atomic is not supportedrefusals in a 19-minute world run).Recommendation: these two should be reconciled into one, not merged separately — they touch the same
image()branch and would conflict anyway. #539 is ahead on the SFI0 flags and on evidence; this one is ahead on simplicity (no separateimage_atomic64function,handle()used uniformly). The two things to settle before either merges are point 1 (annotation vs cache key) and point 2 (validate an emitted 64-bit atomic withdxil.dlland keep whichever flag set it demands).@ashrafsdrop on GitHub · 2026-11-24 16:54 UTC · original
Thanks for the sharp reviews @shortselow-byte and @adamdotpy. Addressed both points in
f89a9d7:Handle cache key collision:
handlescache key now includesprops.1((self.cur, *load, *first, sampler, props.0, props.1)). 32-bit (0x105) and 64-bit (0x107) operations on the same view in the same block produce distinct cache entries with their respective annotations.image_atomic_32_and_64_handles_do_not_collide_in_cacheverifying consecutive 32-bit and 64-bit atomics against the same view.Validator SFI0 / ShaderFlags requirement:
ATOMIC_INT64_ON_TYPED_RESOURCE(1 << 27) andATOMIC_INT64_ON_HEAP_RESOURCE(1 << 32) toShaderFlagsand wired their corresponding SFI0 feature bits (0x40_0000and0x1000_0000).image_atomic_64_bit_lowers_with_int64_featurenow runsValidator::load(...)on the lowered container and asserts all required feature bits (0x8000,0x40_0000,0x1000_0000). Passes DXIL validation with zero errors.All 122 tests in
victory-shaderand policy checks pass cleanly.@adamdotpy on GitHub · 2026-11-24 16:56 UTC · original
Verified
f89a9d7here (Windows 11 / Rust 1.98.1, isolated target dir):cargo test -p victory-shader --lib122 passed / 1 ignored, including both atomic tests; under--nocapturethere is no "no dxil" line, anddxil.dllfrom SDK 10.0.26100 is at the validator's default path here, so theValidator::loadcalls in both tests really ran and the 1.8-style containers with0x8000 | 0x40_0000 | 0x1000_0000validate. Clippy--all-targets --all-features --locked -D warningsclean, release build ofvictoryfine. Point by point on my two findings:1. The cache collision — fixed at the right place, and better than my suggestion. Adding
props.1to thehandleskey fixes it for every caller, not just the atomics, andimage_atomic_32_and_64_handles_do_not_collide_in_cachelowers a 32-bit then a 64-bit atomic on the same view in one block and validates the container. This is also compatible with #539, which keeps0x105for both widths — a more precise key changes nothing for it. Nothing else in the tree keyed on the old five-field tuple (the type change compiles clean), so the blast radius is exactly this map.2. The SFI0 flags — now asserted and validated, not just asserted.
ATOMIC_INT64_ON_TYPED_RESOURCE/ATOMIC_INT64_ON_HEAP_RESOURCEmap to0x40_0000/0x1000_0000, the same values #539 chose, and the test now validates the emitted container withdxil.dlland asserts all three bits. One deliberate difference from #539 worth knowing: you set the heap bit fromself.s.flags & RESOURCE_HEAP != 0(the shader uses a heap anywhere), where #539 sets it per-handle when the source is not a root view. Yours is the conservative direction — declaring a feature you do not use is accepted, missing one is not — so both are correct, yours just declares more in shaders that mix root and heap handles.What is still open on both this and #539 is the same and is now cheap to close with the template from #1065: a GPU fixture (waterfall_tests style) that runs a 64-bit atomic, plus the live-title refusal count, which only #539 has so far. With the collision and the flags settled, the remaining difference between the two PRs is shape (your uniform
handle()call vs #539's separateimage_atomic64), and they still touch the sameimage()branch, so they should land as one.@ashrafsdrop on GitHub · 2026-11-24 16:59 UTC · original
Appreciate the verification and comparison against #539 @adamdotpy! Glad the uniform handle key and SFI0 flag mappings checked out on the live validator.
@fuzeofficlal on GitHub · 2026-11-24 17:18 UTC · original
Reviewed
52a5381against Windows SDKdxil.dll,dxc -T cs_6_6, and live 32-thread contention dispatches on NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics iGPU, and Microsoft D3D12 WARP.Found three issues that prevent
dxil.dllvalidation or break divergent control flow / mixed queries, with fixes verified on top of52a5381infuzeofficlal/VIctory@e2f58d6(branchverify/shader-64bit-image-atomics-1127):SFI064-bit typed/heap atomic feature flags (emit/shader.rs,emit/lower.rs):dxil.dllrejects52a5381output withFlags must match usage: declared=0x40100000, actual=0x148100000.image_atomic_*must setATOMIC_INT64_TYPED(SFI00x40_0000) in addition toINT64(0x8000), plusATOMIC_INT64_HEAP(0x1000_0000) when accessed through descriptor heap handles (!matches!(src, Source::Built { .. })).EXECmasks (emit/lower.rs):let at = self.begin_guarded(guard);ahead ofself.vgprs(...),old, andsubnegation terminatesc(head) and switchesself.curto the guardedthenblock, whilepack64andBin::Substill emit intoc(using values materialized inthen) andend_guardedreferencesoldon thehead -> joinedge.subnegation,cmpswapcompare operands, andself.handle(...)beforebegin_guardedrestores valid SSA dominance for both 32-bit and 64-bit paths, and callingself.end_guarded(at, &[])when!cache.glcavoids emitting a deadi64joinphi.annotateHandleelement tag & per-blockLower::handlescache key collision (emit/lower.rs):DXGI_FORMAT_R32G32_UINT/R32G32_SINTbacking views,dxcemitsResourcePropertiestag0x105(U32) rather than0x107(U64) forRWTexture*<uint64_t / int64_t>atomics (signedness is carried byIMin/IMaxvsUMin/UMax).Lower::handleson fullprops: (u32, u32)instead ofprops.0alone prevents an earlierimage_get_resinfo(0x409float4) in the same block from returning a mismatched handle to a subsequentimage_atomic_*(0x105).Verification (
e2f58d6)dxil.dllvalidation passed across all 11 64-bit atomic opcodes ×glc(false/true), co-locatedimage_get_resinfo, and divergentEXECmasks.addglc=false/truewith 32-bit carry,subunderlane < 16mask verifying inactive VGPR preservation,cmpswapdmask=0xF,swapconservation,smin,smax,umax,or,xoroverDXGI_FORMAT_R32G32_UINTUAV):@ashrafsdrop on GitHub · 2026-11-24 17:25 UTC · original
Thanks @fuzeofficlal for the thorough hardware testing across RTX 5090, AMD iGPU, and WARP, and for catching the SSA ordering and element tag details!
Integrated in commit
a0b441d:vals), 64-bit packing, sub negation, cmpswap compare values, andhandle()now all materialize beforebegin_guarded. Guarded blocks emit only the DXIL intrinsic call;end_guardedavoids dead join phis when!cache.glc.0x105(U32) matching DXC conventions overR32G32backing views.image_atomic_64_bit_executes_across_threads_and_glc_modescovering all 11 atomic opcodes × glc modes across real adapters and WARP.cargo test -p victory-shader(122 tests passed including DXIL validator and multi-adapter execution),cargo clippy -p victory-shader --all-targets --all-features -- -D warnings, andcargo run -p xtask -- policypass with zero warnings.@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
a0b441d:cargo test -p victory-shaderpasses, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@adamdotpy on GitHub · 2026-11-24 19:04 UTC · original
Verified the new head
a0b441dhere (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). The rework sincef89a9d7renames the SFI0 flags (ATOMIC_INT64_TYPED/ATOMIC_INT64_HEAP, bits 0x40_0000/0x1000_0000 unchanged — still validator-tested), reworks the 64-bit image-atomic lowering inlower.rs/host.rswith guarded-SSA handling, and adds 377 lines of tests. Ran here:cargo test -p victory-shader --lib122 passed / 0 failed / 1 ignored (21 s, GPU tests included),cargo clippy -p victory-shader --all-targets --all-features --locked -D warningsclean,cargo build --release -p victorybuilds. Thehandleskey includingprops.1that fixed the #305-style cache collision is still in place. Nothing blocking from my side.@sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: +520 programs over
main, 0 lost.Offline. I merged head
a0b441dontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 22,244 with this PR.mainAll 520 are the same programs that #1467 gains, and the same ones that #1402 gains through #305 (64-bit image atomics). So #305, #539, #1127 and #1467 cover one set. On this data, review can pick between them on correctness and coverage alone.
Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 122, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 00:32 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.64-bit image atomics. In main since today (lower.rs:7404-7510, test image_atomics_of_64_bits). Same as #539; also edits README.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed