shader: lower bound-table descriptor waterfalls in pixel stages #3823

Merged
Leyukaka merged 7 commits from upstream-pr/3823 into main 2026-12-02 05:44:37 +00:00
Leyukaka commented 2026-12-02 05:33:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T05:33:22Z.


Problem

#3091 lowers the v_readfirstlane_b32 descriptor waterfall in pixel stages only when the descriptor is loaded from the resource heap. The same loop over a bound root table is refused, so an ordinary pixel shader that selects one of a few table slots per lane does not translate. A loop that only resembles a waterfall also falls through to the generic loop path without saying which part of the shape was not proven.

Change

  • The waterfall detector accepts a descriptor load from a bound root table (zero high address word) as well as from the resource heap. The sampler heap stays refused.
  • The proven key range selects a span of that table. Only that span is declared, as one SRV array, and the sample uses a single nonuniform binding handle indexed from the start of the span. Slot keys and already shifted byte keys are both accepted.
  • Implicit samples keep the #3091 quad gradients taken from the original coordinates, so helper lanes still contribute.
  • A loop that reads a lane key, partitions EXEC, accesses an image and updates its pending lanes with s_andn2_wrexec is treated as a waterfall attempt. If its shape does not hold, it is refused with the first unproven part (pixel descriptor waterfall: ...).
  • Any other loop, such as a uniform counter around a local CMPX region, is not examined by the detector and stays with the generic loop lowering, as on main.

The heap path from #3091 is unchanged.

Known limit: an outer uniform loop that contains a complete waterfall is refused early. main already refuses the inner waterfall in that case.

Validation

Windows, MSVC, on 17884dd31. Fixtures are source-built: the linked pair from native_sampled_pixel_gpu --write-fixture, patched so each lane derives its slot from its own coordinate.

cmake --build --preset dev --target native_sampled_pixel_gpu compile_dxil
ctest --preset dev --no-tests=error --output-on-failure -R '^native_indexed_pixel_texture_(warp|hardware)$'

Both tests pass, none skipped.

  • Translation: the slot-key, byte-key and implicit-sample waterfalls translate. The manifest has one SRV span and the DXIL has one nonuniform binding handle. The implicit case has one sampleGrad with the quad derivatives.
  • Refusals, each asserted by its reason: unbounded key, span past the declared root range, side effect between the pending-lane update and the retry, pending mask that is not a copy of the entering EXEC, compare on a different key, backedge that skips the key read, branch into the loop body.
  • Counter loop: a uniform counter loop around a local CMPX region gets no waterfall reason. The generic path decides it; on this fixture it refuses for its own reason.
  • GPU readback on WARP and on hardware, three draws: alternate slots (repeated indices in each quad), slots 0 and 2 of a three-slot span (slot 1 has no lane), and the alternate selection at implicit LOD, where the correct mip depends on the scissored helper column. Each draw matches 28 covered pixels and 4 sentinel pixels. Expected colors are computed from the texture contents and the pixel position.

Not covered: a waterfall nested in another loop (refused, see above) and bound-table views other than non-comparison 2D or 2D-array texture SRVs (refused).

Part of #3210. Extends #3091.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5600526786 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3823). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T05:33:22Z. --- ## Problem #3091 lowers the `v_readfirstlane_b32` descriptor waterfall in pixel stages only when the descriptor is loaded from the resource heap. The same loop over a bound root table is refused, so an ordinary pixel shader that selects one of a few table slots per lane does not translate. A loop that only resembles a waterfall also falls through to the generic loop path without saying which part of the shape was not proven. ## Change - The waterfall detector accepts a descriptor load from a bound root table (zero high address word) as well as from the resource heap. The sampler heap stays refused. - The proven key range selects a span of that table. Only that span is declared, as one SRV array, and the sample uses a single nonuniform binding handle indexed from the start of the span. Slot keys and already shifted byte keys are both accepted. - Implicit samples keep the #3091 quad gradients taken from the original coordinates, so helper lanes still contribute. - A loop that reads a lane key, partitions EXEC, accesses an image and updates its pending lanes with `s_andn2_wrexec` is treated as a waterfall attempt. If its shape does not hold, it is refused with the first unproven part (`pixel descriptor waterfall: ...`). - Any other loop, such as a uniform counter around a local CMPX region, is not examined by the detector and stays with the generic loop lowering, as on `main`. The heap path from #3091 is unchanged. Known limit: an outer uniform loop that contains a complete waterfall is refused early. `main` already refuses the inner waterfall in that case. ## Validation Windows, MSVC, on 17884dd31. Fixtures are source-built: the linked pair from `native_sampled_pixel_gpu --write-fixture`, patched so each lane derives its slot from its own coordinate. ```powershell cmake --build --preset dev --target native_sampled_pixel_gpu compile_dxil ctest --preset dev --no-tests=error --output-on-failure -R '^native_indexed_pixel_texture_(warp|hardware)$' ``` Both tests pass, none skipped. - Translation: the slot-key, byte-key and implicit-sample waterfalls translate. The manifest has one SRV span and the DXIL has one nonuniform binding handle. The implicit case has one `sampleGrad` with the quad derivatives. - Refusals, each asserted by its reason: unbounded key, span past the declared root range, side effect between the pending-lane update and the retry, pending mask that is not a copy of the entering EXEC, compare on a different key, backedge that skips the key read, branch into the loop body. - Counter loop: a uniform counter loop around a local CMPX region gets no waterfall reason. The generic path decides it; on this fixture it refuses for its own reason. - GPU readback on WARP and on hardware, three draws: alternate slots (repeated indices in each quad), slots 0 and 2 of a three-slot span (slot 1 has no lane), and the alternate selection at implicit LOD, where the correct mip depends on the scissored helper column. Each draw matches 28 covered pixels and 4 sentinel pixels. Expected colors are computed from the texture contents and the pixel position. Not covered: a waterfall nested in another loop (refused, see above) and bound-table views other than non-comparison 2D or 2D-array texture SRVs (refused). Part of #3210. Extends #3091.
R0Y00 commented 2026-12-02 05:44:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:44:22Z.

Review: APPROVED


Independent Windows Debug result at 17884dd3: ctest --preset dev --no-tests=error -j 1 -R '^native_indexed_pixel_texture_(warp|hardware)$' --output-on-failure passed 2/2 on Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The three waterfall draws each matched 28 covered and four sentinel pixels per backend. The waterfall subcommand did not enable the debug layer. As a local mutation, I changed the descriptor-source guard to require the resource heap. The WARP control then failed on the expected bound-table translation at +0x88. Restored the source and rebuilt the compiler.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145395449 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3823#pullrequestreview-6145395449). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:44:22Z. **Review:** APPROVED --- Independent Windows Debug result at `17884dd3`: `ctest --preset dev --no-tests=error -j 1 -R '^native_indexed_pixel_texture_(warp|hardware)$' --output-on-failure` passed 2/2 on Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The three waterfall draws each matched 28 covered and four sentinel pixels per backend. The waterfall subcommand did not enable the debug layer. As a local mutation, I changed the descriptor-source guard to require the resource heap. The WARP control then failed on the expected bound-table translation at +0x88. Restored the source and rebuilt the compiler.
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
R0Y00/Xbox2Windows!3823
No description provided.