shader: lower gfx1030 2D image LOD queries #1438

Merged
stan495 merged 3 commits from upstream-pr/1445 into main 2026-11-24 12:35:46 +00:00
stan495 commented 2026-11-24 11:39:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-24T11:39:05Z.


Summary

Lower image_get_lod for a single gfx1030 2D texture and an ordinary sampler in the pixel AOT profile. A contiguous quad-provenance UV pair produces the clamped and unclamped LOD in lane order (dmask:0x3). The lowering checks ready image and sampler descriptors and requires vmcnt(0) before results are consumed. Comparison samplers, two-texture binding, unverified operand flags, and non-quad coordinates are outside the tested profile.

The fixture compares translated DXIL and independent hand-written HLSL with the same texture, sampler, constants, and viewport. Following the independent RTX 4060 Laptop result in review, only the rendered red channel of the two-mip upper-clamp case (raw LOD - 2) accepts an absolute difference of one LOD step (1/256) from the CPU reference. The translated/direct comparison, clamped channel, other outputs and clear pixels, and the signed negative case remain exact. The existing SPIR-V MinLod operation retains its strict comparator.

Verification

Tested clean head 8b2df3dc5edfbc34498cde57b80de9d35413ad52. From PowerShell with the test Python environment configured:

. .\tools\dev.ps1
$root = (Get-Location).Path
$filter = '^(pixel_aot_(get_lod|sample_lod|dmask)_(warp|hardware)|offscreen_capability_table_self_test|spirv_minlod_(warp|hardware))$'
foreach ($preset in 'dev','release') {
    cmake --preset $preset
    cmake --build --preset $preset --target offscreen_check
    ctest --preset $preset --no-tests=error -R $filter -V --output-junit "$root/out/get-lod-$preset.xml"
    python -B tools/form_coverage.py "out/get-lod-$preset.xml" --records "out/build/$preset/form_coverage" --json "out/get-lod-$preset.coverage.json"
}
python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

Each preset reported 7 passed, 0 failed and 2 skips (legacy spirv_minlod_{hardware,warp} cases, because spirv-as, spirv-val and spirv-cross were absent at configure time). Both passing get-LOD records contain image_get_lod. The five full readbacks matched bit-for-bit between translated and direct on Intel Arc B390 32.0.101.8509 and Microsoft WARP 10.0.26100.9818 on Windows 11 build 26300.9974, with the debug layer unavailable. The new head has not been run on NVIDIA here.

Both backends accepted the injected one-step red deviation and rejected the two-step deviation first at (0,0), channel 0: 00000000 expected, bc000000 actual. The clamp-both control still failed at (0,0), channel 1: bf800000 expected, 00000000 actual. The unclamp-both control failed at the same channel: 3f800000 expected, 40000000 actual. Text checks reject an early result read, an unverified mask, a wrong dimension, a pending sampler load, and a non-quad UV.

python3 -B tests/pixel_get_lod_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1

The LLVM 15 assembly, disassembly, container CLI and rejection checks passed. git diff --check origin/main...HEAD passed. git merge-tree --write-tree origin/main HEAD succeeded against 06e2ff78aec68fc9aabb9f57531b04e0f249e644 and in a separate simulation with #1451 integrated first. These simulations were not integration test runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580918609 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445). Originally posted by [stan495](https://github.com/stan495) on 2026-11-24T11:39:05Z. --- ## Summary Lower `image_get_lod` for a single gfx1030 2D texture and an ordinary sampler in the pixel AOT profile. A contiguous quad-provenance UV pair produces the clamped and unclamped LOD in lane order (`dmask:0x3`). The lowering checks ready image and sampler descriptors and requires `vmcnt(0)` before results are consumed. Comparison samplers, two-texture binding, unverified operand flags, and non-quad coordinates are outside the tested profile. The fixture compares translated DXIL and independent hand-written HLSL with the same texture, sampler, constants, and viewport. Following the independent RTX 4060 Laptop result in review, only the rendered red channel of the two-mip upper-clamp case (`raw LOD - 2`) accepts an absolute difference of one LOD step (`1/256`) from the CPU reference. The translated/direct comparison, clamped channel, other outputs and clear pixels, and the signed negative case remain exact. The existing SPIR-V MinLod operation retains its strict comparator. ## Verification Tested clean head `8b2df3dc5edfbc34498cde57b80de9d35413ad52`. From PowerShell with the test Python environment configured: ```powershell . .\tools\dev.ps1 $root = (Get-Location).Path $filter = '^(pixel_aot_(get_lod|sample_lod|dmask)_(warp|hardware)|offscreen_capability_table_self_test|spirv_minlod_(warp|hardware))$' foreach ($preset in 'dev','release') { cmake --preset $preset cmake --build --preset $preset --target offscreen_check ctest --preset $preset --no-tests=error -R $filter -V --output-junit "$root/out/get-lod-$preset.xml" python -B tools/form_coverage.py "out/get-lod-$preset.xml" --records "out/build/$preset/form_coverage" --json "out/get-lod-$preset.coverage.json" } python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` Each preset reported 7 passed, 0 failed and 2 skips (legacy `spirv_minlod_{hardware,warp}` cases, because `spirv-as`, `spirv-val` and `spirv-cross` were absent at configure time). Both passing get-LOD records contain `image_get_lod`. The five full readbacks matched bit-for-bit between translated and direct on Intel Arc B390 `32.0.101.8509` and Microsoft WARP `10.0.26100.9818` on Windows 11 build `26300.9974`, with the debug layer unavailable. The new head has not been run on NVIDIA here. Both backends accepted the injected one-step red deviation and rejected the two-step deviation first at `(0,0)`, channel 0: `00000000` expected, `bc000000` actual. The clamp-both control still failed at `(0,0)`, channel 1: `bf800000` expected, `00000000` actual. The unclamp-both control failed at the same channel: `3f800000` expected, `40000000` actual. Text checks reject an early result read, an unverified mask, a wrong dimension, a pending sampler load, and a non-quad UV. ```sh python3 -B tests/pixel_get_lod_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 ``` The LLVM 15 assembly, disassembly, container CLI and rejection checks passed. `git diff --check origin/main...HEAD` passed. `git merge-tree --write-tree origin/main HEAD` succeeded against `06e2ff78aec68fc9aabb9f57531b04e0f249e644` and in a separate simulation with #1451 integrated first. These simulations were not integration test runs.
R0Y00 commented 2026-11-24 12:03:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:58:06Z.

