Skip to content

shader: lower direct D16 image loads (Part of #3703) - #3836

Merged
R0Y00 merged 9 commits into
R0Y00:mainfrom
timbot103:shader/mesh-image-load-d16
Dec 3, 2026
Merged

R0Y00 merged 9 commits into
R0Y00:mainfrom
timbot103:shader/mesh-image-load-d16

Conversation

@timbot103

@timbot103 timbot103 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Lowers direct D16 image_load (and image_load_mip) across mesh Texture1D heap loads and direct compute/pixel/vertex image_io, clearing "unsupported image dimension or D16" (609 mesh programs in #3703).

Part of #3703. Refs #3641.
(Opened as Draft per #3514 until an active review slot frees.)

Summary

  • src/gfx1013_compute_native.cpp & src/gfx1013_compute_native.h:
    • Admits D16 on direct image_load (op == 0) and image_load_mip (op == 1) alongside sample_d16 for non-cube, non-MSAA dimensions (dim != 3 && dim < 6).
    • Adds shared image_result_registers(const Inst&) accounting for popcount(dmask) and D16 halfword packing, reused in vector-spill clearing (gfx1013_compute_native.cpp), loop/helper touch tracking (gfx1013_direct_graphics.inl), and mesh narrowed-EXEC VGPR preservation (gfx1013_direct_mesh.inl).
    • Adds ComputeViewKind::d16_load_srv (serialized/named in src/direct_compute_cache.cpp) and NativeComputeShader::mesh_texture_heap_d16 (reported in tools/startup/compile_dxil.cpp and gated on d16_srv_mode(Format) == float_exact in src/startup_stubs/native_mesh86.inl).
  • src/gfx1013_direct_compute.inl & src/gfx1013_direct_mesh.inl:
    • Extracts shared write_d16_image_result packing DMASK-selected channels consecutively into 16-bit halves (low half first) via existing round-to-nearest-even packed_half_rne.
    • Lowers mesh D16 Texture1D heap loads for arbitrary non-zero DMASK with destination-overflow checks and before_vec / partial_writes tracking under narrowed EXEC.
    • Bound compute/graphics D16 loads compile to DXIL with ComputeViewKind::d16_load_srv (manifest publication fails closed until format-aware runtime binding lands; existing d16_sample_srv behavior unchanged).
  • tests/native_mesh_image_d16_check.py + tests/cmake/native_mesh_image_d16.cmake + tests/startup_compute_d16_sample_srv_check.py + docs/experiments/native-image-load-d16.md + README.md:
    • native_mesh_image_d16_ir (runs in pr CTest preset): covers sparse DMASK packing, destination bounds, inactive-lane preservation under narrowed EXEC, neighbor-VGPR preservation, direct compute/pixel/vertex image_load & image_load_mip, and fail-closed refusals.

Verification

Host: Windows 11 (10.0.26200.9974), MSVC C++20 /W4 (zero warnings on edited lines), inbox WARP (10.0.26100.9818), NVIDIA GeForce RTX 5080 (32.0.16.2140; D3D12 debug layer unavailable). Base origin/main f365f125.

  • Built compile_dxil, offscreen_check, native_compute_ir_dump, native_pixel_ir_dump, and startup_indirect_draw_indexed (compiling src/startup_stubs/native_mesh86.inl) in both Debug (dev) and Release (release) with zero warnings on edited lines.
  • ctest --preset pr --no-tests=error -R "^native_mesh_image_d16_ir$": 1/1 passed.
  • Debug & Release focused checks (native_mesh_image_d16_ir, startup_compute_d16_sample_srv_controls, native_direct_mesh, native_direct_container, plus existing WARP & RTX 5080 D16 readbacks): all passed.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 43c061f3 (draft) by reading the diff; not built or run.

Verdict: approve. D16 packing matches the ISA, and every path that cannot yet bind a format-checked view stays refused. No MUST.

  • SHOULD Run a before/after m86 census on f365f125. Offline, the 609 should mostly move, but at run time a mesh D16 heap load still needs a float-exact SRV format (native_mesh86.inl:570). A count of which formats the D16 programs bind would show how many can actually draw.
  • NIT image_result_registers (gfx1013_compute_native.cpp:121) counts 4 registers only for gathers 64, 68, 71, 79 and 87. Those are the only ones the direct lowering accepts (gfx1013_direct_compute.inl:1305), so nothing is undercounted today. A 0x40 <= op < 0x60 test would stay right if more gathers are added, since emit_graphics_loops now trusts this count instead of a fixed 4.
  • NIT #3831 rewrites the entry_barycentric scan this PR edits (gfx1013_direct_graphics.inl:1591), so one of them will need a rebase.
  • Checked, no finding:
    • write_d16_image_result: the channels DMASK selects go into consecutive halves, low half first, with the same RNE helper as the existing D16 sample. Destination overflow is checked before the load. D16 gathers are still refused at decode, so the gather-to-4 rule never meets D16.
    • The mesh Texture1D load now masks out the DMASK and D16 bits (0x3f0ff, 0x7fe00000), refuses DMASK 0 and non-D16 DMASK other than 15, and preserves inactive lanes for vec_count registers.
    • Fail-closed elsewhere: bound compute loads (d16_load_srv) are refused by name at publication, Mesh86 pixel views refuse the kind ("unsupported native Mesh86 SRV shape"), and pixel heap images accept only texture_srv.

Tests: native_mesh_image_d16_ir is in the pr filter. It covers sparse DMASK packing, destination bounds, inactive lanes, and the compute/pixel/vertex image_load/image_load_mip forms.

@lukaslw-lab lukaslw-lab left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review on b447ef5b (rebased on 5770f14e: new cache field mesh_texture_heap_d16, view kind d16_load_srv after root_buffer_uav, image result width in the helper-touch tracking).

Verdict: approve.

Census, same capture and method as before (6,685 distinct mesh programs), main 5770f14e vs this head:

Programs
Translate, main / with this PR 1,047 / 1,047
Lost / gained 0 / 0
First refusal moved 796

Largest moves: Texture1D heap contract → unsupported mesh image load dmask 187; unsupported image dimension or D16 → s_load_dwordx4 root mapping 179, → unproven packed mesh signature rows 169, → graphics register undefined on an incoming path 168, → position mask 56, → v_pack_b32_f16 constant source 15.

Checked:

  • The cache tuple grows to 22 with the visitor, the reader's kind bound and view_kind_name updated together. The frontend revision is the SHA-256 of these sources, so old cache rows cannot be read with the new layout.
  • The helper-touch tracking in the graphics frontend now uses image_result_registers(op). (Correction: I first wrote that an overlap check for images and MUBUF changed here; this head does not change one.)

Main has since merged #3758 (mesh image_load through a full table descriptor) next to this code. The rebase will need a fresh census.

Update: the first run was on a main that refused 257 programs early (my #3707, #3892; fixed by #3893). I reran main 5770f14e and this head, both with that fix: 796 moved (the table and list above now show this run), 0 lost, 0 gained.

AI-assisted.

Share the table and remapped Texture1D paths across level-zero and mip loads. Preserve the separate full-descriptor heap path and use the merged Mesh86 table format validator.
A seeded destination now preserves its incoming value when EXEC excludes the lane. Assert that the selected value reaches the export and keep a refusal for a destination with no incoming value.
Keep the current descriptor-token and image-field cache entries, and append the D16 load binding without changing existing binding values. The mesh contract is reconciled separately.
Use the packed register width and the existing address, descriptor and EXEC rules for D16 mesh loads. Bind table loads as format-aware D16 SRVs and keep the float-exact gate for remapped Texture1D loads. Cover mip addressing, packed writes and refusal diagnostics.
Use an explicit function template for the output writer so the native compute pack refusal frontend can build in C++17. Remove the unused C++20 bit header.
@timbot103

Copy link
Copy Markdown
Contributor Author

Stacked on #3844. This branch now contains #3844's commits, because both PRs rewrite the same mesh image-load path, as noted in review. Please land #3844 first. Once it merges, only this PR's own commits remain in the diff.

  • cf1c9832 merges this PR onto shader: extend mesh image load contracts (Part of #3703) #3844 as updated for main 67862ee4. The reviewed commit b447ef5b is unchanged.
  • 9ef97598 moves the D16 packing into shader: extend mesh image load contracts (Part of #3703) #3844's addressing and descriptor checks for both remapped and bound mesh textures, with a float-exact format gate on both paths. The cache merge keeps main's heap-token binding IDs and appends the D16 entries. The fixtures now expect D16 to be accepted, with updated refusal messages and a D16 mip-load case.
  • 25cdcd03 replaces an abbreviated function template with an explicit template. native_compute_pack_refusal_check builds the frontend as C++17, which main CI compiles but PR CI does not.

Tests, Windows 11 26200 with RTX 5080 and WARP:

  • ctest --preset pr --no-tests=error -R '^native_mesh_image_(d16|contract)_ir$' passed 2/2.
  • In Debug, the mesh filter plus image_load|d16|native_compute_|native_direct_cache passed 90, with 0 failures and 5 skips. The skips were wave32 fixtures, which WARP's 4-lane waves don't support.
  • In Release the same filter passed 87, with 3 failures and 5 skips. The 3 failures were the existing asynchronous WARP allocation fixtures, and all three passed with X2W_SYNC_MESH_REQUESTS=1.
  • startup_image_load_d16 passed on WARP and the RTX 5080. All five compute D16 sample cases matched on the RTX 5080.

Keep the D16 delta on top of the merged mesh image contract and preserve the current mesh and pixel lowering paths.
@timbot103

Copy link
Copy Markdown
Contributor Author

No longer stacked: #3844 has merged. Merged main (f3ab02fe) into this branch (67cb41ec), with the D16 changes applied to main's mesh lowering, docs and the two fixtures. The PR diff against main now contains only the D16 work. The PR preset passes 2/2. With the mesh, image-load and D16 filter, Debug passed 91 with 1 failure and 5 skips, and Release passed 88 with 4 failures and 5 skips. Those failures also fail on clean main: native_mesh_entry_registers_ir (fixed in #3909) and the asynchronous WARP allocation fixtures, which pass with X2W_SYNC_MESH_REQUESTS=1. The skips are WARP's 4-lane waves. The D16 readbacks pass on WARP and the RTX 5080.

@timbot103
timbot103 marked this pull request as ready for review December 3, 2026 01:38
@timbot103

Copy link
Copy Markdown
Contributor Author

Marked Ready for review now that #3844 has merged and this branch no longer depends on it. This keeps us within 5 non-draft PRs per #3514.

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

Independently reviewed c21baf7. D16 loads use packed result widths at EXEC joins, the Mesh86 binder requires float-exact formats, and the native cache key fingerprints the changed source and serializer. On MSVC Debug, Windows 11 build 26300, ctest --preset dev --no-tests=error -j 1 covered native_mesh_image_(d16|contract)ir, native_direct_mesh, native_mesh_entry_registers_ir, native_direct_cache(key_)?controls and startup_compute_d16_sample_srv_(controls|warp|hardware). Eight passed, including the RTX 4060 Laptop (616.56) sample regression, and WARP reported capability skip 77 for the wave32 sample. The source-built Mesh86 evidence here is IR and binding-contract validation. Changing the high-half shift from 16 to 17 failed the D16 fixture; the restored head passed. The former mesh-entry CI failure also passed after the baseline update.

@R0Y00
R0Y00 enabled auto-merge (squash) December 3, 2026 02:18
@R0Y00
R0Y00 merged commit 7db6f19 into R0Y00:main Dec 3, 2026
5 checks passed
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