shader: track texture sample readiness across partial VM waits #175

Merged
descent81 merged 5 commits from upstream-pr/176 into main 2026-11-22 06:41:02 +00:00
descent81 commented 2026-11-21 17:59:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-21T17:59:42Z.


<html>

Motivation

A pixel shader can issue samples for textures A and B, start computing with A as soon as it is ready, and wait for B only when the blend needs it. On 583fee5, the translator stops at instruction 18 of the source-built fixture with Unsupported instruction 18: s_waitcnt vmcnt(1).

Recognizing the instruction alone would leave a correctness problem. With A issued first and B second, vmcnt(1) makes A available while B can still be outstanding. The translator needs to know which sample supplies each operand.

What changes

The lowerer tracks outstanding image_sample results in issue order. A VM wait retains at most the newest N outstanding samples. Arithmetic and packing then check the result they actually consume. The ordering rule is scoped to the texture-sample instruction class supported by this translator.

Issue order Wait Next use Expected result
A, then B vmcnt(1) Scale A’s red channel Accept
B, then A vmcnt(1) Scale A’s red channel Reject
A, then B vmcnt(1) Pack one channel from A and one from B Reject
A, then B vmcnt(0) Blend A and B Accept

Reversing the issue order is the main regression control. The arithmetic instruction and its source register stay the same. Only the identity of the outstanding sample changes, so accepting both programs would expose an error that a final-color comparison alone could miss.

Verification

  • Instruction round-trip. Assembled all four source-built dual-texture fixtures with LLVM 15 for gfx1013, extracted and disassembled the machine code, and checked that it lowered to the same HLSL as the assembly input.

  • GPU readback. pixel_aot_hardware on NVIDIA GeForce RTX 4060 and pixel_aot_warp on Microsoft WARP both passed. The partial-wait fixture matched the existing CPU blend reference on both backends.

  • Wait boundaries. The controls also reject an early read after vmcnt(2) with two samples outstanding and confirm that a later wait leaves an already completed sample available.

The new fixture runs through the existing LLVM binary check and Windows draw tests. All inputs are built from repository source. To repeat the GPU comparison after a dev build, run:

ctest --preset dev --no-tests=error -R '^pixel_aot_(warp|hardware)$' --output-on-failure
</html>
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532454151 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/176). Originally posted by [descent81](https://github.com/descent81) on 2026-11-21T17:59:42Z. --- <html> <body> <!--StartFragment--><h2><span>Motivation</span></h2><p><span>A pixel shader can issue samples for textures A and B, start computing with A as soon as it is ready, and wait for B only when the blend needs it. On </span><code><span>583fee5</span></code><span>, the translator stops at instruction 18 of the source-built fixture with </span><code><span>Unsupported instruction 18: s_waitcnt vmcnt(1)</span></code><span>.</span></p><p><span>Recognizing the instruction alone would leave a correctness problem. With A issued first and B second, </span><code><span>vmcnt(1)</span></code><span> makes A available while B can still be outstanding. The translator needs to know which sample supplies each operand.</span></p><h2><span>What changes</span></h2><p><span>The lowerer tracks outstanding </span><code><span>image_sample</span></code><span> results in issue order. A VM wait retains at most the newest </span><em><span>N</span></em><span> outstanding samples. Arithmetic and packing then check the result they actually consume. The ordering rule is scoped to the texture-sample instruction class supported by this translator.</span></p> Issue order | Wait | Next use | Expected result -- | -- | -- | -- A, then B | vmcnt(1) | Scale A’s red channel | Accept B, then A | vmcnt(1) | Scale A’s red channel | Reject A, then B | vmcnt(1) | Pack one channel from A and one from B | Reject A, then B | vmcnt(0) | Blend A and B | Accept <p><span>Reversing the issue order is the main regression control. The arithmetic instruction and its source register stay the same. Only the identity of the outstanding sample changes, so accepting both programs would expose an error that a final-color comparison alone could miss.</span></p><h2><span>Verification</span></h2><ul><li><p><strong><span>Instruction round-trip.</span></strong><span> Assembled all four source-built dual-texture fixtures with LLVM 15 for </span><code><span>gfx1013</span></code><span>, extracted and disassembled the machine code, and checked that it lowered to the same HLSL as the assembly input.</span></p></li><li><p><strong><span>GPU readback.</span></strong><span> </span><code><span>pixel_aot_hardware</span></code><span> on NVIDIA GeForce RTX 4060 and </span><code><span>pixel_aot_warp</span></code><span> on Microsoft WARP both passed. The partial-wait fixture matched the existing CPU blend reference on both backends.</span></p></li><li><p><strong><span>Wait boundaries.</span></strong><span> The controls also reject an early read after </span><code><span>vmcnt(2)</span></code><span> with two samples outstanding and confirm that a later wait leaves an already completed sample available.</span></p></li></ul><p><span>The new fixture runs through the existing LLVM binary check and Windows draw tests. All inputs are built from repository source. To repeat the GPU comparison after a dev build, run:</span></p><pre><code><span>ctest --preset dev --no-tests=error -R '^pixel_aot_(warp|hardware)$' --output-on-failure</span></code></pre><!--EndFragment--> </body> </html>
upstream-sync closed this pull request 2026-11-24 06:41:41 +00:00
R0Y00 commented 2026-11-24 06:47:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:11:54Z.


#144 has landed. Please reconcile the partial-wait queue with its v_mov_b32 path. Keep the pending-destination write checks for each outstanding sample, and exercise a move after vmcnt(1) for both the older completed sample and the newer outstanding one. Please rerun the LLVM round trip and pixel_aot_warp on the reconciled head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067074687 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/176#issuecomment-7067074687). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T18:11:54Z. --- #144 has landed. Please reconcile the partial-wait queue with its `v_mov_b32` path. Keep the pending-destination write checks for each outstanding sample, and exercise a move after `vmcnt(1)` for both the older completed sample and the newer outstanding one. Please rerun the LLVM round trip and `pixel_aot_warp` on the reconciled head.
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!175
No description provided.