Skip to content

startup: lower D16 image_load_mip in gfx2hlsl - #2575

Open
consolelogkyo wants to merge 2 commits into
R0Y00:mainfrom
consolelogkyo:feat/startup-image-load-mip-d16
Open

consolelogkyo wants to merge 2 commits into
R0Y00:mainfrom
consolelogkyo:feat/startup-image-load-mip-d16

Conversation

@consolelogkyo

Copy link
Copy Markdown
Contributor

Summary

Extend the D16 MIMG load lowering in tools/startup/gfx2hlsl.py (#2139) from level-zero image_load to explicit-mip image_load_mip on 2D, 3D and 2D-array resources:

  • Explicit-mip D16 lowering (tools/startup/gfx2hlsl.py): Accept d16 alongside unorm, glc, slc and dlc on image_load_mip (Texture2D<float4>.Load(int3(x, y, mip)) and Texture2DArray<float4> / Texture3D<float4>.Load(int4(x, y, slice_or_z, mip))), including non-sequential address (NSA) register lists and both vertex and pixel stages.
  • Shared IEEE binary16 narrowing & SRV validation: Reuse pack16_d16 (pack16_rne + exact pack16_unorm16 selected per SRV via udsrc <ud> d16unorm16 <index>), d16srv <index> exact manifest gating against the 14 GPU-verified exact DXGI formats (src/startup_stubs/d16_image_format.h), and odd-dmask low-16-bit provenance tracking (low16_only_v).
  • Multi-mip & 2D-array D3D12 verification (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): Extend offscreen_check --startup-image-load-d16 (r16_unorm[_array], rgba32f[_array]) to two-mip (8x2 mip 0 + 4x1 mip 1, including 0xffaf and 0xffef double-rounding discriminators on mip 1) 2D and two-slice 2D-array textures, adding explicit-mip fixtures C (2D) and D (2D-array), odd-dmask upper-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-stage d16 image loads, non-exact bound SRV formats, whole-word reads after odd-dmask D16 loads (including passing an odd-dmask VGPR as a Load coordinate), and mismatched destination or address register widths remain refused.

Verification

Verified on rebased origin/main (381abc31) on Windows 11 26H2 across:

  • WARP: Microsoft Basic Render Driver (1414:008c, driver 10.0.26100.9818), debug_layer=enabled, debug_errors=0 debug_warnings=0
  • Hardware: AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010), debug_layer=enabled, debug_errors=0 debug_warnings=0
  • Compilers: DXC (vs_6_0 / ps_6_0) and FXC (vs_5_1 / ps_5_1)

Results:

  • Fixtures A, B, C (2D image_load_mip across mips 0 and 1) and D (2D-array image_load_mip across slices 0..1 and mips 0..1) match all 64 readback words per draw on R16_UNORM and R32G32B32A32_FLOAT 2D and 2D-array textures under both DXC and FXC, and stay bit-identical when 0xdead0000 is injected into bits 31:16 of odd-dmask registers.
  • All 14 GPU negative-control mutations (8 level-zero + 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.
  • ctest passed startup_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 76 startup_gfx2hlsl_* control tests.
  • Not run locally on Windows: the Linux CI llvm-mc-15 (binary) and libLLVM-15.so.1 (decode) steps (covered by disasm_rdna2 round-trip checks locally and by GitHub Actions Linux CI).
cmake --build --preset release --target offscreen_check startup_d16_image_format_check startup_stream_consumer
ctest --test-dir out/build/release --output-on-failure --no-tests=error -R "^(startup_image_load_d16_controls|startup_image_load_d16_warp|startup_image_load_d16_hardware|startup_image_load_mip_controls|startup_image_load_mip_warp|startup_image_load_mip_hardware|startup_image_2d_array_controls|startup_image_2d_array_warp|startup_image_2d_array_hardware|startup_d16_image_format|startup_d16_srv_warp|startup_d16_srv_hardware|startup_translator)$" -V

Part of #2023

AI-assisted.

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.
@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Seven mutations of the D16 path, all caught — and the refusal text naming the instruction is now enforced too

Control modes run clean here, device-free

python -B tests/startup_image_load_d16_check.py
    refusals: sample/sample_lz, 1D/cube, mip/3D/array a16, compute d16, tfe/lwe/r128/reserved and bad tuple widths refused
python -B tests/startup_image_load_mip_check.py
    plain 2D load: packed A16 coordinates, cache policy unchanged, unsupported layouts refused
python -B tests/startup_image_2d_array_check.py
    mip model: 42 distinct cells; 7 mutants each read another cell

That last line is a good sign on its own: the 2D-array fixture carries seven mutants that each read a different cell of a
42-cell model, so the model is checked against itself rather than against a hand-written expectation.

Mutations of tools/startup/gfx2hlsl.py

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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_mip now takes d16 through the same checks as image_load (destination width, SRV format list, pack16_d16 narrowing, odd-dmask low-16 tracking). The refusal text now names the real instruction. The 14 exact SRV formats still match d16_image_format.h.
  • Test coverage: startup_image_load_d16_check.py now 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 load path, startup_image_load_mip_check.py and startup_image_2d_array_check.py still 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: pass
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: clean
  • Mutation 1: packed_d16 limited back to load only: 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.

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