Skip to content

Shaders: one console wave sharing LDS runs in the console flow on 32-lane hosts - #439

Open
r4tedx wants to merge 85 commits into
Marvisak:mainfrom
r4tedx:shader/console-flow-lds
Open

r4tedx wants to merge 85 commits into
Marvisak:mainfrom
r4tedx:shader/console-flow-lds

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Needs a BVH builder gate when merged alone. This PR makes some BVH builder programs translate while a sibling stage can stay refused on a 32-lane host. A half-run builder crashed the title at load in neonbyte1's runs (see the comment below and #2118, comment 7179788584). Merge it together with, or after, an all-or-none builder gate such as #2118.

Current head 7587052 (2026-11-26), on top of e9f18c9 below, still with main at 63bcca4 (merge-tree clean). New since e9f18c9: the placed-UAV test fix merged up from #223; steven-seagull27's partial-group reductions and f16 whole-wave sums from fork PR #19 (611184e, f968c54, author kept) and 2658128; e2d3cfd keeps LDS, whole-wave sections and *permute* in halves out of programs that reach title memory (root_memory, from latentdev's patch); 7587052 adds latentdev's console-flow tests (co-authored). lower.rs is 506,876 bytes. At 7587052, WARP only: cargo xtask policy ok, clippy clean, VICTORY_WARP=1 cargo test --locked -p victory-shader --lib -- --test-threads=1 349 passed, 4 failed, 3 ignored (2658128: 343 / 4 / 3; the same 4 main failures as below). nathanbzrr's review ran the shader tests at 7587052 on an RX 7600 (native 64-lane): 353 passed, 0 failed. Nobody has run these split tests on 32-lane hardware at 7587052. No title run for this update.

At e9f18c9, merged with main at 63bcca4 (merges only, no rebase: main into #223, then each PR's new head into the one above it). With main's growth, crates/victory-shader/src/emit/lower.rs would pass the asset policy's 512 KiB limit, so #233 first moves lower.rs's inline tests into emit/lower/tests.rs, unchanged but for one indent level, (desplmfao's idea, beside main's emit/lower/bvh.rs). Here lower.rs is 506,583 bytes. The conflict resolutions follow kawaii-shakal's notes, and each merge commit lists them. Local verification at this head and at the head of each PR under it, on Windows 11 with the software renderer only (WARP, no hardware adapter for this update): cargo xtask policy ok; cargo clippy --locked -p victory-shader --all-targets -- -D warnings clean; VICTORY_WARP=1 cargo test --locked -p victory-shader --lib -- --test-threads=1: 341 passed, 4 failed, 3 ignored. The 4 failures are main's own: on main 63bcca4 the same command gives 298 passed and the same 4 failed. They are synthetic_tests whose "hardware" pass VICTORY_WARP=1 puts on WARP. No title run for this update. AI-assisted (Claude).

Stacked on #320, which is on #233, which is on #223. They are one line of work and merge in that order; each PR's diff contains the ones under it. The commits that are new here start at 7388024 (table below). Head: 7587052.

History, 2026-11-24: The whole stack was rebased onto main 8e79c80 on 2026-11-24 (upstream merged about 55 PRs that day and added CI). New upstream tests call emit and build lower::Parts directly, so the wave-range argument and the two fields this stack adds are given to them in the commits that introduce them (in #223, #233 and #320). CI's first run on these PRs failed in tests, not in clippy: GitHub's runner has no GPU and lists Windows' software renderer (4-lane waves) as an adapter, and tests here assumed every listed adapter runs 32-lane waves. The tests are fixed where they were introduced: the hardware-adapter list leaves that renderer out by its ids and name, and the one test that takes the default device accepts a host without 32-lane waves. No translator code changed. The test-only commit e6936e3 (the lane-read loop test skips hosts without SM 6.6) is folded into #320, where that test is added, so 16 commits are new here. Each commit builds on its own. The head before the rebases was 055aef9. Commit ids in testers' reports below and in older comments are from before the rebases; the table gives each commit's old id.

No new features will be added to this PR. It has grown as testers and contributors reported things; from here it only gets fixes for what review finds. The next step of the work (groups of more than 64 threads) is on a fork branch and is not part of this.

What

#233 runs console wave64 compute programs on hosts without 64-lane waves (NVIDIA) as two 32-lane waves, in the "console flow" where a program needs its whole wave. It still stopped programs that share LDS inside one wave, and a few other forms. This PR takes those:

  • One console wave sharing LDS without s_barrier. The console runs an instruction in all 64 lanes before the next, so a lane reads what another lane wrote one instruction earlier. In the console flow both halves reach every LDS access together, so a group barrier before each access puts it after every earlier one.
  • Whole-wave sections (reductions and prefix sums) in groups of exactly 64 threads: each half's result is exchanged and combined, integers and floats.
  • ds_bpermute_b32, which did not translate on any host: a read within the lane's own 32-lane half.
  • Selects on masks held as numbers, on every host.
  • Loop-carried mask joins in the console structure.
  • Refusals that say why (... in a group of more than 64 threads, ds_permute across the halves, a whole-wave section), and a translate --validate line that prints a failing module's thread-group size, wave size and dx.op names.

Nothing changes for programs that translated before, with two exceptions measured below: on hosts that run 64-lane waves about 18 title programs with a lane read in a divergent branch change from the per-lane form to the console flow, and programs both forms refuse may report a different reason.

Commits new in this PR

commit by what test id before the rebase
7388024 me single-wave LDS in the console flow; specific refusal reasons one_wave_shares_lds_in_instruction_order, lds_order_holds_when_one_half_is_busy 88cb024
c7806a8 me translate --validate prints what a refused module declares and calls the_last_modules_summary_... 9745f35
a31c82e @Raxstreams integer whole-wave reductions and prefix sums across the halves (reviewed here) its prefix test 9b73d66
b0f64c9, 6090b47 me tests for the above (sum, max, min, or, masked sum); plan document whole_wave_reductions_join_both_host_waves, masked_whole_wave_sum_straddles_the_halves 3925b8f, e49302a
fa72507 me test only: LDS written and read in different exec-masked blocks, the pattern measured on #189 lds_written_and_read_in_different_masked_blocks a32c177
ddaae36 me the startup warning's text (a review nit from #233) none 8876ed3
ab7882d @Raxstreams ds_bpermute_b32 as an in-half read (r4tedx/VIctory#2) its two tests 416714c
826577e me more tests for it (masks over both halves, groups of 128 / 48 / 32, beside a lane read) backward_permute_in_other_masks_groups_and_forms f653ea4
00888ac me float sum, min, max and prefix sums across the halves float_whole_wave_reductions_join_both_host_waves, masked_and_prefix_float_sums_cross_the_halves 965ce30
783feee me plan document only none 2467891
e461457 me compute v_cndmask_b32 takes masks held as numbers; fixes the high dword of such a wave64 mask when two instructions write it selects_on_masks_held_as_numbers d2189ff
1c06edd @ifBars loop-carried inputs of console mask joins (r4tedx/VIctory#6) lane_read_loop_with_a_joined_exec_back_edge 9e98b2b
04971f8 me that test dispatched on every hardware adapter same 901eef9
f12df1e me a lane read in a divergent branch beside a whole-wave section takes the console flow on 64-lane hosts too; a mask copied dword by dword no longer recurses until the stack runs out (reachable since #233; found with @aycow's fixture) lane_reads_in_branches_beside_a_whole_wave_section, a_mask_copied_dword_by_dword_stops_instead_of_recursing e4d899f
1ca87f7 MichaelSmithAI (r4tedx#5) a numeric select nothing consumes no longer makes a program declare the console wave size (a side effect of d2189ff) selects_from_independently_written_mask_words 055aef9

Measured

On the title, by testers on their own copies

RTX 3070 Ti Laptop, driver 610.88, four-build comparison: across three runs containing #439, DRED named compute 42683eebec081520, dispatched as (128, 64, 1), at device removal on its first world dispatch. On main the driver refused this pipeline and the run later hung in ExecuteIndirect. With #578 alone the run lasted 420 s and dropped 85–98% of world draws. The separate RTX 3070 skip run below used a different stack and driver.

On an RTX 3070 with the #439 1ca87f7 integration stack and loop limit 32, skipping direct and indirect dispatches of 42683eebec081520 still ended in device removal at menu frame 1880. DRED named an indirect mesh operation with a null u9 and empty breadcrumbs. The faulting operation is undetermined. RTX 3070 skip run

Nobody has run the title on a head after f653ea4. The world hang (#71) is unchanged by this stack at the default loop limit.

Locally: an offline translate over a local copy of the title's shaders

victory translate --host-lanes 32-32 --validate --list (and 32-64): CPU only, no pipelines, nothing launched or rendered. Counts and reasons only; nothing from the title is in this PR. At 055aef9 (before the rebases), and again after the first rebase on main 2e4e280 with the same results; not rerun on 8e79c80, which merged more shader PRs:

  • For a 32..32 host: 1,691 of 2,581 compute programs emitted, 1,637 validated. Vertex, pixel and mesh counts are those of main. A tester's count at f653ea4 (1,668) matches mine at that head. For a 32..64 host: 1,735 emitted, 1,681 validated, which a tester measured independently on an RX 9070 with pipelines created (1,735 / 1,681 / 1,735).
  • All 54 compute modules that fail validation give the stage-incompatibility message and call sample (see the note below).
  • Step by step, program by program, with 0 programs lost at every step: float reductions +8, loop-carried joins +9, the e4d899f rule +6 (32..32) and +12 (32..64), numeric selects +3 (32..64 only). On the tester tree, which has the descriptor PRs, the numeric-select commit is worth 24.
  • Still stopped for wave size on a 32..32 host: 43 programs in groups of more than 64 threads, 4 whole-wave sections in other group sizes, 2 section steps the simulation does not follow.
  • On a 32..64 host about 18 programs that translated per lane before e4d899f now take the console flow (they have a lane read in a divergent branch beside a whole-wave section).

Validation note

Compute programs that sample with implicit derivatives (image_sample) are emitted as dx.op.sample, which validator 1.6 / 1.7 rules do not allow outside pixel shaders. main emits 23 such modules; this stack lets more such programs translate, so more of them appear (54 here). The cause is not in this stack: diagnosis with a hand-assembled reproduction. #180 replaces these samples and #201 tracks the class; a census rerun measured #180 taking the class to 0 on main. Merging #180 first, or together, keeps those modules from reaching a driver unvalidated.

How this relates to other open PRs

docs/wave64-on-wave32.md shows as deleted in this diff, with this PR's plan text in it: #233 folded the plan into docs/architecture.md, and the merge carries that up. The design notes are in this description.

Not verified

  • No console hardware. Expected values in the tests follow the ISA's semantics. Why ds_bpermute_b32 stays in each half: AMD, "RDNA 2" Instruction Set Architecture Reference Guide (30 Nov 2020), §10.4.4 "LDS Lane-permute Ops", pp. 96–97: "in wave64 mode the permute operates only across 32 lanes at a time of each half of a wave64 … it executes as if were two independent wave32's. Each half-wave can use indices in the range 0-31 to reference lanes in that same half-wave", "only index bits [6:2] are used", "Reading from disabled lanes returns zero". The lowering follows this (lane ((addr + offset) >> 2) & 31 in the reader's half, 0 where it is inactive). The opcode table's pseudocode (§12.13, p. 206) writes mod 64, which disagrees with §10.4.4; we follow §10.4.4. ds_permute_b32 is not translated yet and still keeps a program out of the split.
  • Nothing after f653ea4 has been run in the title, by anyone. The local run only translates and validates.
  • What the barriers and guards cost on real dispatches, beyond the one frame-time figure above.
  • A float sum across the halves adds each half's sum last: one more order of additions, so its last bits may differ, as they already may within one host wave.
  • Of the LDS tests, one needs the barrier before each LDS access on an RTX 5070 (masked write and masked read with no branch between: the lower half reads 0 in 20 of 20 runs without it). The others pass either way on that card, so they check the result and not the need.
  • Masks copied dword by dword (EXEC restored with two s_mov_b32) stop with a reason; following them is not done.

Tested

Historical, at an earlier head: Independent Windows 10 22H2 run on an RTX 4060 Ti at c153b21 with #175 and #362: 155 shader tests passed, 0 failed, 1 benchmark ignored. The split-wave and joined-back-edge tests executed on hardware and returned exact results. WARP, DXIL validation, and compiler-dependent comparisons had skips. Hardware run and skip breakdown

Windows 11, an NVIDIA RTX 5070 (32..32) and an AMD Radeon iGPU (RDNA2, 32..64) in one machine. Every test in the table is hand-assembled GFX10, validated by dxil.dll, dispatched on each hardware adapter and compared lane by lane with the console's result, except the two that only check what the translator emits (the_last_modules_summary_..., selects_from_independently_written_mask_words).

  • Historical, before the merge of main 63bcca4: At 1ca87f7, on main 8e79c80, with the commands upstream's CI runs: cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features are clean at the head of each of the four PRs; cargo test --workspace --locked: 346 passed, 0 failed, 6 ignored (RTX 5070 + Radeon iGPU). Under the CI runner's conditions emulated here (the software renderer as the default device and no hardware adapter listed) the shader crate's tests pass at each head, the GPU ones by skipping. Before the rebases, cargo test --workspace at 055aef9: 299 passed, 0 failed, 4 ignored.
  • cargo xtask policy: ok at that head and, after the tests move, at e9f18c9.
  • Others ran the split tests on an RTX 4070 SUPER, 5080, 5090, a GTX 1660 Ti (Windows 10 with the Agility SDK) and the shader crate's tests on macOS.

AI-assisted. The tests are synthetic and do not use the title. The counts under "Locally" come from the offline translate run described there.

🤖 Generated with Claude Code

@Raxstreams

Copy link
Copy Markdown

On an RTX 3080 Ti (32 lanes), I replayed 77 captured compute shaders that the #414 translator had rejected for wave64 lanes or shared LDS. With this change applied, 20 of 77 passed both DXIL validation and actual D3D12 compute pipeline creation. The other 57 still failed. This is offline pipeline coverage. I have not verified the dispatch outputs for these shaders.

@r4tedx
r4tedx marked this pull request as draft November 24, 2026 03:34
@DaviTostes

Copy link
Copy Markdown

Verified 88cb024 on Arch Linux x86_64 (rustc 1.98.1, cargo test -p victory-shader): 58 passed, 0 failed, 0 ignored.

Not covered: the new console-wave LDS paths executed on a Windows/Wine GPU (parser/emit tests only here) and title behaviour (no game data).

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you. 20 of 77 passing both checks is a useful floor, and the 57 are the more interesting part.

Could you post how the 57 split, as counts only?

No game data used on my side. AI-assisted.

@DaviTostes

Copy link
Copy Markdown

Re-checked the new head 9745f35 (“translate: say what a module the validator refuses declares and calls”) on Arch Linux x86_64 (rustc 1.98.1): cargo test -p victory-shader 58 passed, 0 failed, 0 ignored — same result as 88cb024, no regression from the force-push.

@SpaghettiMaster545

Copy link
Copy Markdown

Tested with the title at 9745f35 (this PR with the #223 / #233 / #320 stack under it), merged onto main d2a4bae. The same setup as my runs on #320: RTX 5070 Ti, driver 621.24 (32-lane waves), Ryzen 7 9800X3D, Windows 11 10.0.26100, Rust 1.98.1, diag build, its own empty VICTORY_CACHE_DIR, VICTORY_KEYS into story mode, until the host GPU failure (#71).

Program by program:

against gained lost notes
main d2a4bae 71 0 of main's 119 driver-refused compute programs, 70 run now (26 with #320 alone), 45 stop in translation, 4 not reached
#320 a5ba4a4 45 0 a wave64 group sharing LDS without barriers on a host without 64-lane waves: 38 → 0

Not tested: a 64-lane adapter, a release build, image results, cargo test on this head.

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

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, that is exactly the split I was after: 70 of main's 119 driver-refused programs running, nothing lost, and the rest now named (whole-wave sections 24, groups of more than 64 threads 20).

That orders what comes after this PR: whole-wave sections in the console flow first, then groups of several console waves. I am not stacking either on top yet. #320 and this PR are drafts because a whole-title validate run found 20 modules the console flow emits that dxil.dll refuses, and a title run cannot show those. If you ever run victory translate --validate over the same files on this head, the validator lines (they now carry thread-group size, wave size and the dx.op operations of our module, nothing of the console program) are what would unblock both.

I have added your numbers to the description.

No game data used on my side. AI-assisted.

@Raxstreams

Copy link
Copy Markdown

Following the offline check above, I tested integer whole-wave scans across the two hardware waves. The synthetic 64-lane prefix sum reads back exactly on an RTX 3080 Ti, including 528 for lane 32. The follow-up against this PR's head is r4tedx#1.

In a local integration build the material-tile initialization shader passed offline D3D12 compute pipeline creation and dispatched during the opening scene. The final scene color was still dark in the captured frame.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@r4tedx
r4tedx marked this pull request as ready for review November 24, 2026 04:16
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…64 stack

For testers: the wave64 stack (Marvisak#223, Marvisak#233, Marvisak#320, Marvisak#439) with Marvisak#180, whose
sampleGrad form makes compute programs that sample with implicit
derivatives pass dxil.dll validation.

One conflict, in emit/lower.rs, where a compute program is found to
need the console's lanes: Marvisak#180's quad gradients read within four lanes,
so they go with DPP and ds_swizzle among the reads that stay inside a
32-lane half, and such a program runs on a 32-lane host in two halves.

Checked on an RTX 5070 and a Radeon iGPU: cargo test --workspace passes,
and a hand-assembled compute image_sample validates and samples the
right value in groups of 64x1x1, 8x8x1, 32x1x1, 128x1x1 and 4x4x2.
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…73d66, and Marvisak#180)

The wave64 stack (Marvisak#223, Marvisak#233, Marvisak#320, Marvisak#439, with Peter Bonanni's
whole-wave sections across the halves, 9b73d66) merged with Marvisak#180 (twin
descriptor loads and quad gradients for compute samples), at 24b3bcc.
That commit has one parent (e49302a); Marvisak#180's changes come in without
its commits. Marvisak#233 is in this tree as 1eb9995, the same tree as
3098672, so each file was merged with 3098672 as the base instead of
the e0865d2 git chooses.

Conflict resolutions:
- emit/wave.rs, v_permlane16/x16 in whole-wave sections: Marvisak#98's "every
  lane active" and 9b73d66's "or fi set" are both kept, for both
  instructions.
- emit/lower.rs, Lower::new: Marvisak#320's test for lane reads and writes in
  divergent programs counts live instructions only, as Marvisak#233's does
  with Marvisak#309 (dead SGPR-spill lane instructions are no lane reads).
  Marvisak#307's waterfall arm of v_readfirstlane still comes before the
  console-flow arm; Marvisak#320 adds no arm of its own.
- Compute samples with implicit derivatives (Marvisak#160, Marvisak#180, Marvisak#306): Marvisak#180
  decides plain and biased samples, all of Marvisak#160's forms of them
  (implicit_derivatives from sample_form: _o, _cl, cube, a16), with
  Marvisak#160's bias address (bias_at) and level clamp; Marvisak#306's validator 1.8
  is now declared only for what still uses the host's derivatives in
  compute (comparison samples, op 64). The Marvisak#306 test of image_sample
  now asserts no 1.8 (48-byte PSV0) and still validates and creates
  the pipeline; a twin test with image_sample_c asserts 1.8.
- sgpr_spill test (Marvisak#309): without forwarding, the per-lane form still
  stops with "a lane mask holding lanes elsewhere read as data", but
  emit now takes the console flow (Marvisak#320); the test checks both, and
  that forwarded spills do not ask for the console flow.
- Mechanical: per_lane_only in two hand-built Parts in emit/lower.rs
  tests; emit/mod.rs module order (split_tests before threading).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
Marvisak#320 and Marvisak#439 (with peter-bonanni's 9b73d66) are in, with Marvisak#180, whose
quad gradients fix the compute samples that failed validation. Records
the in-title measurement by testers and this merge's resolutions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

64-lane AMD result for e49302a: AMD Radeon 610M, driver 32.0.21030.2001, Windows 11 build 22631; D3D12 reports 32..64 lanes. I ran translate --validate --pipelines --list --jobs 8 on this head and main d2a4bae, explicitly selecting the Radeon adapter.

All 22,178 emitted modules on this head successfully created D3D12 pipelines. Across 25,889 shared program labels, the comparison against main found 0 DXIL-validation gains/losses and 0 pipeline-creation gains/losses. The aggregate compute totals were 1,715 emitted / 1,672 validated / 1,715 pipelines here versus 1,693 / 1,670 / 1,693 on main; these are whole-stack totals and are not attributed to Wave64 alone.

Full stage table, label-exclusion rule and reason changes: #293 (comment)

Offline only; no title executable or world run. AI-assisted (Kimi).

@Halfect

Halfect commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up correction to my 64-lane comparison: after normalizing the instruction offset present only on failure labels, the matched result is 22 pipeline-creation gains, 2 DXIL-validation gains, and 0 losses across 25,912 shared labels. The 22 gains are a lane-mask join of an untracked mask → ok, accounting for the aggregate compute increase from the underlying stack.

Details: #293 (comment)

The earlier stage totals were correct; the initial 0-gain figure omitted these emit-to-success transitions. No 64-lane regression was found.

@latentdev

Copy link
Copy Markdown

This PR on an RTX 4090 in the opening cutscene, and a heads-up on lower.rs's size

Size, for the rebase onto current main. cargo xtask policy allows 512 KiB per file (MAX_FILE_SIZE in xtask/src/policy.rs). crates/victory-shader/src/emit/lower.rs is already 520,563 bytes on main 63bcca4. This PR adds 38,546 bytes to it (451,690 at 940d32f, 490,236 at 3fab5a1). A trial merge onto 63bcca4 leaves it at about 559 KB, so part of it will need to move to another file. The trial merge conflicts in apps/victory/src/main.rs, emit/host.rs and emit/lower.rs.

Setup. RTX 4090, driver 621.24, Windows 11, title 1.0.2.1, diag build, opening cutscene. Tree: main 63bcca4 + #1630 + #1832 + #2332 + #2178 + #2121, this PR at 3fab5a1, #2118 (af8b9ad) and #2703 (7bb3eba).

Translation. bad01f53f53248e5 translates with this PR for a 32-lane target, passes the validator, and the 4090 makes its pipeline. It's the tiled lighting's tile classifier. Without it, the three tiled lighting passes run no groups on NVIDIA (details in #1835). In a run, 51 programs the title uses still don't translate, 33 of them console wave64 lanes in a group of more than 64 threads (#2214's case).

In game, two runs with #2118 and #2703:

I don't have a clean picture from this PR yet. In the first run, frame 80 of the cutscene was still dark; the lighting had started 51 frames earlier. The second run ended before frame 80. A local change of mine does the same for this program (a barrier after each LDS access, sections combined across the halves). With it, the cutscene is lit by frame 80.

@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@latentdev thanks, and the size figures match ours. Our trial merge of main 63bcca4 upward through the stack gives lower.rs at 521,541 bytes at #223 (under the limit), 541,045 at #233, 547,008 at #320 and 559,844 at #439, so the policy check would refuse the merge from #233 up. The plan is to move the stack's console-flow lowering (console_read_lane, the half exchange and the console-flow refusals) into emit/lower/console.rs, next to main's emit/lower/bvh.rs. That goes on #233 as its own commit and is then merged up through #320 and #439. The conflicts we hit match yours: apps/victory/src/main.rs, emit/host.rs and emit/lower.rs. The rebase starts after our current game-run window, and this PR will show the new head.

Your frame-80 result is useful. Is the local change (a barrier after each LDS access, sections combined across the halves) on a branch you could share, or could you post it as a patch? We would test it on top of the rebased head.

No title data was used for this reply; the sizes come from our trial merges in git. AI-assisted

r4tedx and others added 5 commits November 26, 2026 06:51
The one conflict was in apps/victory/src/main.rs, where main's
`--jobs` became a `NonZeroUsize` and the branch added `--host-lanes`:
`translate::run` takes both, `jobs.map(NonZeroUsize::get)` as main
passes it and the branch's `host_lanes` after it.

The `emit` and `lower::Parts` call sites main added in tests (census,
crosslane, memory, synthetic, `emit::tests`, `resource` and lower.rs's
own) pass `Target::ANY`, as the earlier merge did for the ones before
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pure move, so that the merge of main (63bcca4) keeps emit/lower.rs
under the asset policy's 512 KiB limit: the inline `mod tests` becomes
`mod tests;` beside `mod bvh;`, and its body, one indent level less and
otherwise unchanged, is emit/lower/tests.rs. Its `super::` paths still
name `lower`.

Moving the tests out of lower.rs is desplmfao's idea (Marvisak#2309).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… flow

Conflicts, resolved with kawaii-shakal's notes on Marvisak#439:

- emit/host.rs: main's process-wide WARP device (`SharedDevice`,
  `WARP_LOCK`, `lock_warp`, `from_device`) is kept, and its
  `create_device` takes an optional adapter for the branch's
  `VICTORY_ADAPTER` and `Host::on`.
- emit/lower.rs: `console_read_lane` stays beside main's new
  `helpers_read` doc; main's `uniform_join` sits above `never_taken`,
  which keeps the branch's console-flow note.
- Lane-mask joins: main's path for data joined with masks at a uniform
  join (the BVH walks pop masks from memory) stays beside the console
  flow's masks; `lane_bit` now returns a `Result`, so it takes `?`.
  `no_mask_lane_on_edge` is kept out of the console flow, whose lanes go
  along the wave's edges.
- emit/lower/tests.rs (lower.rs's tests, moved out before this merge):
  main's test changes are ported there. Its `lowers` helper calls
  `lower` directly, so it now lowers a program again in the console flow
  when the first try asks for it, as `emit_with` does
  (`a_scalar_result_needs_no_exec`).
- The `lower::Parts` sites main added in tests (crosslane, memory,
  synthetic, lower's) pass `console_cf: false`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… branch

Conflicts:

- emit/lower.rs, lane-mask joins: the branch's console-flow masks
  (constants and masks built from scalars, `st.other`) feed main's
  `match`, which keeps main's path for data joined with masks at a
  uniform join (the BVH walks) and keeps `no_mask_lane_on_edge` out of
  the console flow, after kawaii-shakal's notes on Marvisak#439.
- emit/lower.rs's tests now live in emit/lower/tests.rs (moved on the
  console flow branch): the branch's `per_lane_only: false` lines are
  ported there, and the `lowers` helper keeps the per-lane form where
  the console flow cannot lower a program, as `emit_with` does here.
- The `lower::Parts` sites main added in tests (crosslane, memory,
  synthetic, lower's) pass `per_lane_only: false`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… LDS branch

Conflicts:

- emit/lower.rs: the branch's `numeric` and main's `scalar_def`,
  `sgpr_operand` and `scalar_constant` were added side by side; both
  are kept.
- `ds_bpermute_b32`: main's lowering, which adds the reader's half as
  the base only for wave64 programs, so a wave32 program reads no
  `waveGetLaneIndex` (main's
  `ds_bpermute_wave64_preserves_32_lane_half`), as kawaii-shakal
  noted. The lane is the same as the branch's in both cases. The
  comment keeps main's ISA reference and the branch's note on programs
  split in halves.
- lower.rs's tests now live in emit/lower/tests.rs (moved on the
  console flow branch): the branch's one change to them (`lower_wave`
  names `crate::emit::Target::ANY`) is ported there. The branch's
  `select_tests` module stays in lower.rs, as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main (63bcca4) into the whole stack. Merges only, no rebase or force-push: main into #223, then each PR's new head into the one above it. New heads: #223 91aa056, #233 1c74ab4, #320 db85706, this PR e9f18c9. Each merges cleanly with main.

  • File-size policy: with main's growth, emit/lower.rs would pass the 512 KiB limit from Shaders: wave64 compute on 32-lane hosts, in halves and in the console flow #233 up. So Shaders: wave64 compute on 32-lane hosts, in halves and in the console flow #233 first moves lower.rs's inline tests, unchanged, into emit/lower/tests.rs, beside main's emit/lower/bvh.rs. Here lower.rs is 506,583 bytes; at Shaders: wave64 compute on 32-lane hosts, in halves and in the console flow #233 it's 488,121.
  • Conflicts: they follow @kawaii-shakal's notes above, and the merge commits credit them.
    • main's uniform_join/number path sits beside the console flow's masks;
    • no_mask_lane_on_edge stays out of the console flow;
    • lane_bit takes ?;
    • main's shared WARP device is kept, and create_device takes an optional adapter;
    • ds_bpermute_b32's half base is wave64-only;
    • the lowers test helper retries in the console flow, as emit_with does.
  • Checks at each of the four heads, Windows 11, WARP only:
    • cargo xtask policy: ok;
    • clippy -D warnings: clean;
    • VICTORY_WARP=1 cargo test -p victory-shader --lib -- --test-threads=1: 341 passed, 4 failed here; at the PRs below, 301, 316 and 322 passed, each with the same 4 failures. Every level gains main's 53 tests and loses none of the stack's. The 4 failures are main's own: on 63bcca4 the same command gives 298 passed and the same 4 failed (synthetic_tests whose hardware pass runs on WARP under VICTORY_WARP=1).
  • The description is updated, with older heads marked as history. The note at the top about merging with a BVH builder gate such as GPU: the BVH builder runs whole or not at all #2118 stands.

Still open on this head, as triage noted: crissuper20's GTX 1650 hang, and steven-seagull27's partial-group reduction fix. That fix is next, reviewed against this head.

Synthetic tests only for this update; no title data used.

AI-assisted

r4tedx and others added 4 commits November 26, 2026 07:11
Main's view-mark test builds emit::Options by hand; this branch adds a
target field to Options, so the test now fills the rest from Default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Correction to my last comment: CI's clippy failed on the previous head. Main's view-mark draw test (crates/victory-gpu/src/draw.rs) builds emit::Options { view_marks: true } by hand, and this stack adds a target field to Options. My local clippy run left out the test targets, so I missed it. New head 8a320556 has the fix merged up from #320: the test fills the remaining fields with ..Options::default(). Nothing else changed.

Verified on #223 0f6dec04 and #439 8a320556: cargo clippy --workspace --all-targets --locked -- -D warnings is clean, and cargo xtask policy passes. No title data was used.

AI-assisted

r4tedx and others added 4 commits November 26, 2026 07:17
Main's placed-UAV diagnostics test calls emit::emit with the six arguments
it had before this branch added the target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Second follow-up: CI's diagnostics clippy (--all-features) found one more call from main that this stack's Target argument breaks. In crates/victory-gpu/src/pipeline/placed_uav_tests.rs:77, emit::emit was called with six arguments. New head 13be4c2c has the fix merged up from #320: the call passes emit::Target::ANY, the same default the other callers use.

Verified on #223 fbfd3c67 and #439 13be4c2c: both CI clippy commands are clean, cargo clippy --workspace --all-targets --locked -- -D warnings and the same command with --all-features. I didn't run the CI cargo test --workspace step on this PC, so CI will be the first to run it on this head. No title data was used.

AI-assisted

steven-seagull27 and others added 3 commits November 26, 2026 07:35
Machad3x reported the missing-upper-half minimum and proposed skipping the exchange at 32 threads or fewer in Marvisak#2214. Exercise a nonzero minimum and both sides of the host-wave boundary on the current Marvisak#439 stack.

(cherry picked from commit 9cc76b8)
…gh bits

Machad3x proposed the split f16 reduction in Marvisak#2214. Exercise both halves of the packed source word for full, lower-forty and upper-half EXEC masks.

(cherry picked from commit 591c51c)
The split-halves f16 sum test dispatches only on hardware adapters, so
CI and WARP runs check its translation, not which lane gives the high
half. Assert that the scan ending in lane 31 leaves Shape::Half with
lane 31 (and 63 for the other form), and that the sum translates for
groups of 32 and 48 threads as well as 64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks to Machad3x for finding both problems in #2214 and proposing the fixes, and to @steven-seagull27 for the two branches (9cc76b8, and the f16 sums in fork PR r4tedx#19).

Both are taken as they are, with their authorship, plus one small test of ours. The head is now 2658128c:

  • 611184ee (9cc76b8): whole-wave reductions in partial groups now run in the console flow. A group of 32 threads or fewer skips the exchange between the two halves, so a min, max or And no longer reads the missing half's 0. Groups over 64 threads are still refused.
  • f968c54c (591c51c): for f16 sums, the two halves' f32 sums are exchanged and added before the single rounding to f16. The packed high half now comes from the right lane, through the ballot and lane read across both halves.
  • 2658128c: checks the high-half lane from the section simulation, and that f16 sums translate at 32, 48 and 64 threads.

What we could check here (WARP only):

  • VICTORY_WARP=1 cargo test -p victory-shader --lib -- --test-threads=1: 343 passed, 4 failed, 3 ignored. The 4 failures are the synthetic_tests that also fail on main. The two added tests make up the difference from 341 before.
  • clippy with -D warnings, both default and --all-features: clean. cargo xtask policy: 194 files ok.

With VICTORY_WARP=1 no adapter is listed, so the program cases only translate and validate, and nothing is dispatched. The results on 32-lane hardware are steven-seagull27's alone: RTX 5080, 0 of 1,884 wrong over 1-64 threads. A split_tests run on a 32-lane card at 2658128c would still help, especially for an f16 sum in a partial group with a mask, which no test covers on hardware yet.

No title data was used.

AI-assisted

@latentdev

Copy link
Copy Markdown

@r4tedx here it is, as a patch against #233's head 87d1f42. It only touches emit/lower.rs and emit/split_tests.rs, and applies with git apply.

What it does in the console flow, one console wave per group:

  • LDS: after each LDS instruction other than ds_swizzle and the permutes, it adds a group barrier (in Lower::inst). Both halves reach every block, so one half's access finishes before the other half's next.
  • Whole-wave sections: each half reduces its own lanes with a wave op over the masked inputs, then the halves trade results through exchange. A reduction combines the two. A prefix adds the lower half's total in the upper half (Lower::console_shape). It covers integer and float sums, min, max, and/or/xor; f16 is refused.
  • Eligibility: LDS and sections are allowed, and permutes only inside sections. A group of one console wave that shares LDS without lane reads also takes the console flow.
  • Title memory: the extension applies only to programs that don't reach title memory by address (root_memory). Without that limit, the builder stages caa78b8ca62bc3d6 and 28918b7150a7aad5 translated, part of the builder ran, and the GPU hung.

#320 and #439 cover the same ground. Your LDS barrier comes before each access, and your sections now handle partial groups and f16. So this is more for comparison than to merge as it is.

Tests: five new ones in split_tests, hand-assembled from the tile classifier bad01f53f53248e5's own sections:

  • a whole-wave sum over all lanes;
  • a whole-wave sum over lane 0 alone;
  • an exclusive prefix over all lanes;
  • an exclusive prefix over lane 0 alone;
  • an LDS counter shared by both halves.

On an RTX 4090 (split) and the Radeon iGPU of a Ryzen 9 7950X3D (native wave64), all 17 split_tests are exact on both.

The whole victory-shader lib on this machine: 321 passed, 3 failed. The three are a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and gathers_at_a_level_match_the_hardware, and they fail the same way at 87d1f42 without the patch. I skipped heap_direct_texture_reads_mark_their_heap_index, which crashes on this card on main too.

The frame-80 result in my earlier comment came from this change on a 63bcca4 stack.

Patch against 87d1f42
diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs
index 4b7e321..53e16d9 100644
--- a/crates/victory-shader/src/emit/lower.rs
+++ b/crates/victory-shader/src/emit/lower.rs
@@ -668,16 +668,38 @@ impl<'a> Lower<'a> {
                 && (0..p.blocks.len()).all(|b| super::wave::sections(p, b).is_empty());
             // The rest of such programs need the halves to exchange values
             // (masks read whole, lanes of the other half): the console flow,
-            // for a group of one console wave without LDS.
-            wants_console_flow = console_lanes
+            // for a group of one console wave.
+            // LDS: a group barrier follows each access (`Lower::inst`); whole-wave
+            // sections: each half reduces its lanes and the halves exchange
+            // (`Lower::console_shape`), so a permute inside one is the
+            // simulation's; one outside reads lanes the halves do not exchange.
+            let permute_outside = (0..p.blocks.len()).any(|b| {
+                let secs = super::wave::sections(p, b);
+                p.blocks[b].insts.iter().enumerate().any(|(i, inst)| {
+                    inst.name().contains("permute")
+                        && !secs.iter().any(|(&start, sec)| i > start && i < sec.end)
+                })
+            });
+            // (A group of one console wave sharing LDS needs the halves ordered
+            // too, even without lane reads.)
+            let one_console_wave = cs.threads.iter().product::<u32>() <= 64;
+            let has_sections = (0..p.blocks.len()).any(|b| !super::wave::sections(p, b).is_empty());
+            let any_permute = insts().any(|i| i.name().contains("permute"));
+            // LDS and whole-wave sections only in programs that do not reach title
+            // memory by address: in the console flow every lane runs every block,
+            // and a lane the console wave had left out would load from whatever
+            // address it holds (the ray-tracing structure builder's stages, which
+            // also run all or none: run them partly and their stores land on
+            // garbage offsets).
+            let plain = s.lds_dwords == 0 && !has_sections && !any_permute;
+            let extended = !root_memory && !permute_outside;
+            wants_console_flow = (console_lanes || !root_memory && one_console_wave && s.lds_dwords > 0)
                 && !split
                 && x.native.wave64
                 && !x.target.runs(64)
                 && x.target.runs(32)
-                && s.lds_dwords == 0
-                && cs.threads.iter().product::<u32>() <= 64
-                && !insts().any(|i| i.name().contains("permute"))
-                && (0..p.blocks.len()).all(|b| super::wave::sections(p, b).is_empty());
+                && one_console_wave
+                && (plain || extended);
             if x.console_cf {
                 console_lanes = true;
                 split = true;
@@ -1319,7 +1341,10 @@ impl<'a> Lower<'a> {
         {
             return Err("a wave reduction in a mesh shader");
         }
-        if self.split {
+        // In the console flow both halves run the section (every lane runs
+        // every block): each half's result over its own lanes, then the two
+        // combined through the halves' exchange (below).
+        if self.split && !self.console_cf {
             return Err("a wave reduction in a wave64 program split in halves");
         }
         let c = self.cur;
@@ -1334,6 +1359,9 @@ impl<'a> Lower<'a> {
         let id = self.s.m.i32(ident);
         let x = self.s.m.select(c, on, x, id);
         self.s.flags |= flags::WAVE_OPS;
+        if self.console_cf {
+            return self.console_shape(op, prefix, x);
+        }
         let float = matches!(op, Op::AddF | Op::MinF | Op::MaxF);
         let (i32t, f32t) = (self.s.t.i32, self.s.t.f32);
         let arg = if float { self.as_float(x) } else { x };
@@ -1389,6 +1417,108 @@ impl<'a> Lower<'a> {
         Ok(if float { self.as_int(r) } else { r })
     }
 
+    /// Console flow: a whole-wave section's reduction or prefix of `x` (each
+    /// lane's input, the identity where the section's mask leaves it out)
+    /// over the console wave's 64 lanes, which are two host waves of 32.
+    /// Each half reduces its own lanes; the halves exchange those results
+    /// ([`Self::exchange`]): a reduction combines both, a prefix adds the
+    /// lower half's total in the upper half.
+    fn console_shape(&mut self, op: super::wave::Op, prefix: Option<bool>, x: V) -> Result<V, Why> {
+        use super::wave::Op;
+        let c = self.cur;
+        let float = matches!(op, Op::AddF | Op::MinF | Op::MaxF);
+        let (i32t, f32t) = (self.s.t.i32, self.s.t.f32);
+        let arg = if float { self.as_float(x) } else { x };
+        let ty = if float { f32t } else { i32t };
+        let sfx = if float { "f32" } else { "i32" };
+        let reduce = |me: &mut Self, arg: V| -> V {
+            match op {
+                Op::Or | Op::And | Op::Xor => {
+                    let k = me.s.m.i8(match op {
+                        Op::And => 0,
+                        Op::Or => 1,
+                        _ => 2,
+                    });
+                    me.s.op(c, "waveActiveBit.i32", Attr::NoUnwind, i32t, 120, &[arg, k])
+                }
+                _ => {
+                    let (code, unsigned) = match op {
+                        Op::AddU => (0, 1),
+                        Op::AddF => (0, 0),
+                        Op::MinU => (2, 1),
+                        Op::MaxU => (3, 1),
+                        Op::MinI | Op::MinF => (2, 0),
+                        _ => (3, 0),
+                    };
+                    let (k, u) = (me.s.m.i8(code), me.s.m.i8(unsigned));
+                    me.s.op(c, &format!("waveActiveOp.{sfx}"), Attr::NoUnwind, ty, 119, &[arg, k, u])
+                }
+            }
+        };
+        let bits = |me: &mut Self, v: V| if float { me.as_int(v) } else { v };
+        let value = |me: &mut Self, v: V| if float { me.as_float(v) } else { v };
+        match prefix {
+            Some(inclusive) => {
+                if !matches!(op, Op::AddU | Op::AddF) {
+                    return Err("a wave prefix of an operation other than a sum");
+                }
+                let (k0, k1) = (self.s.m.i8(0), self.s.m.i8(1));
+                let mut r =
+                    self.s.op(c, &format!("wavePrefixOp.{sfx}"), Attr::NoUnwind, ty, 121, &[arg, k0, k1]);
+                if inclusive {
+                    r = self.s.m.bin(c, Bin::Add, r, arg);
+                }
+                // The upper half's lanes follow the lower half's.
+                let total = reduce(self, arg);
+                let total = bits(self, total);
+                let (lo, _) = self.exchange(c, total);
+                let lo = value(self, lo);
+                let (_, half) = self.console_lane();
+                let z = self.s.m.i32(0);
+                let upper = self.s.m.cmp(c, pred::NE, half, z);
+                let zero = if float { self.as_float(z) } else { z };
+                let add = self.s.m.select(c, upper, lo, zero);
+                let r = self.s.m.bin(c, Bin::Add, r, add);
+                Ok(bits(self, r))
+            }
+            None => {
+                let mine = reduce(self, arg);
+                let mine = bits(self, mine);
+                let (lo, hi) = self.exchange(c, mine);
+                let r = match op {
+                    Op::AddU => self.s.m.bin(c, Bin::Add, lo, hi),
+                    Op::Or => self.s.m.bin(c, Bin::Or, lo, hi),
+                    Op::And => self.s.m.bin(c, Bin::And, lo, hi),
+                    Op::Xor => self.s.m.bin(c, Bin::Xor, lo, hi),
+                    Op::AddF => {
+                        let (a, b) = (self.as_float(lo), self.as_float(hi));
+                        let s = self.s.m.bin(c, Bin::Add, a, b);
+                        self.as_int(s)
+                    }
+                    Op::MinF | Op::MaxF => {
+                        let (a, b) = (self.as_float(lo), self.as_float(hi));
+                        // dx.op FMax 35, FMin 36.
+                        let code = if op == Op::MaxF { 35 } else { 36 };
+                        let m = self.binary(code, a, b);
+                        self.as_int(m)
+                    }
+                    Op::MinU | Op::MaxU | Op::MinI | Op::MaxI => {
+                        let p = match op {
+                            Op::MinU => pred::IULT,
+                            Op::MaxU => pred::IUGT,
+                            Op::MinI => pred::SLT,
+                            _ => pred::SGT,
+                        };
+                        let take_lo = self.s.m.cmp(c, p, lo, hi);
+                        self.s.m.select(c, take_lo, lo, hi)
+                    }
+                    Op::AddH => return Err("a 16-bit wave reduction in the console flow"),
+                };
+                Ok(r)
+            }
+        }
+    }
+
     fn run(mut self) -> Result<Lowered, Stop> {
         if self.wants_console_flow && !self.x.console_cf {
             return Err(unsupported(0, CONSOLE_FLOW));
@@ -3730,7 +3860,26 @@ impl<'a> Lower<'a> {
             Fields::Image { .. } => self.image(inst, b, i),
             Fields::Buffer { .. } => self.buffer(inst, b, i),
             Fields::Exp { .. } => self.export(b, i),
-            Fields::Ds { .. } => self.ds(inst, b, i),
+            Fields::Ds { .. } => {
+                let r = self.ds(inst, b, i);
+                // Console flow: the console wave runs an LDS instruction in all
+                // its lanes before the next, and its compiler leaves out the
+                // barriers between lanes of one wave. Here its two halves are
+                // two host waves: each LDS access is followed by a group
+                // barrier, which both halves reach (every lane runs every block,
+                // `CONSOLE_FLOW`), so one half's accesses are done before the
+                // other's next.
+                if self.console_cf
+                    && r.is_ok()
+                    && !(name.starts_with("ds_swizzle") || name.contains("permute"))
+                {
+                    let mode = self.s.m.i32(1 | 8);
+                    let void = self.s.t.void;
+                    self.s
+                        .op(self.cur, "barrier", Attr::NoDuplicate, void, 80, &[mode]);
+                }
+                r
+            }
             Fields::Flat { .. } if name.starts_with("global_") => self.flat(inst, b, i),
             Fields::Flat { .. } => Err("flat memory"),
         };
diff --git a/crates/victory-shader/src/emit/split_tests.rs b/crates/victory-shader/src/emit/split_tests.rs
index 2f096fa..8e95530 100644
--- a/crates/victory-shader/src/emit/split_tests.rs
+++ b/crates/victory-shader/src/emit/split_tests.rs
@@ -433,3 +433,170 @@ fn a_mask_copied_dword_by_dword_stops_instead_of_recursing() {
         assert!(e.contains(why), "{lanes_min}..{lanes_max}: {e}");
     }
 }
+
+/// The console compiler's whole-wave sum (HLSL `WaveActiveSum` on wave64:
+/// DPP within rows, `v_permlanex16` across rows, `v_readlane` 32 across
+/// the halves), as the tile classifier `bad01f53f53248e5` has it: each
+/// half sums its own lanes and the halves exchange.
+const SECTION_SUM: &[u32] = &[
+    0xBE80_25C1, // s_or_saveexec_b64 s[0:1], -1
+    0xD501_0002,
+    0x0002_2080, // v_cndmask_b32 v2, 0, v16, s[0:1]
+    0x4A04_04E9,
+    0xDE54_C102, // v_add_nc_u32 v2, v2, v2 dpp8:[1,0,3,2,5,4,7,6]
+    0x4A04_04E9,
+    0x9360_1202, // v_add_nc_u32 v2, v2, v2 dpp8:[2,2,0,0,6,6,4,4]
+    0x4A04_04E9,
+    0x0009_2402, // v_add_nc_u32 v2, v2, v2 dpp8:[4,4,4,4,0,0,0,0]
+    0x4A04_04FA,
+    0xFF09_4002, // v_add_nc_u32 v2, v2, v2 row_mirror bound_ctrl:1
+    0xD778_0003,
+    0x0201_0102, // v_permlanex16_b32 v3, v2, 0, 0
+    0x4A04_0503, // v_add_nc_u32 v2, v3, v2
+    0xD760_0002,
+    0x0001_4102, // v_readlane_b32 s2, v2, 32
+    0x4A04_0402, // v_add_nc_u32 v2, s2, v2
+    0xD760_000C,
+    0x0001_0102, // v_readlane_b32 s12, v2, 0
+    0xBEFE_0400, // s_mov_b64 exec, s[0:1]
+];
+
+/// The console compiler's whole-wave exclusive prefix sum of v16 into v3
+/// (rows by DPP shifts, rows of 16 by `v_permlanex16`, the upper half
+/// after lane 31 of the lower), as `bad01f53f53248e5` has it.
+const SECTION_PREFIX: &[u32] = &[
+    0xBE8A_25C1, // s_or_saveexec_b64 s[10:11], -1
+    0xD501_0002,
+    0x002A_2080, // v_cndmask_b32 v2, 0, v16, s[10:11]
+    0x7E06_0302, // v_mov_b32 v3, v2
+    0x4A06_06FA,
+    0xFF09_1103, // v_add_nc_u32 v3, v3, v3 row_shr:1 bound_ctrl:1
+    0x4A06_06FA,
+    0xFF01_1203, // v_add_nc_u32 v3, v3, v3 row_shr:2
+    0x4A06_06FA,
+    0xFF01_1403, // v_add_nc_u32 v3, v3, v3 row_shr:4
+    0x4A06_06FA,
+    0xFF01_1803, // v_add_nc_u32 v3, v3, v3 row_shr:8
+    0xBEFE_03FF,
+    0xFFFF_0000, // s_mov_b32 exec_lo, 0xffff0000
+    0xBEFF_03FF,
+    0xFFFF_0000, // s_mov_b32 exec_hi, 0xffff0000
+    0xD778_4804,
+    0x0305_8303, // v_permlanex16_b32 v4, v3, -1, -1 fi:1
+    0x4A06_0704, // v_add_nc_u32 v3, v4, v3
+    0xD760_000D,
+    0x0001_3F03, // v_readlane_b32 s13, v3, 31
+    0xBEFE_0380, // s_mov_b32 exec_lo, 0
+    0xBEFF_03C1, // s_mov_b32 exec_hi, -1
+    0x4A06_060D, // v_add_nc_u32 v3, s13, v3
+    0xBEFE_03C1, // s_mov_b32 exec_lo, -1
+    0xBEFF_03C1, // s_mov_b32 exec_hi, -1
+    0x4C06_0503, // v_sub_nc_u32 v3, v3, v2
+    0xBEFE_040A, // s_mov_b64 exec, s[10:11]
+];
+
+/// Lane 0 alone in EXEC (s[14:15] keeps the whole wave's).
+const LANE_0_ONLY: &[u32] = &[
+    0x7D84_0080, // v_cmp_eq_u32 vcc, 0, v0
+    0xBE8E_246A, // s_and_saveexec_b64 s[14:15], vcc
+];
+const WHOLE_AGAIN: u32 = 0xBEFE_040E; // s_mov_b64 exec, s[14:15]
+
+fn joined(parts: &[&[u32]]) -> Vec<u32> {
+    parts.iter().flat_map(|p| p.iter().copied()).collect()
+}
+
+/// A whole-wave sum over every lane of the console wave: both halves'.
+#[test]
+fn whole_wave_sums_add_both_halves() {
+    let body = joined(&[
+        &[0x7E20_0300], // v_mov_b32 v16, v0
+        SECTION_SUM,
+        &[0x7E04_020C], // v_mov_b32 v2, s12
+    ]);
+    console_flow_case("whole-wave sum of lane ids", &body, 64, |_| (0..64).sum());
+}
+
+/// The classifier's append: lane 0 alone in EXEC, the sum of its 8.
+#[test]
+fn whole_wave_sums_of_one_lane() {
+    let body = joined(&[
+        &[0x7E20_0288], // v_mov_b32 v16, 8
+        LANE_0_ONLY,
+        SECTION_SUM,
+        &[WHOLE_AGAIN, 0x7E04_020C], // s_mov_b64 exec, s[14:15]; v_mov_b32 v2, s12
+    ]);
+    console_flow_case("whole-wave sum of lane 0's 8", &body, 64, |_| 8);
+}
+
+/// An exclusive prefix over the console wave: lanes of the upper half
+/// count every lane of the lower one.
+#[test]
+fn whole_wave_prefixes_run_on_from_the_lower_half() {
+    let body = joined(&[
+        &[0x7E20_0281], // v_mov_b32 v16, 1
+        SECTION_PREFIX,
+        &[0x7E04_0303], // v_mov_b32 v2, v3
+    ]);
+    console_flow_case("exclusive prefix of ones", &body, 64, |t| t);
+}
+
+/// The classifier's offsets: lane 0 alone gives 8; the section writes every
+/// lane, past lane 0 the prefix is 8.
+#[test]
+fn whole_wave_prefixes_of_one_lane() {
+    let body = joined(&[
+        &[0x7E20_0288], // v_mov_b32 v16, 8
+        LANE_0_ONLY,
+        SECTION_PREFIX,
+        &[WHOLE_AGAIN, 0x7E04_0303], // s_mov_b64 exec, s[14:15]; v_mov_b32 v2, v3
+    ]);
+    console_flow_case("exclusive prefix of lane 0's 8", &body, 64, |t| if t == 0 { 0 } else { 8 });
+}
+
+/// [`console_flow_case`] for a program with 512 bytes of LDS.
+fn lds_flow_case(label: &str, body: &[u32], threads: u32, want: impl Fn(u32) -> u32) {
+    let Ok(names) = adapters() else {
+        eprintln!("no DXGI; skipped");
+        return;
+    };
+    for name in names {
+        let Ok(host) = Host::on(&name) else {
+            continue;
+        };
+        let mut p = program(body, threads);
+        if let StageIo::Cs(cs) = &mut p.io {
+            cs.rsrc2 |= 1 << 15;
+        }
+        let split = !host.target().runs(64);
+        let groups = 2;
+        let out = run(&host, &p, groups).unwrap_or_else(|e| panic!("{name}: {label}: {e}"));
+        let expect: Vec<u32> = (0..groups).flat_map(|_| (0..threads).map(&want)).collect();
+        assert_eq!(out, expect, "{name}: {label}, {threads} threads (split {split})");
+        eprintln!("{name}: {label}, {threads} threads exact (split {split})");
+    }
+}
+
+/// LDS the console wave shares without barriers (its compiler leaves them
+/// out within one wave): lane 0 clears a counter, every lane adds 1, every
+/// lane reads it. Both halves' adds land before either half reads.
+#[test]
+fn lds_shared_within_the_console_wave_orders_both_halves() {
+    let body = joined(&[
+        &[0x7E02_0280, 0x7E08_0281], // v_mov_b32 v1, 0; v_mov_b32 v4, 1
+        LANE_0_ONLY,
+        &[
+            0xD834_0000,
+            0x0000_0101, // ds_write_b32 v1, v1
+            0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
+            WHOLE_AGAIN,
+            0xD800_0000,
+            0x0000_0401, // ds_add_u32 v1, v4
+            0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
+            0xD8D8_0000,
+            0x0200_0001, // ds_read_b32 v2, v1
+            0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
+        ],
+    ]);
+    lds_flow_case("LDS counter of the whole wave", &body, 64, |_| 64);
+}

r4tedx and others added 2 commits November 26, 2026 09:40
…le memory

On a host without 64-lane waves, a wave64 program that reaches title
memory by address (root_memory) no longer takes the console flow in
halves when it also shares LDS, has whole-wave sections or permutes
lanes; it stops with a reason instead. Programs that only exchange
lanes or read masks whole keep the console flow, and hosts with
64-lane waves are unchanged.

latentdev found the limit (patch on Marvisak#439 against 87d1f42): without it
the ray-tracing structure builder stages caa78b8ca62bc3d6 and
28918b7150a7aad5 translated, part of the builder ran and the GPU hung
on an RTX 4090. Offline at 32-32 the XboxBvhBuilder.dll programs at
0x25c40 and 0x28770 (those two) validated before and are refused now;
the other 50 programs are unchanged.

The check lives in emit/lower/console.rs (lower.rs is near the file
size limit). The test builds an LDS program with and without a load
from an address it makes: refused at 32-32 only with the load, both
translate with 64-lane waves.

Co-authored-by: latentdev <3763127+latentdev@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ctions

Five split_tests hand-assembled by latentdev from the tile classifier
bad01f53f53248e5's own code (patch on Marvisak#439 against 87d1f42): a
whole-wave sum over every lane and over lane 0 alone, an exclusive
prefix over every lane and over lane 0 alone, and an LDS counter both
halves add to before either reads it.

Adapted to the stack's helpers: the LDS case uses program_lds and
program_case. Each test also checks, without an adapter, that the
program translates for a 32-lane host in halves (wave size 32) and
validates where a validator is installed; the values are checked on
hardware adapters only. latentdev ran them exact on an RTX 4090 (in
halves) and a Radeon 7950X3D iGPU (native wave64) with their patch.

Co-authored-by: latentdev <3763127+latentdev@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@latentdev

Copy link
Copy Markdown

split_tests at 2658128 on an RTX 4090 and a Radeon iGPU

I ran cargo test -p victory-shader --lib split_tests -- --test-threads=1 at 2658128c on Windows 11, on one machine with two adapters:

  • an RTX 4090 (driver 621.24, 32-lane waves, so split);
  • the Radeon iGPU of a Ryzen 9 7950X3D (64-lane waves, not split).

All 35 passed, and every hardware case printed exact on both adapters: 87 cases on the 4090 and 88 on the Radeon. That covers:

  • whole_wave_reductions_in_partial_groups: sum, min and max at 1, 6, 31, 32, 33, 36, 48, 63 and 64 threads;
  • the f16 tests (half_sum_and_packed_lane_cross_host_halves with all six masks, and half_sum_takes_the_high_half_of_the_lane_it_ends_in);
  • the float sums, both masked and inclusive prefix.

As you said, none of them is an f16 sum in a partial group with a mask, so that case still has no hardware run.

@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @latentdev. The root_memory limit is the part #439 was missing, and thanks for the split_tests run at 2658128c on the RTX 4090 and the 7950X3D iGPU.

I compared your patch (against 87d1f42) with 2658128c:

Offline only, I translated XboxBvhBuilder.dll from my local copy of the title data for a 32-lane host, to see whether your two stages take the console flow. Nothing was dispatched or run.

  • At 2658128c, 28918b7150a7aad5 (@0x25c40) and caa78b8ca62bc3d6 (@0x28770) both validate in the console flow in halves.
  • With the limit they are refused, with the new reason.
  • The other 50 builder programs are unchanged.

Pushed as a fast-forward to 75870526, two commits crediting you as co-author:

  • e2d3cfd5 adds your limit in emit/lower/console.rs. A program that reaches title memory by address and also shares LDS, has whole-wave sections or permutes lanes no longer takes the console flow in halves on a host without 64-lane waves. A synthetic test (lds_in_halves_keeps_out_of_programs_reaching_title_memory) fails with the check switched off.
  • 75870526 adds your five tile-classifier tests, adapted to the stack's program_lds/program_case helpers. Each also checks, without a GPU, that the program translates for a 32-lane host.

Checks on the software adapter (WARP), one test thread:

  • The shader lib gives 349 passed, 4 failed and 3 ignored at 75870526, against 343/4/3 at 2658128c. The four failures are the same at both heads, all in main's synthetic_tests.
  • cargo xtask policy and clippy (plain and --all-features) are clean.

I can't run tests on hardware here, so the five tests' values have only been checked on your two adapters, and only with your patch. A run of split_tests at 75870526 would cover them on #439's own code. Your note also stands: an f16 sum in a partial group with a mask still has no hardware run.

AI-assisted

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

Reviewed updated 7587052 (through e2d3cfd + 7587052 vs main 63bcca4) on Windows 11 with AMD Radeon RX 7600 (native Wave64) and WARP:

  • git merge-tree against main (63bcca4): clean (4dbc0d507237c0e5b5dba90fdc87083c2f859839), crates/victory-shader/src/emit/lower.rs is 506,876 bytes.
  • cargo run -p xtask --locked -- policy: asset policy: 195 files ok.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default & --all-features): clean.
  • cargo test -p victory-shader --lib --locked split_tests -- --nocapture --test-threads=1 (RX 7600): 41 passed; 0 failed (32.68s) — includes the 6 newly added tests (lds_in_halves_keeps_out_of_programs_reaching_title_memory, whole_wave_sums_*, whole_wave_prefixes_*, lds_shared_within_the_console_wave_orders_both_halves); RX 7600 executions logged split false (zero native Wave64 regression).
  • VICTORY_WARP=1 cargo test -p victory-shader --lib --locked split_tests -- --nocapture --test-threads=1: 41 passed; 0 failed (0.18s) — translates_in_halves (32-lane Wave32 DXIL lowering + DXIL validator) and sgpr_spills_across_a_divergent_branch_stay_per_lane (Host::new(true)) ran cleanly, while adapters() tests skip WARP (host.rs:105-107).
  • cargo test -p victory-shader --lib --locked -- --test-threads=1 (RX 7600): 353 passed; 0 failed; 3 ignored (153.89s).

Notes:

  • e2d3cfd's crates/victory-shader/src/emit/lower/console.rs (leaves_title_memory_out) cleanly gates one_wave LDS, whole-wave sections, and *permute* (including ds_bpermute_b32) out of console-flow halves when root_memory is true (lower.rs:829-830), and 7587052's unit/validator tests cover both the gate and the whole-wave sum/prefix/LDS patterns on Wave32 targets.
  • Minor doc note: the PR description body still cites e9f18c9 before e2d3cfd / 7587052.
  • Hardware scope note: no hardware 32-lane GPU (e.g., NVIDIA) was available on this host, so runtime execution of the split 32-lane LDS barrier / section tests is verified via Wave32 DXIL lowering + validator and RX 7600 native Wave64 (split false), not hardware 32-lane silicon.

AI-assisted; synthetic tests only, no game files.

@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nathanbzrr. The description now names head 7587052 and lists what is new since e9f18c9, with your RX 7600 run (353 passed, 0 failed). AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.