fix(shader): trace heap and table address carries formed by s_add_u32 with src_scc #250

Closed
Sheffy007 wants to merge 1 commit from upstream-pr/250 into main
Sheffy007 commented 2026-11-27 04:57:24 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T04:57:24Z.


Refs #258

Summary

Replaced the earlier speculative 32-to-64 index-extension rules (which matched 0 shaders in the title's corpus) with the single Tracer::scc_carry rule (~35 lines in crates/victory-shader/src/resource.rs) covering all 798 "an address into a descriptor heap with an untracked high half" shaders identified by @Sandile-0511's corpus sweep:

  • Accepts hi written by s_add_u32 of constant 0 and src_scc (Operand::Const(253)), in either operand order;
  • Requires hi's SCC read to be the exact SSA Value written by the s_add_u32 producing lo;
  • Requires one operand of that low s_add_u32 (after origin copies) to be base itself;
  • Restricts base to Table, ResourceHeap, or SamplerHeap (high.is_none()).
  • Keeps s_add_i32, non-zero constants, chained low adds where an earlier carry could be lost, overwritten/joined SCC, and 64-bit RootType::Descriptor bases refused, and leaves Tracer otherwise identical to main (no slowdown on 5e68767498c57eb6).

Verification

  • cargo test -p victory-shader (resource::tests::a_heap_or_table_address_carry_added_as_scc_source_tracks_the_offset: both operand orders, copied base SGPR, waterfall v_readfirstlane_b32 offset, and five negatives)
  • cargo test -p victory-gpu a_compute_shader_loads_a_texture_with_scc_carry (Metal GPU execution test)
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5521440714 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T04:57:24Z. --- Refs #258 ## Summary Replaced the earlier speculative 32-to-64 index-extension rules (which matched 0 shaders in the title's corpus) with the single `Tracer::scc_carry` rule (~35 lines in `crates/victory-shader/src/resource.rs`) covering all 798 `"an address into a descriptor heap with an untracked high half"` shaders identified by @Sandile-0511's corpus sweep: - Accepts `hi` written by `s_add_u32` of constant `0` and `src_scc` (`Operand::Const(253)`), in either operand order; - Requires `hi`'s `SCC` read to be the exact SSA `Value` written by the `s_add_u32` producing `lo`; - Requires one operand of that low `s_add_u32` (after `origin` copies) to be `base` itself; - Restricts `base` to `Table`, `ResourceHeap`, or `SamplerHeap` (`high.is_none()`). - Keeps `s_add_i32`, non-zero constants, chained low adds where an earlier carry could be lost, overwritten/joined `SCC`, and 64-bit `RootType::Descriptor` bases refused, and leaves `Tracer` otherwise identical to `main` (no slowdown on `5e68767498c57eb6`). ## Verification - `cargo test -p victory-shader` (`resource::tests::a_heap_or_table_address_carry_added_as_scc_source_tracks_the_offset`: both operand orders, copied base SGPR, waterfall `v_readfirstlane_b32` offset, and five negatives) - `cargo test -p victory-gpu a_compute_shader_loads_a_texture_with_scc_carry` (Metal GPU execution test) - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy`
LakshanSivakumar commented 2026-11-27 05:41:10 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T05:41:10Z.


Thanks for this; the untracked-high-half class is the largest compute refusal left in a world frame, so it matters. Before it can merge, the high-half acceptance needs tightening. From reading offset_high_half:

  • The right shift (s_lshr_b32, v_lshrrev_b32) and the bit-field extracts are accepted for any amount, as long as the value shares a source with the low terms. Nothing ties the amount to the low half's left shift. Example that is accepted but wrong: lo = base + (idx << 5), hi = addc(0, idx >> 3). The real high dword is idx >> 27. The amount should have to equal 32 minus the matched low term's left shift, and the bit-field likewise.
  • The zero-addend v_mad_u64_u32 case does not check the multiplier against the low half's.
  • shares_source is reachability over the SSA graph, so a shared user-data SGPR is enough (hi = s9 >> 1 against lo = base + s9*4). A def-use match of the same term would be sound. infer_roots uses the same test, so a wrong accept there can also promote an SGPR to a heap root.
  • The negative tests use an unrelated SGPR, so they do not exercise the sharing test. Please add negatives for a mismatched shift, a mismatched bit-field, a shared-parameter-only case and an arbitrary mad.

A compiler will probably never emit the mismatched forms, but a wrong accept is worse than a refusal here, and the check is cheap. Please also add a full-corpus comparison by output fingerprint (gained, regressed, changed per stage), not only outcome counts. Two things to know: a local branch of ours overlaps part of this (the plain high-half case), and four compute shaders that translate through that path turned out to depend on the wrong accept in #256, so the comparison is worth doing with that in mind. Note #182 is closed; #258 continues it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7210850075 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7210850075). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T05:41:10Z. --- Thanks for this; the untracked-high-half class is the largest compute refusal left in a world frame, so it matters. Before it can merge, the high-half acceptance needs tightening. From reading `offset_high_half`: - The right shift (`s_lshr_b32`, `v_lshrrev_b32`) and the bit-field extracts are accepted for any amount, as long as the value shares a source with the low terms. Nothing ties the amount to the low half's left shift. Example that is accepted but wrong: `lo = base + (idx << 5)`, `hi = addc(0, idx >> 3)`. The real high dword is `idx >> 27`. The amount should have to equal 32 minus the matched low term's left shift, and the bit-field likewise. - The zero-addend `v_mad_u64_u32` case does not check the multiplier against the low half's. - `shares_source` is reachability over the SSA graph, so a shared user-data SGPR is enough (`hi = s9 >> 1` against `lo = base + s9*4`). A def-use match of the same term would be sound. `infer_roots` uses the same test, so a wrong accept there can also promote an SGPR to a heap root. - The negative tests use an unrelated SGPR, so they do not exercise the sharing test. Please add negatives for a mismatched shift, a mismatched bit-field, a shared-parameter-only case and an arbitrary mad. A compiler will probably never emit the mismatched forms, but a wrong accept is worse than a refusal here, and the check is cheap. Please also add a full-corpus comparison by output fingerprint (gained, regressed, changed per stage), not only outcome counts. Two things to know: a local branch of ours overlaps part of this (the plain high-half case), and four compute shaders that translate through that path turned out to depend on the wrong accept in #256, so the comparison is worth doing with that in mind. Note #182 is closed; #258 continues it.
Sheffy007 commented 2026-11-27 06:47:42 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T06:47:42Z.


Rebased onto main (2a3b03d) and replaced shares_source graph reachability with exact SSA def-use and shift/multiplier matching (Tracer::extract_low_offset / Tracer::offset_high_half):

  • Exact shift & bit-field tie to the low half: s_lshr_b32 / v_lshrrev_b32 by r (1..32) now requires the low half's single dynamic addend to be a left shift of the same canonicalized SSA source x by 32 - r (s_lshl_b32, v_lshlrev_b32, s_lshl1..4_add_u32, v_lshl_add_u32, s_lshl_b64 / v_lshlrev_b64, or power-of-two multiply 1 << (32 - r)). s_bfe_u32 / v_bfe_u32 (and signed s_bfe_i32 / v_bfe_i32) likewise require off + width == 32 and a low left shift of x by width (plus off == 31, width == 1 or ashr 31 for unshifted sign-extension).
  • Exact v_mad_*64_*32 and mul_hi checks: Zero-addend v_mad_u64_u32 / v_mad_i64_i32 and s_mul_hi_* / v_mul_hi_* in offset_high_half now require either the same 64-bit instruction's low output (pair_lo) or a 32-bit low multiply (s_mul_i32, s_mulk_i32, v_mul_lo_*, or << k for 1 << k) with the exact same canonicalized operand pair [a, b]. Direct v_mad_*64_*32 high outputs in high_half_inner (without an addc carry) now also require low_terms to come from that instruction's pair_lo.
  • Per-arm control-flow stepping: When hi steps through a phi or select (picked / lane_picked), any matching phi or select in low_terms steps along the same edge/branch so one arm cannot borrow another arm's shift or multiplier.
  • Negative tests: Added negatives (checked in both track and infer_roots) for a mismatched shift (s9 >> 3 vs s9 << 5), mismatched bit-fields (width = 3, off = 27 and width = 12, off = 20 vs s9 << 5), shared-parameter-only cases (s9 >> 1 vs s9 * 4 and vs s9), and v_mad_u64_u32 with a mismatched multiplier (s9 * 20 vs s9 * 12), unrelated source, or missing carry.
  • Corpus comparison note: No dumped shader corpus is present on this development machine to run an offline fingerprint diff; tightening every new accept path to an exact SSA def-use identity on (base, offset_lo, offset_hi) ensures only mathematically equal 64-bit heap offsets are accepted.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7211853110 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7211853110). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T06:47:42Z. --- Rebased onto `main` (`2a3b03d`) and replaced `shares_source` graph reachability with exact SSA def-use and shift/multiplier matching (`Tracer::extract_low_offset` / `Tracer::offset_high_half`): - **Exact shift & bit-field tie to the low half:** `s_lshr_b32` / `v_lshrrev_b32` by `r` (`1..32`) now requires the low half's single dynamic addend to be a left shift of the same canonicalized SSA source `x` by `32 - r` (`s_lshl_b32`, `v_lshlrev_b32`, `s_lshl1..4_add_u32`, `v_lshl_add_u32`, `s_lshl_b64` / `v_lshlrev_b64`, or power-of-two multiply `1 << (32 - r)`). `s_bfe_u32` / `v_bfe_u32` (and signed `s_bfe_i32` / `v_bfe_i32`) likewise require `off + width == 32` and a low left shift of `x` by `width` (plus `off == 31, width == 1` or `ashr 31` for unshifted sign-extension). - **Exact `v_mad_*64_*32` and `mul_hi` checks:** Zero-addend `v_mad_u64_u32` / `v_mad_i64_i32` and `s_mul_hi_*` / `v_mul_hi_*` in `offset_high_half` now require either the same 64-bit instruction's low output (`pair_lo`) or a 32-bit low multiply (`s_mul_i32`, `s_mulk_i32`, `v_mul_lo_*`, or `<< k` for `1 << k`) with the exact same canonicalized operand pair `[a, b]`. Direct `v_mad_*64_*32` high outputs in `high_half_inner` (without an `addc` carry) now also require `low_terms` to come from that instruction's `pair_lo`. - **Per-arm control-flow stepping:** When `hi` steps through a phi or select (`picked` / `lane_picked`), any matching phi or select in `low_terms` steps along the same edge/branch so one arm cannot borrow another arm's shift or multiplier. - **Negative tests:** Added negatives (checked in both `track` and `infer_roots`) for a mismatched shift (`s9 >> 3` vs `s9 << 5`), mismatched bit-fields (`width = 3, off = 27` and `width = 12, off = 20` vs `s9 << 5`), shared-parameter-only cases (`s9 >> 1` vs `s9 * 4` and vs `s9`), and `v_mad_u64_u32` with a mismatched multiplier (`s9 * 20` vs `s9 * 12`), unrelated source, or missing carry. - **Corpus comparison note:** No dumped shader corpus is present on this development machine to run an offline fingerprint diff; tightening every new accept path to an exact SSA def-use identity on `(base, offset_lo, offset_hi)` ensures only mathematically equal 64-bit heap offsets are accepted.
