xshader: prove a heap descriptor copied in both arms of an if/else for its waterfall read #370

Merged
NickStallman merged 4 commits from upstream-pr/370 into main 2026-11-28 09:22:22 +00:00
NickStallman commented 2026-11-28 04:36:03 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T04:36:03Z.


Refs #358 (T7, group b: sampler descriptors).

Cause

RAGE's VfxVBuffer vertex programs (VS_Transform_VfxVBuffer*, VS_TransformSkin_VfxVBuffer*) work like this:

  1. They load a sampler from the directly indexed sampler heap at a constant index (FSSM class 6 base, s_load_dwordx4 …, 0x410).
  2. Both arms of an if/else copy it into VGPRs.
  3. A waterfall loop (v_readfirstlane, v_cmp_eq_u64, s_and_saveexec, image_sample_lz, s_xor exec) reads it back for the sample.

descriptor_broadcast only accepted EXEC narrowing between a copy and its read. The if/else's closing s_mov_b64 exec, saved widens EXEC again, so the read had no descriptor. The program was refused with "not a sampler descriptor (None)", or earlier with "buffer record count read from a descriptor with no one host buffer". The copy of the sampler's word 2 was counted as a read of a buffer's record count.

In the recent ProjectScarlett runs this was the only T7 group still costing pipelines: 4 per run.

Change

Four commits. Each is a no-op on the recorded requests alone; only together do they change anything.

  1. Scalar widths (descriptor_broadcast): a 32-bit scalar result and a lane read write one SGPR, not a pair. Before this, s_addc_u32 s55 and v_readfirstlane_b32 s7 "overwrote" masks kept in s[56:57] and s[8:9].

  2. Table descriptors through proven copies:

    • a descriptor loaded from a table at a known offset is carried through a proven copy and read, as heap descriptors already were;
    • the copy is a move (like s_mov_b32), not a record-count read;
    • a numeric use of the word read back is still a count read, and as certain as a use of the loaded word;
    • the exception is the loop's own v_cmp_eq lane test, which is never certain: a sampler's word 2 isn't a count.
  3. If/else join: at s_mov_b64 exec, saved, the proof finds the s_and_saveexec_b64 saved head and the single hand-back that starts the else arm. It then requires:

    • each arm has one way in, and branches that stay inside it;
    • each arm keeps EXEC within the lanes it began with;
    • on every path to an arm's end, the last write of the register is a copy made with all of that arm's lanes on.

    An if that never writes the register is passed over.

  4. Lanes raster-sampler-waterfall:

    • a console vertex program samples heap texture 100 with sampler heap slot 5, read back through such a waterfall after an if/else;
    • the sampled value is the position's w, and slot 5 is the only point sampler (every other slot is linear), so a wrong sampler shrinks the triangle;
    • a refused program leaves the target clear;
    • it runs in lanes-raster-tables.

Without 3 nothing is proven; without 2 the proven read carries no table descriptor; without 4 (scalar widths) half the joins fail on the kept mask.

Effect on recorded shaders (ProjectScarlett, 34,677 requests)

  • 51 recovered, all VfxVBuffer vertex programs: 23 "not a sampler descriptor (None)" and 28 "buffer record count …". In each of the four newest game runs, 18 failing pipelines use one of them.
  • 249 changed outputs, all mesh programs (MS_VS_*, MSNC_VS_*), plus 0 regressed, 0 new failures, and no change on wave32 hosts.
    • A before/after comparison of all 249 shows every difference is one substitution, 1,782 times: SamplerDescriptorHeap[NonUniformResourceIndex(sR)], with sR each lane's own read-back of the VGPR, becomes a static SamplerDescriptorHeap[K] the program already declares.
    • K is the heap index the old translation wrote into the copied register (the static heap index of that s_load).
    • So every lane already sampled with K once every lane holds the copy, which is what the new proof shows. Nothing else in those programs changes.
  • 3 VfxVBuffer requests are still refused: 50eb030f, 5f5c4f49 and ede2f851. An execz branch from an earlier s_and_saveexec jumps straight to the restore, and the saved-mask register is saved again inside the region. The one-entry rule refuses that correctly. Handling it needs the lane model of T8.

Tests

  • Translator unit tests, each failing without its commit:
    • a_32_bit_scalar_result_beside_a_kept_mask_leaves_it_alone
    • a_table_descriptor_read_back_from_a_waterfall_copy_is_that_descriptor
    • a_count_read_back_from_a_waterfall_copy_is_still_a_count
    • copies_in_both_arms_of_an_if_else_reach_every_lane
    • an_if_that_leaves_the_register_alone_is_passed_over
  • Negative cases that stay refused: a copy in one arm only, narrowing before the copy, a write after the copy, a clobbered saved mask, an arm widened from a mask it didn't keep, a branch into an arm or into the if body from outside, and a no-host-buffer count use.
  • Lanes raster-sampler-waterfall, with a control branch that reverts the join commit: there the scenario fails on both cards, as intended.

Results

GPU (run on 8f7f1a5b, the same changes before this rebase):

Check AMD (RADV, 1002:13c0) NVIDIA (RTX 5090, 10de:2b85)
lanes-raster-tables incl. raster-sampler-waterfall PASS PASS
Translator GPU checks 59/59 59/59
Control (join reverted) lanes-raster-sampler-waterfall fails fails

