shader: lower image_sample_lz, image_sample_l and image_sample_b in pixel_aot #504

Merged
PrivacyOnion merged 2 commits from upstream-pr/510 into main 2026-11-23 11:00:07 +00:00
PrivacyOnion commented 2026-11-22 08:36:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by PrivacyOnion on 2026-11-22T08:36:37Z.


## Summary

  • Extend tools/pixel_aot.py to lower image_sample_lz, image_sample_l, and image_sample_b (dmask:0xf dim:SQ_RSRC_IMG_2D) alongside image_sample:
    • image_sample_lz (v[u:v]) -> tex.SampleLevel(samp, float2(u, v), 0.0f)
    • image_sample_l (v[u:lod]) -> tex.SampleLevel(samp, float2(u, v), lod)
    • image_sample_b (v[bias:v], bias first per RDNA2 MIMG address component order) -> tex.SampleBias(samp, float2(u, v), bias)
  • Allow explicit-LOD variants (image_sample_lz, image_sample_l) to consume constant or ALU-computed coordinates without requiring whole-quad interpolation, while keeping helper-lane quad-coordinate validation on implicit-derivative variants (image_sample, image_sample_b).
  • Add tests/pixel_sample_lod_check.py and register pixel_aot_sample_lod_warp and pixel_aot_sample_lod_hardware in CMakeLists.txt (with FORM_COVERAGE_RECORD and SKIP_RETURN_CODE 77 on hardware):
    • Rejects wrong coordinate widths, uninitialized LOD registers, non-quad UV coordinates on image_sample_b, and unwaited vmcnt(0) sample dependencies.
    • Verifies mip-level selection on the 2-mip quad-LOD fixture (--check-pixel-quad-lod) with mutation controls proving image_sample_lz stays on mip 0 under 4x UV scaling, image_sample_l selects mip 1 when lod=1.0, and image_sample_b shifts implicit mip 0 to mip 1 when bias=1.0.
    • Verifies spatially varying 8x8 ramp coordinates (--check-pixel-case), including non-WQM constant-buffer UVs on image_sample_lz and UV-swap mutation control on image_sample_b.

Verification

  • Environment: Windows 11, VS Build Tools MSVC, DXC 10.0.26100.0, D3D12 debug layer enabled
  • Hardware adapter: NVIDIA GeForce RTX 5070 (vendor=10de device=2f04, driver=32.0.16.1664)
  • WARP adapter: Microsoft Basic Render Driver (vendor=1414 device=008c, driver=10.0.26100.9818)
  • Commands run:
    • ctest --preset dev --no-tests=error -R "^(pixel_aot_sample_lod_warp|pixel_aot_sample_lod_hardware|pixel_aot_three_way_warp)$" -V -> 3/3 PASSED (max_absolute_error=0, debug_errors=0 debug_warnings=0 on both WARP and RTX 5070)
    • out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -> OK (29 tests, 1 skipped)
    • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> PASS
    • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> PASS
    • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> PASS
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6540340419 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/510). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-22T08:36:37Z. --- ## Summary - Extend `tools/pixel_aot.py` to lower `image_sample_lz`, `image_sample_l`, and `image_sample_b` (`dmask:0xf dim:SQ_RSRC_IMG_2D`) alongside `image_sample`: - `image_sample_lz` (`v[u:v]`) -> `tex.SampleLevel(samp, float2(u, v), 0.0f)` - `image_sample_l` (`v[u:lod]`) -> `tex.SampleLevel(samp, float2(u, v), lod)` - `image_sample_b` (`v[bias:v]`, bias first per RDNA2 MIMG address component order) -> `tex.SampleBias(samp, float2(u, v), bias)` - Allow explicit-LOD variants (`image_sample_lz`, `image_sample_l`) to consume constant or ALU-computed coordinates without requiring whole-quad interpolation, while keeping helper-lane quad-coordinate validation on implicit-derivative variants (`image_sample`, `image_sample_b`). - Add `tests/pixel_sample_lod_check.py` and register `pixel_aot_sample_lod_warp` and `pixel_aot_sample_lod_hardware` in `CMakeLists.txt` (with `FORM_COVERAGE_RECORD` and `SKIP_RETURN_CODE 77` on hardware): - Rejects wrong coordinate widths, uninitialized LOD registers, non-quad UV coordinates on `image_sample_b`, and unwaited `vmcnt(0)` sample dependencies. - Verifies mip-level selection on the 2-mip quad-LOD fixture (`--check-pixel-quad-lod`) with mutation controls proving `image_sample_lz` stays on mip 0 under 4x UV scaling, `image_sample_l` selects mip 1 when `lod=1.0`, and `image_sample_b` shifts implicit mip 0 to mip 1 when `bias=1.0`. - Verifies spatially varying 8x8 ramp coordinates (`--check-pixel-case`), including non-WQM constant-buffer UVs on `image_sample_lz` and UV-swap mutation control on `image_sample_b`. ## Verification - Environment: Windows 11, VS Build Tools MSVC, DXC `10.0.26100.0`, D3D12 debug layer enabled - Hardware adapter: `NVIDIA GeForce RTX 5070` (`vendor=10de device=2f04`, `driver=32.0.16.1664`) - WARP adapter: `Microsoft Basic Render Driver` (`vendor=1414 device=008c`, `driver=10.0.26100.9818`) - Commands run: - `ctest --preset dev --no-tests=error -R "^(pixel_aot_sample_lod_warp|pixel_aot_sample_lod_hardware|pixel_aot_three_way_warp)$" -V` -> 3/3 PASSED (`max_absolute_error=0`, `debug_errors=0 debug_warnings=0` on both WARP and RTX 5070) - `out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py` -> OK (29 tests, 1 skipped) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> PASS - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> PASS - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> PASS
upstream-sync closed this pull request 2026-11-24 06:43:25 +00:00
thepatrickworld commented 2026-11-24 06:48:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T18:16:17Z.


@PrivacyOnion Independent AMD (RDNA4) result on fb0315a, plus coverage observations. Measurements only, no code change.

Environment

  • Windows 11 25H2, build 26200.9711
  • MSVC 19.44.35230 (toolset 14.44.35207), Windows SDK 10.0.26100.0, DXC 1.9.2602.17
  • AMD Radeon RX 9070 XT, vendor 1002, device 7550, driver 32.0.32029.2010, native wave width 64
  • debug_layer=unavailable (Tools.Graphics.DirectX is NotPresent here — your RTX 5070 run had the layer on, so this is the one axis I cannot reproduce)
  • Clean worktree of the PR head fb0315a.

Commands

cmake --preset dev
cmake --build --preset dev --parallel 12 --target offscreen_check
set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT
ctest --preset dev --no-tests=error -V -R "^pixel_aot_|^rdna2_tools"

Observed

11 tests, 11 passed, 0 failed, 0 skipped, of which the new pair:

Test #197: pixel_aot_sample_lod_hardware ... Passed  2.18 sec
Test #209: pixel_aot_sample_lod_warp ....... Passed  1.17 sec
  • Whole run: 260 draw measurements, 260 at max_absolute_error=0, no non-zero line at all.
  • pixel_aot_sample_lod_hardware on the RX 9070 XT: 7 per-draw counters, three at pixels=64 channels=256 and four at pixels=4096 channels=16384, all zero. The harness prints no case label, so these cannot be attributed to named cases; the three expected-mismatch mutations leave no counter line, which is why 7 lines are logged for the 10 GPU cases in the diff.
  • WARP: same shape, same zeros.
  • No D3D12 debug-layer error or warning was available to check: the layer is absent on this machine, unlike your run.

Coverage observations

The lowering itself is right, and I verified the part that is claimable from the diff: bias = sample_coord(coord_regs[0]) then uv = coord_regs[1:], so bias really is the first address register, matching the ISA. What follows is about what the suite proves, not about the code being wrong.

  • Nothing in the suite distinguishes bias-first from uv-first. swap_uv only swaps attr0.x and attr0.y in base_prefix, i.e. v8 and v9. No control moves a coordinate into the bias slot or the bias out of v7. Detection of an order bug would only come from bias1/bias_ramp failing incidentally.
  • The LOD axes are only 0.0 and 1.0. Both are integers sitting on the mip boundary, which cannot separate floor from nearest, and no case has a fractional LOD (0.5, 1.49) or an out-of-range LOD (−3.0, 4.0 against 2 mips). So neither the trilinear blend nor the clamp is exercised, and SampleBias is semantically covered by exactly one case (bias1).
  • _b never runs with ALU-computed or uniform UVs. bias_program uses base_prefix() without quad_scale, so the v_fma-on-interpolator-plus-bias path — the one real Series X shaders use — has no case.
  • Asymmetric rejections: bad_lod_dep covers a LOD reading an in-flight sample destination, but there is no equivalent for a _b bias taken from an unwaited image_sample_lz, nor for a bias read before lgkmcnt(0).
  • Structural limit, worth stating once: every expected value is produced by the test itself or by the D3D12 renderer. If the tool and the fixtures shared a wrong convention, the suite would stay green. Only a capture from real Scarlett hardware could settle the convention; nothing here does.

