Skip to content

shader: lower startup 2D-array image LOD queries - #2947

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
chadhyatt:backport/startup-array-lod
Nov 27, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
chadhyatt:backport/startup-array-lod

Conversation

@chadhyatt

Copy link
Copy Markdown
Contributor

AI-assisted backport patch from x2w-microlift.

Extends #2311 and #2342 to 2D-array SRVs: consume the guest slice address but query LOD with spatial coordinates only. Retain the derivative and static-sampler refusals. Extend the authored raw array mip-view fixture across two slices and two derivative scales.

Verification on Apple Silicon macOS, revision 31d4532:

  • python3 -B tests/startup_gfx2hlsl_image_get_lod_check.py: passed, including negative controls.
  • Source-built fixture generation: four array input variants; distinct slice address literals verified.
  • git diff --check: passed.

DXC, WARP and Windows GPU readback not run on this host.

@thepatrickworld

Copy link
Copy Markdown
Contributor

Independent AMD RDNA 4 and WARP result on 31d45324: the new 2D-array image_get_lod lane runs and passes on both Windows adapters

Not a code change; measurements only. The body says the DXC/WARP/GPU half was not run on the author's host, so this covers it for one Windows machine.

Environment

Captured in the run's own log directory on the machine:

Microsoft Windows [version 10.0.26200.9974]
cl 19.44.35230 (banner)   VCToolsVersion=14.44.35207   (only 14.44.35207 under VC\Tools\MSVC)
DXC 1.9.2602.17           FXC 10.0.26100.9457
AMD Radeon RX 9070 XT | 32.0.32029.2010 | 18/11/2026   (1002:7550)
WARP: Microsoft Basic Render Driver | 1414:008c | 10.0.26100.9818
D3D12 debug layer: unavailable  -> no validation-layer output anywhere below
git rev-parse HEAD = 31d4532417d5734f02f21262fd161ab2c81e0d95
git status --porcelain --untracked-files=no : empty
ctest -N : Total Tests: 2444        preset: dev, INTAKE_PYTHON = out\pe-env\Scripts\python.exe
sha256 tools/startup/gfx2hlsl.py                              2DCA60C31243307396EEE9DD1D77F74BD227FA681B89886573839FA930DB21C2
sha256 tests/startup_gfx2hlsl_image_get_lod_check.py          63BAF7BEDE3AA96BDD37EDD08EB09D3AA4B51B16313E040BDA558673F0787CA3
sha256 tests/startup_image_get_lod_view_check.py              1CD150EB1E369B564DD0D5C256184E4784A28E5FF51863C7796B8379FF5205F1
sha256 tests/startup_image_get_lod_flow_check.py              357DFCEDFFADAF8D927F90D878878F7F278B279694742EED10C1589555FBC0C5

Commands

git fetch origin pull/2947/head:pr2947 && git worktree add <dir> pr2947
cmake --preset dev -DINTAKE_PYTHON=C:/.../out/pe-env/Scripts/python.exe
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R "image_get_lod" -V

Observed

1/6 Test #869: startup_gfx2hlsl_image_get_lod_controls ...   Passed    1.04 sec
2/6 Test #870: startup_image_get_lod_view_warp ...........   Passed    7.27 sec
3/6 Test #871: startup_image_get_lod_view_hardware .......   Passed    9.25 sec
4/6 Test #939: startup_image_get_lod_flow_controls .......   Passed    0.70 sec
5/6 Test #940: startup_image_get_lod_flow_warp ...........   Passed    7.30 sec
6/6 Test #941: startup_image_get_lod_flow_hardware .......   Passed   10.00 sec
100% tests passed out of 6          Total Test time (real) = 35.69 sec

#869/#939 are the translation-only entries (no device argument). The four adapter entries print their adapters: #870/#940 adapter=Microsoft Basic Render Driver vendor=1414 device=008c driver=10.0.26100.9818, #871/#941 adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 driver=32.0.32029.2010. Each view entry issues 23 renderer invocations (7 2D cases and 4 array cases, each drawn once for the translated and once for the direct programme, plus the ordinary-sampler control) and none of them skipped (code 77 would have).

Readback words, first two components are (clamped LOD, unclamped LOD), duplicated into RGBA. WARP and the RX 9070 XT returned the same word for every one of these:

view=0/3   step=1     min=0   max=2    mip_filter=1  rgba=40000000400000004000000040000000  (2, 2)
view=1/2   step=1     min=0   max=2    mip_filter=1  rgba=3f8000003f8000003f8000003f800000  (1, 1)
view=1/1   step=1     min=0   max=2    mip_filter=1  rgba=000000003f800000000000003f800000  (0, 1)
view=0/1   step=1     min=0   max=2    mip_filter=1  rgba=00000000400000000000000040000000  (0, 2)
view=0/3   step=1     min=0   max=0.75 mip_filter=1  rgba=3f800000400000003f80000040000000  (1, 2)
view=0/3   step=1     min=0   max=0.75 mip_filter=2  rgba=3f400000400000003f40000040000000  (0.75, 2)
ordinary sampler control                            rgba=40000000400000004000000040000000  (2, 2)
view=0/3   step=0.125 min=0.5 max=2    mip_filter=2  rgba=3f000000bf8000003f000000bf800000  (0.5, -1)
array slice=0 step=1     min=0 max=2  mip_filter=1  rgba=40000000400000004000000040000000  (2, 2)
array slice=1 step=1     min=0 max=2  mip_filter=1  rgba=40000000400000004000000040000000  (2, 2)
array slice=0 step=0.125 min=0.5 max=2 mip_filter=2 rgba=3f000000bf8000003f000000bf800000  (0.5, -1)
array slice=1 step=0.125 min=0.5 max=2 mip_filter=2 rgba=3f000000bf8000003f000000bf800000  (0.5, -1)

The three SRV-window cases (view=1/2, 1/1, 0/1) show the clamped component following the view's mip window while the unclamped one stays at the LOD of the whole resource, which is the relation the fixture's comment states. The flow entries printed, for their seven cases and both compilers, <adapter> dxc|fxc <case>: GPU (…) == CPU reference (…), with the mutated variants beside them (e.g. kill: GPU (2.0, 2.0) == CPU reference (2.0, 2.0); every lane writes u -> (1.0, 1.0)).

The array lane depends on this PR's translator change

Nothing rebuilt: only tools/startup/gfx2hlsl.py was put back to the base revision.

git show 6ee878d8:tools/startup/gfx2hlsl.py > tools/startup/gfx2hlsl.py
sha256 before 2DCA60C31243307396EEE9DD1D77F74BD227FA681B89886573839FA930DB21C2
sha256 then   0EB758407558CD2997E850712ADBDA1B0D01A49514976A5B2FAA89FE60A8FD38   git status: " M tools/startup/gfx2hlsl.py"
tests/startup_gfx2hlsl_image_get_lod_check.py            -> exit 1
gfx2hlsl.Unsupported: image_get_lod form v4, v[0:2], s[16:23], s[24:27] dmask:0x1 dim:SQ_RSRC_IMG_2D_ARRAY
tests/startup_image_get_lod_view_check.py <dxc> <offscreen_check.exe> warp  -> exit 1
the seven 2D cases print their values, then draw_array raises before any array draw:
gfx2hlsl.Unsupported: image_get_lod form v[4:5], v[0:2], s[16:23], s[24:27] dmask:0x3 dim:SQ_RSRC_IMG_2D_ARRAY
after git checkout --: sha256 back to 2DCA60C3…, status --untracked-files=no empty, controls entry exit 0

So under the base translator the array lane has no coverage at all — the refusal happens while translating, before compile_hlsl or any draw — and the seven 2D readbacks are unchanged by the swap.

The draw mode compiles the array stage under both compilers, and no ctest entry runs it

python -B tests\startup_gfx2hlsl_image_get_lod_check.py draw <dxc> <fxc>
dxc compiles the dmask 0x3 2D stage
fxc compiles the dmask 0x3 2D stage
dxc compiles the dmask 0x3 2D array stage
fxc compiles the dmask 0x3 2D array stage
exit 0

CMakeLists.txt:3733 registers startup_gfx2hlsl_image_get_lod_controls with the fixture path only — no draw, no compiler paths — and ctest -N -R image_get_lod lists exactly the six entries above. The ps_6_0/ps_5_1 compile of the Texture2DArray form is therefore only reachable by hand today.

Fractional LOD values: the two adapters do not return the same raw word

Probe (not pushed) reusing this fixture's own stage/Pipeline/read_pixel and the same renderer, with the array lane's UV scale widened from the two hardcoded scales (1 and 0.125) to eleven LOD targets, linear filter, min 0 max 2:

LOD 0.25 : WARP raw 0.249999911 (3e7ffffa) | card raw 0.250000000 (3e800000)   clamped 0.25 both
LOD 0.50 : WARP raw 0.499999940 (3efffffe) | card raw 0.500000000 (3f000000)   clamped 0.5 both
LOD 0.75 : 0.75 both
LOD 1.25 : WARP raw 1.249999881 (3f9fffff) | card raw 1.250000000 (3fa00000)
LOD 1.50 : 1.5 both
LOD 2.50 / 3.50 / 4.50 / 6.50 : exact on both, clamped 2.0 on both
LOD 8.50 : WARP raw 8.499999046 (4107ffff) | card raw 8.500000000 (41080000)
LOD 12.50: WARP raw 12.499999046 (4147ffff) | card raw 12.500000000 (41480000)

WARP lands below the card by 6 float steps at LOD 0.25, 2 at 0.5 and 1 at 1.25/8.5/12.5; the largest absolute difference is 9.54e-7 (LOD 8.5 and 12.5) and the card is exact at all eleven. The clamped component is identical everywhere. The cause is not isolated — the difference can sit in the derivatives, in the log2, or in the coordinate arithmetic — and this probe is not in the tree.

