compute: lower sub-DWORD scalar global loads in the direct path #3517
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3517
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3515"
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?
@Ammmae0x on GitHub · 2026-11-29 20:16 UTC · original
Ammmae0x:compute/global-subdword-loads→main· +948 −16 · 12 files · 4 commits · merged 2026-11-30 02:37 UTCLower sub-DWORD scalar-base global loads (
global_load_ubyte,global_load_sbyte,global_load_ushort,global_load_sshort) in the direct C++ compute path.Refs #3226, #2935
Change
src/gfx1013_compute_native.cpp: admitsubdword_load = (i.op >= 8 && i.op <= 11)alongside DWORD loads/stores. The refusal substring for _d16 loads/stores,global_store_byte/global_store_shortand atomics is unchanged, as are thelds,segment != 2,saddr == 125andsaddr == 127refusals.src/gfx1013_direct_compute.inl:global_rootnow takes the byte transfer size and a sub-DWORD flag. Sub-DWORD loads allow any signed 12-bit byte immediate offset (-2048..2047); the DWORD/wideroffset % 4refusal is unchanged. Binding span covers the aligned DWORD(s) touched:((max(offset, 0) + width + 3) & ~3). The 32-bit wrap guard covers the last byte (offset + width - 1). Byte extraction shifts by((addr & 3) * 8)and masks0xff, with sign extension forsbyte; halfwords handle the in-word case and the cross-DWORD case (addr & 3 == 3), where the second DWORD is loaded only on a cross-DWORD lane (the result is still selected to 0 when the wrap guard fails). Root SRV and root UAVsaddrandglc/slc/dlcare accepted as forglobal_load_dword.tests/native_global_subdword_load_check.py(encodingsand hardware modes),tests/cmake/native_global_subdword_load.cmake, wired intotests/checks/python-linux/native-global-subdword-load.txt. The dispatch checks 29 cases per lane: all four opcodes, all four intra-DWORD byte alignments, cross-DWORD halfwords, boundary bytes (0x00, 0x7f, 0x80, 0xff) and halfwords (0x0000, 0x7fff, 0x8000, 0xffff), signed/unsigned odd negative and positive offsets, root SRV and root UAV,glc slc dlc, both 32-bit wrap guards, and avdst == vaddralias program. The module check counts 50 raw buffer loads (29 sub-DWORD loads, 19 cross-DWORD second loads, plus 2 scalar size loads), 52 upper-bound wrap guards (24 sub-DWORD loads plus 28 nonzero-offset output stores) and 4 lower-bound wrap guards, and pins the ushort wrap bound at -18.docs/experiments/native-direct-global-subdword-load.md, linked fromdocs/experiments.md; the global-load note now points to it for sub-DWORD opcodes.Linux verification (this host cannot run compile_dxil, DXC or hardware)
/tmp/pe-env/bin/python -B tests/native_global_subdword_load_check.py encodings— pass (four sub-DWORD opcodes, all four byte alignments, cross-DWORD, odd and extreme offsets, policy bits, pattern stores, alias-free dispatch program)/tmp/pe-env/bin/python -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux— all 59 checks passedtests/form_coverage_check.py— passed;tests/docs_links_check.py— 178 Markdown files, 718 links;tests/bidi_controls_check.py— 2680 tracked files, no bidirectional controlsgit diff --check— clean;git merge-tree --write-tree origin/main HEAD— exit 0Mutation audit
28/28 enumerated mutants killed (no survivors). Killed by hardware readback: decode-gate bounds, alignment refusal, byte/halfword shift and mask, sign extension, cross-DWORD predicate/shift/mask, width mapping, upper wrap guard. Killed by the module dumpbin checks: lower wrap guard (readback-equivalent, guard count 4 -> 0) and the last-offset formula (widening/narrowing moves the pinned -18 bound). Killed by the extent checks: the span
+3and& ~3uterms (ubyte at offset 1 sizes a view to 4 bytes, ushort at offset 3 to 8 bytes; ubyte at offset 2047 to 2048, ushort to 2052).Windows verification
Pending: compile_dxil and hardware readback on Windows (not runnable on this Linux host).
WIN-VERIFY fix (
f6a3d606)Windows verification of
d5993681failednative_global_subdword_load_hardwareatcompile_dxilwithinconsistent DXIL declaration: the dispatch loads both a root SRV (nounwind readonly) and a root UAV(
nounwind) through the same@dx.op.rawBufferLoad.i32intrinsic, andDxilModule::invoke()threw onthe second declaration. The fix merges the two forms into a single
nounwinddeclaration in eitherorder (dxc accepts one shared declaration for
ByteAddressBufferandRWByteAddressBufferloads;dropping
readonlypreserves UAV store-load ordering); any other attribute or signature mismatchstill throws. Coverage: new
tests/dxil_module_invoke_check.py(host C++ probe, 10 cases: both orders,readonly-only/plain-only unchanged, mismatch controls) with an 8/8 mutation audit of the widening
logic, plus a UAV-then-SRV compile-only program in the sub-DWORD check alongside the SRV-then-UAV
dispatch. The probe against the pre-fix header aborts with the same
inconsistent DXIL declaration,reproducing the Windows failure on Linux.
Linux re-verification on
f6a3d606: encodings pass,tests/dxil_module_invoke_check.pypass (10 cases,8/8 mutants killed),
tools/run_checks_parallel.py --from-dir tests/checks/python-linux— all 60 checkspassed, form/docs/bidi pass,
git diff --checkclean, merge-tree exit 0.Windows verification
Pending: compile_dxil and hardware readback on Windows (not runnable on this Linux host).
WIN-VERIFY fix (
12793ffb)Windows verification of
f6a3d606failednative_global_subdword_load_hardwareatcompile_dxilwithglobal store base is an advanced or mismatched root address:prologue()andalias_program()wrotethe group*32 temporary to
s9, clobbering the high half ofs[8:9](root UAVu1). The fix uses freeSGPR
s12for the temporary (s_lshl_b32 s12, s10, 5/v_add_nc_u32 v9, s12, v0) in both programsand pins both instructions in
encodings().Linux re-verification on
12793ffb: encodings pass,tools/run_checks_parallel.py --from-dir tests/checks/python-linux— all 60 checks passed, form/docs/bidi pass,git diff --checkclean,merge-tree exit 0.
Windows verification
Pending: compile_dxil and hardware readback on Windows (not runnable on this Linux host).
WIN-VERIFY fix (
d02f73e3)Windows verification of
12793ffbleft one assertion: module counts(50, 52, 4)where the checkexpected
(50, 24, 4). The dumpbin count is module-wide:upperis 24 sub-DWORD load guards plus28 upper guards from the 28 output
global_store_dwordinstructions at offsets 4..112 (slots 1..28);the slot-0 store has offset 0 and emits no guard. The expected count is now
(50, 52, 4)in thecheck, its print message, and the docs note, with a comment pinning the composition. Local verification
in a throwaway copy confirmed that both
devandreleasepass all 29 cases per lane (64 lanes + pattern UAVLinux re-verification on
d02f73e3: encodings pass,tools/run_checks_parallel.py --from-dir tests/checks/python-linux— all 60 checks passed, form/docs/bidi pass,git diff --checkclean.Windows Verification (
d02f73e3)AI-assisted.
@Leyukaka on GitHub · 2026-11-29 21:09 UTC · original · approved these changes
Approving at
d02f73e3. Read the full diff: the decode gate admits only FLAT ops 8..11 (src/gfx1013_compute_native.cpp:282,291),global_rootgives the same span and wrap bound as before for the DWORD loads and stores, and the byte/halfword extraction with the cross-DWORD second load and phi (src/gfx1013_direct_compute.inl:666-711) is correct.Independent run in an isolated environment (network off, PR tree read-only, dev preset,
-DX2W_WITH_OPUS=OFF):ctest --preset dev --no-tests=error -R '^(native_global_subdword_load_.*|native_global_load_.*|native_global_store_.*)$'→ 5/5 passed, no skips, includingnative_global_subdword_load_hardware(29 cases per lane, alias and reverse programs). The test log does not identify the adapter. CI does not run these tests.Finding (not blocking): the two paths assume different alignment modes. The DWORD path drops the low two address bits and says so (
src/gfx1013_direct_compute.inl:599-600, "DWORD alignment mode");tools/startup/gfx2hlsl.py:7382records the existing assumption: DWORD rounds down, UNALIGNED gathers across neighbouring DWORDs, the console's setting is unmeasured. The new halfword path reads an odd address byte-granular and gathers across two DWORDs ataddr & 3 == 3(src/gfx1013_direct_compute.inl:688-705), which is the UNALIGNED behaviour; under DWORD mode that halfword would round down. Bytes and even-address halfwords are the same in both modes.docs/experiments/native-direct-global-subdword-load.mdshould state which mode it assumes for odd-address halfwords.Minor:
src/gfx1013_compute_native.cpp:586callsclear_spills(256 + dst)forglobal_load_dwordonly, so a sub-DWORD load over a VGPR holding spill lanes leaves stale entries.global_load_dwordx2/x3/x4already have this gap on main; a follow-up is enough.Minor: line 66 of the new doc still says the hardware readback is pending Windows verification.
Revert check, by reading: with the
src/changes reverted,native_global_subdword_load_hardwarefails atcompile_words(program()), before any replay.native_global_subdword_load_encodingschecks only the Python-built words against the disassembler and does not depend onsrc/, so it would still pass.@Not-Saii on GitHub · 2026-11-29 22:10 UTC · original · approved these changes
Approving at
d02f73e3. I read the full diff and the code it touches, and ran the PR's tests in an isolated environment (results below). I agree with the earlier review's three points: the alignment mode for odd-address halfwords, the missingclear_spillsfor the new opcodes, and the stale "pending" line in the new doc. I don't repeat them here, except where I have new evidence.Findings
None of these block the merge.
SHOULD 1: the Windows report is missing two required fields. AGENTS.md asks GPU reports to identify the adapter, driver, Windows build, commit and debug-layer status. The "Windows Verification (
d02f73e3)" block in the PR body gives the commit, adapter and driver. It does not give the Windows build or the debug-layer status.SHOULD 2: the comment this PR edited still names one alignment mode for every caller. This adds evidence to the earlier alignment point. At
src/gfx1013_direct_compute.inl:596-602the PR extends theglobal_rootcomment, which says the low two address bits are dropped ("DWORD alignment mode"). The sub-DWORD path (:679-705) keeps those bits, reads an odd-address halfword one byte at a time, and gathers across two DWORDs ataddr & 3 == 3. The fixture depends on that reading in 9 of the 29 slots per lane (slots 5, 6, 7, 8, 10, 13, 24, 25 and 26) and in slot 1 of the alias program. If the assumption changes later, those slots and the reference model change with it. The comment and the doc should both name the mode the halfword path assumes.NIT 3: the declaration merge applies to every intrinsic. The merge in
DxilModule::invoke()(src/dxil_module.h:106-125) applies to any intrinsic whose two declarations differ only by a trailingreadonly, not only torawBufferLoad/bufferLoad. It reaches both the direct compute path andsrc/gfx1013_rect_geometry.cpp.readonlyis conservative.Either limit the merge to the two buffer-load names or say in the comment that it is general.
NIT 4: the 28/28 mutation audit cannot be reproduced. The PR body lists the 28 mutants by category but gives no script or command. The 8/8 audit for the header lives in
tests/dxil_module_invoke_check.py, where anyone can run it again.NIT 5: two sentences in
docs/experiments/native-direct-global-subdword-load.mdneed rewording.NIT 6 (optional): the module-wide guard counts are fragile.
tests/native_global_subdword_load_check.py:439checks exacticmpcounts across the whole module, and those counts already needed one correction ind02f73e3. Counting only the sub-DWORD load guards would make the check independent of the output stores.These look correct on reading:
src/gfx1013_compute_native.cpp:282,291), after the segment,lds, saddr 125 and saddr 127 refusals;transfer_bytes = count * 4);(max(offset,0) + width + 3) & ~3;crossonly and merged with a phi, and the in-range select then discards any value from a lane whose guard failed;What each test proves
native_global_subdword_load_encodingschecks the Python-built words againsttools/disasm_rdna2.py, plus asserts on the reference model. It does not depend onsrc/.native_global_subdword_load_hardwareproves the lowering on one adapter. It covers:vdst == vaddralias program;On Windows, this test is also the only coverage of the
dxil_module.hmerge.tests/dxil_module_invoke_check.pyruns 10 cases and 8 mutants against the header. It is listed only intests/checks/python-linux/. Its compiler search does not includecl, so on a Windows host without a gcc-style compiler it skips (77).native_global_load_hardwareandnative_global_store_{encodings,hardware}are regression checks for the sharedglobal_rootchange.CI
The pull_request run at
d02f73e3passed.native_global_subdword_load_check.py encodingsanddxil_module_invoke_check.py: 10 cases, 8/8 mutants killed.native_global_*, because the PR check skipsnative_*. CI did not run the hardware readback.Independent run
Windows Sandbox with networking disabled. The PR tree was exported at the head and mapped read-only, with one writable output folder.
d02f73e3f3d3d12SDKLayers.dll, and the test tools do not enable it.native_global_load_hardwarenative_global_store_encodingsnative_global_store_hardwarenative_global_subdword_load_encodingsnative_global_subdword_load_hardware: 29 cases per lane, module counts (50, 52, 4), and the alias and reverse programs.Revert check
Each mutation was applied to a scratch copy, then
compile_dxilwas rebuilt (no compile errors) and the two subdword tests were run.subdword_loaddeclaration and the|| subdword_loadterm insrc/gfx1013_compute_native.cpp._encodingspassed._hardwarefailed at the non-root-base refusal control: it expected "global load base is not a root buffer address" and got the generic DWORD-only decode refusal.mul byte_lane, 8tomul byte_lane, 0atsrc/gfx1013_direct_compute.inl:680._encodingspassed._hardwarepassed the module checks and failed the readback, starting at lane 0 slot 1 (the sbyte at offset 2). The first diff is 0x0 against 0xffffffaa.