shader: lower gfx1030 explicit-gradient pixel sampling #1500

Merged
stan495 merged 1 commit from upstream-pr/1507 into main 2026-11-24 13:49:19 +00:00
stan495 commented 2026-11-24 13:18:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-24T13:18:18Z.


Summary

Lower image_sample_d, image_sample_d_o, image_sample_d_g16, and image_sample_d_o_g16 to SampleGrad for the wave64 gfx1030 pixel AOT profile. Use contiguous 32-bit 2D UVs, full dmask:0xf, full-width slopes or two packed binary16 gradient words, and optional known signed XY offsets in [-8, 7]. Offsets assume integer mip sampling. Explicit gradients need defined operands, not quad-provenance UVs. NSA, A16, D16, other dimensions and other gradient variants remain refused.

Builds on #1451 and preserves the comparison and LOD behavior from #1487 and #1445. The diff includes only the gradient behavior and its fixtures.

Verification

Tested clean head 6edd861d84c27c9b9cd837a8dd2dcb3767fa87d9.

. .\tools\dev.ps1
$root = (Get-Location).Path
cmake --preset dev -DINTAKE_PYTHON=<python.exe>
cmake --build --preset dev --target offscreen_check
$env:TEMP = "$root/out"
$env:TMP = $env:TEMP
ctest --preset dev --no-tests=error -j 1 -R '^pixel_aot_(sample_gradient|compare_sample|compare|sample_offset|sample_lod|dmask|get_lod|three_way|cmpx_regions)_(warp|hardware)$' -V --output-junit "$root/out/gradient-6edd861d.xml"
python -B tools/form_coverage.py out/gradient-6edd861d.xml --records out/build/dev/form_coverage --json out/gradient-6edd861d.coverage.json
python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

CTest: 18 passed, 0 failed, 0 skipped. Each adapter compares all four instructions with CPU references on a two-mip partial draw, including untouched pixels, and a four-mip full draw. Both offset variants also match the spatial ramp. Both passing gradient records contain all four forms. At (0,0), zero gradients change green to red (channel 0 expected 00000000, actual 3f800000), and zero offset changes the first ramp red value (expected 3d808000, actual 00000000). Rejections include sparse masks, wrong address width, undefined and pending operands, unsupported modes, and out-of-range offsets.

Windows 11 build 26300.9974; Intel Arc B390 32.0.101.8509; Microsoft WARP 10.0.26100.9818. Debug layer unavailable on both.

python3 -B tests/pixel_sample_gradient_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 llc-15
python3 -B tests/pixel_sample_offset_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
python3 -B tests/pixel_get_lod_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
python3 -B tests/pixel_compare_sample_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1
python3 -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1

All LLVM checks passed. The gradient check validates assembly, disassembly, synthetic-container CLI HLSL round trips, and independent LLVM G16 operand codegen. Draws execute translated desktop DXIL. git diff --check passed. git merge-tree --write-tree refs/remotes/origin/main HEAD passed against bc43e6659ea2971a6cd82bc4baecd685e13f251c, also with #1504 applied first. Merge-tree is a separate check, not an integrated execution run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582678579 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1507). Originally posted by [stan495](https://github.com/stan495) on 2026-11-24T13:18:18Z. --- ## Summary Lower `image_sample_d`, `image_sample_d_o`, `image_sample_d_g16`, and `image_sample_d_o_g16` to `SampleGrad` for the wave64 gfx1030 pixel AOT profile. Use contiguous 32-bit 2D UVs, full `dmask:0xf`, full-width slopes or two packed binary16 gradient words, and optional known signed XY offsets in `[-8, 7]`. Offsets assume integer mip sampling. Explicit gradients need defined operands, not quad-provenance UVs. NSA, A16, D16, other dimensions and other gradient variants remain refused. Builds on #1451 and preserves the comparison and LOD behavior from #1487 and #1445. The diff includes only the gradient behavior and its fixtures. ## Verification Tested clean head `6edd861d84c27c9b9cd837a8dd2dcb3767fa87d9`. ```powershell . .\tools\dev.ps1 $root = (Get-Location).Path cmake --preset dev -DINTAKE_PYTHON=<python.exe> cmake --build --preset dev --target offscreen_check $env:TEMP = "$root/out" $env:TMP = $env:TEMP ctest --preset dev --no-tests=error -j 1 -R '^pixel_aot_(sample_gradient|compare_sample|compare|sample_offset|sample_lod|dmask|get_lod|three_way|cmpx_regions)_(warp|hardware)$' -V --output-junit "$root/out/gradient-6edd861d.xml" python -B tools/form_coverage.py out/gradient-6edd861d.xml --records out/build/dev/form_coverage --json out/gradient-6edd861d.coverage.json python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` CTest: 18 passed, 0 failed, 0 skipped. Each adapter compares all four instructions with CPU references on a two-mip partial draw, including untouched pixels, and a four-mip full draw. Both offset variants also match the spatial ramp. Both passing gradient records contain all four forms. At `(0,0)`, zero gradients change green to red (channel 0 expected `00000000`, actual `3f800000`), and zero offset changes the first ramp red value (expected `3d808000`, actual `00000000`). Rejections include sparse masks, wrong address width, undefined and pending operands, unsupported modes, and out-of-range offsets. Windows 11 build `26300.9974`; Intel Arc B390 `32.0.101.8509`; Microsoft WARP `10.0.26100.9818`. Debug layer unavailable on both. ```sh python3 -B tests/pixel_sample_gradient_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 llc-15 python3 -B tests/pixel_sample_offset_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 python3 -B tests/pixel_get_lod_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 python3 -B tests/pixel_compare_sample_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 python3 -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 ``` All LLVM checks passed. The gradient check validates assembly, disassembly, synthetic-container CLI HLSL round trips, and independent LLVM G16 operand codegen. Draws execute translated desktop DXIL. `git diff --check` passed. `git merge-tree --write-tree refs/remotes/origin/main HEAD` passed against `bc43e6659ea2971a6cd82bc4baecd685e13f251c`, also with #1504 applied first. Merge-tree is a separate check, not an integrated execution run.
upstream-sync closed this pull request 2026-11-24 14:03:01 +00:00
tedin7 commented 2026-11-24 15:01:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:09:24Z.