Also: this PR is in conflict

GitHub reports mergeable: false, mergeable_state: dirty against main, and #506 touches the same tools/pixel_aot.py region, so whichever lands second needs a rebase. This run measured a head that cannot merge as-is; the numbers above should be re-read against the rebased head.

AI-assisted; runs executed locally. The coverage observations come from a separate code review and were re-verified against the diff (address-slot decoding, swap_uv scope) before posting.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7083474952 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/510#issuecomment-7083474952). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-22T18:16:17Z. --- @PrivacyOnion **Independent AMD (RDNA4) result on `fb0315a`**, plus coverage observations. Measurements only, no code change. ### Environment - Windows 11 25H2, build **26200.9711** - MSVC **19.44.35230** (toolset 14.44.35207), Windows SDK 10.0.26100.0, DXC **1.9.2602.17** - **AMD Radeon RX 9070 XT**, vendor 1002, device 7550, driver **32.0.32029.2010**, native wave width 64 - `debug_layer=unavailable` (`Tools.Graphics.DirectX` is `NotPresent` here — your RTX 5070 run had the layer on, so this is the one axis I cannot reproduce) - Clean worktree of the PR head `fb0315a`. ### Commands ``` cmake --preset dev cmake --build --preset dev --parallel 12 --target offscreen_check set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT ctest --preset dev --no-tests=error -V -R "^pixel_aot_|^rdna2_tools" ``` ### Observed **11 tests, 11 passed, 0 failed, 0 skipped**, of which the new pair: ``` Test #197: pixel_aot_sample_lod_hardware ... Passed 2.18 sec Test #209: pixel_aot_sample_lod_warp ....... Passed 1.17 sec ``` - Whole run: **260 draw measurements, 260 at `max_absolute_error=0`**, no non-zero line at all. - `pixel_aot_sample_lod_hardware` on the RX 9070 XT: **7 per-draw counters**, three at `pixels=64 channels=256` and four at `pixels=4096 channels=16384`, all zero. The harness prints no case label, so these cannot be attributed to named cases; the three expected-mismatch mutations leave no counter line, which is why 7 lines are logged for the 10 GPU cases in the diff. - WARP: same shape, same zeros. - No D3D12 debug-layer error or warning was available to check: the layer is absent on this machine, unlike your run. ### Coverage observations The lowering itself is right, and I verified the part that is claimable from the diff: `bias = sample_coord(coord_regs[0])` then `uv = coord_regs[1:]`, so bias really is the first address register, matching the ISA. What follows is about what the suite *proves*, not about the code being wrong. - **Nothing in the suite distinguishes bias-first from uv-first.** `swap_uv` only swaps `attr0.x` and `attr0.y` in `base_prefix`, i.e. `v8` and `v9`. No control moves a coordinate into the bias slot or the bias out of `v7`. Detection of an order bug would only come from `bias1`/`bias_ramp` failing incidentally. - **The LOD axes are only 0.0 and 1.0.** Both are integers sitting on the mip boundary, which cannot separate `floor` from `nearest`, and no case has a fractional LOD (0.5, 1.49) or an out-of-range LOD (−3.0, 4.0 against 2 mips). So neither the trilinear blend nor the clamp is exercised, and `SampleBias` is semantically covered by exactly one case (`bias1`). - **`_b` never runs with ALU-computed or uniform UVs.** `bias_program` uses `base_prefix()` without `quad_scale`, so the `v_fma`-on-interpolator-plus-bias path — the one real Series X shaders use — has no case. - **Asymmetric rejections**: `bad_lod_dep` covers a LOD reading an in-flight sample destination, but there is no equivalent for a `_b` bias taken from an unwaited `image_sample_lz`, nor for a bias read before `lgkmcnt(0)`. - **Structural limit, worth stating once**: every expected value is produced by the test itself or by the D3D12 renderer. If the tool and the fixtures shared a wrong convention, the suite would stay green. Only a capture from real Scarlett hardware could settle the convention; nothing here does. ### Also: this PR is in conflict GitHub reports `mergeable: false`, `mergeable_state: dirty` against `main`, and #506 touches the same `tools/pixel_aot.py` region, so whichever lands second needs a rebase. This run measured a head that cannot merge as-is; the numbers above should be re-read against the rebased head. _AI-assisted; runs executed locally. The coverage observations come from a separate code review and were re-verified against the diff (address-slot decoding, `swap_uv` scope) before posting._
R0Y00 commented 2026-11-24 06:49:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T10:25:36Z.


