Skip to content

Translate 64-bit texture atomics and follow proven shader branches - #48

Closed
flapwarp78 wants to merge 1 commit into
Marvisak:mainfrom
flapwarp78:shader/typed-atomics-and-branch-threading
Closed

flapwarp78 wants to merge 1 commit into
Marvisak:mainfrom
flapwarp78:shader/typed-atomics-and-branch-threading

Conversation

@flapwarp78

Copy link
Copy Markdown

What changed

  • Translate 64-bit texture atomics to native SM 6.6 DXIL. Preserve both halves of the old value when the instruction requests it, and declare the typed-resource and descriptor-heap capability bits.
  • Follow a branch directly when the shader proves its outcome on an incoming edge. This lets a reused register carry a descriptor address on one path and buffer data on the other.
  • Cover both atomic widths and branch cases in regression tests.

Verification

Microsoft's DXIL validator accepted 628 shaders from a local shader-pack scan. Texture atomics recovered 520 translations, and the control-flow change recovered another 108. The first 520 outputs were byte-for-byte identical with the control-flow change applied.

The shader, game, and format suites passed 73 tests. The asset-policy check passed. Rendering in the game still needs a Windows D3D12 run.

@DaviTostes

Copy link
Copy Markdown

Tested d55ca40 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • main alone does not build on Linux (E0425 in victory-gpu), so the check uses Build: make workspace tests run on Linux #39 as the base; the merge is clean.
  • cargo test --workspace: 158 passed, 0 failed, 3 ignored across all test binaries, with no new failure from the 64-bit atomics or the branch-specialization code.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

@jeremygold02

jeremygold02 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

I verified the texture-atomic change on a physical RTX 5070 (Windows 11, NVIDIA 621.01). On 97c78d1, four 32-bit cases produced the expected texel and the translator rejected all four 64-bit cases. At d55ca40, all eight produced the expected texel.

I used the register sequence in heap_texture_atomic_widths with one thread and one initialized texel. The test covered compare-exchange with a matching and mismatching comparand, addition, and subtraction at both widths. The second atomic added the first operation’s returned value back into the texel. With a 64-bit comparand that differed only in the high word, the final low/high words were 00000006 / 00000012, as calculated on the CPU. The wide add and subtract cases also exercised carry and borrow across the 32-bit boundary.

The device reported typed-resource and descriptor-heap 64-bit atomic support. The SDK DXIL validator accepted each emitted shader, the driver created each compute pipeline, and the queue fence reached 1 before readback. The 32-bit view used R32_UINT and the 64-bit view used R32G32_UINT.

I also matched all nine distinct pixel shaders that had reported the 64-bit atomic error during a local mission-loading run. Offline translation on 97c78d1 reproduced the same error on all nine. With d55ca40, seven translated and passed the SDK validator. The remaining two reached the separate barycentrics read directly limitation. The rebased 56f0072 has the same crates/victory-shader Git tree as the tested revision. The title shaders were only translated and validated offline. Mission rendering is still unverified on this PR.

@flapwarp78
flapwarp78 force-pushed the shader/typed-atomics-and-branch-threading branch from d55ca40 to 56f0072 Compare November 24, 2026 00:06
@DaviTostes

Copy link
Copy Markdown

Re-checked the new head 56f0072 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

AI-assisted (DeepSeek V4.1 Flash coding agent).

@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

checked: 56f0072 on Linux x86_64 (Debian, kernel 6.12), Rust 1.98.1 (rust-toolchain.toml), cargo -j4. No GPU, no Windows, no game files, no DXIL validator. Others have already reported Windows hardware runs and the Linux workspace on #39; this adds a before/after on main and a few review points.

What I ran (throwaway worktree of the PR head, base 35b054e):

  • cargo test -j4 -p victory-shader -p victory-formats -p victory-game: victory-shader 54 passed, victory-formats 17 passed (3 ignored), victory-game 2 passed, 0 failed. That is 73 passed, which matches the PR text.
  • cargo fmt --check -p victory-shader: no diff.
  • cargo clippy -j4 -p victory-shader --tests: one new warning from this PR: very complex type used (clippy::type_complexity) at lower.rs:157, the handles map key, which now contains a nested (u32, u32). The same command on current main (9aef3d9) only gives the existing dead_code warning for constant_color. A type alias or small key struct would clear it, in case warnings are meant to be zero.
  • Test fails before the fix: I appended atomic_tests::heap_texture_atomic_widths from this PR to main (9aef3d9) and ran it: FAILED with Unsupported { offset: 36, what: "a 64-bit image atomic" } (the 64-bit cases). On the PR it passes. This test runs on Linux; only its optional validator step is Windows-only.
  • Branch threading, before/after: I fed the program from threading.rs (WORDS) through the full emit() with a table SRV + UAV layout. Main refuses it: "GFX10 code at 0x40: a scalar memory read as data is not supported". The PR translates it (2252-byte container); constant_edges returns [(0, 2, 4)]. This shows the retry path is exercised end to end by that program. I did not validate or run the resulting DXIL.
  • Merge check (trial git merge-tree of PR heads): clean with current main and with 17 other open PRs. It conflicts with shader: emit WaveSize(32) for small Wave64 groups and elide SGPR spills in SSA #54 in emit/mod.rs: both change emit(), Translate 64-bit texture atomics and follow proven shader branches #48 wraps it in a retry and shader: emit WaveSize(32) for small Wave64 groups and elide SGPR spills in SSA #54 adds emit_for.
  • On Linux the PR head alone does not build victory-gpu (E0425 host_resource, also on main); I did not run the full workspace here.