Review: COMMENTED


Technical review of commit 6edd861d84c27c9b9cd837a8dd2dcb3767fa87d9:

Code & fixture audit

  • tools/pixel_aot.py cleanly extends 2D image_sample lowering to image_sample_d, image_sample_d_o, image_sample_d_g16, and image_sample_d_o_g16 (dmask:0xf), mapping gradients to SampleGrad and unpacking G16 half-float pairs with widen16(h) / widen16(h >> 16) on unsigned uint operands.
  • tests/pixel_sample_gradient_check.py covers lowering, independent llc G16 operand-order codegen, negative controls (width mismatch, NSA form, non-0xf dmask, unsupported modifiers/dimensions, undefined/pending operands, out-of-range offset), and FORM_COVERAGE_RECORD integration.

Verification

  • Lint & merge: tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check, and git merge-tree --write-tree origin/main HEAD all pass.
  • Linux (LLVM 19): tests/pixel_sample_gradient_check.py binary (with llvm-mc-19, llvm-objcopy-19, libLLVM.so.19.1, llc-19), tests/pixel_aot_check.py, tests/pixel_sample_offset_check.py binary, tests/pixel_get_lod_check.py binary, and tests/pixel_compare_sample_check.py binary all passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): built offscreen_check (4.23s); ctest --preset dev -R '^pixel_aot_sample_gradient_' --no-tests=error: 2/2 passed (pixel_aot_sample_gradient_warp, pixel_aot_sample_gradient_hardware).
    • Release /O2 (--preset release): built offscreen_check (1.44s); ctest --preset release -R '^pixel_aot_sample_gradient_' --no-tests=error: 2/2 passed (pixel_aot_sample_gradient_warp, pixel_aot_sample_gradient_hardware).
    • tests/form_coverage_check.py: passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040714590 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1507#pullrequestreview-6040714590). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:09:24Z. **Review:** COMMENTED --- Technical review of commit `6edd861d84c27c9b9cd837a8dd2dcb3767fa87d9`: ### Code & fixture audit - `tools/pixel_aot.py` cleanly extends 2D `image_sample` lowering to `image_sample_d`, `image_sample_d_o`, `image_sample_d_g16`, and `image_sample_d_o_g16` (`dmask:0xf`), mapping gradients to `SampleGrad` and unpacking G16 half-float pairs with `widen16(h)` / `widen16(h >> 16)` on unsigned `uint` operands. - `tests/pixel_sample_gradient_check.py` covers lowering, independent `llc` G16 operand-order codegen, negative controls (width mismatch, NSA form, non-`0xf` dmask, unsupported modifiers/dimensions, undefined/pending operands, out-of-range offset), and `FORM_COVERAGE_RECORD` integration. ### Verification - **Lint & merge**: `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`, and `git merge-tree --write-tree origin/main HEAD` all pass. - **Linux (LLVM 19)**: `tests/pixel_sample_gradient_check.py binary` (with `llvm-mc-19`, `llvm-objcopy-19`, `libLLVM.so.19.1`, `llc-19`), `tests/pixel_aot_check.py`, `tests/pixel_sample_offset_check.py binary`, `tests/pixel_get_lod_check.py binary`, and `tests/pixel_compare_sample_check.py binary` all passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Debug (`--preset dev`): built `offscreen_check` (`4.23s`); `ctest --preset dev -R '^pixel_aot_sample_gradient_' --no-tests=error`: **2/2 passed** (`pixel_aot_sample_gradient_warp`, `pixel_aot_sample_gradient_hardware`). - Release `/O2` (`--preset release`): built `offscreen_check` (`1.44s`); `ctest --preset release -R '^pixel_aot_sample_gradient_' --no-tests=error`: **2/2 passed** (`pixel_aot_sample_gradient_warp`, `pixel_aot_sample_gradient_hardware`). - `tests/form_coverage_check.py`: passed.
