startup: lower compute global_load_dword saddr form in gfx2hlsl #2715
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!2715
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2715/head"
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?
@consolelogkyo on GitHub · 2026-11-26 03:15 UTC · original
consolelogkyo:feat/startup-compute-global-load→main· +1044 −9 · 6 files · 2 commits · merged 2026-11-26 06:27 UTCChange
Lowers the RDNA 2 one-dword
GLOBALsaddrload (global_load_dword vdst, vaddr, s[base:base+1] [offset:imm]) in the compute (cs) stage oftools/startup/gfx2hlsl.py(#2618starting ticketC500-01/031,#2022):FLAT/GLOBAL, LLVM 15SelectGlobalSAddr):ADDR = SADDR[63:0] + zext(VADDR[31:0]) + sext(OFFSET[11:0]).s[base:base+1]must be an even-aligned SGPR pair (0 <= base <= 104) holding a proven 64-bit root buffer pointer (('ptr', ('root', index))with matchingptr_high_symbol, includings_mov_b32/s_mov_b64copies and completed literals_add_u32+s_addc_u32advances). Because RDNA 2 low-bitGLOBALalignment depends onSH_MEM_CONFIG.ALIGNMENT_MODE(unmeasured on Scarlett) and HLSLByteAddressBuffer.Loadrequires a multiple of four,base_off,offset, andvaddr(align4_v/align4_s) must each be proven 4-byte aligned. Each distinct root parameter binds aByteAddressBuffer r<i> : register(t<i>)(srv <i> buf root <index>inComputePipeline.manifest()), capturesa = vaddrfirst (preservingvdst == vaddraliasing), guards the signed 64-bit view-relative sumzext(a) + base_off + immagainst[0, 0xffffffff]before converting to a 32-bitLoadoffset (a <= 0xffffffff - total_off ? r<i>.Load(a + total_off) : 0ufortotal_off > 0,a >= -total_off ? r<i>.Load(a - (-total_off)) : 0ufortotal_off < 0, andr<i>.Load(a)fortotal_off == 0), and writesv<dst>throughStage.set_v(preserving inactive lanes under partialEXEC).check_encodingrejects reserved bitw0[25],nv(w1[23]), and non-zero unuseddata(w1[15:8]).calculated_pc_prooftreatsglobal_alongsidebuffer_/tbuffer_as preservingSCC.Stage.op_global_load_dwordchecks modifiers before operand count so the two-operandldsform refuses onglobal load modifier lds, accepts cache flags (glc,slc,dlc) and 4-byte-aligned signed 12-bitoffset(-2048..2044), refuses unaligned immediate/pointer/vaddroffsets and|total_off| > 0xffffffff, and keepsoff(saddr = 0x7d), sub-dword and multi-dwordGLOBALloads (ubyte/sbyte/ushort/sshort/dwordx2/dwordx3/dwordx4),GLOBALstores and atomics,FLAT/SCRATCHloads, non-compute stages (vs/ps/ms), table/heap/descriptor/numeric pairs, and incomplete or mismatched pointer pairs refused.src/untouched so it merges cleanly alongside #2603 (whosed3d12_compute.inlalready bindssrv <i> buf root <param>).Refs #2618, #2022.
Verification
Added
tests/startup_compute_global_load_check.py(source-built synthetic gfx1013 words only; wired intoCMakeLists.txt,.github/workflows/windows.ymlfor Linuxllvm-mc-15+libLLVM-15.so.1and Linux Python checks,AGENTS.md, anddocs/experiments.md):startup_compute_global_load_controls: PASSED (3 compute kernels over a bounded 320-dword root view with nonzero sentinels across all low-range words, varying per-lanevaddr, scalar base pairs via direct entrys[6:7],s_mov_b64copy, single and chaineds_add_u32+s_addc_u32advances, multi-root SRVr0/r1, signed offsets+8,-12,-16,+2044,-2048, 64-bit sum overflow/underflow guards, 4-byte alignment proofs and low-bit refusals includingvaddr = 1..3,vdst == vaddraliasing, partialEXECmasking, encoding/provenance/stage/opcode refusals, and unlowered negative control).startup_compute_global_load_warp(Microsoft Basic Render Driver1414:008c, driver10.0.26100.9818,debug_layer=enabled,debug_errors=0 debug_warnings=0): PASSED (9 DXCcs_6_0--compute-store-sized-casedispatches across 320 nonzero words including positive-offset overflow0xfffffffc + 8 -> base + 0x100000004, negative-offset underflow0..12below16/4, and low-bit offsets across distinct neighboring DWORDs + 4 reference controls + 10 negative HLSL mutations caught at exact word/value).startup_compute_global_load_hardware(AMD Radeon RX 9070 XT1002:7550, driver32.0.32029.2010,debug_layer=enabled,debug_errors=0 debug_warnings=0): PASSED (same 9 DXCcs_6_0dispatches + 4 reference controls + 10 negative HLSL mutations caught).startup_gfx2hlsl_*,startup_translator,docs_links, andbidi_controls: PASSED.Checklist
AI-assisted.
Lower the RDNA 2 one-dword `GLOBAL` `saddr` load (`global_load_dword vdst, vaddr, s[base:base+1] [offset:imm]`) in the compute (`cs`) stage of `tools/startup/gfx2hlsl.py`: - Validate an even-aligned SGPR pair `s[base:base+1]` (`0 <= base <= 104`) holding a proven 64-bit root buffer pointer (`('ptr', ('root', index))` and matching `ptr_high_symbol`, including `s_mov_b32`/`s_mov_b64` copies and completed literal `s_add_u32` + `s_addc_u32` advances), constrain `base_off`, `offset`, and `vaddr` (`align4_v` / `align4_s`) to proven multiples of four (since RDNA 2 low-bit `GLOBAL` alignment depends on `SH_MEM_CONFIG.ALIGNMENT_MODE` and HLSL `ByteAddressBuffer.Load` requires a multiple of four), bind `ByteAddressBuffer r<i> : register(t<i>)` (`srv <i> buf root <index>` in the manifest), capture `a = vaddr` first, and guard the signed 64-bit view-relative sum `zext(a) + base_off + sext(offset)` against `[0, 0xffffffff]` before converting to a 32-bit `Load` offset (`ADDR = SADDR[63:0] + zext(VADDR[31:0]) + sext(OFFSET[11:0])` per AMD RDNA 2 ISA §9.2 and LLVM 15 `SelectGlobalSAddr`). - Reject reserved bit `w0[25]`, `nv` (`w1[23]`), and non-zero unused `data` (`w1[15:8]`) in `check_encoding`, mark `global_` as non-SCC-clobbering in `calculated_pc_proof`, check modifiers before arity so `lds` refuses by modifier name, and keep `off` (`saddr = 0x7d`), unaligned offsets, sub-dword/multi-dword `GLOBAL` loads, `GLOBAL` stores/atomics, `FLAT`/`SCRATCH` loads, non-compute stages, `|total_off| > 0xffffffff`, and unproven or incomplete pointer pairs refused. Add `tests/startup_compute_global_load_check.py` covering 3 synthetic compute kernels over a bounded 320-dword root view (`--compute-store-sized-case`) with nonzero sentinels across all low-range words, varying per-lane offsets, scalar bases, signed 12-bit offsets, positive-offset 64-bit overflow, negative-offset underflow, low-bit offsets masked across distinct neighboring DWORDs, `EXEC` masking, LLVM 15 `llvm-mc` / `libLLVM` round-trips, encoding/provenance/alignment refusal controls, and WARP / hardware DXC `cs_6_0` dispatches with reference and HLSL negative controls. Refs #2618, #2022. AI-assisted.@R0Y00 on GitHub · 2026-11-26 03:43 UTC · original · requested changes
I ran the exact fixture translator. The scalar-base GLOBAL load emits a 32-bit vaddr + 8u and reads r0.Load(a). With a runtime vaddr of 0xfffffffc, that selects byte 4 of the bound view. The documented guest address is base plus 0x100000004. The same truncation can select a valid low word from the wrong address with a bounded root view. Please guard the 64-bit sum before conversion or refuse the unproven form. Keep the existing in-range cases and add a positive-offset overflow and a negative-offset underflow control with a nonzero sentinel in the would-be wrapped low range.
@consolelogkyo on GitHub · 2026-11-26 04:12 UTC · original
Updated and rebased onto
main:tools/startup/gfx2hlsl.py):Stage.op_global_load_dwordnow capturesa = vaddrfirst and guardszext(a) + base_off + sext(offset)against[0, 0xffffffff]before converting to a 32-bitByteAddressBuffer.Loadoffset (a <= 0x<limit>u ? r<i>.Load(a + <total_off>u) : 0ufortotal_off > 0,a >= <mag>u ? r<i>.Load(a - <mag>u) : 0ufortotal_off < 0, andr<i>.Load(a)fortotal_off == 0, refusing|total_off| > 0xffffffff).tests/startup_compute_global_load_check.py): kept all 6 existing in-range dispatches, switched the runner to--compute-store-sized-case(bounded 320-dword raw buffer SRV view with nonzero sentinels across all 320 low-range words), and addedKERNEL_Ccovering positive-offset overflow (vaddr = 0xfffffffcwith+8->base + 0x100000004and+36->base + 0x100000020, plus boundary sweep across0xfffffff4..0x100000004) and negative-offset underflow (vaddr = 0..12with-16and+8 - 20 = -12), along with reference and HLSL negative controls on both WARP and AMD Radeon RX 9070 XT (debug_errors=0 debug_warnings=0).AI-assisted.
@R0Y00 on GitHub · 2026-11-26 04:32 UTC · original · requested changes
The 32-bit wrap issue is fixed. I ran the exact Python translator and its dispatch fixture on WARP and RTX 4060 Laptop: all 8 dispatches, both reference controls and all 9 mutations behaved as expected on each. One remaining input boundary needs a clear rule. The 64-bit range check still admits an odd effective byte offset (for example vaddr=1 with zero scalar advance and immediate), and HLSL ByteAddressBuffer.Load requires a multiple of four. Please establish how the guest DWORD load handles the low bits, or constrain the lowering to proven-aligned offsets. Add a low-bit case with different neighboring DWORDs alongside the existing overflow and underflow controls. HLSL Load
@consolelogkyo on GitHub · 2026-11-26 05:21 UTC · original
Constrained the lowering to proven 4-byte-aligned offsets and rebased onto
main:tools/startup/gfx2hlsl.py): in the RDNA 2 ISA, low-bitGLOBAL_LOAD_DWORDbehavior is governed bySH_MEM_CONFIG.ALIGNMENT_MODE(DWORDrounds down,DWORD_STRICT/STRICTraisesMEMVIOL,UNALIGNEDgathers across neighboring DWORDs; Scarlett's setting is unmeasured), and HLSLByteAddressBuffer.Loadrequires a multiple of four.Stagenow tracks proven multiple-of-four SGPR/VGPR values (align4_s/align4_v, cleared on unaligned writes, partial-EXECoverwrites of unaligned lanes, and control-flow splits/joins), andStage.op_global_load_dwordrefuses unalignedoffset, unalignedbase_off, or unprovenvaddr.tests/startup_compute_global_load_check.py):vaddr = 1..3, unshiftedv0,v0 << 1,v0 & -2, adding unmasked root constants4, droppingv_and_b32 -4fromKERNEL_C, partial-EXECoverwrite ofv9 = 1, unaligned immediate offsets (1..3,-1..-3,2047,-2047), and unaligned scalar base advances (1..3).KERNEL_Calongside the existing overflow/underflow controls withc_low_bits_neighbor_dwords(ud0 = 1,ud1 = 5, raw per-lane byte offsets stepping 1 byte per lane across distinct neighboring DWORDssrc_low[0] != src_low[1]and aligned viav_and_b32 -4), plus two reference controls (ref_low_bit_unaligned_gather,ref_low_bit_upper_neighbor) andmut_low_bits_unaligned_gather(ldugather across neighboring DWORDs), verified on WARP and AMD Radeon RX 9070 XT (9dispatches +4reference controls +10negative HLSL mutations per adapter,debug_errors=0 debug_warnings=0).AI-assisted.
@R0Y00 on GitHub · 2026-11-26 06:27 UTC · original · approved these changes
The range and low-bit findings are addressed. I reproduced the missing low-level alignment guard in a direct Stage probe and retested its fix. The fresh generated fixture passed 9 dispatches, 4 reference controls and 10 mutations on each of WARP and RTX 4060 Laptop. The fixture binds the root SRVs directly. The startup manifest consumer remains separate.