Review notes (none blocking):

  • emit() retries with threading only when the first attempt returned Unsupported. Programs that already translate never take the new path, which fits the "first 520 outputs identical" statement.
  • The 64-bit atomic path reads consistently with the 32-bit one: cmpswap passes (comparand, new value), sub negates at the same width, and with glc the old value is split into v[reg] and v[reg+1], while inactive lanes keep their original data. I only read this; the Windows runs reported above are the real check.
  • Including the full props in the handles key looks like it also fixes a collision between 32-bit and 64-bit views at the same load site.
  • thread_edges ends in unreachable!("threading an incoming edge") for other exit kinds. I could not find a way to reach it from constant_edges, but returning a ShaderError would keep a future change from turning into a panic in the translator.
  • constant_edges threads at most one incoming edge per join (it stops after the first proven one). Fine for correctness; mentioning it in case it is intended.
  • The translator does not check the device caps for 64-bit atomics on typed resources and on descriptor-heap resources (D3D12_FEATURE_DATA_D3D12_OPTIONS9 and OPTIONS11). A device without them would fail at pipeline creation instead of being refused at translation. Reports above are from a device that has both.
  • I did not cross-check the two new shader-feature bit values (0x40_0000, 0x1000_0000) against DXC's DxilConstants.h; there is no DXC here. The Windows validator results from other testers cover them.
  • The threading unit tests check the rewritten IR (block indexes). A test that goes through emit(), like the check above, would also cover the retry itself.

Not verified: Windows/D3D12 runtime, any GPU, DXIL validation, the 628-shader scan (520 + 108), behavior of translated threaded shaders, bit values against DXC.

@DaviTostes

Copy link
Copy Markdown

Tested 56f0072 on Arch Linux x86_64, rustc 1.98.1: pass.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

@SpaghettiMaster545

Copy link
Copy Markdown

Tested with the title 56f0072 (this PR), against main and against #305 on the same machine.

  • NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124); Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build of the PR merged alone onto main d2a4bae, its own empty VICTORY_CACHE_DIR, scripted keys into story mode, until the host GPU failure (NVIDIA RTX 5070 Ti: world hang (DEVICE_HUNG) on 97c78d1 is not one program, not loops, not barriers; 77 compute pipelines refused #71, unrelated), compared program by program with a main run made the same way.
  • In the main run, 14 pixel programs stop with a 64-bit image atomic.
  • With this PR: 0 programs stop with that reason; 10 of the 14 translate and their pipelines are made; 2 stop at a later reason; 2 were not reached in this run.
  • 10 more pixel programs run that stopped on main with a scalar memory read as data (7) and a descriptor read only as data (3), presumably from the branch-following part of this PR. 20 gained in all, 0 programs that ran on main stop, and no pipeline is newly refused by the driver.
  • For comparison, Shaders: lower 64-bit image atomics #305 under the same conditions: 0 programs stop with that reason and 9 of the 14 run, with nothing else gained.

Not tested

  • AMD GPUs, a release build, the image results themselves (only translation and pipeline creation are compared).

(Claude Code, Claude Opus 5.5: ran the title on each build and compared the logs program by program.)

@ghost ghost mentioned this pull request Nov 24, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
… lane count past 32 KiB)

AnoHunted's Marvisak#459: a mesh shader whose declared vertex and primitive
maxima take more than D3D12's 32 KiB of outputs declares the lane count
instead, where that is lower.