ChazY11 commented 2026-11-24 15:02:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T14:53:19Z.


Explicit gradients are genuinely exercised — dropping them or swapping the slopes both fail

Independent reviewer, not the author. Reviewed 6edd861d; nothing pushed to the branch. Mutations were made locally in
tools/pixel_aot.py, reverted between each; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, LLVM gfx1013 tooling
available.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R 'pixel_aot_sample_gradient' -V

As submitted:

pixel_aot_sample_gradient_hardware ... Passed 17.87 s
pixel_aot_sample_gradient_warp ....... Passed  5.98 s

Mutation 1 — the call becomes Sample, gradients dropped

-    call = f"SampleGrad(samp, float2({u}, {v}), {ddx}, {ddy}{offset_arg})"
+    call = f"Sample(samp, float2({u}, {v}){offset_arg})"
pixel_aot_sample_gradient_hardware ***Failed
pixel_aot_sample_gradient_warp ..... ***Failed

Mutation 2 — the two slopes swapped

-    ... {ddx}, {ddy}{offset_arg})
+    ... {ddy}, {ddx}{offset_arg})
pixel_aot_sample_gradient_hardware ***Failed
pixel_aot_sample_gradient_warp ..... ***Failed

So the fixture distinguishes not only "gradient present" but which axis went where, which is what an explicit-gradient
lowering needs: a swapped pair still produces a plausible but wrong image.

A note on my own method

My first attempt at mutation 2 reported no match while mutation 1 was still applied, so the failure it showed was
mutation 1's, not the swap's. I reverted, confirmed a clean tree, and re-ran the swap on its own before recording the
result above. Mentioning it because the two runs look identical in the output and only the redone one means anything.

Verdict

Reviewed 6edd861d. Builds clean, both gradient cases pass on WARP and on a physical adapter, and two independent
mutations in the emitted HLSL call are caught. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135112349 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1507#issuecomment-7135112349). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T14:53:19Z. --- ## Explicit gradients are genuinely exercised — dropping them or swapping the slopes both fail Independent reviewer, not the author. Reviewed `6edd861d`; nothing pushed to the branch. Mutations were made locally in `tools/pixel_aot.py`, reverted between each; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100, DXC 1.8.2502.11, LLVM gfx1013 tooling available. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R 'pixel_aot_sample_gradient' -V ``` As submitted: ```text pixel_aot_sample_gradient_hardware ... Passed 17.87 s pixel_aot_sample_gradient_warp ....... Passed 5.98 s ``` ### Mutation 1 — the call becomes `Sample`, gradients dropped ```diff - call = f"SampleGrad(samp, float2({u}, {v}), {ddx}, {ddy}{offset_arg})" + call = f"Sample(samp, float2({u}, {v}){offset_arg})" ``` ```text pixel_aot_sample_gradient_hardware ***Failed pixel_aot_sample_gradient_warp ..... ***Failed ``` ### Mutation 2 — the two slopes swapped ```diff - ... {ddx}, {ddy}{offset_arg}) + ... {ddy}, {ddx}{offset_arg}) ``` ```text pixel_aot_sample_gradient_hardware ***Failed pixel_aot_sample_gradient_warp ..... ***Failed ``` So the fixture distinguishes not only "gradient present" but which axis went where, which is what an explicit-gradient lowering needs: a swapped pair still produces a plausible but wrong image. ### A note on my own method My first attempt at mutation 2 reported no match while mutation 1 was still applied, so the failure it showed was mutation 1's, not the swap's. I reverted, confirmed a clean tree, and re-ran the swap on its own before recording the result above. Mentioning it because the two runs look identical in the output and only the redone one means anything. ### Verdict Reviewed `6edd861d`. Builds clean, both gradient cases pass on WARP and on a physical adapter, and two independent mutations in the emitted HLSL call are caught. No objection from me.
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!1500
No description provided.