CPU, on this head against main 7bafe6b6:

  • tools/shader_harness.py run --no-gpu --compile-limit 0 (6 jobs): PASS
    • wave64: 27,921 → 27,972 translated (51 recovered, 249 changed)
    • 300 of 300 changed or recovered programs compile through DXC and DXV
    • code checks (tuxbox.py check --no-gpu) passed
  • tests.test_lanes_raster passes, and Lanes builds.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5536699618 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/370). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T04:36:03Z. --- Refs #358 (T7, group b: sampler descriptors). ## Cause RAGE's VfxVBuffer vertex programs (`VS_Transform_VfxVBuffer*`, `VS_TransformSkin_VfxVBuffer*`) work like this: 1. They load a sampler from the directly indexed sampler heap at a constant index (FSSM class 6 base, `s_load_dwordx4 …, 0x410`). 2. Both arms of an if/else copy it into VGPRs. 3. A waterfall loop (`v_readfirstlane`, `v_cmp_eq_u64`, `s_and_saveexec`, `image_sample_lz`, `s_xor exec`) reads it back for the sample. `descriptor_broadcast` only accepted EXEC narrowing between a copy and its read. The if/else's closing `s_mov_b64 exec, saved` widens EXEC again, so the read had no descriptor. The program was refused with "not a sampler descriptor (None)", or earlier with "buffer record count read from a descriptor with no one host buffer". The copy of the sampler's word 2 was counted as a read of a buffer's record count. In the recent ProjectScarlett runs this was the only T7 group still costing pipelines: 4 per run. ## Change Four commits. Each is a no-op on the recorded requests alone; only together do they change anything. 1. **Scalar widths** (`descriptor_broadcast`): a 32-bit scalar result and a lane read write one SGPR, not a pair. Before this, `s_addc_u32 s55` and `v_readfirstlane_b32 s7` "overwrote" masks kept in s[56:57] and s[8:9]. 2. **Table descriptors through proven copies**: - a descriptor loaded from a table at a known offset is carried through a proven copy and read, as heap descriptors already were; - the copy is a move (like `s_mov_b32`), not a record-count read; - a numeric use of the word read back is still a count read, and as certain as a use of the loaded word; - the exception is the loop's own `v_cmp_eq` lane test, which is never certain: a sampler's word 2 isn't a count. 3. **If/else join**: at `s_mov_b64 exec, saved`, the proof finds the `s_and_saveexec_b64 saved` head and the single hand-back that starts the else arm. It then requires: - each arm has one way in, and branches that stay inside it; - each arm keeps EXEC within the lanes it began with; - on every path to an arm's end, the last write of the register is a copy made with all of that arm's lanes on. An if that never writes the register is passed over. 4. **Lanes `raster-sampler-waterfall`**: - a console vertex program samples heap texture 100 with sampler heap slot 5, read back through such a waterfall after an if/else; - the sampled value is the position's w, and slot 5 is the only point sampler (every other slot is linear), so a wrong sampler shrinks the triangle; - a refused program leaves the target clear; - it runs in `lanes-raster-tables`. Without 3 nothing is proven; without 2 the proven read carries no table descriptor; without 4 (scalar widths) half the joins fail on the kept mask. ## Effect on recorded shaders (ProjectScarlett, 34,677 requests) - **51 recovered, all VfxVBuffer vertex programs**: 23 "not a sampler descriptor (None)" and 28 "buffer record count …". In each of the four newest game runs, 18 failing pipelines use one of them. - **249 changed outputs, all mesh programs (`MS_VS_*`, `MSNC_VS_*`)**, plus 0 regressed, 0 new failures, and no change on wave32 hosts. - A before/after comparison of all 249 shows every difference is one substitution, 1,782 times: `SamplerDescriptorHeap[NonUniformResourceIndex(sR)]`, with sR each lane's own read-back of the VGPR, becomes a static `SamplerDescriptorHeap[K]` the program already declares. - K is the heap index the old translation wrote into the copied register (the static heap index of that `s_load`). - So every lane already sampled with K once every lane holds the copy, which is what the new proof shows. Nothing else in those programs changes. - **3 VfxVBuffer requests are still refused**: 50eb030f, 5f5c4f49 and ede2f851. An `execz` branch from an earlier `s_and_saveexec` jumps straight to the restore, and the saved-mask register is saved again inside the region. The one-entry rule refuses that correctly. Handling it needs the lane model of T8. ## Tests - Translator unit tests, each failing without its commit: - `a_32_bit_scalar_result_beside_a_kept_mask_leaves_it_alone` - `a_table_descriptor_read_back_from_a_waterfall_copy_is_that_descriptor` - `a_count_read_back_from_a_waterfall_copy_is_still_a_count` - `copies_in_both_arms_of_an_if_else_reach_every_lane` - `an_if_that_leaves_the_register_alone_is_passed_over` - Negative cases that stay refused: a copy in one arm only, narrowing before the copy, a write after the copy, a clobbered saved mask, an arm widened from a mask it didn't keep, a branch into an arm or into the if body from outside, and a no-host-buffer count use. - Lanes `raster-sampler-waterfall`, with a control branch that reverts the join commit: there the scenario **fails** on both cards, as intended. ## Results GPU (run on 8f7f1a5b, the same changes before this rebase): | Check | AMD (RADV, 1002:13c0) | NVIDIA (RTX 5090, 10de:2b85) | |---|---|---| | `lanes-raster-tables` incl. `raster-sampler-waterfall` | PASS | PASS | | Translator GPU checks | 59/59 | 59/59 | | Control (join reverted) | `lanes-raster-sampler-waterfall` fails | fails | CPU, on this head against main 7bafe6b6: - `tools/shader_harness.py run --no-gpu --compile-limit 0` (6 jobs): **PASS** - wave64: 27,921 → 27,972 translated (51 recovered, 249 changed) - 300 of 300 changed or recovered programs compile through DXC and DXV - code checks (`tuxbox.py check --no-gpu`) passed - `tests.test_lanes_raster` passes, and Lanes builds. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!370
No description provided.