Skip to content

Shaders: a scalar joining a lane mask and a number lowers in pixel and vertex programs - #1073

Closed
undeadhuman37 wants to merge 1 commit into
Marvisak:mainfrom
undeadhuman37:fix/mask-phi-ballot
Closed

undeadhuman37 wants to merge 1 commit into
Marvisak:mainfrom
undeadhuman37:fix/mask-phi-ballot

Conversation

@undeadhuman37

Copy link
Copy Markdown

A register can hold a compare result's high dword on one path and a loaded number on another. The join's mask side was refused as "a lane mask read as data". A pixel or vertex program now takes the mask's ballot as that incoming value (counts and zero tests mean the same on any wave size).

Known limit: the ballot is the host wave's, so a join read some other way would differ from the console.

Measured offline over the shader corpus (26148 programs):

  • "a lane mask read as data": 250 -> 212
  • vertex/pixel programs emitted: 12243 -> 12250 (the other 31 move on to descriptor / scalar-memory refusals)

Tests: a synthetic wave64 pixel program fails to lower before the change and lowers after. cargo clippy -p victory-shader --all-targets -- -D warnings is clean. Not run on a GPU, hence draft.

No game data. AI-assisted: written with Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

…d vertex programs

A register can hold a compare result's high dword on one path and a loaded
number on another; the compiler only reads it where the number is live. The
join's mask side was "a lane mask read as data", which refused the program.
A pixel or vertex program now takes the mask's ballot as that incoming value
(counts and zero tests mean the same on any wave size). shortcut: the ballot
is the host wave's, so a join read some other way would differ from the console.

Offline corpus: "a lane mask read as data" 250 -> 212, vertex/pixel programs
emitted 12243 -> 12250; the other 31 move on to descriptor/scalar-memory
refusals. Synthetic wave64 pixel program fails before, lowers after.

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

@DenRakEiw DenRakEiw 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 merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader: 121 passed, 0 failed, 1 ignored (all hardware + WARP VALU/waterfall/diff tests green on RTX 5090 and WARP)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean lowering of mixed lane-mask/number scalar joins across pixel and vertex stages. Approving.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft noted — the lowering change is the same hunk as #1074 (emit/lower.rs identical, same index line), and #1074 additionally carries the structure.rs spilled-lane tracking plus a second test. If both are meant to land, #1074 subsumes this one; if this is the smaller first step, say so and I'll review it as such.

On the change itself: the ballot fallback for a mask dword joined with a number is a pragmatic approximation, and the comment is honest about its limit (a join read any other way than a zero test/count would diverge from console). Two things worth pinning before it leaves draft: (1) a host-execution test on the Windows lane showing the joined value is only ever consumed by a zero test or count in the programs this targets, since the fallback silently changes semantics otherwise; (2) the ballot_ok gate requires def_block != cur_ir — a same-block join still refuses, which is the safe direction, but worth a test so the boundary is intentional.

Verified locally: test-merge with main clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 97 passed / 0 failed / 1 ignored (the new emit test runs on macOS).

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…wers in pixel and vertex programs

Head 986fa6d (undeadhuman37). Conflict in fill_phis: the edge keeps our
lazy barycentrics and #269's loop finals, then #1073's ballot. #999's
missing_phis (merged before) would redo such a phi before fill_phis
ever reaches the ballot, so it now makes the ballots first and takes a
mask dword that has one as a value. #1073's test passes the host
target to emit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…table names

Brings #193's runtime stride table (#155) with #704's raw view pool.

Conflicts and fitting it to this tree:
- Heap layout is title slots, dynamic slots, the guard slot, then the raw
  view pool (alias_base = count + extra + 1). A heap capped at
  PORTABLE_VIEWS takes a pool of 2^14 (ALIASES_CAPPED), not 2^16, since
  each pool slot is a mirrored title slot less.
- Stride entries follow every slot write of ours: mirror, make_at, the
  bindless buffer and placed-texture slots, typed nulls, null kinds,
  raw_at, bindless CBVs and unmapped nulls.
- viewed_bytes cuts the raw view to its host copy as make does
  (cut_to_copy), so the host never refuses it.
- stride_entry gets the slot through our uniform_heap_index (#1012);
  #704's heap_slot is dropped. handles keeps our props key.
- Our cut_to_copy clamps stay in buffer_srv/uav; #704's are dropped.
- The tests pass the heap guard in its user-data dword, take our make_at
  and emit signatures, and count the guard slot.
- Shader cache MAGIC VSH3, KeySpec version 3 (stride_table encoded).
- Formatting-only hunks from #704 left out.

translate --host-lanes 32-32: compute 2285 -> 2487, vertex/geometry/pixel
14186 -> 14256 (with #1073, #1084, #416 before it), mesh 8381 -> 8383;
"a structured buffer of unknown stride" 206 -> 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
#1215 #1135 #1296 #1277 #1238 #464 #1073 #1057 #1084 #416 #704 #621.

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
…sak#704 + Marvisak#1511

Conflicts in crates/victory-shader/src/emit/lower.rs, resolved by hand:

1. descriptor_data: the bundle (Marvisak#953 s_buffer_load uses, Marvisak#1067 "read only as data"
   from the table's range) and Marvisak#180 (twin loads of the same dwords) both rewrote how
   the view's kind is found. Kept Marvisak#180's lookup (own uses, else a twin load's) and the
   bundle's handling of the use and of the unused case, plus the one case Marvisak#180 accepted
   that the bundle did not: an 8-dword load outside a table/heap range, taken as a 2D
   image (Marvisak#180's "image the program only measures"). Where both accepted a descriptor
   they built the same view.
2. phi joins: the bundle's arm (Marvisak#1073, a mask dword joined by ballot) and Marvisak#180's arm
   (a descriptor dword at a data join is undef) were inserted at the same place. Both
   kept, bundle first; the first needs a tracked lane mask, which a descriptor dword
   is not, so they do not overlap.
3. No textual conflict, did not compile: the bundle (Marvisak#306) gave `addr_val` a start
   position (`addr_val(l, start, k)`); Marvisak#180's compute image_sample_b arm read the bias
   with the old form at dword 0 through `as_float`. It now reads it as the bundle's
   sampleBias does: after the offset word when there is one, an f16 with a16
   (`to_float`). This is the bias half of the Marvisak#160/Marvisak#180 interaction described in
   Marvisak#160 (comment) , which the
   bundle's offset forms already expose.
@Marvisak

Copy link
Copy Markdown
Owner

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

Draft. A register joining a mask and a number in pixel/vertex programs: main resolves these joins by proving the mask edge dead or the join data (dead_on_edge, live_edges, joins_loaded; 0b35b7f, a7fc47a), 250 to 4 programs, without taking a host-wave ballot as the console's number.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants