shader: measure MinLod mip selection and blending against an HLSL control #810

Merged
lukaslw-lab merged 2 commits from upstream-pr/816 into main 2026-11-23 08:18:56 +00:00
lukaslw-lab commented 2026-11-23 07:40:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T07:40:25Z.


Change

Adds spirv_minlod_levels_{hardware,warp} for the plain Sample + MinLod form claimed in #809. It builds on #804's fixture. The texture has four solid-color mips and the coordinate is constant, so the LOD equals the clamp. Each clamp runs as the translated SPIR-V shader and as a direct HLSL control (tests/spirv_window/minlod_control.hlsl) on the same adapter.

  • Point mip filtering: clamps 0, 1, 2, 3, 1.4375, 1.5625 and 3.75 must read the nearest mip exactly. The 1.5 tie may read mip 1 or 2, but the translated shader and the control must agree.
  • MIN_MAG_POINT_MIP_LINEAR: nine clamps from 1 to 3.75 must match the exact mip blend within 1/128. The translated and control bits must be identical on each adapter.

Shared test code touched:

  • tests/pixel_aot_vs.hlsl is also built with -D PIXEL_MIP_LINEAR=1, which gives a root signature with a mip-linear static sampler.
  • PixelInput gains linearMips and tolerance. Existing checks keep the bit-exact default. max_absolute_error= now prints the measured value, which stays 0 for exact checks.
  • New operations: --check-pixel-mip-clamp and --check-pixel-mip-blend.
  • All MinLod draws, including #804's spirv_minlod_* through a new --spirv-minlod-quad-lod operation, check for Shader Model 6.6 before creating the pipeline, as #763 did for the ballot fixture. On a runtime capped at SM 6.5 they used to fail at ps_6_6 pipeline creation; they now skip (77). The shared --check-pixel-quad-lod stays ungated for pixel_aot_check.py.
  • spirv_minlod_levels_warp is added to require_warp_results.py.

Refs #809

Verification

Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7, DXC 1.9.2609, Agility SDK 1.620.2, WARP 1.0.22. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047. Debug layer on.

At af94238 (rebased on d2ac415), w10 build (dev preset plus the app-local Agility SDK and WARP):

ctest -R '^(spirv_minlod|pixel_aot_title_loads_|pixel_aot_warp$)'
7 total: 7 passed (spirv_minlod_{hardware,warp}, spirv_minlod_levels_{hardware,warp},
pixel_aot_title_loads_{hardware,warp}, pixel_aot_warp)

Before the rebase, the same change on 66669bb passed the shader area in the dev build (^pixel_aot_|dxil_retarget|shader_|rdna2_tools|ffx_dispatch|rcas|pso_readiness|effect_candidates): 69 total, 69 passed.

The full local suite at af94238 is still running; I'll post its result as a comment.

At a5176cc (the SM 6.6 gate), in both dev (Windows 10 in-box runtime, SM 6.5) and w10:

ctest -R '^(spirv_minlod|offscreen_capability_table_self_test$)'
dev: 5 total: 1 passed, 4 skipped ("skip: MinLod fixture requires SM 6.6")
w10: 5 total: 5 passed

Measured blends (first pixel, green and blue channels; all 64 pixels matched within the tolerance):

Clamp Exact WARP 1.0.22 RTX 3080 Ti
1.25 0.75, 0.25 exact 0.7499962, 0.2500038
1.3 0.7, 0.3 0.6992188, 0.3007813 0.7031205, 0.2968795
1.001953125 0.9980469, 0.0019531 1, 0 1, 0

First difference between the adapters: pixel (0, 0), channels 1 and 2 (green, blue), plus channel 0 at clamp 2.5, which blends blue and yellow. Alpha was 1 on both adapters. The adapters differed at clamps 1.25, 1.3, 1.5, 1.75, 1.00390625 and 2.5, and were identical at 1, 1.001953125 and 3.75. With point filtering they did not differ.

Classification: every difference was a finite value. No pixel kept the clear value (-1), no run timed out, and nothing was skipped on the Agility SDK runtime. The Windows 10 in-box runtime skips (77) at Shader Model 6.6.

Tools and flags, as run by tests/spirv_window/minlod_levels.py:

  • SPIRV-Tools 262bdab (v2025.5), SPIRV-Headers b824a46, SPIRV-Cross 57e4efc with tools/patches/spirv-cross-minlod.patch, all from tools/setup-spirv-tools.ps1.
  • spirv-as --target-env vulkan1.2, spirv-val --target-env vulkan1.2
  • spirv-cross --hlsl --shader-model 66
  • dxc -T ps_6_6 -E main for the translated HLSL; dxc -T ps_6_6 -E main -DCLAMP=<clamp> for minlod_control.hlsl
  • offscreen_check <adapter> --check-pixel-mip-clamp <dxil> <mip> and --check-pixel-mip-blend <dxil> <clamp> 0.0078125

Evidence and follow-up

Source-built inputs only. The texture is generated in check_pixel_mip_clamp, and the shaders are the existing MIT minlod.spvasm template and a new 8-line HLSL control.

Negative controls: a clamp of 1 checked against mip 2, and a 1.25 clamp checked against the 1.5 blend. Both must fail at pixel (0, 0), and both do on both adapters.

Confirmed in this fixture:

  • The translated and control results are bit-identical on each adapter for every clamp and both filters.
  • With point filtering, both adapters agree exactly. The 1.5 tie reads mip 2 on both.
  • With linear mip filtering, both adapters quantize the blend weight to 1/256. At 1.3, WARP's result matches rounding the weight to 77/256, and the RTX's matches truncating it to 76/256. The RTX values also differ from those steps by up to 7.6e-6.
  • Fractions below 1/256 (1.001953125) produce no blend on either adapter.

Not established:

  • Whether this explains the twelve archive differences in #809. Their sampler state and coordinates are unknown here.
  • The rounding versus truncation reading rests on the 1.3 case. A finer sweep, and how WARP handles an exact half step, are open.
  • The 1/128 tolerance comes from these measurements, not from a specified precision.
  • Scope: one NVIDIA adapter and driver plus WARP, plain Sample only, R8G8B8A8_UNORM, constant coordinates, point filtering within a mip.

Follow-up others can pick up: other adapters (AMD, Intel), and the SampleBias, SampleGrad and SampleCmp forms with the same operations.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6554624319 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/816). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T07:40:25Z. --- ## Change Adds `spirv_minlod_levels_{hardware,warp}` for the plain `Sample` + `MinLod` form claimed in #809. It builds on #804's fixture. The texture has four solid-color mips and the coordinate is constant, so the LOD equals the clamp. Each clamp runs as the translated SPIR-V shader and as a direct HLSL control (`tests/spirv_window/minlod_control.hlsl`) on the same adapter. - Point mip filtering: clamps 0, 1, 2, 3, 1.4375, 1.5625 and 3.75 must read the nearest mip exactly. The 1.5 tie may read mip 1 or 2, but the translated shader and the control must agree. - `MIN_MAG_POINT_MIP_LINEAR`: nine clamps from 1 to 3.75 must match the exact mip blend within 1/128. The translated and control bits must be identical on each adapter. Shared test code touched: - `tests/pixel_aot_vs.hlsl` is also built with `-D PIXEL_MIP_LINEAR=1`, which gives a root signature with a mip-linear static sampler. - `PixelInput` gains `linearMips` and `tolerance`. Existing checks keep the bit-exact default. `max_absolute_error=` now prints the measured value, which stays 0 for exact checks. - New operations: `--check-pixel-mip-clamp` and `--check-pixel-mip-blend`. - All MinLod draws, including #804's `spirv_minlod_*` through a new `--spirv-minlod-quad-lod` operation, check for Shader Model 6.6 before creating the pipeline, as #763 did for the ballot fixture. On a runtime capped at SM 6.5 they used to fail at `ps_6_6` pipeline creation; they now skip (77). The shared `--check-pixel-quad-lod` stays ungated for `pixel_aot_check.py`. - `spirv_minlod_levels_warp` is added to `require_warp_results.py`. Refs #809 ## Verification Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7, DXC 1.9.2609, Agility SDK 1.620.2, WARP 1.0.22. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047. Debug layer on. At `af94238` (rebased on `d2ac415`), `w10` build (dev preset plus the app-local Agility SDK and WARP): ctest -R '^(spirv_minlod|pixel_aot_title_loads_|pixel_aot_warp$)' 7 total: 7 passed (spirv_minlod_{hardware,warp}, spirv_minlod_levels_{hardware,warp}, pixel_aot_title_loads_{hardware,warp}, pixel_aot_warp) Before the rebase, the same change on `66669bb` passed the shader area in the `dev` build (`^pixel_aot_|dxil_retarget|shader_|rdna2_tools|ffx_dispatch|rcas|pso_readiness|effect_candidates`): 69 total, 69 passed. The full local suite at `af94238` is still running; I'll post its result as a comment. At `a5176cc` (the SM 6.6 gate), in both `dev` (Windows 10 in-box runtime, SM 6.5) and `w10`: ctest -R '^(spirv_minlod|offscreen_capability_table_self_test$)' dev: 5 total: 1 passed, 4 skipped ("skip: MinLod fixture requires SM 6.6") w10: 5 total: 5 passed Measured blends (first pixel, green and blue channels; all 64 pixels matched within the tolerance): | Clamp | Exact | WARP 1.0.22 | RTX 3080 Ti | |---|---|---|---| | 1.25 | 0.75, 0.25 | exact | 0.7499962, 0.2500038 | | 1.3 | 0.7, 0.3 | 0.6992188, 0.3007813 | 0.7031205, 0.2968795 | | 1.001953125 | 0.9980469, 0.0019531 | 1, 0 | 1, 0 | First difference between the adapters: pixel (0, 0), channels 1 and 2 (green, blue), plus channel 0 at clamp 2.5, which blends blue and yellow. Alpha was 1 on both adapters. The adapters differed at clamps 1.25, 1.3, 1.5, 1.75, 1.00390625 and 2.5, and were identical at 1, 1.001953125 and 3.75. With point filtering they did not differ. Classification: every difference was a finite value. No pixel kept the clear value (-1), no run timed out, and nothing was skipped on the Agility SDK runtime. The Windows 10 in-box runtime skips (77) at Shader Model 6.6. Tools and flags, as run by `tests/spirv_window/minlod_levels.py`: - SPIRV-Tools `262bdab` (v2025.5), SPIRV-Headers `b824a46`, SPIRV-Cross `57e4efc` with `tools/patches/spirv-cross-minlod.patch`, all from `tools/setup-spirv-tools.ps1`. - `spirv-as --target-env vulkan1.2`, `spirv-val --target-env vulkan1.2` - `spirv-cross --hlsl --shader-model 66` - `dxc -T ps_6_6 -E main` for the translated HLSL; `dxc -T ps_6_6 -E main -DCLAMP=<clamp>` for `minlod_control.hlsl` - `offscreen_check <adapter> --check-pixel-mip-clamp <dxil> <mip>` and `--check-pixel-mip-blend <dxil> <clamp> 0.0078125` ## Evidence and follow-up Source-built inputs only. The texture is generated in `check_pixel_mip_clamp`, and the shaders are the existing MIT `minlod.spvasm` template and a new 8-line HLSL control. Negative controls: a clamp of 1 checked against mip 2, and a 1.25 clamp checked against the 1.5 blend. Both must fail at pixel (0, 0), and both do on both adapters. Confirmed in this fixture: - The translated and control results are bit-identical on each adapter for every clamp and both filters. - With point filtering, both adapters agree exactly. The 1.5 tie reads mip 2 on both. - With linear mip filtering, both adapters quantize the blend weight to 1/256. At 1.3, WARP's result matches rounding the weight to 77/256, and the RTX's matches truncating it to 76/256. The RTX values also differ from those steps by up to 7.6e-6. - Fractions below 1/256 (1.001953125) produce no blend on either adapter. Not established: - Whether this explains the twelve archive differences in #809. Their sampler state and coordinates are unknown here. - The rounding versus truncation reading rests on the 1.3 case. A finer sweep, and how WARP handles an exact half step, are open. - The 1/128 tolerance comes from these measurements, not from a specified precision. - Scope: one NVIDIA adapter and driver plus WARP, plain `Sample` only, R8G8B8A8_UNORM, constant coordinates, point filtering within a mip. Follow-up others can pick up: other adapters (AMD, Intel), and the `SampleBias`, `SampleGrad` and `SampleCmp` forms with the same operations. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:55 +00:00
lukaslw-lab commented 2026-11-24 06:49:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T08:05:05Z.