Review: CHANGES_REQUESTED


Windows Release on RTX 4060 Laptop driver 32.0.16.1656: the four lower-scale cases passed, including negative unclamped LOD, and the clamp-both control failed as intended. The failure is the positive upper-clamp case at pixel (0,0): red (raw LOD minus 2) expected 0 and was -0.00390625 (0xbb800000). Green (clamped LOD) stayed 1. WARP and the four neighboring sample_lod/dmask regressions passed.

I also ran an independently written HLSL shader with the same texture, sampler and scale, using a plain multiply and the two D3D LOD operations. It gave the same -0.00390625 on RTX and exactly 0 on WARP. Please keep the exact clamped channel and the polarity controls, and confine any precision allowance to the upper raw-LOD component. This measures one 1/256 step. Microsoft lists eight fractional LOD bits under D3D12_MIP_LOD_FRACTIONAL_BIT_COUNT in https://learn.microsoft.com/en-us/windows/win32/direct3d12/constants.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038764212 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445#pullrequestreview-6038764212). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T11:58:06Z. **Review:** CHANGES_REQUESTED --- Windows Release on RTX 4060 Laptop driver 32.0.16.1656: the four lower-scale cases passed, including negative unclamped LOD, and the clamp-both control failed as intended. The failure is the positive upper-clamp case at pixel (0,0): red (raw LOD minus 2) expected 0 and was -0.00390625 (0xbb800000). Green (clamped LOD) stayed 1. WARP and the four neighboring sample_lod/dmask regressions passed. I also ran an independently written HLSL shader with the same texture, sampler and scale, using a plain multiply and the two D3D LOD operations. It gave the same -0.00390625 on RTX and exactly 0 on WARP. Please keep the exact clamped channel and the polarity controls, and confine any precision allowance to the upper raw-LOD component. This measures one 1/256 step. Microsoft lists eight fractional LOD bits under D3D12_MIP_LOD_FRACTIONAL_BIT_COUNT in https://learn.microsoft.com/en-us/windows/win32/direct3d12/constants.
upstream-sync closed this pull request 2026-11-24 13:00:28 +00:00
tedin7 commented 2026-11-24 13:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:21:00Z.

Review: COMMENTED


Reviewed PR #1445 (3892513b):

Summary

Clean, well-scoped lowering for gfx1030 image_get_lod (dmask:0x3, dim:SQ_RSRC_IMG_2D) in tools/pixel_aot.py with matching direct-HLSL comparison, CPU footprint reference, negative/mutation controls, and docs updates.

Verification

  • Win2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at 3892513b:
    • tests/form_coverage_check.py: PASS (44.87s)
    • Debug (--preset dev): offscreen_check built; ctest --preset dev -R '^pixel_aot_get_lod_warp$' 1/1 passed (3.72s).
    • Release /O2 (--preset release): offscreen_check built; ctest --preset release -R '^pixel_aot_get_lod_warp$' 1/1 passed (4.00s).
    • Note: pixel_aot_get_lod_hardware was not run (the Win2025 node only has WARP).
  • Linux checks at 3892513b:
    • tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main..HEAD: PASS
    • tests/pixel_get_lod_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: PASS

