Repository navigation
Shaders: lower 64-bit image atomics - #305
tarcisioads wants to merge 1 commit into
Conversation
|
Thanks @tarcisioads and @flapwarp78. I compared the current diffs: both implement 64-bit image-atomic lowering. #48 also declares both typed-resource and descriptor-heap 64-bit atomic capabilities and adds an end-to-end synthetic |
|
Review note: running the DXIL validator (dxil.dll from the Windows SDK) on this PR's wide-add fixture fails with "Flags must match usage": the module declares the 64-bit-atomics-on-typed-resource feature but not the one for atomics on resources reached through the descriptor heap, which is how these handles are created here. DXC declares both for the same heap-based operation, and #48 does too. The validator's difference is The three open PRs for this (#48, #305, and the closed #173) agree on the rest: the wide data masks ( D3D12 only checks the container hash, so a driver may still take the module; hence the test passing without the validator. From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware. |
|
Tested with the title
Not tested
(Claude Code, Claude Opus 5.5: ran the title on each build and compared the logs program by program.) |
|
Validation data for this PR, from
So the ~524 programs this PR lets through (the 64-bit image atomic ones) are emitted, but every one fails validation with Why it matters: VIctory doesn't validate at run time, so in game these go to the driver. In a play run with this PR in a larger shader stack, AMD's shader compiler crashed ( No game data in this comment. AI-assisted (Claude Code); I ran the measurements on my machine. |
|
From a tester working with Claude (AI-assisted); measured on my own machine. The lowering looks right to me, but on my machine What happens: every 64-bit atomic in the corpus is Cause: the image's handle comes from Fix on top of this PR: // shader.rs, mod flags
pub const ATOMIC_INT64_ON_HEAP_RESOURCE: u64 = 1 << 32;
// shader.rs, SFI0 features
if self.flags & flags::ATOMIC_INT64_ON_HEAP_RESOURCE != 0 {
features |= 0x1000_0000;
}
// lower.rs, the wide branch
self.s.flags |= flags::INT64
| flags::ATOMIC_INT64_ON_TYPED_RESOURCE
| flags::ATOMIC_INT64_ON_HEAP_RESOURCE;(plus Measured (
The 133 remaining 64-bit-atomic programs now stop on later causes (104 "a scalar memory read as data", 23 barycentrics). With |
|
Measured on the full retail shader pack (26,503 containers) with
|
|
#705 matches this PR almost line for line: 157 of its 158 added lines are identical, including the #539 is a different implementation of the same lowering. It also covers image atomics through the descriptor heap ( Checked by comparing the diffs against |
038a36f to
78dae83
Compare
|
Rebased onto
|
|
Offline coverage on AI-assisted (Claude Code). Counts only, no game data. |
|
Tested
AI-assisted; executed locally on RTX 3050 + WARP. |
|
Neither 64-bit image atomics PR had a GPU test, so I wrote one:
It is a synthetic RDNA2 compute shader. It first runs
The test checks the texels. It skips devices without On AMD RX 9070 (RDNA4) and WARP, merged onto
So both produce correct results on real hardware. The handle-cache concern I raised about #305 (no element type in the key) does not show up with a size query before the atomic in one block. Feel free to cherry-pick the test into either PR. |
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)
|
Verified + integrated. Stack: main The "a 64-bit image atomic" class in our captured runtime containers is cleared (2 → 0); compute emission 493/560. Clean merge, no regressions (148 logic tests pass; the GPU-readback failures are the permanent environmental SM 6.6 baseline on this Win10 box). AI use: Qwen Code; local measurements, user-confirmed visuals. No game data posted. |
|
In-game data for Tree:
This one merges cleanly onto that tree. #539 conflicts there in No game data attached. AI-assisted (Claude Code). |
…ored, views off their copy's elements get their own bytes, card room for the first world frame, levels on demand run on the card - Descriptor records the title copies into its heap as bytes are mirrored before each submission (pull request Marvisak#305 by Flyander, after upstream VIctory 86a5ed6), with a per-slot fingerprint so only records that changed are mirrored, the page read through the kernel, a switch (VICTORY_HEAP_SYNC=0) and a counter: about 40,000 records a frame on the test machine. - A buffer view off its copy's elements gets a copy of its own bytes (after upstream 86a5ed6; VICTORY_VIEW_OWN_COPY=0: refused as before). - Room on the card for the world's first-frame bursts: buffer copies (VICTORY_CARD_ROOM_FOR_BUFFERS, now on) and render targets (VICTORY_CARD_ROOM_FOR_TARGETS_MB, 3,072); a copy turned down gives its room up and is logged; the texture pass asks again every 32 MiB. 98 buffer copies made (945 MB) where earlier runs made 1; 25 MB compared on the processor a frame where it was 550 to 710. - Levels on demand: the fixes of pull request Marvisak#747 by AscilCH. First run on a card (RTX 4070, VICTORY_LEVELS_ON_DEMAND=1): no device loss, 3.1 GB not allocated for levels the title does not hold. Still off by default. - The guarded blocks under storage writes into physical pages are opened by default (VICTORY_PAGE_WRITES=0: counted only). - Shaders: a program is translated with first-half interpolation pairs only if it was refused for one (with it on for every program 8,551 working pixel programs came out changed); parked lane-mask pairs, f64 conversions and sums, lane permutations: 14 more programs translate. - Counted, not fixed: an indirect compute pass asks for about 77,500 groups in x and is cut to 65,535. One five-minute game run of these changes on the test machine: no device loss, no failed request. This merged tree was built; its test suites were not run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…integration Already covered by the 64-bit texture atomics of Marvisak#48 (which also sets the heap-atomics feature and returns the old value under the guard), so the code is ours unchanged; only the PR's test is taken, and it passes against our lowering. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
…ored, views off their copy's elements get their own bytes, card room for the first world frame, levels on demand run on the card - Descriptor records the title copies into its heap as bytes are mirrored before each submission (pull request Marvisak#305 by Flyander, after upstream VIctory 86a5ed6), with a per-slot fingerprint so only records that changed are mirrored, the page read through the kernel, a switch (VICTORY_HEAP_SYNC=0) and a counter: about 40,000 records a frame on the test machine. - A buffer view off its copy's elements gets a copy of its own bytes (after upstream 86a5ed6; VICTORY_VIEW_OWN_COPY=0: refused as before). - Room on the card for the world's first-frame bursts: buffer copies (VICTORY_CARD_ROOM_FOR_BUFFERS, now on) and render targets (VICTORY_CARD_ROOM_FOR_TARGETS_MB, 3,072); a copy turned down gives its room up and is logged; the texture pass asks again every 32 MiB. 98 buffer copies made (945 MB) where earlier runs made 1; 25 MB compared on the processor a frame where it was 550 to 710. - Levels on demand: the fixes of pull request Marvisak#747 by AscilCH. First run on a card (RTX 4070, VICTORY_LEVELS_ON_DEMAND=1): no device loss, 3.1 GB not allocated for levels the title does not hold. Still off by default. - The guarded blocks under storage writes into physical pages are opened by default (VICTORY_PAGE_WRITES=0: counted only). - Shaders: a program is translated with first-half interpolation pairs only if it was refused for one (with it on for every program 8,551 working pixel programs came out changed); parked lane-mask pairs, f64 conversions and sums, lane permutations: 14 more programs translate. - Counted, not fixed: an indirect compute pass asks for about 77,500 groups in x and is cut to 65,535. One five-minute game run of these changes on the test machine: no device loss, no failed request. This merged tree was built; its test suites were not run.
Descriptor records the title copies into a placed shader-visible heap as bytes, with no descriptor call, are mirrored before each submission: the heap's range is tracked by the write journal or the guards (watch::Tracked), its changed pages are read through the kernel, and the records on them whose fingerprint is not the one last seen there are made in the host heap (HostHeap::mirror_copied). Capped host heaps stop before their dynamic slots. VICTORY_HEAP_SYNC=0: not done, as before; a frame line counts pages, records and time. A buffer view whose bytes do not start on an element of its buffer's host copy (the title places views at ring positions in its big heap) gets a copy of its own bytes (shadow::exact), brought up to date and written back like any other, kept while a list or slot holds it. Before, such a view was refused and read zeros. VICTORY_VIEW_OWN_COPY=0: refused, as before. The fork's author reports the first room rendering right with these. Ported from fxceless/victory-fork a26859f (the mirroring is pull request Marvisak#305 by Flyander, after upstream VIctory 86a5ed6), these two parts only. Its card room for the first world frame, levels on demand, the page-write default, the counts of cut indirect compute groups and the shader changes are not taken.
Implement lowering for 64-bit
image_atomic_*instructions invictory-shader:flags::ATOMIC_INT64_ON_TYPED_RESOURCE(1 << 27inDxilShaderFlags) and map it to0x40_0000(ShaderFeatureInfo_AtomicInt64OnTypedResource) inSFI0(crates/victory-shader/src/emit/shader.rs).dmask == 3for binary ops,dmask == 0xFforcmpswap) incrates/victory-shader/src/emit/lower.rs, declaring typedU64resource properties (0x107), packing 2/4 VGPRs viapack64, emittingatomicBinOp.i64/atomicCompareExchange.i64, and splittingglcresults back intov[reg..reg+2].image_atomics_64_bit_lower_with_typed_int64_flagcovering 64-bitimage_atomic_addandimage_atomic_cmpswapand verifyingSFI0feature bits.Verification
cargo test -p victory-shader(57/57 passed on macOS; Windowsdxil.dllvalidation and host D3D12R32G32_UINTview mapping invictory-gpunot run)rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower.rs crates/victory-shader/src/emit/shader.rs(ok)cargo xtask policy(ok)