Skip to content

Fix/typed image atomic int64 - #705

Closed
Abhishek-Sood wants to merge 7 commits into
Marvisak:mainfrom
Abhishek-Sood:fix/typed-image-atomic-int64
Closed

Abhishek-Sood wants to merge 7 commits into
Marvisak:mainfrom
Abhishek-Sood:fix/typed-image-atomic-int64

Conversation

@Abhishek-Sood

Copy link
Copy Markdown

No description provided.

@Abhishek-Sood

Copy link
Copy Markdown
Author

The change adds 64-bit typed-image atomic lowering, including arithmetic, bitwise, min/max, swap, and compare-exchange operations. It also handles packing and unpacking 64-bit values across VGPR pairs, adds the required DXIL feature flags, and includes a regression test for the new lowering path.

What this change does
Adds lowering for 64-bit typed image atomic operations: add, subtract, bitwise operations, min/max, swap, and compare-exchange.
Packs pairs of 32-bit VGPR values into DXIL 64-bit integers and splits returned values back into register pairs.
Declares the required 64-bit integer and typed-resource atomic feature flags.
Adds a shader-lowering regression test covering the 64-bit typed-image atomic path.

Files changed
crates/victory-shader/src/emit/lower.rs — 64-bit value packing and typed-image atomic lowering.
crates/victory-shader/src/emit/shader.rs — required shader feature-flag mapping.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech 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 and verified on Windows 11 MSVC (Rust 1.98.1). \image_atomics_64_bit_lower_with_typed_int64_flag\ passes along with the full 70 unit tests in \�ictory-shader.

  • \dmask\ matching correctly distinguishes 32-bit (1/3) vs 64-bit (3/0xF cmpswap) atomic payloads.
  • Correctly sets \ lags::INT64 | flags::ATOMIC_INT64_ON_TYPED_RESOURCE\ with DXIL SFI0 feature bit \

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

Heads-up: this no longer merges cleanly with current main (7374bfb) — textual conflict in crates/victory-shader/src/emit/lower.rs. Needs a rebase.

Head itself is green on macOS 26 arm64, rustc 1.98.1 (cargo test -p victory-shader: 57 passed / 0 failed against its own base, +1 ungated test).

@Abhishek-Sood
Abhishek-Sood force-pushed the fix/typed-image-atomic-int64 branch from 92d6d41 to 92ed309 Compare November 24, 2026 08:28

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

Re-checked after the rebase: merges cleanly with current main (8e79c80), and cargo test -p victory-shader --locked on macOS arm64 / rustc 1.98.1 → 71 passed / 0 failed (1 ignored, the Windows-only execution suite).

Static pass on the lowering: the dmask/cmpswap width table ((1,false)|(3,true) → 32-bit, (3,false)|(0xF,true) → 64-bit, anything else refused) is consistent, pack64 zero-extends both dwords before the shift/or, and the new ATOMIC_INT64_ON_TYPED_RESOURCE flag maps to SFI feature bit 0x40_0000 alongside the existing INT64 → 0x8000 path. Refusing unsupported widths instead of silently truncating is the right call.

Windows-side execution (the valu_tests/image_tests suites and the DXIL validator) is covered by the new CI; nothing in the diff is macOS-visible beyond the unit tests above.

@justr4mzi

Copy link
Copy Markdown

Tested PR #705 (92ed309d) on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2), Rust 1.98.1 (x86_64-pc-windows-msvc), and dxil.dll from Windows SDK 10.0.26100.0, against main (02f404e) as negative control.

victory translate --validate (full game shader set, 26,599 containers / 26,148 programs)