No textual conflict. Mechanical, crates/victory-shader/src/emit/mod.rs:
git placed Marvisak#459's three test items at the end of the file, inside
`atomic_tests` (Marvisak#48's module, which is last in this tree); they are
moved to the end of `tests`, where Marvisak#459 has them, and its `emit` call
passes `Target::ANY` (Marvisak#223's argument).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…rol flow; waterfall loops proven)

Marvisak#566 is stacked on Marvisak#307, which this tree holds as its first two commits
(the tree's resource.rs was identical to ffa6635's). The merge so also
brings Marvisak#307's last two commits, 077ec8b and 6285e19. Git found upstream
main as the base, which sets Marvisak#307's own lines against themselves; each
file was merged with ffa6635 as the base instead.

- crates/victory-shader/src/resource.rs: Marvisak#566's, unchanged (the tree had
  no edits of its own there).
- crates/victory-shader/src/emit/lower.rs: no conflict on that base. The
  tree's lowering is kept (Marvisak#307's waterfall arm of v_readfirstlane before
  the console-flow form, fetched_index through Marvisak#483's heap guard), with
  Marvisak#566's Source::LanePhi arms and tests. lane_heap_index joins the
  indices heap_index and fetched_index return, so each is already
  guarded. Marvisak#226's annotation test passes the per-lane form to track.
- crates/victory-shader/src/structure.rs: both sides' additions kept:
  MAX_MEMO (Marvisak#288) with MAX_MEET, and in Structured the wave64 stack's
  execs, others and pairs with Marvisak#566's reach and paired_masks.
  paired_masks is filled last, since it takes the masks pairs reads.
- crates/victory-shader/src/emit/mod.rs: translate keeps Marvisak#309's spill
  forwarding and Marvisak#223's target, structures first and passes the per-lane
  form to track as Marvisak#566 does. The threading retry of emit passes its
  own. The tests' helpers (Marvisak#223's, Marvisak#306's, Marvisak#459's, Marvisak#48's) pass it too.
- apps/victory/src/translate.rs: Marvisak#566's arm (Source::LanePhi is no
  leaf); the tree's fix already counted Fetched as loaded, as 077ec8b
  does.
- docs/architecture.md: no conflict on that base; Marvisak#566's text.
- emit/image_tests.rs (Marvisak#160), emit/lane_read_loop_tests.rs (Marvisak#439),
  sgpr_spill.rs (Marvisak#309, Marvisak#320): track takes the per-lane form. Helpers
  that return the error keep the order of failures (resources, I/O,
  then structure).
- emit/waterfall_tests.rs (new, Marvisak#566): lower::Parts gets the tree's
  target, console_cf and per_lane_only; the dispatch fills Marvisak#483's guard
  dwords.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Marvisak Marvisak closed this Nov 24, 2026
mercuryVM pushed a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
A direct eight-word scalar load can supply the resource of an image atomic without exposing any descriptor words as values. Avoid emitting a float-annotated dimension query in that case while retaining reconstruction for scalar reads, PHIs, and other consumers.

Refs: Marvisak#48, Marvisak#177, Marvisak#259
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…ntains Marvisak#223)

Conflicts:
- crates/victory-shader/src/emit/lower.rs, Lower::new: shader-tracking
  (Marvisak#309) ignores the dead lane instructions of SGPR spills when deciding
  a compute program reads other lanes; Marvisak#233 splits that test into
  in-half reads (swizzles, DPP) and whole-wave reads. Marvisak#233's split is
  kept, with both of its lane-read tests over the live instructions only
  (a `live` closure over sgpr_spill::dead). Its other instruction scans
  (v_readfirstlane, permutes) stay over all instructions, as Marvisak#233 has
  them.
- lower.rs, v_readfirstlane_b32: shader-tracking's (Marvisak#307) arm for a waterfall
  loop's read of a descriptor dword (each lane's own) and Marvisak#233's arm for
  the console flow (the console wave's first lane in EXEC) are both kept,
  the waterfall arm first: the waterfall's compares are taken as true
  per lane before anything else (Lower::valu), in the console flow too,
  so its reads must stay each lane's own.
- crates/victory-shader/src/emit/mod.rs: module list (threading and
  split_tests) and test imports of both; the test import of
  bitcode::Attr stays removed as shader-opcodes left it (the tests take
  it from `super::*`). emit_program (split from emit by Marvisak#48 in the opcodes
  branch, for the retry after edge threading) takes and passes Marvisak#233's
  `target`.
- crates/victory-gpu/src/shader_cache.rs: tests of both sides kept.

Mechanical, for Marvisak#233's new arguments (no test checks changed):
`target: Target::ANY, console_cf: false` in hand-built lower::Parts in
emit/lower.rs tests (two), and Target::ANY as emit's last argument in
emit/image_tests.rs, emit/mod.rs tests (two) and sgpr_spill.rs tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dieharddillon1 pushed a commit to dieharddillon1/VIctory that referenced this pull request Nov 24, 2026
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)
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.

6 participants