Repository navigation
startup: lower D16 image_load_mip in gfx2hlsl - #2575
consolelogkyo wants to merge 2 commits into
Conversation
Extend the D16 MIMG load lowering in `tools/startup/gfx2hlsl.py` (`R0Y00#2139`) from level-zero `image_load` to explicit-mip `image_load_mip` on 2D, 3D and 2D-array resources: - Accept `d16` alongside cache-policy and `unorm` modifiers on `image_load_mip` (`Texture2D.Load(int3(x, y, mip))` and `Texture2DArray`/`Texture3D.Load(int4(x, y, slice_or_z, mip))`), including non-sequential address (`NSA`) register lists and both vertex and pixel stages. - Reuse the exact IEEE binary32-to-binary16 RNE (`pack16_rne`) and exact `UNORM16` (`pack16_unorm16`) helpers, `udsrc <ud> d16unorm16 <index>` selection, `d16srv <index> exact` manifest validation against the 14 GPU-verified exact DXGI formats, and odd-`dmask` low-16-bit provenance tracking (`low16_only_v`). - Keep `a16`, `tfe`, `lwe`, `r128`, set reserved MIMG bits, `dmask:0x0`, 1D and cube dimensions, compute `d16` image loads, and mismatched destination or address register widths refused. - Extend `offscreen_check --startup-image-load-d16` (`tests/startup_image_3d.cpp`) and `tests/startup_image_load_d16_check.py` (plus the explicit-mip layout checks in `tests/startup_image_load_mip_check.py` and `tests/startup_image_2d_array_check.py`) to two-mip (`8x2` + `4x1`) 2D and two-slice 2D-array `R16_UNORM` and `R32G32B32A32_FLOAT` textures, covering explicit-mip fixtures C and D, odd-`dmask` upper-half poison checks, and six additional HLSL mutations (`mip_zero`, `mip_drop_nsa`, `mip_rtz`, `mip_double_round`, `swap_slice_mip`, and `array_drop_nsa`). Part of R0Y00#2023 AI-assisted.
Seven mutations of the D16 path, all caught — and the refusal text naming the instruction is now enforced tooControl modes run clean here, device-freeThat last line is a good sign on its own: the 2D-array fixture carries seven mutants that each read a different cell of a Mutations of
|
| mutation | caught by |
|---|---|
packed_d16 reverts to how == 'load' only |
all three checks |
the second d16 branch reverts to how == 'load' |
all three checks |
op_name pinned to 'image_load' (refusal misnames the instruction) |
d16 check |
| the d16 destination-register count check removed | d16 check |
the D16_EXACT_SRV_FORMATS membership check removed |
d16 check |
expected_dst loses the + 1) // 2 rounding |
all three checks |
mip pinned to '0' (load_mip reads mip 0 regardless) |
all three checks |
The third one is the one I would not have expected to be caught, and it is worth saying why that matters: pinning
op_name changes only the text of a refusal, not whether it refuses. The d16 check catches it, so the fixture
asserts that a refusal names the instruction it came from. That is exactly the convention you asked for when the
gfx2hlsl scalar-table guard went in, and it is now enforced on this path as well — a reader of Unsupported: image_load d16 destination … can no longer be looking at a load_mip that mislabelled itself.
The last one is the substantive risk of the change — load_mip exists to read a mip level, and pinning it to zero would
leave every non-zero-level load silently reading level 0 — and it is caught by all three, including the 42-cell model.
Worth noting on proportions
13 lines of production change against 480 lines of fixture is the right ratio for a change whose claim is "this
instruction now lowers correctly on the device". I ran only the control modes here; the GPU half (offscreen_check,
startup_image_3d) I did not rebuild, so I am not claiming anything about the hardware result — docs/experiments.md
being updated alongside suggests you have it.
Reminder in case it bites you: tools/startup/gfx2hlsl.py is CRLF, so any patch script needs the
read-\r\n→\n, patch, write-back-\r\n dance. A \n anchor silently never matches.
AI-assisted; pure Python, Windows 11 build 26300, no build or GPU for the rows above.
tedin7
left a comment
There was a problem hiding this comment.
Review of head 28e5848 (comment only, no approval).
Result: sound. No blocking findings.
What I checked
tools/startup/gfx2hlsl.py: the change is small.image_load_mipnow takesd16through the same checks asimage_load(destination width, SRV format list,pack16_d16narrowing, odd-dmask low-16 tracking). The refusal text now names the real instruction. The 14 exact SRV formats still matchd16_image_format.h.- Test coverage:
startup_image_load_d16_check.pynow covers all 15 dmasks for load and load_mip, 2D / NSA / 3D / 2D-array, VS and PS, and the mip 1 double-rounding cases. The GPU readback path (offscreen_check --startup-image-load-d16) now has 2-mip and 2-slice fixtures with the CPU reference. - Sibling code: the
loadpath,startup_image_load_mip_check.pyandstartup_image_2d_array_check.pystill pass unchanged in behavior. No duplicate PR: #2139 (level-zero d16) is merged, #2119 is closed. - The PR does not claim to advance game startup.
Commands run in a clean worktree on this head
python3 -B tests/startup_image_load_d16_check.py,tests/startup_image_load_mip_check.py,tests/startup_image_2d_array_check.py: passpython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: clean- Mutation 1:
packed_d16limited back toloadonly: d16 check fails - Mutation 2: d16 narrowing at the call site limited back to
load: d16 check fails - Mutation 3: drop DXGI format 56 from
D16_UNORM16_SRV_FORMATS: d16 check fails
The D3D12 GPU readback part is covered by the Win2025 WARP run, which I will post separately.
AI-assisted; commands listed were executed locally.
Summary
Extend the D16 MIMG load lowering in
tools/startup/gfx2hlsl.py(#2139) from level-zeroimage_loadto explicit-mipimage_load_mipon 2D, 3D and 2D-array resources:tools/startup/gfx2hlsl.py): Acceptd16alongsideunorm,glc,slcanddlconimage_load_mip(Texture2D<float4>.Load(int3(x, y, mip))andTexture2DArray<float4>/Texture3D<float4>.Load(int4(x, y, slice_or_z, mip))), including non-sequential address (NSA) register lists and both vertex and pixel stages.pack16_d16(pack16_rne+ exactpack16_unorm16selected per SRV viaudsrc <ud> d16unorm16 <index>),d16srv <index> exactmanifest gating against the 14 GPU-verified exact DXGI formats (src/startup_stubs/d16_image_format.h), and odd-dmasklow-16-bit provenance tracking (low16_only_v).tests/startup_image_3d.cpp,tests/offscreen_check.cpp,tests/startup_image_load_d16_check.py,tests/startup_image_load_mip_check.py,tests/startup_image_2d_array_check.py): Extendoffscreen_check --startup-image-load-d16(r16_unorm[_array],rgba32f[_array]) to two-mip (8x2mip 0 +4x1mip 1, including0xffafand0xffefdouble-rounding discriminators on mip 1) 2D and two-slice 2D-array textures, adding explicit-mip fixtures C (2D) and D (2D-array), odd-dmaskupper-half poison checks, and six new GPU negative-control mutations (mip_zero,mip_drop_nsa,mip_rtz,mip_double_round,swap_slice_mip,array_drop_nsa).Scope & Refusals
a16,tfe,lwe,r128, set reserved MIMG bits,dmask:0x0, 1D and cube dimensions, compute-staged16image loads, non-exact bound SRV formats, whole-word reads after odd-dmaskD16 loads (including passing an odd-dmaskVGPR as aLoadcoordinate), and mismatched destination or address register widths remain refused.Verification
Verified on rebased
origin/main(381abc31) on Windows 11 26H2 across:Microsoft Basic Render Driver(1414:008c, driver10.0.26100.9818),debug_layer=enabled,debug_errors=0 debug_warnings=0AMD Radeon RX 9070 XT(1002:7550, driver32.0.32029.2010),debug_layer=enabled,debug_errors=0 debug_warnings=0vs_6_0/ps_6_0) and FXC (vs_5_1/ps_5_1)Results:
image_load_mipacross mips 0 and 1) and D (2D-arrayimage_load_mipacross slices 0..1 and mips 0..1) match all 64 readback words per draw onR16_UNORMandR32G32B32A32_FLOAT2D and 2D-array textures under both DXC and FXC, and stay bit-identical when0xdead0000is injected into bits31:16of odd-dmaskregisters.mip_zero,mip_drop_nsa,mip_rtz,mip_double_round,swap_slice_mip,array_drop_nsa) fail against the reference words (returncode == 1) and match their corresponding mutated CPU models (returncode == 0) on both WARP and Radeon RX 9070 XT under DXC and FXC.ctestpassedstartup_image_load_d16_{controls,warp,hardware},startup_image_load_mip_{controls,warp,hardware},startup_image_2d_array_{controls,warp,hardware},startup_d16_srv_{warp,hardware},startup_d16_image_format,startup_translator, and all 76startup_gfx2hlsl_*control tests.llvm-mc-15(binary) andlibLLVM-15.so.1(decode) steps (covered bydisasm_rdna2round-trip checks locally and by GitHub Actions Linux CI).Part of #2023
AI-assisted.