Repository navigation
startup: lower compute global_load_dword saddr form in gfx2hlsl - #2715
Conversation
818c812 to
46aefa4
Compare
R0Y00
left a comment
There was a problem hiding this comment.
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.
46aefa4 to
fa98827
Compare
|
Updated and rebased onto
AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
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
fa98827 to
c61450f
Compare
|
Constrained the lowering to proven 4-byte-aligned offsets and rebased onto
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 R0Y00#2618, R0Y00#2022.
AI-assisted.
c61450f to
d027cbf
Compare
R0Y00
left a comment
There was a problem hiding this comment.
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.
Change
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 Integrate mesh translation, D3D12 rendering and memory handling #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.