Code Audit Notes

  • tools/pixel_aot.py: descriptor/sampler readiness, sample_dest overlap, entry mask, comparison/two-texture exclusion, quad-provenance UV check, and vmcnt(0) consumption tracking are all properly enforced.
  • tests/pixel_get_lod_check.py: good negative controls (missing vmcnt(0), wrong sampler SGPR, wrong dmask, wrong dim, non-quad UV) and draw mutations (clamping raw LOD, unclamping clamped LOD).
  • Merges cleanly with origin/main (git merge-tree --write-tree origin/main HEAD succeeded).

LGTM from Linux + Win2025 WARP verification.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039091068 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445#pullrequestreview-6039091068). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:21:00Z. **Review:** COMMENTED --- Reviewed PR #1445 (`3892513b`): ### Summary Clean, well-scoped lowering for gfx1030 `image_get_lod` (`dmask:0x3`, `dim:SQ_RSRC_IMG_2D`) in `tools/pixel_aot.py` with matching direct-HLSL comparison, CPU footprint reference, negative/mutation controls, and docs updates. ### Verification - **Win2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at `3892513b`:** - `tests/form_coverage_check.py`: **PASS** (`44.87s`) - **Debug (`--preset dev`):** `offscreen_check` built; `ctest --preset dev -R '^pixel_aot_get_lod_warp$'` **1/1 passed** (`3.72s`). - **Release `/O2` (`--preset release`):** `offscreen_check` built; `ctest --preset release -R '^pixel_aot_get_lod_warp$'` **1/1 passed** (`4.00s`). - Note: `pixel_aot_get_lod_hardware` was not run (the Win2025 node only has WARP). - **Linux checks at `3892513b`:** - `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check origin/main..HEAD`: **PASS** - `tests/pixel_get_lod_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so`: **PASS** ### Code Audit Notes - `tools/pixel_aot.py`: descriptor/sampler readiness, `sample_dest` overlap, `entry` mask, `comparison`/two-texture exclusion, quad-provenance UV check, and `vmcnt(0)` consumption tracking are all properly enforced. - `tests/pixel_get_lod_check.py`: good negative controls (missing `vmcnt(0)`, wrong sampler SGPR, wrong `dmask`, wrong `dim`, non-quad UV) and draw mutations (clamping raw LOD, unclamping clamped LOD). - Merges cleanly with `origin/main` (`git merge-tree --write-tree origin/main HEAD` succeeded). LGTM from Linux + Win2025 WARP verification.
R0Y00 commented 2026-11-24 13:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:35:30Z.

Review: APPROVED


Re-reviewed 8b2df3dc after the scoped upper raw LOD bound. Windows Release on RTX 4060 Laptop and WARP passed get_lod, sample_lod and dmask (6/6). The direct and translated readbacks still agree bitwise; the one-step control is accepted and the two-step control is rejected. Earlier modes retain the exact reference.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039283521 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445#pullrequestreview-6039283521). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:35:30Z. **Review:** APPROVED --- Re-reviewed 8b2df3dc after the scoped upper raw LOD bound. Windows Release on RTX 4060 Laptop and WARP passed get_lod, sample_lod and dmask (6/6). The direct and translated readbacks still agree bitwise; the one-step control is accepted and the two-step control is rejected. Earlier modes retain the exact reference.
stan495 commented 2026-11-24 13:00:52 +00:00 (Migrated from github.com)

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


Thanks for narrowing this to the two-mip upper-clamp case. I added an independent, handwritten desktop HLSL comparison in 3892513b071d0f9c5f380abb0ac1077084b5fa9e. It binds the same texture and sampler and uses the same UVs, constants, viewport and readback as the translated shader. Each path still runs the exact CPU comparison. Even if that comparison fails, the test runs both paths, prints the first pixel as float values and raw FP32 words, and compares the full 256-channel readbacks. No precision tolerance was added.

On Windows 11 26300.9974, Intel Arc B390 32.0.101.8509 and WARP 10.0.26100.9818 produced bit-identical direct and translated results for all five draws. The debug layer was unavailable. Release and Debug each had 6 passes, 0 failures and 0 skips for ^pixel_aot_(get_lod|sample_lod|dmask)_(warp|hardware)$; the LLVM 15 container check also passed. The two relevant raw first pixels were:

Case Translated RGBA words Direct RGBA words
One mip, scale 0.5, (clamped, raw, 0.5, 1) 00000000,bf800000,3f000000,3f800000 00000000,bf800000,3f000000,3f800000
Two mips, (raw - 2, clamped, 0, 1) 00000000,3f800000,00000000,3f800000 00000000,3f800000,00000000,3f800000