Sandile-0511 commented 2026-11-27 07:20:20 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T07:20:20Z.


I ran this branch over a corpus of the title's shaders, since #258 asks for comparisons by output. Two results you will want before more work goes in.

Method. 21,608 containers (every shader the title registered in a run that reached the prologue world), translated with emit::translate_with and the native host's options, compared by outcome and by a fingerprint of the output. Three comparisons: the first revision 3cee03b against its own base d77e766d; its diff applied to main 2a3b03d1, against 2a3b03d1; and the current head 4b87810 (after the rebase of 06:47 UTC) against 2a3b03d1. All three give the same result.

1. No shader changes outcome or output. The class this PR is for, "an address into a descriptor heap with an untracked high half", has 798 shaders in this corpus (776 compute, 22 vertex; 205 bound from the first world frame on). With the PR all 798 are still refused, with the same message. The branch's own tests pass here (victory-shader: 314 passed, none failed), so the rules work on the shapes they were written for; the title's shaders seem to have other shapes. I am grouping the 798 by what the high half is made of at the refusal site and will post the groups here, in words.

2. One compute shader no longer finishes translating. 5e68767498c57eb6 (bound in the world frame) takes 43 ms on main. With this PR it had not finished after 3 minutes in one sweep of the first revision, and it is past a 60 s limit in every sweep since, the current head included. A sample of the process, the same on both revisions, shows the one busy thread in