Full local suite at af94238, dev build (Windows 10 in-box runtime, SM 6.5; in-box WARP 10.0.19041.7811): 387 total, 337 passed, 44 skipped, 6 failed.

  • spirv_minlod_{hardware,warp} and spirv_minlod_levels_{hardware,warp} failed at ps_6_6 pipeline creation instead of skipping. Fixed in a5176cc: at that commit all four skip with "skip: MinLod fixture requires SM 6.6".
  • gpu_alias_lookup_writes_warp: known in-box WARP failure (#332).
  • pixel_aot_title_loads_warp: fails the same way on d2ac415 without this PR, on the in-box WARP only. It passes on WARP 1.0.22 and the RTX 3080 Ti.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7095020869 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/816#issuecomment-7095020869). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T08:05:05Z. --- Full local suite at `af94238`, `dev` build (Windows 10 in-box runtime, SM 6.5; in-box WARP 10.0.19041.7811): 387 total, 337 passed, 44 skipped, 6 failed. - `spirv_minlod_{hardware,warp}` and `spirv_minlod_levels_{hardware,warp}` failed at `ps_6_6` pipeline creation instead of skipping. Fixed in `a5176cc`: at that commit all four skip with "skip: MinLod fixture requires SM 6.6". - `gpu_alias_lookup_writes_warp`: known in-box WARP failure (#332). - `pixel_aot_title_loads_warp`: fails the same way on `d2ac415` without this PR, on the in-box WARP only. It passes on WARP 1.0.22 and the RTX 3080 Ti.
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!810
No description provided.