The lower wrong-clamp control still fails at (0,0), channel 1, bf800000 expected vs 00000000 actual. The upper wrong-unclamp control fails there with 3f800000 expected vs 40000000 actual on both local backends.

I do not have an NVIDIA adapter on this host. Could you rerun the Release hardware case at the new head on driver 32.0.16.1656 and share the upper-clamp path=translated and upper-clamp path=direct blocks? This command emits both even if the binary32 CPU reference still fails:

. .\tools\dev.ps1
cmake --preset release
cmake --build --preset release --target offscreen_check
ctest --preset release --no-tests=error -R '^pixel_aot_get_lod_hardware$' -V

The reported -0.00390625 would appear as bb800000 in the red word. The direct readback will tell us whether that difference also occurs without the translator.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131093592 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445#issuecomment-7131093592). Originally posted by [stan495](https://github.com/stan495) on 2026-11-24T12:11:32Z. --- Thanks for narrowing this to the two-mip upper-clamp case. I added an independent, handwritten desktop HLSL comparison in `3892513b071d0f9c5f380abb0ac1077084b5fa9e`. It binds the same texture and sampler and uses the same UVs, constants, viewport and readback as the translated shader. Each path still runs the exact CPU comparison. Even if that comparison fails, the test runs both paths, prints the first pixel as float values and raw FP32 words, and compares the full 256-channel readbacks. No precision tolerance was added. On Windows 11 `26300.9974`, Intel Arc B390 `32.0.101.8509` and WARP `10.0.26100.9818` produced bit-identical direct and translated results for all five draws. The debug layer was unavailable. Release and Debug each had 6 passes, 0 failures and 0 skips for `^pixel_aot_(get_lod|sample_lod|dmask)_(warp|hardware)$`; the LLVM 15 container check also passed. The two relevant raw first pixels were: | Case | Translated RGBA words | Direct RGBA words | | --- | --- | --- | | One mip, scale 0.5, `(clamped, raw, 0.5, 1)` | `00000000,bf800000,3f000000,3f800000` | `00000000,bf800000,3f000000,3f800000` | | Two mips, `(raw - 2, clamped, 0, 1)` | `00000000,3f800000,00000000,3f800000` | `00000000,3f800000,00000000,3f800000` | The lower wrong-clamp control still fails at `(0,0)`, channel 1, `bf800000` expected vs `00000000` actual. The upper wrong-unclamp control fails there with `3f800000` expected vs `40000000` actual on both local backends. I do not have an NVIDIA adapter on this host. Could you rerun the Release hardware case at the new head on driver `32.0.16.1656` and share the `upper-clamp path=translated` and `upper-clamp path=direct` blocks? This command emits both even if the binary32 CPU reference still fails: ```powershell . .\tools\dev.ps1 cmake --preset release cmake --build --preset release --target offscreen_check ctest --preset release --no-tests=error -R '^pixel_aot_get_lod_hardware$' -V ``` The reported `-0.00390625` would appear as `bb800000` in the red word. The direct readback will tell us whether that difference also occurs without the translator.
stan495 commented 2026-11-24 13:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-24T12:28:35Z.


Thanks for the independent NVIDIA readback. The new head 8b2df3dc5edfbc34498cde57b80de9d35413ad52 permits one D3D12 LOD step only in the covered upper-clamp red channel. The signed negative result, the clamped channel, background, both polarity controls, and translated/direct bit equality remain exact. Both local backends accepted the injected one-step value and rejected a two-step value at (0,0), channel 0 (00000000 expected, bc000000 actual).

The PR body records the fresh Debug and Release results and the two unrelated SPIR-V tooling skips. Could you retest the new Release head on the RTX 4060 Laptop with ctest --preset release --no-tests=error -R '^pixel_aot_get_lod_hardware$' -V after rebuilding offscreen_check? The raw words are still printed for both paths.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131492305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1445#issuecomment-7131492305). Originally posted by [stan495](https://github.com/stan495) on 2026-11-24T12:28:35Z. --- Thanks for the independent NVIDIA readback. The new head `8b2df3dc5edfbc34498cde57b80de9d35413ad52` permits one D3D12 LOD step only in the covered upper-clamp red channel. The signed negative result, the clamped channel, background, both polarity controls, and translated/direct bit equality remain exact. Both local backends accepted the injected one-step value and rejected a two-step value at `(0,0)`, channel 0 (`00000000` expected, `bc000000` actual). The PR body records the fresh Debug and Release results and the two unrelated SPIR-V tooling skips. Could you retest the new Release head on the RTX 4060 Laptop with `ctest --preset release --no-tests=error -R '^pixel_aot_get_lod_hardware$' -V` after rebuilding `offscreen_check`? The raw words are still printed for both paths.
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!1438
No description provided.