startup: lower image_get_lod on a 2D texture in gfx2hlsl #2303
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2311"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:48:02Z.
What
image_get_lodreturns [0], the clamped LOD a sample would use, and [1], the computed LOD before the clamp. This is Mesanir_texop_lod, which ACO emits asimage_get_lod; GLSLtextureQueryLodx/y.tools/startup/gfx2hlsl.pyhad no handler, so a pixel stage that uses it was refused.It is now lowered to HLSL
CalculateLevelOfDetailandCalculateLevelOfDetailUnclampedon the same texture and sampler, int.xandt.y.image_sample_bapplies: a pixel stage with the entry mask and no branches.image_sample_b: no LOD bias, mipmapping enabled, MIN_LOD <= MAX_LOD. Its limits are carried to the static sampler. A heap or register sampler is refused.Test
tests/startup_gfx2hlsl_image_get_lod_check.py(new). It is registered in CMake asstartup_gfx2hlsl_image_get_lod_controls, in the Python CI job and in AGENTS.md.The fixture is synthetic. It is the recorded
c_lzstage ofstartup_image_sample_c_checkwith three changes: the MIMG opcode set to 0x60, sampler word 2 loaded from a literal (mip filter point), and for the second form dmask 0x3.op_image_get_lodthe stage is refused, as onmain.On
main, the check fails withgfx2hlsl.Unsupported: image_get_lod.The same check with
draw <dxc> <fxc>also compiles the dmask 0x3 stage. Both compile with the Windows SDK 10.0.26100 compilers: dxc forps_6_0and fxc forps_5_1.tests/startup_gfx2hlsl_*_check.py,tests/startup_image_*_check.py,startup_translator_check.pyandstartup_flat_param_check.pypasses on this branch.allbuilds (Ninja Release, MSVC Build Tools 18, Windows 11). Device-free, so there were no GPU runs and no capability skips.Refs #1723
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:50:26Z.
Review: COMMENTED
Review of head
96b7468edac87a66c80c6eaa50e6822eed583c10(comment only, no approval).Verdict: no P1, no P2. Logic matches the ISA/GLSL meaning (
image_get_lod: x = clamped LOD, y = unclamped LOD).Checked
pending. I did not wait for them.dmaskbits map tot.x/t.ythrough the existing packing loop (gfx2hlsl.py~2404-2409), so dmask 0x2 would write the unclamped LOD to the first dest register, as the ISA packs it.image_sample_b. The sampler must be constant and is validated withlod_sampler_words, with its LOD limits carried.Commands run locally (worktree at the head SHA)
python3 -B tests/startup_gfx2hlsl_image_get_lod_check.py-> PASSpython3 -B tests/startup_image_sample_c_check.py(sibling fixture) -> PASSpython3 tests/docs_links_check.py-> 18 files, 446 links OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanCalculateLevelOfDetailUnclampedtoCalculateLevelOfDetail-> test FAILS (killed).dmask & ~3guard -> test FAILS (accepted, expected 'image_get_lod form', killed).git checkout -- ..Nits (not blocking)
dmask 0x2alone is accepted by the guard but not covered by the test. A one-line control would pin the packing.draw). For a lowering of math semantics, a D3D12 WARP readback against a CPU reference of the LOD would be stronger. The PR already states that the mip-range clamp assumption is unmeasured.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T12:04:50Z.
Tested
96b7468eon RTX 4060 (32.0.15.9579), Intel UHD 770 (32.0.101.5973) and WARP (10.0.26100.9711). The startup translator selected the correct channels for dmask 1, 2, and 3 on all three backends. Each adapter passed nine 8×8 draws. Every strict fixture comparison exited 0; all 64 RGBA32F pixels per draw matched the expected vector within 1/256.I kept the fixture’s descriptor and query and used LLVM 15.0.7 to assemble a packed-position input instead of the two constant coordinates. The synthetic stage unpacks unsigned X and Y, converts each to float and multiplies by 1/16, 1/8 or 1/4. On the 8×8 one-mip view the clamped reference is zero and the three raw references are −1, 0 and +1. Mask 2 packed raw into v4; mask 3 exported
(clamped, raw, clamped, raw). For example, the negative-LOD case returned(0, -1, 0, -1)under mask 3. Replacing the unclamped method with the clamped method made all three adapters exit 1 and changed all 64 pixels to(0, 0, 0, 0).The draw used
--check-pixel-case, DXC 1.9.2609.5,ps_hw_inputs=(0x8000, 0x8000)and the offscreen vertex shader. Its output declares TEXCOORD0 before SV_Position, so I inserted the matching unused TEXCOORD0 in the generated input signature. The fixture bound its own point sampler. This measures channel packing and derivatives on a single-mip view; guest sampler installation and multi-mip view limits remain open.Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T12:09:42Z.
Thanks, both of you.
v4 = U(t.y);and reads not.x. The commit is on the branch;python -B tests/startup_gfx2hlsl_image_get_lod_check.pypasses.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T12:46:50Z.
I measured the two open desktop cases with the startup translator's emitted
smplline installed throughcreate_translated_root. A synthetic gfx1013 pixel shader and an independently written HLSL shader returned the same four binary32 words in all 36 paired comparisons (12 cases on each adapter). Each draw reads one RGBA32F pixel. The source texture was 4×4 with three mips. I’m putting together a regression test for the sampler and view cases.Changing only the manifest tag from
smpltosmpin the second row restored (2, 2) on all three. The raw value followed the dimensions of the most detailed visible mip. With point mip filtering and MinLOD exactly 0.5 or 1.5, WARP and NVIDIA selected 1 and 2, while Intel selected 0 and 1. The independent shader reproduced the same split. With linear mip filtering all three returned the exact fractional MinLOD values. The native console side of the comparison remains unmeasured.Windows 11, DXC 1.9.2609.5, RTX 4060 (32.0.15.9579), UHD 770 (32.0.101.5973), WARP (10.0.26100.9711). Measurement driver and all cases · renderer source · pinned renderer build.
upstream-sync referenced this pull request2026-11-25 15:01:50 +00:00