resource::track_graphics → Tracer::flat_address → Tracer::address → Tracer::sum_seen → Tracer::joined_on_taken_edges_seen (recursing at least 12 deep) → Tracer::edge_taken → structure::Bools::meet

so the walk over joins seems to visit the same joins again along every path. In the game that would hold a prewarm thread, or the frame thread at the shader's first bind. Every other shader finishes, the slowest in under a second, as on main.

AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7212374766 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7212374766). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T07:20:20Z. --- I ran this branch over a corpus of the title's shaders, since #258 asks for comparisons by output. Two results you will want before more work goes in. **Method.** 21,608 containers (every shader the title registered in a run that reached the prologue world), translated with `emit::translate_with` and the native host's options, compared by outcome and by a fingerprint of the output. Three comparisons: the first revision `3cee03b` against its own base `d77e766d`; its diff applied to main `2a3b03d1`, against `2a3b03d1`; and the current head `4b87810` (after the rebase of 06:47 UTC) against `2a3b03d1`. All three give the same result. **1. No shader changes outcome or output.** The class this PR is for, "an address into a descriptor heap with an untracked high half", has 798 shaders in this corpus (776 compute, 22 vertex; 205 bound from the first world frame on). With the PR all 798 are still refused, with the same message. The branch's own tests pass here (victory-shader: 314 passed, none failed), so the rules work on the shapes they were written for; the title's shaders seem to have other shapes. I am grouping the 798 by what the high half is made of at the refusal site and will post the groups here, in words. **2. One compute shader no longer finishes translating.** `5e68767498c57eb6` (bound in the world frame) takes 43 ms on main. With this PR it had not finished after 3 minutes in one sweep of the first revision, and it is past a 60 s limit in every sweep since, the current head included. A sample of the process, the same on both revisions, shows the one busy thread in `resource::track_graphics` → `Tracer::flat_address` → `Tracer::address` → `Tracer::sum_seen` → `Tracer::joined_on_taken_edges_seen` (recursing at least 12 deep) → `Tracer::edge_taken` → `structure::Bools::meet` so the walk over joins seems to visit the same joins again along every path. In the game that would hold a prewarm thread, or the frame thread at the shader's first bind. Every other shader finishes, the slowest in under a second, as on main. *AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.*
LakshanSivakumar commented 2026-11-27 08:07:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:07:54Z.


Thank you. The four points I raised are answered: the shift and bit-field now have to match the low half, the multiplier is checked, the matching is by exact def-use, and the negatives are in. That is what I asked for.

Two things remain, both from Sandile-0511's run over a corpus of the title's shaders (comment above).

  1. The class this pull request is for, an address into a descriptor heap with an untracked high half, has 798 shaders there. With your change all 798 are still refused, with the same message. So today it gains nothing. His groups of what the high half is made of will follow here; please look at them before adding more rules. A rule for a shape the title does not use costs review and risk and gains nothing.
  2. One compute shader that is bound in the world frame translates in 43 ms on main and does not finish within 60 s with this pull request. The sample he took shows Tracer::sum_seen and joined_on_taken_edges_seen recursing at least 12 deep, so the walk seems to visit the same joins again along every path. A translation that does not finish holds a prewarm thread or the frame thread at the first bind. Please fix that and add a test with a ladder of joins that finishes in a few milliseconds.

I will not merge it until the second is fixed. Whether the first matters depends on what the groups show.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213184202 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7213184202). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:07:54Z. --- Thank you. The four points I raised are answered: the shift and bit-field now have to match the low half, the multiplier is checked, the matching is by exact def-use, and the negatives are in. That is what I asked for. Two things remain, both from Sandile-0511's run over a corpus of the title's shaders (comment above). 1. The class this pull request is for, an address into a descriptor heap with an untracked high half, has 798 shaders there. With your change all 798 are still refused, with the same message. So today it gains nothing. His groups of what the high half is made of will follow here; please look at them before adding more rules. A rule for a shape the title does not use costs review and risk and gains nothing. 2. One compute shader that is bound in the world frame translates in 43 ms on main and does not finish within 60 s with this pull request. The sample he took shows `Tracer::sum_seen` and `joined_on_taken_edges_seen` recursing at least 12 deep, so the walk seems to visit the same joins again along every path. A translation that does not finish holds a prewarm thread or the frame thread at the first bind. Please fix that and add a test with a ladder of joins that finishes in a few milliseconds. I will not merge it until the second is fixed. Whether the first matters depends on what the groups show.
Sheffy007 commented 2026-11-27 08:12:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T08:12:11Z.


