Skip to content

shader: lower image_store on SQ_RSRC_IMG_2D_ARRAY in gfx2hlsl - #2744

Merged
R0Y00 merged 5 commits into
R0Y00:mainfrom
triggered02:startup/image-store-2d-array
Nov 26, 2026
Merged

R0Y00 merged 5 commits into
R0Y00:mainfrom
triggered02:startup/image-store-2d-array

Conversation

@triggered02

@triggered02 triggered02 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Lowers the plain image_store form on dim:SQ_RSRC_IMG_2D_ARRAY, which adds the full-mask FP32 compute translation. Refs #2742.

What changed

  • tools/startup/gfx2hlsl.py: op_image_store accepts SQ_RSRC_IMG_2D_ARRAY — three address registers (x, y, layer), uav(key, 'tex2da'), uint3 index — and the stored-image declaration map gains RWTexture2DArray<float4>. The compute manifest kind follows the UAV kind (tex2da for arrays, unchanged tex2d for 2D). Every existing restriction is untouched: dmask:0xf only, four data VGPRs (packed D16 array stores stay refused), integer coordinates, the EXEC guard, fixed_table_image for compute and the existing 2D pixel path. 1D/3D/CUBE keep the verbatim refusal.
  • Emitted for arrays: w0[uint3(v8, v9, v10)] = asfloat(uint4(v14, v15, v16, v17)); with RWTexture2DArray<float4> w0 : register(u0); and manifest uav 0 tex2da float table 1 64 channels 4. 2D output is byte-identical to before (w0[uint2(v8, v9)], RWTexture2D, uav 0 tex2d).
  • Fixtures: tests/startup_compute_image_store_check.py gains the array case — layer 1 (middle of a 4-layer, 3-mip array) and layer 3 (last), 16 texels × 4 words per layer with pinned values, verified against a 5,376-word sentinel-prefilled reference (first changed index 1344 / 4032, last 1503 / 4191, remaining 5,312 words untouched), plus refusals for 2-register and 4-register array addresses and for 1D/3D/CUBE. Dispatch cases are wired into the existing startup_compute_image_store_* test (selector 1<<31): layer 1 and 3 → 0 mismatches; omission → 64; one-layer-off → 128.
  • tests/startup_pixel_image_store_check.py: keeps the original pixel-stage array refusal and all 2D controls.
  • docs/experiments.md: one paragraph next to the existing image-store notes.

Verified on 38dec200 (parent fd033046)

startup_compute_image_store_check.py     0
startup_pixel_image_store_check.py       0
startup_image_2d_array_check.py          0
startup_translator_check.py              0
form_coverage_check.py                   0
docs_links_check.py                      0
startup_gfx2hlsl_refusals_check.py       0
git diff --check                         0

Fail-first mutants (temporary, reverted): 2 address registers for arrays → Unsupported: image_store with 3 address registers: x, y and layer expected; uint2 index with the slice dropped → AssertionError on the emitted-HLSL pin; dim guard widened to accept 1D/3D/CUBE → existing 3D control and the new 1D/3D/CUBE loop both fail.

