Skip to content

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

Merged
R0Y00 merged 7 commits into
R0Y00:mainfrom
Leyukaka:shader/3210-bound-table-pixel-waterfall
Dec 2, 2026
Merged

R0Y00 merged 7 commits into
R0Y00:mainfrom
Leyukaka:shader/3210-bound-table-pixel-waterfall

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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 shader: compile native mesh interfaces and prewarm compute requests #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 17884dd. 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.

Accept the single-block readfirstlane waterfall when its descriptor load reads a bound root table instead of the resource heap. The proven key range selects a span of that table, which is declared as an SRV array and indexed nonuniformly. Implicit samples keep the quad gradients of the original coordinates. Refs R0Y00#3210.
Patch the sampled MRT fixture so each lane selects a slot of table 0 from its own U coordinate. Check the manifest span, the single nonuniform binding handle and the sample variant in the DXIL, and keep refusals for an unbounded key, a span past the declared range, a loop side effect, an unproven pending mask and a mismatched key. Refs R0Y00#3210.
Add a --waterfall draw to native_sampled_pixel_gpu. Guest table 0 holds three two-mip textures and the offset buffer. The test passes the translated register order from the manifest. Lanes select a slot from their pixel column: 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 mip 1 is correct only if the quad gradient includes the scissored helper column. Expected colors come from the texture contents and pixel positions. Refs R0Y00#3210.
A backward edge around an EXEC compare and an image operation is now refused with the first part of the waterfall shape that does not hold, instead of falling through to the generic loop path. The bound-table negatives assert each reason, and two more cover a backedge that skips the key read and a branch into the loop body. Refs R0Y00#3210.
Only a loop that reads a lane key with v_readfirstlane_b32, partitions EXEC, accesses an image and updates its pending lanes with s_andn2_wrexec is refused by waterfall reason. A uniform counter loop around a local CMPX region and an image translates again, as on main, and the linked-pair check covers it. Refs R0Y00#3210.
The fixture sampler leaves MIP_FILTER at zero, which the frontend refuses for implicit-LOD samples. Load word 2 with MIP_FILTER = point for the implicit cases, as the draw's static sampler uses. Refs R0Y00#3210.
The generic lowering refuses the counter fixture's CMPX region without a whole-quad parent. Enter whole-quad mode before the loop, and assert only that no waterfall reason is given: the generic path may translate the loop or refuse it for its own reason. Refs R0Y00#3210.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@R0Y00
R0Y00 merged commit f365f12 into R0Y00:main Dec 2, 2026
5 checks passed
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.

2 participants