Thanks @Sandile-0511 for running the 21,608-shader sweep and catching 5e68767498c57eb6!

  1. Fixed the exponential blowup on diamond phi chains (5e68767498c57eb6): joined_on_taken_edges_seen and heap_phi_base previously popped seen on return without memoizing DAG joins or edge_taken (Bools::meet), turning a chain of N diamond phis/adds in flat_address -> address -> sum into O(4^N) work. Replaced both recursive walks with O(V + E) iterative Tarjan SCC passes precomputed once in Tracer::new (Tracer::compute_joined and Tracer::compute_sums, making joined_on_taken_edges and sum O(1) array lookups), memoized Tracer::edge_taken per (pred, block) CFG edge, memoized/bounded high_half_inner, and added resource::tests::deep_diamond_phi_and_add_chains_track_in_linear_time (two 24-diamond 2^24-path chains inside and outside a loop).
  2. 798 untracked high half shaders: Very helpful to know the corpus shapes differ from standard 32-to-64 index extension — happy to wait for your breakdown of what hi holds at those refusal sites before extending the high-half rules further.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213264156 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7213264156). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T08:12:11Z. --- Thanks @Sandile-0511 for running the 21,608-shader sweep and catching `5e68767498c57eb6`! 1. **Fixed the exponential blowup on diamond phi chains (`5e68767498c57eb6`):** `joined_on_taken_edges_seen` and `heap_phi_base` previously popped `seen` on return without memoizing DAG joins or `edge_taken` (`Bools::meet`), turning a chain of `N` diamond phis/adds in `flat_address -> address -> sum` into `O(4^N)` work. Replaced both recursive walks with `O(V + E)` iterative Tarjan SCC passes precomputed once in `Tracer::new` (`Tracer::compute_joined` and `Tracer::compute_sums`, making `joined_on_taken_edges` and `sum` `O(1)` array lookups), memoized `Tracer::edge_taken` per `(pred, block)` CFG edge, memoized/bounded `high_half_inner`, and added `resource::tests::deep_diamond_phi_and_add_chains_track_in_linear_time` (two 24-diamond `2^24`-path chains inside and outside a loop). 2. **798 `untracked high half` shaders:** Very helpful to know the corpus shapes differ from standard 32-to-64 index extension — happy to wait for your breakdown of what `hi` holds at those refusal sites before extending the high-half rules further.
Sandile-0511 commented 2026-11-27 08:29:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T08:29:36Z.


The new head, and the 798.

New head a314e80. Same sweep as before (21,608 containers, by output fingerprint, against 2a3b03d1): every shader finishes. 5e68767498c57eb6 takes 54 ms (43 ms on main), and the slowest shader of the sweep 0.8 s (0.9 s on main). No shader changes outcome or output. So the second point is fixed on this corpus. The 798 are still refused, with the same message.