Every raw value the fixture itself asserts is an exact integer (2, 1, 0, −1), so this class of difference is invisible to the entry as written; if a fractional case were added, the 1/256 tolerance in check_color would absorb the 9.5e-7 difference seen here.

What these runs do not establish

  • One machine, two adapters, one DXC and one FXC. No debug layer, so no API validation.
  • The readback cannot separate "slice dropped" from "slice silently ignored": a LOD query reads no texel, and the direct programme the fixture compares against also passes float2 (DIRECT_ARRAY_PS is DIRECT_PS with Texture2D replaced by Texture2DArray), so neither side carries the array coordinate. What proves the drop is the static control (array_call text plus 'F(v2)' not in text), not the draw.
  • pixel == reference compares the translated programme with the direct HLSL on the same adapter; "identical on WARP and on the card" above is my comparison of the two logs, not something the fixture asserts.
  • In draw_array the max clamp never binds: both step=1 cases have raw 2.0 against max=2, so only MIN_LOD is separated (0.5 clamped against −1 raw), and only with the linear filter. The 2D lane does separate MAX_LOD (0.75 clamped against 2 raw, with both filters). One array case with max=0.75 would close it.
  • CI: the pr preset include regex (CMakePresets.json:45) matches none of the six entry names, so on a pull_request ctest runs none of them; the python-linux job does run tests/startup_gfx2hlsl_image_get_lod_check.py (windows.yml:288), which is translation-only, no DXC and no device. On a push, the dev sweep with -E '_hardware$' (windows.yml:494) keeps the two _controls and the two _warp entries and leaves the two _hardware ones manual. Adding startup_image_get_lod_view to the pr regex would give the new draw its first automated run.

Conclusion

On Windows 26200 with DXC 1.9.2602.17, the 2D-array image_get_lod lowering emits Texture2DArray r0 with the slice consumed and a float2 LOD query, compiles under ps_6_0 (DXC) and ps_5_1 (FXC), and the drawn values match the separately authored direct HLSL word for word on WARP 10.0.26100.9818 and on the RX 9070 XT 32.0.32029.2010, for both slices and both derivative scales, with MIN_LOD and the sampler clamp reproduced. The base translator refuses the same programme.

AI-assisted.

@chadhyatt

Copy link
Copy Markdown
Contributor Author

Thank you for independently running the exact head on both WARP and the RX 9070 XT, including the base-translator negative control. This closes the previously unverified Windows execution lane. Agreed on the scope: the fractional raw-LOD differences are adapter observations, not proven translator defects, and the array coordinate is tested statically.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The independent WARP and RX 9070 XT results cover 31d45324. A merge trial against current main (fb955a51, after #2970) found conflicts in tests/offscreen_check.cpp and tests/startup_image_get_lod_view_check.py. Please update the branch and preserve both the sampler-join fixture's root selector and this PR's array-slice selection. The two source-built fixtures can then be run together on the updated head.

@chadhyatt

Copy link
Copy Markdown
Contributor Author

@R0Y00 I am rebasing against fb955a5 and preserving both the optional root selector and array-view mode. I will rerun the portable sampler-join and array-LOD controls on the updated head, with no new GPU claim.

Use spatial-only DXIL LOD queries while consuming the guest array address. Preserve derivative and static-sampler validation and extend the source-built raw array mip-view fixture.
AI-assisted backport patch from x2w-microlift.
@chadhyatt
chadhyatt force-pushed the backport/startup-array-lod branch from 31d4532 to 54567b5 Compare November 27, 2026 03:42
@chadhyatt

Copy link
Copy Markdown
Contributor Author

Rebased on current upstream fb955a5 after #2970, now 54567b5. The existing selector and new array-view mode are both preserved. Portable image_get_lod controls pass, as do sampler-join controls (3 forms, both selector outcomes, swapped bindings, 7 refusals) and all 10 authored LLVM15 encodings. The earlier independent Windows 6/6 result belongs to the prior head; Windows GPU not rerun here. Ready for follow-up review.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed rebased head 54567b51d6f11ad13cfc37d81188e6cecb75152b. A merge trial against main e05b3ced was clean. The 2D-view selector and the separate 2D-array fixture are both preserved. On Windows 11 build 26200.9974 I rebuilt offscreen_check in Release and ran ctest --preset release --no-tests=error --output-on-failure -R '^startup_(gfx2hlsl_image_get_lod|image_get_lod_view|image_sample_l_join)': all six passed. WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) matched the direct HLSL array reference for both slices and both derivative scales. They also passed the sampler-join readbacks, with zero D3D12 debug-layer warnings or errors. Required Windows CI passed.

@R0Y00
R0Y00 merged commit 8895045 into R0Y00:main Nov 27, 2026
5 checks passed
@chadhyatt
chadhyatt deleted the backport/startup-array-lod branch November 27, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants