Skip to content

Shaders: forward SGPRs reloaded from VGPR lanes as the spilled value - #309

Closed
AntoninMichelq wants to merge 1 commit into
Marvisak:mainfrom
AntoninMichelq:up/sgpr-spill-lanes
Closed

AntoninMichelq wants to merge 1 commit into
Marvisak:mainfrom
AntoninMichelq:up/sgpr-spill-lanes

Conversation

@AntoninMichelq

Copy link
Copy Markdown

Requested by 4nto · project thread

Summary

When it runs short of SGPRs, the console compiler spills a dword, often a lane mask, into one lane of a VGPR with v_writelane_b32. It reloads the dword later with v_readlane_b32 at the same lane. Reads of such a reload now read the spilled value directly, so a reloaded lane mask is again the same mask for the structurer and the lowering. This is a port of the spill resolution from #54 by alessiodeia, on its own and without #54's Wave64/host-wave changes.

What changed

  • New victory_shader::sgpr_spill module:
    • forward(&mut Program) replaces every read of a reload whose VGPR lane provably holds one scalar value with that value. "Provably" covers other lanes' writes, agreeing joins, lane bits masked to the wave size, and the value being available wherever the reload runs.
    • dead(&Program) names the spills and reloads that nothing reads any more.
  • forward runs right after ir::build, in emit::translate and in victory translate.
  • Lowering skips dead spills and reloads. They are also left out of the console-lane and whole-wave-section scans.
  • When a scalar mask operation's SCC is read as data (for example by s_cselect), it now lowers as "some lane is set", meaning the mask's ballot is not zero. This applies where masks may be read as data (compute). Before, it failed with "a lane mask read as data".
  • A whole-wave section now ends at the EXEC write that reads the saved mask from any register, so a forwarded reload of a spilled saved EXEC closes it.

No dependency on other open PRs.

How it was tested

  • cargo test -p victory-shader on Linux: all tests pass. New tests in sgpr_spill::tests:

    • a_reloaded_mask_is_the_spilled_mask
    • a_spilled_mask_holding_lanes_elsewhere_is_used_as_a_mask_again
    • only_the_same_lane_written_by_a_lane_write_is_forwarded
    • a_reload_needs_the_value_wherever_it_runs
    • the_scc_of_a_mask_operation_is_whether_a_lane_is_set

    Also emit::wave::tests::a_section_restores_exec_from_a_reload_of_the_saved_mask.

  • cargo check for Windows (x86_64-pc-windows-msvc) passes, for victory-shader and for victory with CARGO_FEATURE_PURE=1.

  • On the game's 26,148 programs, "a lane mask holding lanes elsewhere read as data" went from 276 to 42. This was measured with victory translate on the integration stack.

Where 3D rendering stands on an RX 7600 (Windows 11)

  • In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view).
  • Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black.
  • No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs.
  • About 10,000 draws per frame, at well under 1 fps.

These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66

Short of SGPRs, the console compiler spills a dword into one lane of a
VGPR (v_writelane_b32) and reloads it later with v_readlane_b32 at the
same constant lane. Lane masks are spilled like this too, and the reload
is used as a mask again (s_andn2_b64 vcc, exec, sM; s_and_saveexec;
EXEC restores; s_and + s_cselect(exec, 0) + s_cbranch_vccnz). The spill
read the mask as a number (failing with "a lane mask holding lanes
elsewhere read as data" for an else-mask), and the reload was an opaque
cross-lane read the lane-mask analysis no longer knew as that mask.

New pass sgpr_spill::forward, run right after the IR is built (in
translation and in `victory translate`): every read of a
reload whose VGPR lane provably holds one scalar value (through other
lanes' writes and agreeing joins, lane bits masked to the wave size, the
value available wherever the reload runs) reads that value directly, so
structure tracks the reloaded mask as the same mask. sgpr_spill::dead
names the reloads and spills nothing reads any more; lowering leaves
them out (and out of the console-lane and whole-wave-section scans).

Also:
- SCC of a scalar mask operation read as data (s_cselect on it) is
  "some lane is set": the mask's ballot is not zero, where masks may be
  read as data (compute). Was "a lane mask read as data".
- A whole-wave section ends at the EXEC write reading the saved mask
  from any register, so a forwarded reload of a spilled saved EXEC
  closes it.

Based on the spill resolution in Marvisak#54 by alessiodeia.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested the spill forwarding as a retry on Causeway's 32-lane translation path with the saved shaders from our RTX 3060 Ti story trace. The Windows SDK validator accepted 44 more compute shaders (53 → 97 successes out of 177 previously rejected shaders). All prior successful outputs stayed byte-identical across this set, 118 controls and a separate historical set of 50.

I sampled five of the 44 newly validated programs for compute pipeline creation on Microsoft WARP. Four created pipelines in 89–101 ms. The fifth reached our process memory guard during compilation. This measured pipeline creation only. The two mesh shaders responsible for most dropped draws in our trace still stop at sampler reconstruction.

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Correction to our earlier 44-shader result. During review we found that a separate descriptor matcher on our branch equated first-lane offsets across different active masks. Once I restricted that matcher to provable identity, only two of the 177 previously rejected shaders still validated on the combined branch. The earlier 44 additional outputs passed the DXIL validator, but they depended on the unsafe matcher and should not be counted as recovered story programs. The forwarding fixtures still pass. This issue was in our descriptor matching, separate from this PR's spill forwarding.

@SpaghettiMaster545

Copy link
Copy Markdown

Tested with the title at 64c7188.

Not tested: this PR together with #320, AMD GPUs, a release build, image results.

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

@Mesrine67

Copy link
Copy Markdown

Local DXIL translation/validation comparison for this PR head 64c7188 against its exact base d2a4bae, using the same local shaders.rpf, Windows SDK 10.0.26100.0 dxil.dll, and translate --validate --jobs 4:

Stage Base emitted / validated PR emitted / validated Delta
Vertex + pixel 12,272 / 12,172 12,368 / 12,268 +96 / +96
Compute 1,693 / 1,670 1,732 / 1,698 +39 / +28
Mesh 8,191 / 8,129 8,192 / 8,130 +1 / +1
Total 22,156 / 21,971 22,292 / 22,096 +136 / +125

The translator's lane mask holding lanes elsewhere read as data rejection bucket fell from 276 to 20. Both runs processed 26,084 programs after skipping the same 614 duplicate containers.

This was CPU-side translation plus DXIL validation only: zero D3D12 pipelines were created, and no title code was executed. The RX 6750 XT in this Windows 11 PC was not exercised by this scan, so these numbers do not establish GPU acceptance or a rendered in-game scene. Logs are available locally if a reproducer is useful.

@EduAzevedo

Copy link
Copy Markdown

Measured 64c7188 on the retail shaders (v1.0.2.1, Series X package), offline with victory translate --jobs 8 --list against main d2a4bae, same 26,148 programs. This was asked for in #160's thread: the 4 cube image_sample_d_cl programs #160 leaves at a cross-lane operation outside compute.

main this PR #160 (25e917b) #160 + this PR #160 + #54 (f30734f)
Vertex and pixel programs emitted 12,284 12,380 12,357 12,457 12,412
The 27 cube image_sample_d_cl programs translating 0 0 (the opcode is #160's) 23 27 27
Programs that translated on main and stop – 0 0 0 0

Both merges were clean (no conflicts). On its own, this PR clears a select on an untracked mask (288 → 0), a cross-lane operation outside compute (46 → 0), an opaque lane mask (29 → 0) and a conditional export (8 → 0), and cuts a lane mask holding lanes elsewhere read as data from 276 to 20. Most of the programs that get further now stop at a descriptor read only as data (183 → 692).

AI-assisted.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17 (DXC v1.9.2602):

  • Translation failures: 3,733 on main → 3,597 with this PR (−136). "a select on an untracked mask" disappears and "a lane mask holding lanes elsewhere read as data" drops from 276 to 20.
  • 11 compute programs that failed to emit on main (9 × "a lane mask holding lanes elsewhere read as data", 2 × "a lane-mask join of an untracked mask") now emit but fail DXIL validation with Entry function performs some operation that is incompatible with the shader stage or other entry properties. No program that validated on main fails now.
  • Merges cleanly with Shaders: track every incoming edge of a lane-mask phi #385: 3,572 failures together (−161), and that validation error goes from 24 to 55 modules.

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
…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>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…isak#306 Marvisak#333 Marvisak#105 Marvisak#288 Marvisak#343 Marvisak#353 Marvisak#326 Marvisak#259 Marvisak#179 Marvisak#176 Marvisak#226 Marvisak#286)

Conflicts:
- emit/lower.rs: shader-opcodes and shader-tracking each keyed heap
  handles by the resource properties (a tuple vs two flattened words);
  the same key, shader-tracking's form and comment kept. Lowered's
  test-only fields, test imports and tests of both sides kept.
- emit/wave.rs: tests of both sides kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>

@mercuryVM mercuryVM 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 64c7188 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 75 passed, and cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 programs.

  • The forwarding is sound in SSA terms. spilled follows the VGPR value at a v_readlane_b32 back through a chain of v_writelane_b32:
    • A write to another lane recurses into its old value.
    • The same constant lane yields the spilled SGPR.
    • Any other definition of that VGPR (a VALU write, an abs/neg/DPP/SDWA form, a non-constant lane) returns None, so nothing is forwarded.
    • At a phi, all incoming values must agree.
      So a lane overwritten between spill and reload can't be forwarded by mistake.
  • mask_sccs and the dead set keep the structurer and lowering consistent with the forwarded reads, and dead spill pairs no longer force console_lanes.

AI-assisted (Claude Code).

suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Conflicts resolved against the current tree: translate_for and the CLI
keep build_with and structure-first order and run sgpr_spill::forward
after the build; the console-lane scan keeps main's split of whole-wave
and in-half reads and leaves the dead spills and reloads out of the
whole-wave one; both sides' new Lower fields are kept. The PR's test
helper uses the current track/emit signatures, and one test no longer
requires the idiom to fail without forwarding (main takes some now).

In the cutscene set this translates the pixel program behind about 144
draws a frame (a lane mask spilled to a VGPR lane and reloaded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
Merged PR Marvisak#309 over PR Marvisak#385 and previous local changes:
- sgpr_spill::forward pass to forward SGPRs spilled to/reloaded from VGPR lanes.
- Dead reloads/spills are excluded from console-lanes / whole-wave scans.
- SCC of scalar mask operations tracked as mask ballot != 0.
- Resolved conflicts in emit/lower.rs keeping both numeric_select and mask_sccs.
- Updated emit() call in sgpr_spill.rs to supply Target::ANY. All 116 tests pass.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
Marvisak#704 + Marvisak#1511

- emit/mod.rs: the bundle structures the program before tracking resources
  (resource::track takes the structure since the bundle); Marvisak#309 forwards spilled SGPRs,
  which rewrites the IR. Order kept: forward, then structure, then track.
- emit/wave.rs: no conflict on this Marvisak#1511 head. On the previous bundle (which carried
  Marvisak#98's v_permlane16 tests) both sides added tests at the end of the module and the
  bundle's side was closed before Marvisak#309's tests; without Marvisak#98 git merges the two test
  lists itself, with Marvisak#309's tests as separate items of `mod tests` (not nested).
- sgpr_spill.rs (new in Marvisak#309, no textual conflict): its test helper called
  resource::track with the old 3-argument signature; adapted to the bundle's
  (structure first, passed to track). Test-only change.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…d masks

`sgpr_spill::tests::a_spilled_mask_holding_lanes_elsewhere_is_used_as_a_mask_again`
asserts that, without Marvisak#309's forwarding, the else-mask spilled to a VGPR lane is
refused ("a lane mask holding lanes elsewhere read as data"). On the bundle stack the
same words translate without forwarding (the stack already follows a lane mask
spilled to a VGPR lane, the idiom of Marvisak#1074), so the assertion fails with `Ok(())`.

Integration-only change: the control now accepts either outcome without forwarding
and still requires forwarding to translate. It records an overlap: for this idiom
Marvisak#309 adds nothing on top of the bundle; its measured gain (+125 vs its merge base,
Marvisak#1247) has not been re-measured on the stack.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…ge samples) onto Marvisak#309 + Marvisak#180 + Marvisak#704 + Marvisak#1511

PR Marvisak#160 head 5ce85c5, merged onto integ/next-v3 (0bb7335). The bundle
(Marvisak#1511) already carries Marvisak#306 (a16 bias as f16, a16 derivatives 32-bit),
10ac6ce (cube gradient samples, image_sample_d_cl) and cbc8c33 (image_get_lod
on cubes); Marvisak#180 adds compute image_sample/_b as sampleGrad with quad gradients.
Where Marvisak#160 and the bundle implement the same thing, they read the same address
layout: offset, bias and reference a full dword each (a16 bias an f16 in the low
half), derivatives 32-bit unless _g16, a16 packing only coordinates and level or
clamp. The bundle's Marvisak#306 layout is kept as the base and Marvisak#160's forms are added
to it.

gfx10/fields.rs (image_addr_dwords): both sides size derivatives by _g16 and
pack only coordinates and levels with a16. Kept the bundle's Marvisak#306 version (a g16
token rather than Marvisak#160's ends_with("_g16"), which gives the same count for every
opcode name) together with its a16_keeps_derivatives_32bit_outside_g16 test.

emit/host.rs (1 hunk): Marvisak#160 adds a test-host arm for Levels/CubeLevels/Depth
SRVs; the bundle (Marvisak#704) extended the UAV arm to BufferUav with a stride column.
Both arms kept: Marvisak#160's arm first, then the bundle's UAV arm unchanged.

emit/lower.rs:
1. Free functions after half_outputs: the bundle added half_inputs and Marvisak#160
   added SampleForm/sample_form/GATHER_AT_LEVEL in the same place. Kept both.
2. Opcode match: the bundle added "image_sample_d" | "image_sample_d_cl" to the
   fixed list, and Marvisak#160 replaced the list with the parsed form (_ if form.is_some()).
   Took Marvisak#160's. d_cl is the form {d, cl}, so it still lowers to SampleGrad with
   its clamp.
3-4. Address layout: the bundle had (Marvisak#306) first = offset + bias + cmp
   full dwords, 32-bit derivatives (2 per direction on a cube, 10ac6ce), and
   `at` = first + grads, from which the a16-packed coordinates and level start.
   Marvisak#160 had the same layout as whole/per_direction/first, plus _g16 derivatives and
   _cl. Kept the bundle's names and layout (first, graded, at, addr_dword) and put
   Marvisak#160's pieces on them: first is now o + b + c from the form (it was
   offset_word + (name == image_sample_b) + cmp); per_direction halves the
   derivative dwords for _g16 only; grad_at, coord_at, bias_at, float and known
   (Marvisak#160) read through the bundle's addr_dword in place of Marvisak#160's duplicate `raw`.
   Marvisak#306's to_float/addr_val pair for coordinates and Marvisak#160's float(coord_at(k))
   compute the same thing; the latter is kept because the level, clamp and known
   checks use it. The a16 refusal of comparisons in the bundle's code is
   dropped, as in Marvisak#160 (the reference is a full dword).
   Also, without a textual conflict: Marvisak#160 refused level queries on cubes
   ("... or a level query"), but the bundle lowers image_get_lod on cubes
   (cbc8c33). That refusal is dropped and only texel coordinates (both sides)
   and texel offsets (Marvisak#160) are refused on cubes. The bundle's `face` variable is
   kept in place of Marvisak#160's `cube_face`.
5. sample (60): the bundle's constant-offset code is the base code with
   addr_dword. Marvisak#160 moved offsets before the match (immediates in -8..7, otherwise
   a coordinate shift at a level known here) and added the clamp. Took Marvisak#160's
   version, reading the word with addr_dword.
6. sampleBias (61): bundle addr_val(offset_word, 0) + to_float, Marvisak#160
   float(bias_at). Both read the same position, an f16 low half with a16. Kept the
   bundle's comment and Marvisak#160's reader, plus Marvisak#160's clamp.
7. sampleGrad (63): the bundle reads `graded` 32-bit derivatives per direction,
   turns cube face derivatives into direction derivatives after reading, and
   reads its own _cl clamp. Marvisak#160 reads through grad_at (g16 too) with a per-face
   branch. Kept the bundle's structure (loop over `graded`, then the cube
   conversion) reading through Marvisak#160's grad_at, so _g16 works. The bundle's inner
   clamp is dropped for Marvisak#160's clamp, which comes from the same position
   (coordinate `coords`) and now covers every _cl form. Marvisak#160's `_cd` shortcut
   comment is kept.
8. sampleCmp/LevelZero (64/65): the bundle reads addr_dword(first - 1) and Marvisak#160
   reads float((o + b, None)). These are the same dword, since first = o + b + c
   and c is set. Kept the bundle's line. Marvisak#160's clamp is pushed for SampleCmp.
9. sampleLevel (62): bundle name == "image_sample_l" with addr_val(at,
   coords), Marvisak#160 f.l with float(coord_at(coords)). These are the same position.
   Took the form test so that _l_o and the others are covered.
10. gather (default arm): the bundle's checks and per-lane offsets are the base
    code with addr_dword. Marvisak#160 moved the checks into the op choice (level 0,
    comparison gathers, GATHER_AT_LEVEL) and the offsets ahead of the match.
    Took Marvisak#160's.
Duplicate method: 10ac6ce (bundle) and Marvisak#160 both add Lower::cube_gradient with
the same table (u, v move by 2 ds, 2 dt, the major axis by 0). With no conflict
git kept both. Kept Marvisak#160's, which shares by_face with cube_direction, and
removed the bundle's.

Marvisak#180 interaction (integration fix from
Marvisak#160 (comment), r4tedx):
Marvisak#180's compute image_sample/_b arm (sampleGrad from quad gradients) dropped the
level clamp, and before 5703405 it also read the bias at dword 0. With Marvisak#160,
_b_o, _cl and _b_cl_o reach that arm. The arm now reads the bias with
float(self, bias_at) (after the offset word, an f16 with a16; this is the same
position 5703405's addr_val(offset_word, 0) + to_float read) and pushes Marvisak#160's
level clamp instead of undef.

Marvisak#160 x Marvisak#306 interaction (no textual conflict; emit/shader.rs, lower.rs):
Marvisak#306 declares dx.valver 1.8 for a compute module with an implicit-derivative
sample (cs_derivatives, which Marvisak#180's sampleGrad arm also sets). Validator 1.8
counts a sample's level clamp (a non-undef clamp operand) as TiledResources use,
and 1.6 does not. Marvisak#160's _cl forms in compute (Marvisak#180's arm with the clamp above,
and SampleCmp for _c_cl) therefore failed "Flags must match usage" in
sample_and_gather_forms_lower_to_valid_dxil, comparisons_and_comparison_gathers_
match_per_texel_comparisons and texel_offsets_and_levels_sample_the_texels_they_name
(declared and actual flags differ by exactly 1 << 12). Marvisak#160 alone declares 1.6,
where this does not apply. Added flags::TILED_RESOURCES (bit 12, SFI0 0x100). It is
set when a sample takes a level clamp (Shader::lod_clamp) and the module declares
valver 1.8. Still needed on this Marvisak#1511 head: its Marvisak#1402 (119b763) only skips two
of Marvisak#306's own tests when dxil.dll is older than validator 1.8 and does not change
what Marvisak#306 declares.

Checked (on the previous Marvisak#1511 head, 289f241, which also carried Marvisak#98; this
replay was checked with cargo check --workspace --all-targets --all-features and
the full suite at the end of the line): cargo build --workspace --all-targets, clippy -D warnings, xtask
policy. cargo test --workspace on an RTX: 427 passed, 0 failed, 6 ignored. With
VICTORY_WARP=1 --no-fail-fast: 426 passed, 1 failed (valu_tests::
v_cndmask_on_an_untracked_mask_tests_this_lanes_bit, which also fails on the base),
6 ignored. #[test] count: base 424 + 8 from Marvisak#160 = 432 in the tree; the
victory-shader lib lists all 204 of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…, Marvisak#320, Marvisak#439) onto Marvisak#160 + Marvisak#309 + Marvisak#180 + Marvisak#704 + Marvisak#1511

PR Marvisak#439 head 28aca3b (46 commits over main: Marvisak#223 wave-range targets, Marvisak#233
split halves and the console flow, Marvisak#320 lane reads where lanes branch,
Marvisak#439 LDS in one console wave, whole-wave sections across the halves,
ds_bpermute, numeric selects), merged onto the Marvisak#160 merge (b821b31), as the wave64 line of integ/next-v3.

emit/wave.rs: no conflict on this Marvisak#1511 head. The previous head carried
Marvisak#98 (f468457, v_permlane16 modelled next to v_permlanex16, only with every
lane active), which conflicted with Marvisak#439's a31c82e (an inactive lane also
accepted when fi, opsel bit 0, is set). Marvisak#98 is no longer in the bundle, so
the whole-wave simulation is Marvisak#439's: v_permlanex16 only, under
`exec == all || v.opsel & 1 != 0`.

structure.rs (1 hunk): the bundle only reformatted `paired_masks`; Marvisak#439
moved it after the new `execs`/`others`/`pairs` fields because `pairs`
borrows `self.masks` before `paired_masks` moves it. Kept Marvisak#439's order with
the bundle's formatting.

emit/waterfall_tests.rs (3 hunks):
1-2. The bundle split `build` into `build_with(words, buffers, nonuniform)`
   (a program with no per-lane handle, whose first-lane read is a wave
   operation); Marvisak#439 split the same function into `native`, `lower_as`
   (per-lane or console flow) and `host_shader`. Kept Marvisak#439's helpers and
   the bundle's `build_with` on top of them (lower_as(.., false), the
   bundle's two asserts, host_shader). host_shader keeps the stride_table
   field (Marvisak#704), which git merged outside the hunk.
3. Tests at the end of the file: the bundle's side ends inside the `for`
   loop of a_descriptor_only_read_as_data_gives_its_views_size, Marvisak#439's
   inside the `for target` loop of its last test. The bundle's test is
   closed before Marvisak#439's tests, so none is nested in another.

emit/lower.rs (6 hunks):
1, 3. Lower fields and their initializers: the bundle's `mask_scc` (Marvisak#309,
   SCC of a mask operation read as data) and Marvisak#439's `opaque_open` (stops
   the recursion of a mask copied dword by dword). Both kept.
2. Which compute programs need the console's lanes. The bundle (Marvisak#309) counts
   only live instructions (`sgpr_spill::dead`: lane moves forwarding left
   unread are not lowered); Marvisak#439 split the test into in-half reads, whole
   reads and masks held as numbers and added the split/console-flow choice.
   Kept Marvisak#439's structure, reading `live()` for reads_whole and in_half, and
   for lane_access_outside_sections (the console-flow trigger for lane reads
   where lanes branch differently). 1ca87f7 (in Marvisak#439) notes that the tester
   tree's `live()` filter belongs here once Marvisak#309 is in.
4-5. Selects on masks the structure does not follow. The bundle (48a41fb,
   from Marvisak#585) added `mask_cond` for v_cndmask_b32 and the v_*_co_ci_u32
   carry-ins: inline 0/-1 constants, the tracked boolean, else with console
   lanes this lane's bit of the register's number (pair in wave64). Marvisak#439
   (e461457, 1ca87f7, ccd9c44) takes, for v_cndmask only, the structure's
   boolean for masks held as numbers (`Structured::others`, which also finds
   the high word written by another instruction), only where the host lane
   is the console lane (not split in halves without the console flow), and
   declares console lanes for them only on a second lowering after the
   first stops on such a select (`lower`). Combined in `mask_cond`: tracked
   boolean, then Marvisak#439's `others` boolean, then the bundle's register number,
   both under Marvisak#439's condition (console lanes and not split without the
   console flow; the bundle's number path called lane_bit, which is wrong in
   a split program, where Marvisak#439 asserts it is never called). Both instructions
   use it; v_cndmask now also takes the bundle's inline constants.
   Without a textual conflict git had also kept the bundle's unconditional
   rule (any untracked select or carry-in declares console lanes) inside
   Marvisak#439's masks_held, which undid 1ca87f7 (a select nothing reads made a
   wave64 program in a group of more than 64 threads untranslatable on a
   32-lane host). The rule now counts live instructions and applies only on
   Marvisak#439's second lowering, which now also follows an untracked carry-in
   ("a carry-in from an untracked mask", UNTRACKED_CARRY). It covers every
   untracked selector, not only Marvisak#439's held masks with an opaque or constant
   atom, since the bundle's number path needs console lanes for selectors
   outside `others` too; on the first lowering nothing changes.
6. lower.rs test helper: Marvisak#439's three new Parts fields with the bundle's
   formatting.

Not textual, did not compile (test code only): Marvisak#439 gives `emit` a Target
and `lower::Parts` target/console_cf/per_lane_only. Tests that came with
the bundle, Marvisak#704, Marvisak#309 and Marvisak#160 used the old forms: image_tests.rs `lower`,
emit/mod.rs (3 emit calls, the stride-table Parts), lower.rs (2 Parts in
the int64 atomics tests), root_view_tests.rs, sgpr_spill.rs tests and
victory-gpu raw_view_tests.rs. They pass Target::ANY, console_cf false and
per_lane_only false, as Marvisak#439 did for the upstream tests.

Not textual, test-only (split_tests.rs): with Marvisak#309 a v_readlane whose
result nothing reads is dead (not lowered and, above, not counted).
saveexec_scc_tests_new_exec_not_saved_exec and
loops_leave_on_the_new_exec_of_saveexec used `v_readlane_b32 s14, v0, 10`
with s14 unread only to take the console flow. After the merge the loop
test failed on the RTX (per-lane form, lane t counted t + 1 iterations
where the console counts 64; it passes on Marvisak#439 alone), and the saveexec
test passed without taking the console flow (its per-lane result is also
42). Both now read s14 once (`s_mov_b32 s15, s14`, the branch over the
body +4), and a first lowering of each was checked to ask for the console
flow again on a 32..32 target.

Marvisak#180 interaction: r4tedx's integration (24b3bcc, from Marvisak#180 5ff639e) put
`implicit_derivatives` among the in-half reads that make a program need
console lanes. The Marvisak#180 merged here is aa69258, whose last commit takes
quad gradients out of the console-lanes test altogether ("a quad's four
lanes share a host wave of any size"), so there is no such term to place.
The quad reads stay inside one host wave in both Marvisak#439 forms (each half is a
host wave in the split and in the console flow, and in the console flow
samples run in every lane and are kept by a select on EXEC).

Checked on the previous Marvisak#1511 head (289f241, with Marvisak#98; this replay was
checked with cargo check --workspace --all-targets --all-features and the
full suite at the end of the line), on an RTX 4060 Laptop (32..32): cargo test --workspace --locked:
468 passed, 0 failed, 6 ignored (base 427 + 41). The 41 tests Marvisak#439 adds all
pass; the GPU ones ran on the RTX in two 32-lane halves ("split true").
VICTORY_WARP=1: 467 passed, 1 failed, 6 ignored; the failure is
valu_tests::v_cndmask_on_an_untracked_mask_tests_this_lanes_bit, which
fails on the base too (a fixed-WaveSize pipeline on WARP). victory-shader
lib tests listed: 204 -> 244 (Marvisak#439 adds 40 there and 1 in victory-gpu).
cargo clippy --workspace --all-targets -D warnings and cargo xtask policy
clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak Marvisak closed this Nov 24, 2026
@AntoninMichelq
AntoninMichelq deleted the up/sgpr-spill-lanes branch November 25, 2026 20:04
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.

10 participants