I resolved the conflict after #506 and pushed bb1eb94 to your branch. This keeps the partial-dmask and descriptor-offset behavior from #506, plus your explicit LOD and bias cases and all four render negative controls. The LOD/bias and dmask checks both passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, Windows build 26200.9974, with the debug layer enabled. The Python pixel controls, form coverage, PSO readiness and docs links passed as well. Waiting for the current-head CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7097939959 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/510#issuecomment-7097939959). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T10:25:36Z. --- I resolved the conflict after #506 and pushed `bb1eb94` to your branch. This keeps the partial-dmask and descriptor-offset behavior from #506, plus your explicit LOD and bias cases and all four render negative controls. The LOD/bias and dmask checks both passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, Windows build 26200.9974, with the debug layer enabled. The Python pixel controls, form coverage, PSO readiness and docs links passed as well. Waiting for the current-head CI.
thepatrickworld commented 2026-11-24 06:49:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T14:58:21Z.


Post-merge check on cea1d92: the conflict resolution merged two sample grammars, and the new fixture exercises only one of them. Measurements plus translation probes.

Environment and observed

  • Windows 11 25H2, build 26200.9711, MSVC 19.44.35230, DXC 1.9.2602.17
  • AMD Radeon RX 9070 XT, vendor 1002, device 7550, driver 32.0.32029.2010, native wave width 64
git checkout cea1d92
cmake --preset dev && cmake --build --preset dev --parallel 12 --target offscreen_check
set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT
ctest --preset dev --no-tests=error -R "^pixel_aot_sample_lod_(hardware|warp)$" -V
ctest --preset dev --no-tests=error -R "^pixel_aot_(three_way|dmask)_(hardware|warp)$" -V
1/2 Test #308: pixel_aot_sample_lod_hardware ...   Passed   2.38 sec
2/2 Test #371: pixel_aot_sample_lod_warp .......   Passed   1.28 sec
1/4 pixel_aot_dmask_hardware ...   Passed   1.87 sec
2/4 pixel_aot_three_way_hardware ...   Passed   2.73 sec
3/4 pixel_aot_dmask_warp .......   Passed   1.13 sec
4/4 pixel_aot_three_way_warp ...   Passed   2.49 sec

The merge is not a copy of the reviewed head

The resolution folded #506's grammar into this one: the sample regex at tools/pixel_aot.py:2382 now accepts image_sample(?:_lz|_l|_b)?, a single-VGPR or a range destination, and dmask:0x([1-9a-f]). On top of that, :2385 pins dmask:0xf for the three new variants. Two consequences:

  • For _lz/_l/_b, popcount(dmask) is always 4, so the single-VGPR destination branch inherited from #506 (:2389) is unreachable for them. A legal single-channel _l is refused, and the message names image_sample rather than the variant: image_sample_l v[12:14], v[8:10], … dmask:0x7 → Multi-channel image_sample requires a VGPR range destination.
  • The new fixture uses dmask:0xf in all six of its programs and never a single-VGPR destination, so neither merged grammar is exercised by it. The interaction #506 and #510 disagreed about is exactly what the test does not touch.

What holds

Probed through translate() at cea1d92: _l and _lz accept constant-buffer UVs (lz_constant_uv_program → SampleLevel(samp, float2(params[0].x, params[0].y), 0.0f)), _b rejects them (Unsupported texture coordinate), bias is coord[0] before uv (SampleBias(samp, float2(uv.x, uv.y), alu15)), and the LOD is coord[2] — pinned for real by the 1.0 → 0.0 mutation control. On the adapter both draws pass, with three_way and the #506 dmask pair still green beside them.

Two test-strength notes

  • The three "using a sampled channel before vmcnt(0)" rejections (tests/pixel_sample_lod_check.py:136-138) actually fail with Unsupported pack operand, not the reason their comment names; only the bad_lod_dep case (:140-150) reaches Sample used before vmcnt wait. must_reject accepts any ValueError/KeyError (tests/pixel_aot_check.py:230), while expect_value_error (:238) exists to prevent exactly this.
  • The dmask:0xf guard and the coords.stop > 256 bound (tools/pixel_aot.py:2401) are pinned by no case: removing either leaves all nine rejections rejecting for other reasons.