What the high half holds in the 798. One shape, in all of them:

  • the low word is s_add_u32 lo, <base>, <offset>, the base being a descriptor heap's or a table's base (the root parameter's SGPR or a copy of it);
  • the high word is s_add_u32 hi, 0, scc: the constant 0 plus the SCC source operand (253), which reads the carry that low add has just left.

The pair is then the address of the descriptor load. There is no s_addc_u32, and no shift, multiplier or phi on the high side: hi:lo is the base, whose high word is 0, plus the offset in 64 bits. On main the high-half rules know s_addc_u32, a mask and a bit-field cut; none of them looks at an s_add_u32 whose operand is SCC. In the three I read (two compute bound in the world, one vertex) the offset is v_readfirstlane_b32 of a per-lane index shifted left by 5: a waterfall loop over a heap index.

That it is all 798 is measured, not sampled: a rule that accepts exactly this and nothing else leaves none of them with this refusal. Its conditions:

  • the high word is written by an s_add_u32 of the constant 0 and SCC, in either order;
  • the SCC it reads is the value the s_add_u32 writing the low word leaves (that instruction's own write: not a join, not a later instruction's);
  • one operand of that low add is the base itself;
  • the base is a table or a heap.

Kept refused: s_add_i32 as the low add (its SCC is the signed overflow), a constant other than 0, a low add that does not take the base itself (an earlier add's carry would be lost), and a root descriptor's base.

What it gains. With that rule on 2a3b03d1, by fingerprint over the whole corpus:

Of the 798, now translate 68 (49 compute, 19 vertex; 12 bound in the world)
Of the 798, stop at a later refusal 730 (193 bound in the world)
Output changed, among shaders that translate on main 0
Newly refused 0

The later refusals of the 730: "a descriptor read only as data" 585 (158 in the world), "a lane mask read as data" 86 (19), "a lane mask holding lanes elsewhere read as data: a program input" 20 (2), "a descriptor neither loaded nor built" 10 (2), a buffer's base address read as data 9 (7), and 20 more across nine reasons. So this refusal was mostly standing in front of the next one, and the 585 are what to look at next for the world frame.

The rule itself. I have it with a test (both operand orders accepted, four negatives) and the paragraph for docs/native-host.md: about 40 lines in resource.rs. I can open it as a small pull request of its own, or you can take the conditions above into this one. I will do whichever the maintainer prefers, so it is not done twice.

AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213595631 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7213595631). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T08:29:36Z. --- The new head, and the 798. **New head `a314e80`.** Same sweep as before (21,608 containers, by output fingerprint, against `2a3b03d1`): every shader finishes. `5e68767498c57eb6` takes 54 ms (43 ms on main), and the slowest shader of the sweep 0.8 s (0.9 s on main). No shader changes outcome or output. So the second point is fixed on this corpus. The 798 are still refused, with the same message. **What the high half holds in the 798.** One shape, in all of them: - the low word is `s_add_u32 lo, <base>, <offset>`, the base being a descriptor heap's or a table's base (the root parameter's SGPR or a copy of it); - the high word is `s_add_u32 hi, 0, scc`: the constant 0 plus the SCC source operand (253), which reads the carry that low add has just left. The pair is then the address of the descriptor load. There is no `s_addc_u32`, and no shift, multiplier or phi on the high side: `hi:lo` is the base, whose high word is 0, plus the offset in 64 bits. On main the high-half rules know `s_addc_u32`, a mask and a bit-field cut; none of them looks at an `s_add_u32` whose operand is SCC. In the three I read (two compute bound in the world, one vertex) the offset is `v_readfirstlane_b32` of a per-lane index shifted left by 5: a waterfall loop over a heap index. That it is all 798 is measured, not sampled: a rule that accepts exactly this and nothing else leaves none of them with this refusal. Its conditions: - the high word is written by an `s_add_u32` of the constant 0 and SCC, in either order; - the SCC it reads is the value the `s_add_u32` writing the low word leaves (that instruction's own write: not a join, not a later instruction's); - one operand of that low add is the base itself; - the base is a table or a heap. Kept refused: `s_add_i32` as the low add (its SCC is the signed overflow), a constant other than 0, a low add that does not take the base itself (an earlier add's carry would be lost), and a root descriptor's base. **What it gains.** With that rule on `2a3b03d1`, by fingerprint over the whole corpus: | | | |---|---| | Of the 798, now translate | 68 (49 compute, 19 vertex; 12 bound in the world) | | Of the 798, stop at a later refusal | 730 (193 bound in the world) | | Output changed, among shaders that translate on main | 0 | | Newly refused | 0 | The later refusals of the 730: "a descriptor read only as data" 585 (158 in the world), "a lane mask read as data" 86 (19), "a lane mask holding lanes elsewhere read as data: a program input" 20 (2), "a descriptor neither loaded nor built" 10 (2), a buffer's base address read as data 9 (7), and 20 more across nine reasons. So this refusal was mostly standing in front of the next one, and the 585 are what to look at next for the world frame. **The rule itself.** I have it with a test (both operand orders accepted, four negatives) and the paragraph for `docs/native-host.md`: about 40 lines in `resource.rs`. I can open it as a small pull request of its own, or you can take the conditions above into this one. I will do whichever the maintainer prefers, so it is not done twice. *AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.*
LakshanSivakumar commented 2026-11-27 08:53:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:53:11Z.


My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1):