NOT established

  • Array bounds/clamping: the translator does not clamp; D3D drops out-of-view writes and console behaviour is unmeasured.
  • The runtime view type/binding for a 2D-array UAV: the manifest now says tex2da, but the shipped runtime parser still accepts only uav … tex2d float table … channels 4 and pixel binding rejects arrays — this PR is translation-only.
  • Partial-dmask arrays (still refused, no fixture), compute d16 array stores (shared path, no fixture), and the GPU dispatch/reassembly cases — those dispatch cases are wired but were not executed locally (no DXC/offscreen_check/llvm-mc in that environment; the test's existing capability-skip convention applies).

Refs #2742. Refs #1545. No game data; synthetic ISA bytes and source-built fixtures only.

AI-assisted.

Maintainer retest at 7e5433a

This is the standalone full-mask compute FP32 array emission slice. The startup runtime still needs the array UAV consumer in #2742. Packed D16 and pixel-stage array stores remain refused. Windows Release on WARP and RTX 4060 Laptop passed all 12 compute image-store, packed D16, pixel store and 2D-array CTests, zero skips. Both array cases compare 5,376 words. The omitted-store and wrong-layer controls fail at 64 and 128 words on each adapter. Windows 11 build 26200, debug layer enabled.

cmake --build --preset release --target offscreen_check
ctest --preset release --no-tests=error -j 1 -R "^(startup_compute_image_store(_d16)?(_warp|_hardware)?|startup_pixel_image_store_(controls|warp|hardware)|startup_image_2d_array_(controls|warp|hardware))$" -V

op_image_store accepted only dim:SQ_RSRC_IMG_2D. The 2D-array form now takes x, y and the layer as three address registers, binds RWTexture2DArray<float4> (manifest kind tex2da) and stores through uint3(x, y, layer), like the sample and load array forms. The dmask:0xf, four-data-VGPR (two for the compute d16 form), integer-coordinate, EXEC-guard, fixed-table and pixel descriptor paths are unchanged, and 1D, 3D and cube keep the same refusal message.

The compute fixture stores at layer 1 (middle of a four-layer array) and layer 3 (its last entry), compares all 5,376 words of every layer and mip, and pins omitted-store (64 words) and one-layer-off (128 words) controls. The pixel fixture checks the descriptor path emits uint3 into a RWTexture2DArray while the 2D form stays RWTexture2D/uint2.

Refs R0Y00#2742
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T05:27:59.668551Z 38dec20 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38dec200fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/startup/gfx2hlsl.py Resolved

@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 e7fafe5 (the PR's own diff is unchanged by the main merge; first read at 38dec20).

Checked:

  • op_image_store now accepts SQ_RSRC_IMG_2D_ARRAY, requires 3 address registers (x, y, layer), binds the view as tex2da and emits RWTexture2DArray<float4> plus uint3 indexing. The manifest line now carries the resource kind (uav N tex2da float ... channels 4). Sibling declaration table and manifest writer are both extended; the pixel path shares the same code.
  • Tests: the compute check adds an assembled 2D-array program (layers 1 and 3), HLSL and manifest assertions, and a full reference of the 4-layer, 3-mip array. Only mip 0 of the target layer may change, every other word keeps its sentinel. The pixel check gets the matching extension. The D3D12 readback side lives in the existing compute_check fixture path.
  • Mutations (each made the compute check fail, then reverted): forcing array = False; binding tex2d instead of tex2da.
  • No other open or merged PR covers the 2D-array store (#1649 and #2155 cover the other forms).

Commands run locally:

  • python3 tests/startup_compute_image_store_check.py and tests/startup_pixel_image_store_check.py: pass
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: pass
  • remote_pycheck.sh --compare origin/main: no failures caused by this PR (the two differing scripts exist only on newer main)

No blocking findings. Windows WARP receipt follows separately.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head e7fafe5 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit e7fafe571c22f638a2264ff5d22ff9efc946d5bd:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 5.19s (configure 2.42s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check -- -j 2): 1.45s (configure 2.56s)
  • Windows Python checks: tests/startup_compute_image_store_check.py ok (0.8s), tests/startup_pixel_image_store_check.py ok (0.2s)
  • sccache: 3/5 hits; wall 21.4s

AI-assisted; commands listed were executed locally.

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

Correction to my earlier review of e7fafe5: CI is red on this head, so this PR is not ready to merge.

Failing job: "Assemble and translate gfx1013 fixtures" (run 45761748737).

  • tests/startup_compute_image_store_check.py --llvm-mc llvm-mc-15 stops at line 99 with AssertionError: 1:
    assemble(llvm_mc, ARRAY_SOURCE.format(layer=layer)) == array_program(layer) is false for layer 1.
  • So at least one hand-written word in ARRAY_PROLOGUE, ARRAY_SLICE, ARRAY_DATA, ARRAY_STORE or ARRAY_END differs from what LLVM 15 encodes for the matching line in ARRAY_SOURCE. My Linux run did not catch it because it has no llvm-mc, so that comparison was skipped; the earlier "pass" for this check only covered the translator side.
  • Likely suspects: the image_store word pair (280f20f0080e0600) and the two v_lshl_add_u32 words. Please diff the llvm-mc-15 output against each constant, word by word.

Left for the author: fix the bytes, push, and the Windows receipt above stays valid only if the translator is unchanged. Not merging.

AI-assisted; commands listed were executed locally.

@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

In addition to the LLVM 15 byte mismatch already in review, please keep #2742 open while the emitted array manifest has no startup runtime consumer. For a narrow translator-only PR, use Refs #2742, retain the pixel and packed-half array refusals, and keep emission checks distinct from runtime acceptance. If you want this PR to finish the FP32 compute path, please add the corresponding production manifest/view binding and use that path for the readback. The fixture should bind a nonzero FirstArraySlice, check adjacent untouched slices, and catch a wrong-layer or dropped-EXEC mutation. The standalone offscreen UAV option alone does not validate startup binding.

The array fixture's data moves v14 = 0x40000000 and v15 = 0x40400000 did not match llvm-mc-15: 0x40000000 is one of the inline float constants LLVM prints (2.0), so the assembler encodes the four-byte inline form (0x7e1c02f4) instead of the eight-byte literal (0xff021c7e 0x00000040). The assembled program is then 80 bytes, not the fixture's 84, and the array comparison in 'startup_compute_image_store_check.py --llvm-mc llvm-mc-15' fails; only that CI job compares the hand-written words because no llvm-mc is available elsewhere.

Use literal data words whose encoding is already pinned against llvm-mc-15: v14 = 0x3f400000 and v15 = 0x3e800000 are the literal moves of tests/startup_image_2d_array_check.py (hand-written v0/v1 heads ff02007e/ff02027e), changed only in the VOP1 vdst field (bits 24:17) to 14 and 15. The prologue, slice moves, v16/v17, image_store and s_endpgm words are unchanged: they are verbatim from compute_mimg_image_uav_load_check.WORDS (LLVM 15.0.7), compute_mimg_float_store_check.WORDS and compute_mimg_float_store_layers ARRAY_WORDS. ARRAY_VALUES and the dispatch first-mismatch needles follow the new words, and a control now asserts that the data words avoid G.D.INLINE_FLOAT_LITERALS so this encoding difference is caught without llvm-mc.

Refs R0Y00#2742
@triggered02

Copy link
Copy Markdown
Contributor Author

Fixed in 42637b0a (test: fix the 2D-array image_store fixture words for llvm-mc-15), on top of 38dec200 — fast-forward, the translator is unchanged so your WARP receipt still applies.

You were right that the check fails at line 99, but the failing words were not image_store or the v_lshl_add pair — both are verbatim LLVM-15 words (the image_store pair 280f20f0 080e0600 is byte-identical to compute_mimg_float_store_layers_check.ARRAY_WORDS, whose source line is the same MIMG store). The mismatch was the v14 data literal:

line old new
v_mov_b32_e32 v14, … ff021c7e 00000040 (0x40000000) ff021c7e 0000403f (0x3f400000)
v_mov_b32_e32 v15, … ff021e7e 00004040 (0x40400000) ff021e7e 0000803e (0x3e800000)

Root cause: 0x40000000 is one of LLVM's inline float constants (2.0, in INLINE_FLOAT_LITERALS), so llvm-mc-15 assembles v_mov_b32_e32 v14, 0x40000000 as the 4-byte inline form 0x7e1c02f4 rather than the 8-byte literal I had written. Assembled length 80 ≠ the fixture's 84, so the equality failed. The pure-Python decoder prints the same text for both encodings, which is why the local run never saw it. 0x40400000 (3.0) is not inline, but v15 was moved to another directly-CI-proof literal spelling (0x3e800000 = 0.25) so both data moves are covered by fixtures that already run llvm-mc-15 in CI.

Evidence behind the new bytes (no llvm-mc on this host, so this is derivation from CI-pinned fixtures plus a disassembler cross-check):

  • prologue + wait are byte-identical to the prefix of compute_mimg_image_uav_load_check.WORDS ("Little-endian instruction words from LLVM 15.0.7");
  • 8102147e (v10,1) is verbatim from compute_mimg_float_store_check.WORDS; 8302147e (v10,3) uses the same VOP1 inline-integer field;
  • v14/v15 come from startup_image_2d_array_check.SAMPLE_WORDS (that test assembles with llvm-mc-15 in CI), changing only the VOP1 vdst bits 24:17;
  • v16/v17 and s_endpgm are verbatim from the float-store fixture;
  • tools/disasm_rdna2.py decodes both array_program(1) and array_program(3) to 13 instructions whose text equals ARRAY_SOURCE line by line.

Also added a local guard: assert not set(ARRAY_VALUES) & set(G.D.INLINE_FLOAT_LITERALS) so a data word can never silently become an inline constant again without llvm-mc present. ARRAY_VALUES and the dispatch first-mismatch needles follow the new literals (counts unchanged: 64 omitted / 128 one-layer-off).

Not established locally: the real --llvm-mc llvm-mc-15 comparison (CI is the confirmation). If CI still fails, the one word not verbatim from an llvm-mc-pinned fixture is 8302147e (v10, 3) and that is where I would look next.

Checks on 42637b0a: startup_compute_image_store_check 0, startup_pixel_image_store_check 0, startup_image_2d_array_check 0, startup_translator_check 0, git diff --check 0.

Copy link
Copy Markdown
Contributor

Hi @triggered02 and @R0Y00 — thanks for the translator work and review guidance. I have a local, AI-assisted runtime follow-up based on c6f140c, reusing the existing FP32 array lowering rather than duplicating it. It consumes the tex2da compute manifest, preserves the caller's array UAV range, and exercises the production startup slot-67/slot-14 binding and fenced GPU readback. Pixel and packed-half array stores remain refused.

On Windows 10 build 19045 (DXC 1.8.2502.11), both WARP (10.0.19041.5794) and RX 7900 XT (32.0.32029.2010) passed: a six-slice RGBA32_FLOAT resource with FirstArraySlice=1, ArraySize=4, relative layers 1 and 3 (physical slices 2 and 4), full and partial EXEC, all 6,144 words compared with zero mismatches in each positive case. Wrong-layer and dropped-EXEC mutants produced the expected 128 and 32 mismatches; an incompatible 2D UAV was refused and its 1,024 words remained unchanged. The new CTests passed on both adapters. Debug layer was unavailable; LLVM 15 assembly verification and integration with current main are still pending. Two existing 2D denied-view reason assertions also failed on the unmodified PR head and the local follow-up; I am checking them against main.

Would you prefer that I provide the incremental patch for this PR, or open a separate dependent runtime PR after the translator changes land? I will preserve the original contribution and avoid a competing implementation. No game data; source-built fixtures only. AI-assisted; the GPU tests above were actually run locally.

@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 enabled form is the full-mask compute FP32 array translator and manifest only. The previously accepted packed D16 array case now refuses before emission, and the original pixel array refusal is restored. All 12 independent Release image store and adjacent CTests passed with no skips on WARP and RTX 4060 Laptop. Each array case matched 5,376 words; omission and wrong layer differed at 64 and 128 words respectively on each adapter. #2742 remains open for the production array binding.

@R0Y00
R0Y00 merged commit 624f592 into R0Y00:main Nov 26, 2026
5 checks passed
tedin7 pushed a commit that referenced this pull request Nov 26, 2026
Refs #2742. Depends on the translator-only #2744; preserves upstream author and maintainer changes. AI-assisted; synthetic fixtures only.
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.

4 participants