One permissiveness note, faithful rather than wrong: image_sample_l v[12:15], v[7:9] — a _b-shaped address range — is accepted and becomes SampleLevel(samp, float2(alu15, uv.x), uv.y), i.e. the interpolated v turns into the LOD. For a real _l instruction the address order is fixed by the ISA, so this is not a miscompile; it just means nothing rejects the shape and no case names it.

AI-assisted; runs executed locally. The translation probes and the grammar analysis come from a separate review pass and were re-run here against cea1d92.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7104824316 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/510#issuecomment-7104824316). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-23T14:58:21Z. --- **Post-merge check on `cea1d92`: the conflict resolution merged two sample grammars, and the new fixture exercises only one of them.** Measurements plus translation probes. ### Environment and observed - Windows 11 25H2, build **26200.9711**, MSVC **19.44.35230**, DXC **1.9.2602.17** - **AMD Radeon RX 9070 XT**, vendor 1002, device 7550, driver **32.0.32029.2010**, native wave width 64 ``` git checkout cea1d92 cmake --preset dev && cmake --build --preset dev --parallel 12 --target offscreen_check set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT ctest --preset dev --no-tests=error -R "^pixel_aot_sample_lod_(hardware|warp)$" -V ctest --preset dev --no-tests=error -R "^pixel_aot_(three_way|dmask)_(hardware|warp)$" -V ``` ``` 1/2 Test #308: pixel_aot_sample_lod_hardware ... Passed 2.38 sec 2/2 Test #371: pixel_aot_sample_lod_warp ....... Passed 1.28 sec 1/4 pixel_aot_dmask_hardware ... Passed 1.87 sec 2/4 pixel_aot_three_way_hardware ... Passed 2.73 sec 3/4 pixel_aot_dmask_warp ....... Passed 1.13 sec 4/4 pixel_aot_three_way_warp ... Passed 2.49 sec ``` ### The merge is not a copy of the reviewed head The resolution folded #506's grammar into this one: the sample regex at `tools/pixel_aot.py:2382` now accepts `image_sample(?:_lz|_l|_b)?`, a single-VGPR or a range destination, and `dmask:0x([1-9a-f])`. On top of that, `:2385` pins `dmask:0xf` for the three new variants. Two consequences: - For `_lz`/`_l`/`_b`, `popcount(dmask)` is always 4, so the single-VGPR destination branch inherited from #506 (`:2389`) is unreachable for them. A legal single-channel `_l` is refused, and the message names `image_sample` rather than the variant: `image_sample_l v[12:14], v[8:10], … dmask:0x7` → `Multi-channel image_sample requires a VGPR range destination`. - The new fixture uses `dmask:0xf` in all six of its programs and never a single-VGPR destination, so neither merged grammar is exercised by it. The interaction #506 and #510 disagreed about is exactly what the test does not touch. ### What holds Probed through `translate()` at `cea1d92`: `_l` and `_lz` accept constant-buffer UVs (`lz_constant_uv_program` → `SampleLevel(samp, float2(params[0].x, params[0].y), 0.0f)`), `_b` rejects them (`Unsupported texture coordinate`), bias is `coord[0]` before uv (`SampleBias(samp, float2(uv.x, uv.y), alu15)`), and the LOD is `coord[2]` — pinned for real by the 1.0 → 0.0 mutation control. On the adapter both draws pass, with `three_way` and the #506 `dmask` pair still green beside them. ### Two test-strength notes - The three "using a sampled channel before `vmcnt(0)`" rejections (`tests/pixel_sample_lod_check.py:136-138`) actually fail with `Unsupported pack operand`, not the reason their comment names; only the `bad_lod_dep` case (`:140-150`) reaches `Sample used before vmcnt wait`. `must_reject` accepts any `ValueError`/`KeyError` (`tests/pixel_aot_check.py:230`), while `expect_value_error` (`:238`) exists to prevent exactly this. - The `dmask:0xf` guard and the `coords.stop > 256` bound (`tools/pixel_aot.py:2401`) are pinned by no case: removing either leaves all nine rejections rejecting for other reasons. One permissiveness note, faithful rather than wrong: `image_sample_l v[12:15], v[7:9]` — a `_b`-shaped address range — is accepted and becomes `SampleLevel(samp, float2(alu15, uv.x), uv.y)`, i.e. the interpolated v turns into the LOD. For a real `_l` instruction the address order is fixed by the ISA, so this is not a miscompile; it just means nothing rejects the shape and no case names it. _AI-assisted; runs executed locally. The translation probes and the grammar analysis come from a separate review pass and were re-run here against `cea1d92`._
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!504
No description provided.