Build VS/PS (emitted / validated) CS (emitted / validated) MS (emitted / validated) 64-bit image atomic refusals Flags must match usage. validator errors
main (02f404e, negative control) 12,236 / 12,160 1,440 / 1,417 8,163 / 8,101 653 0
PR #705 (92ed309) 12,754 / 12,160 1,442 / 1,417 8,163 / 8,101 0 520
  • All 653 emit: a 64-bit image atomic refusals are cleared, emitting 520 extra programs (518 VS/PS + 2 CS; the remaining 133 programs advance to downstream refusals such as scalar memory read as data 604 -> 708 and barycentrics read directly 13 -> 36).
  • However, all 520 newly emitted programs fail dxil.dll validation with validator: error: Flags must match usage., resulting in +0 validated shaders (12,160 VS/PS and 1,417 CS unchanged).
  • Root cause from inspection of crates/victory-shader/src/emit/shader.rs in 92ed309: the PR sets ATOMIC_INT64_ON_TYPED_RESOURCE (1 << 27 / SFI0 0x40_0000), but programs accessing UAVs through ResourceDescriptorHeap[] also require the heap-resource int64 atomic flag (1 << 32 / SFI0 0x1000_0000). Note also that 92ed309 includes #696 and #706 in its branch history ahead of current main (02f404e).

Build and checks

  • cargo clippy -p victory-shader --lib: clean.
  • cargo xtask policy: 152 files ok.
  • cargo build --release -p victory: succeeded.
  • cargo test -p victory-shader -- --test-threads=1 and --all-targets: failed to compile test target on pre-existing main issue #719 (lowers(&words) missing rsrc2 argument at lower.rs:7021), unrelated to this PR.
  • No game data included; the title itself was not launched.

AI-assisted analysis and test execution (reviewed locally).

@dcastell1

Copy link
Copy Markdown

This does not build on current main@ffe310e, so it needs a rebase:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> crates\victory-shader\src\emit\lower.rs:7524:23
7524 |     let res = resource::track(&p, &native.layout, native.stage).unwrap();
     |                  ^^^^^^^^^^^^^^^------------------------------- argument #4 of type `Option<&structure::Structured>` is missing
error: could not compile `victory-shader` (lib test) due to 1 previous error

The PR is based on 8e79c80; resource::track gained the structured-access argument in between (that is #709's subject), so the branch predates it. Nothing else was run.

Environment: Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.98.1, MSVC 14.44.35207, debug build, patch applied clean. AI-assisted (opencode).

@pablogonz12

Copy link
Copy Markdown

Same result as I measured on #539, which covers the same 64-bit image atomics. Over the world's shaders (751 programs dumped from a run into the world, re-translated offline), this PR translates the same 4 extra pixel programs (670/751, none lost). Under vkd3d-proton (dxil-spirv 34f0ff8) all 4 fail spirv-val (OpAtomicUMin with a non-integer result type) unless #177's handle-key change is in as well. Details and numbers in my comment on #539.

Setup: RX 9070 XT, RADV (Mesa 26.3.1), CachyOS, vkd3d-proton master 30b0eb9.

@ErRusso

ErRusso commented Nov 24, 2026

Copy link
Copy Markdown

Audit: ✅ Looks good — verified & tested

Reviewed this PR as part of an audit of mergeable PRs.

  • Scope: crates/victory-shader/src/emit/lower.rs + shader.rs (+176/-26). Adds 64-bit typed image atomics: dmask=3 → atomicBinOp.i64, dmask=0xF (cmpswap) → atomicCompareExchange.i64, packing/unpacking the value through VGPR pairs via the new pack64/split64 helpers. Sets the DXIL feature bits INT64, ATOMIC_INT64_ON_TYPED_RESOURCE, and ATOMIC_INT64_ON_DESCRIPTOR_HEAP_RESOURCE.
  • Merges cleanly into main.
  • Tests: image_atomics_64_bit_lower_with_typed_int64_flag → passed. The test builds both a 64-bit add and cmpswap MIMG shader, lowers them, and asserts all three feature bits are present in the emitted DXIL SFI0 flags.
  • Correctness review: the width matrix (1/3 for 32-bit, 3/0xF for 64-bit, cmpswap takes twice the dwords) and the .glc old-value handling for the hi dword are handled correctly. comp is derived from width (0x105 vs 0x107), and sub negates the full i64.

No issues found. Nice, well-scoped feature with proper feature-bit declaration.

@h0useadv

Copy link
Copy Markdown

Offline coverage on main ffe310e (full retail shader pack, victory translate --validate, programs matched one by one): +520 programs validate, 0 newly fail; a 64-bit image atomic 653 → 0. #305, #539 and #705 give exactly the same 520 programs, so on coverage they're interchangeable and the choice can rest on review alone. Stacked with #180 and the lane-mask branch from #653: +1,193, 0 regressions. Full table: #293 (comment)

AI-assisted (Claude Code). Counts only, no game data.

undeadhuman37 added a commit to undeadhuman37/VIctory that referenced this pull request Nov 24, 2026
The DXIL of a 64-bit image atomic (Marvisak#705) sets the typed and heap int64
atomic feature bits. The host pipeline now reads the module's SFI0 mask and
refuses it (logged once) unless OPTIONS9 and OPTIONS11 report the support,
instead of failing in pipeline creation on another GPU.

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

Copy link
Copy Markdown

Verified offline: the class is gone and 518 more programs emit DXIL

Applied the branch's two-file diff on ffe310e + local diag changes; same container dump
(26,503 containers / 26,084 programs), same host, both runs.

metric before after
emit: a 64-bit image atomic 653 0
vertex+pixel programs emitting DXIL 12252 / 14027 12770 / 14027
compute programs emitting DXIL 1443 / 2582 1445 / 2582
mesh programs emitting DXIL 8214 / 8713 8214 / 8713
emit: a scalar memory read as data 771 875

+518 vertex/pixel programs reaching DXIL is the largest single-patch gain we have measured
offline so far.

One thing to know before merge: a scalar memory read as data rose by 104. That is the next
failure being exposed, not a regression — those programs used to stop at the atomic and now
translate far enough to hit something else. It does mean this class (875) becomes the top
remaining blocker once #705 lands, so it is the natural next thing to attack.

Repro: cargo build --release -p victory then victory translate <container dump>; nothing
else in the failure table moved.

@dpalacios69

Copy link
Copy Markdown
Contributor

Independent check of the current head ee037b0 on Linux (cargo test -p victory-shader --locked; no GPU). It already contains main (ffe310e).

The tests do not compile. resource::track takes a fourth argument on main (lanes: Option<&Structured>, resource.rs:147), and one test still calls it with three: error[E0061]: this function takes 4 arguments but 3 arguments were supplied at crates/victory-shader/src/emit/lower.rs:7524:23. The other calls in the file already pass Some(&st); this one needs the same. cargo clippy -p victory-shader --lib is clean.

For anyone choosing between the three 64-bit image atomics PRs (#305, #539, #705; they conflict in pairs in lower.rs and shader.rs), what I could verify statically on ffe310e:

Only the first point is a defect in this PR; the rest is information for whoever decides the order. AI-assisted; no game data.

@bittertea0323

Copy link
Copy Markdown

Useful: the tree you measured is not the tree we measured, which narrows the regression.

Our A/B in this thread ran on 4efabc4 (the head at the time), and there
cargo test --offline -p victory-shader --lib compiled and ran: 129 passed, 15 failed, 1 ignored.
(The 15 failures are all "no SM 6.6 hardware device; skipped" — environmental, this host has no
device available to those GPU numerical tests at that moment, and they are unrelated to #705.)

So resource::track still took three arguments at 4efabc4. The arity change to four
(lanes: Option<&Structured>) came in with main's later commits, and the stale call at
lower.rs:7524 is wherever #705's branch stopped tracking main. Rebased on
ee037b0's base it will need that fourth argument like the other call sites in the file.

Our offline numbers (653 → 0, +518 vertex/pixel programs) stand for 4efabc4; they should not
change if the rebase is mechanical, but I have not measured ee037b0.

@Abhishek-Sood

Copy link
Copy Markdown
Author

can anyone tell whats the final benchmarks or the bottlenecks that we are currently encountering or at ? i need some clear info

@dpalacios69

Copy link
Copy Markdown
Contributor

@Abhishek-Sood there is no official benchmark yet, but the picture is fairly clear from the README status and the testers' runs in #71. Summary, with the sources:

Where it stands (README, 2026-11-23). Menus, intro video and loading run at 30 fps. The world is reached but frames take 0.5-1.8 s and most of the scene is dark or missing.

Bottlenecks, in order of how much they block:

  1. The GPU hangs shortly after entering the world on NVIDIA (TDR, DEVICE_HUNG). Measured causes: translated loops running to the 2^20 cap (a lower VICTORY_SHADER_LOOP_LIMIT keeps the run alive: h0useadv, Machad3x), unbounded root SRVs (GPU: bind root SRVs as one-view tables bounded to their host copy #493 alone: 19 min in the world vs ~20 s on main on an RTX 4090), and wave64 compute on 32-lane GPUs (Shaders: emulate Wave64 compute shaders on Wave32 and narrower hosts #189). Sunkiller-qc's merge order is the best map of this.
  2. Shaders that don't translate, so draws are dropped. README: mesh 8,191/8,506, vertex/pixel 10,617/12,346, compute 1,643/2,539. 64-bit image atomics are listed as missing, which is what your PR is about; bittertea0323's A/B measured 653 refused programs going to 0 on 4efabc4.
  3. Slow frames even when the device survives (0.1-1.5 fps in the tester runs), mostly from those loops and compute passes.

For #705 itself, the next step is small: the current head ee037b0 already contains main, but the test at lower.rs:7524 still calls resource::track with 3 arguments (it takes 4 now, resource.rs:147), so cargo test -p victory-shader doesn't compile. Passing Some(&st) like the other calls fixes it. #305 and #539 cover the same ground and conflict with yours, so it may be worth asking which one the maintainer wants to land.

AI-assisted; no game data.

nazmi pushed a commit to nazmi/VIctory that referenced this pull request Nov 24, 2026
Taken from Marvisak#705 because a real run refuses them seven times (latest dump, 'a 64-bit image atomic is not supported'). The change adds ATOMIC_INT64_ON_TYPED_RESOURCE and ATOMIC_INT64_ON_DESCRIPTOR_HEAP_RESOURCE to the shader flags and maps them to SFI0 bits 22 and 24, which is what DXC's ShaderFeatureInfo calls AtomicInt64OnTypedResource and AtomicInt64OnDescriptorHeapResource. Their own test asserts both bits after lowering.

Merged by hand: one conflict block where the PR's side was empty (its test had already landed), and one test call site that needed the lanes argument the tracker gained.

Gate: both Clippy commands, 656 passed / 14 ignored / 0 failed, policy 193 files, fmt clean.

Applied as the net diff of upstream PR Marvisak#705 (head ee037b0).
LeagueRaINi pushed a commit to LeagueRaINi/VIctory that referenced this pull request Nov 24, 2026
- the net change of Marvisak#705 on current main
- tests of this and of Marvisak#694 pass the lane structure argument resource::track now takes
@muhammed-aksoy

Copy link
Copy Markdown

I tested ee037b0 on Windows 11 with Rust 1.98.1 and the Windows SDK DXIL validator. With the following test-fixture change in crates/victory-shader/src/emit/lower.rs, the serial shader suite passed 121 tests, with zero failures and one ignored.

-            let res = resource::track(&p, &native.layout, native.stage).unwrap();
+            let res = resource::track(&p, &native.layout, native.stage, None).unwrap();

None preserves the original fixture's tracking behavior. This run used synthetic inputs. AI-assisted.

@alexdeliu

Copy link
Copy Markdown

Merged onto main @ ffe310eb, this PR (ee037b0c) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7524 calls resource::track with 3 arguments. Since 6638098 it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let st = structure::structure(&p).unwrap();.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Empty description; the same 64-bit image atomics as #305, which are in main.

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.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.