Repository navigation
shader: lower compute buffer_store_format_d16_x in gfx2hlsl - #2478
Conversation
Refs R0Y00#2274. Adds compute-stage MUBUF buffer_store_format_d16_x (opcode 0x84) lowering to tools/startup/gfx2hlsl.py: - Validates four untouched descriptor words from a fixed native table entry (refusing modified descriptors including stride clears, shared load/store descriptors, missing local table provenance after branches, non-compute stages, lane-mask soffset, illegal binary lds/reserved MUBUF bits, bad operand shapes, and unsupported modifiers glc/slc/dlc/tfe/lds). - Emits uav <slot> table <param> <offset> plus udsrc entries uav_descword3, uav_stride (unmasked DW1 >> 16, so stride > 0x3fffu rejects DW1[31:30] CACHE_SWIZZLE/SWIZZLE_ENABLE) and uav_numrecords, under an if (exec & 1) guard when EXEC is not proven entry-full. - Supports 1-channel formats BUF_FMT_32_FLOAT (22), BUF_FMT_16_FLOAT (13), BUF_FMT_16_UNORM (7), BUF_FMT_16_SNORM (8), BUF_FMT_16_UINT (11) and BUF_FMT_16_SINT (12) in both GFX10 unified and legacy DFMT/NFMT encodings, checking DST_SEL_X == 4, zero reserved/swizzle/ADD_TID_ENABLE/TYPE flags, and RDNA 2 ISA §8.1.5 Table 35 bounds modes: OOB_SELECT 0 (structured, stride != 0, rec_off = voff + imm_off checked against stride while soffset adds to base) and OOB_SELECT 3 (raw, stride == 0, soffset + rec_off + elem_bytes <= num_records). OOB_SELECT 1/2, mismatched stride/OOB_SELECT, 32-bit overflow, misaligned addresses, unsupported formats/flags and OOB lanes are no-ops. - Uses 4-byte aligned Store for BUF_FMT_32_FLOAT and a lock-free InterlockedCompareExchange CAS loop for 2-byte aligned 16-bit formats. Adds tests/startup_compute_store_d16_x_check.py wired in CMakeLists.txt, .github/workflows/windows.yml and docs/experiments.md. AI-assisted: implementation and tests drafted and verified with an AI coding assistant.
Six mutations on the descriptor validation, all caughtBaseline:
The fourth row is the one worth having. The last row matters for a different reason: What the set says about the shape of this checkSix independent refusal conditions per descriptor word, all pinned — this is a validation surface tested as a validation surface, not just "the happy path stores the right value". For a store that can silently write the wrong element size into a title's buffer, that is the right emphasis: every one of the six is a way to write the right value in the wrong place, which no later comparison would catch. One note
AI-assisted; the six mutations were run locally on Windows 11 build 26300.9974. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 93da95ef (comment only, no approval or merge).
Scope. Lowers compute buffer_store_format_d16_x in tools/startup/gfx2hlsl.py. Adds one test file, CTest entries in CMakeLists.txt, a short docs/experiments.md note, and two lines in .github/workflows/windows.yml.
CI workflow change. The two added lines register tests/startup_compute_store_d16_x_check.py in the existing list and in the Linux checks. They follow sibling entries. The PR's own CI run on this exact head (93da95ef) passed "Assemble and translate gfx1013 fixtures", "Build and test on Windows" and "Run platform-independent Python checks on Linux", so the changed workflow was exercised.
Duplicates. No other open or merged PR lowers this opcode. #2165 covers d16 buffer loads, a different slice. The claim is on #2274 by the author.
Mutations I ran (then reverted with git checkout -- .).
- Accepting
OOB_SELECT 1invalidate_store_d16_x_word3: the offline check fails ("accepted, expected a refusal naming 'OOB_SELECT 1'"). Caught. - Removing the
rec_off > stride - elem_bytesbound from the emitted HLSL: the offline check still passes. That is expected, because the emitted HLSL is only exercised by the WARP dispatch andcontroltests. Those are the tests that need Windows, and I did not run them.
Things to know.
- Windows results: the author reports WARP and hardware results for
93da95ef(19/19). I did not run Win2025 and did not verify those numbers. A Win2025 WARP pass on this head is still needed. - The test has a
tfesnippet that my localllvm-mc-19rejects ("invalid operand"). I could not runllvm-mc-15locally. CI's fixture job, which usesllvm-mc-15, passed on this head, so I treat it as a local tool version difference. - The PR is 33 commits behind main (
behind=33). I did not runupdate-branch, because it would change the head SHA and void the author's test results. - Open design question for @R0Y00: none found. This PR does not claim to advance game startup, and I did not check any startup behaviour.
Commands run locally.
python3 -B tests/startup_compute_store_d16_x_check.py(no arguments): pass.python3 tests/docs_links_check.pyandpython3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.- The two mutations above.
AI-assisted; commands listed were executed locally.
|
The CAS fixture tests neighboring halves and contention on a padded UAV. Please also cover the host backing boundary. The guest check can allow a 2-byte write, but the translated Load and CompareExchange need the entire aligned DWORD inside the bound raw UAV. A short binding can otherwise drop the update or make the retry loop rely on an out-of-view atomic. Show how the runtime binding or shader proves the enclosing DWORD is present, and add a short-binding control beside a valid padded case. Keep this separate from the guest NumRecords/stride checks and from actual slot 67 runtime coverage. |
# Conflicts: # CMakeLists.txt
…-d16-x # Conflicts: # tools/startup/gfx2hlsl.py
|
AI-assisted update addressing the host-backing-boundary review feedback (@R0Y00) and descriptor bit-field note (@ChazY11) at commit
|
…-d16-x # Conflicts: # tests/compute_check.cpp # tools/startup/gfx2hlsl.py
|
While testing the sized-UAV runner used by #2530, I found a fixture result that depends on the D3D12 debug layer being installed. This is in the d16 test inherited unchanged from On Windows 11 build 26100.9711 without the optional debug layer I ran the same Debug binary on Intel UHD 770 (32.0.101.5973), RTX 4060 (32.0.15.9579) and WARP (10.0.26100.9711). On each, The reproduction command is |
tedin7
left a comment
There was a problem hiding this comment.
Review of head c03ecd6 (main merged in, CI green): not ready to merge, one blocking test problem.
Blocking: the dispatch fixtures require the D3D12 debug layer.
tests/startup_compute_store_d16_x_check.py:693 asserts 'debug_errors=0 debug_warnings=0' in run.stdout. On a machine without the debug layer the runner prints debug_layer=unavailable and no such line, so the test fails even though the data compare is clean. This matches the report from @RavenCurseBurg above.
Win2025 WARP (dev, Windows Server 2025, WARP only, debug layer unavailable), regex startup_compute_store_d16_x:
startup_compute_store_d16_x_warpFAIL at caseF-f32:compared_words=320 mismatches=0, then the assertion above fires.b-short-binding_warpandb-tight-host-guard_warpFAIL: the requiredcontrol ... rejected at word=text is not printed (same cause: the earlier assertion aborts the run).- The same three fail on the
_hardwarevariants (the VM has only WARP, so those are the same failure, not extra signal). startup_compute_store_d16_x_controlsand the other controls pass.
Release phase did not run (dev phase failed).
How to fix: accept debug_layer=unavailable (check debug_errors=0 debug_warnings=0 only when the runner reports the layer as active), keeping the strict check where the layer exists. The data compare (mismatches=0) stays the main guard.
Checked and fine
- OOB_SELECT 0/3 handling and stride pairing, 32-bit overflow guards on
soff + rec_offandidx * stride, CAS loop on the enclosing dword, host-backing guard (uav_words), windows.yml entries (both lists), CMake controls list. - No other open or merged PR covers
buffer_store_format_d16_x. - Mutation note (Linux only): removing
rec_off > stride - elem_bytesor theoob_selrefusal from the generated HLSL is not caught by the Python-only check. These runtime guards are covered only by the GPU dispatch controls, so they must run green on a machine without the debug layer.
Commands run: python3 tests/startup_compute_store_d16_x_check.py (pass), python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD (all clean), x2w_pipe.py win2025 2478 --wait 7200 --keep-release --regex startup_compute_store_d16_x (dev: 6 failed, as above).
AI-assisted; commands listed were executed locally.
…16_x_check When the optional Windows Graphics Tools debug layer is absent, keep word comparisons and mutant mismatch checks active while reporting `debug_layer=unavailable`; continue requiring zero errors/warnings whenever `debug_layer=enabled` is reported.
|
Thank you @RavenCurseBurg for catching that and testing the sized-UAV runner across machines without the optional Windows Graphics Tools debug layer! Fixed in
|
|
Thank you @tedin7 for the thorough verification and Win2025 trace on Pushed
|
|
I resolved the registration conflict in |
|
AMD run for
One thing before merge: AI-assisted; commands listed were executed locally. |
* shader: lower compute buffer_store_format_d16_x in gfx2hlsl Refs #2274. Adds compute-stage MUBUF buffer_store_format_d16_x (opcode 0x84) lowering to tools/startup/gfx2hlsl.py: - Validates four untouched descriptor words from a fixed native table entry (refusing modified descriptors including stride clears, shared load/store descriptors, missing local table provenance after branches, non-compute stages, lane-mask soffset, illegal binary lds/reserved MUBUF bits, bad operand shapes, and unsupported modifiers glc/slc/dlc/tfe/lds). - Emits uav <slot> table <param> <offset> plus udsrc entries uav_descword3, uav_stride (unmasked DW1 >> 16, so stride > 0x3fffu rejects DW1[31:30] CACHE_SWIZZLE/SWIZZLE_ENABLE) and uav_numrecords, under an if (exec & 1) guard when EXEC is not proven entry-full. - Supports 1-channel formats BUF_FMT_32_FLOAT (22), BUF_FMT_16_FLOAT (13), BUF_FMT_16_UNORM (7), BUF_FMT_16_SNORM (8), BUF_FMT_16_UINT (11) and BUF_FMT_16_SINT (12) in both GFX10 unified and legacy DFMT/NFMT encodings, checking DST_SEL_X == 4, zero reserved/swizzle/ADD_TID_ENABLE/TYPE flags, and RDNA 2 ISA §8.1.5 Table 35 bounds modes: OOB_SELECT 0 (structured, stride != 0, rec_off = voff + imm_off checked against stride while soffset adds to base) and OOB_SELECT 3 (raw, stride == 0, soffset + rec_off + elem_bytes <= num_records). OOB_SELECT 1/2, mismatched stride/OOB_SELECT, 32-bit overflow, misaligned addresses, unsupported formats/flags and OOB lanes are no-ops. - Uses 4-byte aligned Store for BUF_FMT_32_FLOAT and a lock-free InterlockedCompareExchange CAS loop for 2-byte aligned 16-bit formats. Adds tests/startup_compute_store_d16_x_check.py wired in CMakeLists.txt, .github/workflows/windows.yml and docs/experiments.md. AI-assisted: implementation and tests drafted and verified with an AI coding assistant. * shader: guard buffer_store_format_d16_x against host UAV bounds * shader: lower compute buffer_store_format_xyzw in gfx2hlsl Refs #2274. Depends on #2478, whose descriptor, entry-constant, bounds and EXEC handling this reuses. Lowers compute MUBUF buffer_store_format_xyzw (0x07) in the idxen form with a non-negative inline soffset and optional offset:. FORMAT, stride and num_records are read at dispatch from uav_descword3, uav_stride and uav_numrecords, with the OOB_SELECT 0/3 bounds of buffer_store_format_d16_x (the bounds lines are checked identical). Only the 4-channel formats of tools/compute_store_aot.py write (32x4 UINT/FLOAT, 16x4 FLOAT through pack16_rne, 8_8_8_8 and 2_10_10_10 UNORM, unified and legacy encodings, identity DST_SEL); as in that tool, a format of another channel count writes nothing. offen, off, register soffset, cache/tfe/lds modifiers and non-compute stages are refused by name. Adds tests/startup_compute_store_format_xyzw_check.py, registered in CMakeLists.txt, .github/workflows/windows.yml and AGENTS.md, and a docs/experiments.md entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shader: keep the unknown-op refusal for xyzw stores outside compute Outside a compute stage buffer_store_format_xyzw keeps the bare mnemonic, as buffer_store_format_d16_x and buffer_store_dword do. The index and data are evaluated before the UAV and its entry constants are registered. The experiments entry drops a claim about captured programs and names the prebuilt WARP runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shader: guard buffer_store_format_xyzw against host UAV bounds The xyzw helper now takes the host-view check that #2478 added to the d16_x helper: after the guest bounds and the alignment check it reads the bound view size with GetDimensions and drops an element that would pass its end. The expected helper text and the experiments entry follow; the entry also corrects the case count to 19. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: dispatch xyzw stores through sized descriptor-table views The helper reads the bound view size with GetDimensions, which has no defined result on a root descriptor. Dispatch through --compute-store-sized-case, as the d16_x check does. The experiments entry records which runner mode produced the local WARP result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Vladimir <39053957+Vladimir-Human@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: tedin7 <110300616+tedin7@users.noreply.github.com>
AI-assisted PR. (Claimed
buffer_store_format_d16_xon #2274.)Summary
Lowers compute
buffer_store_format_d16_x(MUBUF) intools/startup/gfx2hlsl.py:OOB_SELECThandling (0=SQ_OOB_INDEX_AND_OFFSETrequiringstride != 0;3=SQ_OOB_COMPLETErequiringstride == 0), refusing invalid modes1/2and mismatched strides cleanly.soffsetseparate fromrec_off = voff + imm_offbounds checks with 32-bit overflow guards.InterlockedCompareExchangeCAS loop for 16-bit half-word read-modify-write under concurrent thread contention.CACHE_SWIZZLE,SWIZZLE_ENABLE,lds/reserved MUBUF bits, lane-masksoffset, and RDNA 2binary16->unorm16/snorm16rounding.Verification (commit
93da95ef)tools/run_checks_parallel.py(6 checks includingstartup_compute_store_d16_x_check.py): 6/6 PASSctest --test-dir build-store-d16x -C Release -j 1 -R "^startup_compute_store_d16_x" --output-on-failure -V: 19/19 PASS, 0 failed, 0 skipped (WARP & RTX 4070 SUPER with D3D12 debug layer:debug_errors=0 debug_warnings=0)binary16->unorm16/snorm16check: 0 RNE diffs.git merge-tree --write-treeclean against latestorigin/main(1a0e506d) and PR#2404.