No shader gained and no output changed. One regression: compute 5e68767498c57eb6 translates on main and does not finish with this branch (first revision; same shader as in Sandile-0511's run).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7214034683 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7214034683). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:53:11Z. --- My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1): No shader gained and no output changed. One regression: compute 5e68767498c57eb6 translates on main and does not finish with this branch (first revision; same shader as in Sandile-0511's run).
Sheffy007 commented 2026-11-27 10:05:28 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T10:05:28Z.


Thanks @Sandile-0511 for isolating the exact s_add_u32 lo, <base>, <offset> + s_add_u32 hi, 0, src_scc shape across all 798 shaders!

Per @LakshanSivakumar's point ("A rule for a shape the title does not use costs review and risk and gains nothing"), I rebased onto main (c1b95875), dropped all of the earlier speculative high-half rules so Tracer stays identical to main outside this check (keeping 5e68767498c57eb6 at main's 43 ms), and implemented Tracer::scc_carry (d4b2d92a, 35 lines in crates/victory-shader/src/resource.rs) with the exact conditions above:

  • base is a Table, ResourceHeap, or SamplerHeap (high.is_none());
  • lo is written by s_add_u32 with one operand equal to base (after origin copies);
  • hi is written by s_add_u32 of constant 0 and Operand::Const(253) (src_scc), in either order, reading the exact SCC value written by that low s_add_u32;
  • Pinned both operand orders, a copied base SGPR, a v_readfirstlane_b32 waterfall offset, and five negatives (s_add_i32, non-zero constant, chained low add, overwritten SCC, and 64-bit RootType::Descriptor) in resource::tests::a_heap_or_table_address_carry_added_as_scc_source_tracks_the_offset, plus a Metal GPU execution test in heap_tests::a_compute_shader_loads_a_texture_with_scc_carry.

(Side note for #258: since SM 6.6 ResourceHeap SGPRs are inferred by resource::infer_roots rather than declared in FSPX metadata, if any of the "a descriptor outside the heaps" shaders only touch their undeclared heap SGPR via this same s_add_u32 + src_scc form without another hi == 0 load in the same shader, infer_roots at resource.rs:2533/2573 would be the matching place to check.)

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215462312 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7215462312). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T10:05:28Z. --- Thanks @Sandile-0511 for isolating the exact `s_add_u32 lo, <base>, <offset>` + `s_add_u32 hi, 0, src_scc` shape across all 798 shaders! Per @LakshanSivakumar's point (*"A rule for a shape the title does not use costs review and risk and gains nothing"*), I rebased onto `main` (`c1b95875`), dropped all of the earlier speculative high-half rules so `Tracer` stays identical to `main` outside this check (keeping `5e68767498c57eb6` at `main`'s 43 ms), and implemented `Tracer::scc_carry` (`d4b2d92a`, 35 lines in `crates/victory-shader/src/resource.rs`) with the exact conditions above: - `base` is a `Table`, `ResourceHeap`, or `SamplerHeap` (`high.is_none()`); - `lo` is written by `s_add_u32` with one operand equal to `base` (after `origin` copies); - `hi` is written by `s_add_u32` of constant `0` and `Operand::Const(253)` (`src_scc`), in either order, reading the exact `SCC` value written by that low `s_add_u32`; - Pinned both operand orders, a copied base SGPR, a `v_readfirstlane_b32` waterfall offset, and five negatives (`s_add_i32`, non-zero constant, chained low add, overwritten `SCC`, and 64-bit `RootType::Descriptor`) in `resource::tests::a_heap_or_table_address_carry_added_as_scc_source_tracks_the_offset`, plus a Metal GPU execution test in `heap_tests::a_compute_shader_loads_a_texture_with_scc_carry`. *(Side note for #258: since SM 6.6 `ResourceHeap` SGPRs are inferred by `resource::infer_roots` rather than declared in FSPX metadata, if any of the `"a descriptor outside the heaps"` shaders only touch their undeclared heap SGPR via this same `s_add_u32 + src_scc` form without another `hi == 0` load in the same shader, `infer_roots` at `resource.rs:2533/2573` would be the matching place to check.)*
LakshanSivakumar commented 2026-11-27 10:32:09 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:09Z.


Thank you. This is what I asked for: one rule, for the shape that Sandile-0511 found in all 798 shaders, and the earlier rules gone. The five negatives and the GPU test are the right ones.

What is missing is a comparison on this head. My run and Sandile-0511's were on earlier revisions (mine hung on 5e68767498c57eb6). I will run d4b2d92a over my corpus and post the table; I have not done it yet. It can merge if it shows no regression, no hang, and no output change among the shaders that translate today. Sandile-0511, if you have already run it, please post your table here.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216000780 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7216000780). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:09Z. --- Thank you. This is what I asked for: one rule, for the shape that Sandile-0511 found in all 798 shaders, and the earlier rules gone. The five negatives and the GPU test are the right ones. What is missing is a comparison on this head. My run and Sandile-0511's were on earlier revisions (mine hung on `5e68767498c57eb6`). I will run d4b2d92a over my corpus and post the table; I have not done it yet. It can merge if it shows no regression, no hang, and no output change among the shaders that translate today. Sandile-0511, if you have already run it, please post your table here.
LakshanSivakumar commented 2026-11-27 11:54:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:36Z.


I ran every shader by output on d4b2d92a (33,625 containers, against main c1b95875):

stage gained lost changed hangs
pixel 0 0 0 0
vertex 38 0 0 0
compute 49 0 0 0

87 gained, none lost, none changed, and the hang I saw on the first revision (compute_5e68767498c57eb6) is gone. 7 of the gained ones are in my list of shaders the game binds in the world. That is a clean result. What is left is a game run on my side, which I have not done yet.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217615274 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7217615274). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:36Z. --- I ran every shader by output on d4b2d92a (33,625 containers, against main c1b95875): | stage | gained | lost | changed | hangs | |---|---|---|---|---| | pixel | 0 | 0 | 0 | 0 | | vertex | 38 | 0 | 0 | 0 | | compute | 49 | 0 | 0 | 0 | 87 gained, none lost, none changed, and the hang I saw on the first revision (`compute_5e68767498c57eb6`) is gone. 7 of the gained ones are in my list of shaders the game binds in the world. That is a clean result. What is left is a game run on my side, which I have not done yet.
Sheffy007 commented 2026-11-27 12:35:38 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:35:38Z.


Rebased onto main (86786a72 -> 15a37b7a) solely to resolve the adjacent test conflict in crates/victory-gpu/src/native/heap_tests.rs after #264 and #278 landed; crates/victory-shader/src/resource.rs is unchanged from d4b2d92a.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218438170 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7218438170). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T12:35:38Z. --- Rebased onto `main` (`86786a72` -> `15a37b7a`) solely to resolve the adjacent test conflict in `crates/victory-gpu/src/native/heap_tests.rs` after #264 and #278 landed; `crates/victory-shader/src/resource.rs` is unchanged from `d4b2d92a`.
LakshanSivakumar commented 2026-11-27 13:36:24 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T13:36:24Z.


This is on main as of b639c175, merged from the head before your latest push, so GitHub still shows the PR open. Your commits are in the history under your name. Checked as part of a batch of nine PRs on main 60baf130: tests, Windows clippy, policy, a full-corpus comparison and one world run (240 s, no crash, no GPU errors, scene colour lit).

If your new head has changes beyond a rebase, please rebase it onto main so only those remain; otherwise please close this. Thank you.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219706460 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7219706460). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T13:36:24Z. --- This is on main as of b639c175, merged from the head before your latest push, so GitHub still shows the PR open. Your commits are in the history under your name. Checked as part of a batch of nine PRs on main 60baf130: tests, Windows clippy, policy, a full-corpus comparison and one world run (240 s, no crash, no GPU errors, scene colour lit). If your new head has changes beyond a rebase, please rebase it onto main so only those remain; otherwise please close this. Thank you.
Sheffy007 commented 2026-11-27 13:47:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T13:47:14Z.


Closing as landed in 78d0ee45 (b639c175); 15a37b7a had no changes beyond rebasing d4b2d92a.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219943082 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/250#issuecomment-7219943082). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T13:47:14Z. --- Closing as landed in `78d0ee45` (`b639c175`); `15a37b7a` had no changes beyond rebasing `d4b2d92a`.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!250
No description provided.