shader: lower compute buffer_store_format_d16_x in gfx2hlsl #2470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2478"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T17:55:39Z.
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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:41:17Z.
Review: COMMENTED
Review of head
93da95ef(comment only, no approval or merge).Scope. Lowers compute
buffer_store_format_d16_xintools/startup/gfx2hlsl.py. Adds one test file, CTest entries inCMakeLists.txt, a shortdocs/experiments.mdnote, and two lines in.github/workflows/windows.yml.CI workflow change. The two added lines register
tests/startup_compute_store_d16_x_check.pyin 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 -- .).OOB_SELECT 1invalidate_store_d16_x_word3: the offline check fails ("accepted, expected a refusal naming 'OOB_SELECT 1'"). Caught.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.
93da95ef(19/19). I did not run Win2025 and did not verify those numbers. A Win2025 WARP pass on this head is still needed.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.behind=33). I did not runupdate-branch, because it would change the head SHA and void the author's test results.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.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:35:32Z.
Six mutations on the descriptor validation, all caught
Baseline:
buffer_store_format_d16_x unit, format, bounds, CAS, provenance and refusal checks pass, exit 0 — and this check runs with no arguments, so it is in the cross-platform list rather than needing a GPU.validate_store_d16_x_word3STORE_D16_X_WORD3_ZERO_MASK)DST_SEL_Xidentity rule removedOOB_SELECTrule removedFORMATaccepted instead of refusedword3int/range check removedThe fourth row is the one worth having.
code = field if ((word3 >> 24) & 1) else STORE_D16_X_LEGACY_FORMATS.get(field)is a two-generation encoding: the same numericFORMATfield means a different format depending on one bit, so a fixture that only exercises the modern half would pass with the table bypassed. Both halves are covered.The last row matters for a different reason:
not isinstance(word3, int) or isinstance(word3, bool)is the guard against aboolarriving where a word is expected, which is exactly the kind of thing a caller can do by accident (Trueis1). Removing it is caught, so the fixture feeds something that is not a plain int.What the set says about the shape of this check
Six 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
STORE_D16_X_WORD3_ZERO_MASK = 0xcef80000is asserted only through its effect. If a future descriptor gains a flag inside that mask that should be accepted, the constant has to change and the fixture will say so — good. But the constant's name says what it is applied to, not what the set of bits means; a one-line comment listing which V# word 3 fields those bits are (or a link to the ISA table) would let a reader verify the mask rather than trust it.AI-assisted; the six mutations were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T18:52:05Z.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T19:31:19Z.
AI-assisted update addressing the host-backing-boundary review feedback (@R0Y00) and descriptor bit-field note (@ChazY11) at commit
41bd92bf7e8cde64085c3d4d35287b51459bd6a8:Enclosing-DWORD host-backing check in
store_format_d16_x(tools/startup/gfx2hlsl.py):buf.GetDimensions(uav_bytes);and enforces host bounds separately from guestnum_records/stride:BUF_FMT_32_FLOAT(fmt == 22u): checksuav_bytes < 4u || addr > uav_bytes - 4ubeforebuf.Store(addr, ...).uint base = addr & 0xfffffffcu;, checksuav_bytes < 4u || base > uav_bytes - 4ustrictly beforebuf.Load(base)and thebuf.InterlockedCompareExchange(base, ...)loop, so any 2-byte guest write whose enclosing aligned DWORD[base, base + 4)does not fit in the bound host raw UAV returns immediately without an out-of-viewLoador CAS retry.STORE_D16_X_WORD3_ZERO_MASK = 0xcef80000now documents the zeroed V# word 3 fields inline (TYPE[31:30], reserved[27:25],ADD_TID_ENABLE[23],INDEX_STRIDE[22:21], reserved[20:19]).Separate host-backing test & short-binding control (
tests/compute_check.cpp,tests/offscreen_check.cpp,tests/startup_compute_store_d16_x_check.py,CMakeLists.txt):--compute-store-sized-case(descriptor-tableu0raw UAV +t0raw SRV +b0CBV) with an optional 6th argumentuav_words(1..320, validated viastd::from_chars) sizinguav.Buffer.NumElements = output_wordswhile retaining the full 320-word readback check, and switchedstartup_compute_store_d16_x_check.pyto it (GetDimensionsrequires a view descriptor rather than a root UAV).B(guestOOB_SELECT=3, stride=0, num_records=6writing 2-byte halves ataddr = 0, 2, 4):uav_words = 2, 8 bytes): updates DWORD 0 and low half of DWORD 1 while preserving high-half/trailing sentinels.uav_words = 1, 4 bytes,b-short-binding): same shader and guestnum_records = 6; verifies host-bounded readback (DWORD 1 untouched sentinel) in dispatch and rejects atword=1(expected=c5c59abc actual=c5c5c5c5) when checked against the padded expectation.b-tight-host-guard): tighteningbase > uav_bytes - 4utobase > uav_bytes - 8uonuav_words = 2rejects atword=1on both adapters.Local Verification (
41bd92bf):29/29CTest checks (^startup_compute_store_d16_x,compute_desc_numeric,compute_store_aot_desc_numeric,startup_gfx2hlsl_compute) passed across WARP (1414:008c) and NVIDIA GeForce RTX 4070 SUPER (10de:2783) withdebug_errors=0 debug_warnings=0.startup_compute_store_d16_x_check.py,compute_desc_numeric_check.py,startup_gfx2hlsl_compute_check.py, andstartup_mesh57_skeleton_check.pyall passed (awaiting GitHub Actions Windows + Linux CI on the new HEAD).Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:43:53Z.
Review: COMMENTED
Review of head
c03ecd69(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:693asserts'debug_errors=0 debug_warnings=0' in run.stdout. On a machine without the debug layer the runner printsdebug_layer=unavailableand 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)._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(checkdebug_errors=0 debug_warnings=0only 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
soff + rec_offandidx * stride, CAS loop on the enclosing dword, host-backing guard (uav_words), windows.yml entries (both lists), CMake controls list.buffer_store_format_d16_x.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.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T20:34:16Z.
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
d96ffa28into3014c7b7. The Server 2025 WARP run with the debug layer enabled passed all 12 d16 CTests. Server 2025 logsOn 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,
dispatchproducedcompared_words=320 mismatches=0forF-f32and then raised at the assertion requiring the literaldebug_errors=0 debug_warnings=0. The renderer printsdebug_layer=unavailablein this environment. The eight ordinary mutation controls passed.b-short-bindingandb-tight-host-guardeach detected the expected mismatch at word 1, then raised at the same debug-counter assertion.The reproduction command is
python -B tests/startup_compute_store_d16_x_check.py dispatch <dxc> <offscreen_check> hardware. The positive readback and the ability to certify a clear D3D12 debug queue are independently observable. The fixture could keep word comparisons active on those machines and report the debug-only portion as unavailable. On a device with a debug queue the zero-error requirement remains testable.Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T20:49:11Z.
Thank you @RavenCurseBurg for catching that and testing the sized-UAV runner across machines without the optional Windows Graphics Tools debug layer!
Fixed in
f02b35cd(tests/startup_compute_store_d16_x_check.py):_check_debug_layer(stdout, label)matching the repo's existing pattern:debug_layer=enabledis reported, it still strictly assertsdebug_errors=0 debug_warnings=0.debug_layer=unavailableis reported, it keeps all GPU word comparisons (mismatches=0, CaseCcontention sentinels) andb-short-binding/b-tight-host-guardmismatch assertions active and notes(debug_layer=unavailable)in the summary output.debug_layer=still fails.check_controls()covering all debug-layer states (enabledclean,enablednon-zero/missing errors,unavailable, and missing status).startup_compute_store_d16_x_check.pyunit checks pass,docs_links_check.py+bidi_controls_check.pypass, and allstartup_compute_store_d16_xCTests pass on WARP and RTX 4070 SUPER (debug_layer=enabled,debug_errors=0 debug_warnings=0).Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T20:51:47Z.
Thank you @tedin7 for the thorough verification and Win2025 trace on
c03ecd69!Pushed
f02b35cdto resolve that blockingdebug_layer=unavailablefailure intests/startup_compute_store_d16_x_check.py:_check_debug_layer()now assertsdebug_errors=0 debug_warnings=0strictly wheneverdebug_layer=enabled, allowsdebug_layer=unavailablewhile keeping all GPU word comparisons (mismatches=0, CaseCcontention sentinels) andb-short-binding/b-tight-host-guardmismatch controls active, and still fails ifdebug_layer=is missing.check_controls()now test all four debug-layer states.f02b35cd: Python unit +docs_links_check.py+bidi_controls_check.pypass, and all 23/23startup_compute_store_d16_xCTests pass on WARP and RTX 4070 SUPER (debug_layer=enabled,debug_errors=0 debug_warnings=0). CI is currently re-running onf02b35cd.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T21:22:49Z.
I resolved the registration conflict in
465aeff4, preserving both the upstream FMA controls and all d16 rows. On the resulting tree the Release WARP and RTX 4060 Laptop suite passed 25/25. The short binding and tight host guard controls still report the expected mismatch, and both nonmutated dispatches check the protected words. Keeping this scoped to d16 and the sized UAV fixture. #2530 remains behind this parent.Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T21:27:39Z.
AMD run for
465aeff4, complementing @R0Y00's WARP and RTX 4060 Laptop result.--preset dev, full build at465aeff4. AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010) and WARP 10.0.26100.9818, with the D3D12 debug layer installed, so thedebug_errors=0assertion applies here.ctest --preset dev --no-tests=error -R 'store_d16_x|compute_desc_numeric|compute_store_aot_desc_numeric|startup_gfx2hlsl_compute' -Vstartup_compute_store_d16_x_b-short-binding_{warp,hardware}and…_b-tight-host-guard_{warp,hardware}, which report their expected mismatches, as theWILL_FAIL-style controls should.One thing before merge:
mainmoved after465aeff4.git merge-treeagainst currentmain(6c7a59a2) conflicts again inCMakeLists.txt(test registration), and GitHub shows the PR as dirty. Once it's rebased and CI is green I can recheck and merge, unless @R0Y00 prefers to merge it himself.AI-assisted; commands listed were executed locally.