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

Manually merged
github merged 5 commits from gh-pr/176/head into gh-pr/176/base 2026-11-26 21:32:19 +00:00
Owner

@⁠descent81 on GitHub · 2026-11-21 17:59 UTC · original
descent81:shader/partial-texture-waits → main · +78 −33 · 4 files · 5 commits · merged 2026-11-22 06:41 UTC

<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>
**@⁠descent81** on GitHub · 2026-11-21 17:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/176) `descent81:shader/partial-texture-waits` → `main` · +78 −33 · 4 files · 5 commits · merged 2026-11-22 06:41 UTC <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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:32:17 +00:00
github manually merged commit 601b4f7872 into gh-pr/176/base 2026-11-26 21:32:19 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 18:11 UTC · original

#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.

**@⁠R0Y00** on GitHub · 2026-11-21 18:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/176#issuecomment-7067074687) #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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.