Skip to content

startup: lower compute global_load_dword saddr form in gfx2hlsl - #2715

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
consolelogkyo:feat/startup-compute-global-load
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
consolelogkyo:feat/startup-compute-global-load

Conversation

@consolelogkyo

@consolelogkyo consolelogkyo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Change

Lowers 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 (#2618 starting ticket C500-01/031, #2022):

  • Address, alignment, and resource provenance (AMD RDNA 2 ISA §9.2 FLAT / GLOBAL, LLVM 15 SelectGlobalSAddr): 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 matching ptr_high_symbol, including s_mov_b32 / s_mov_b64 copies and completed literal s_add_u32 + s_addc_u32 advances). Because RDNA 2 low-bit GLOBAL alignment depends on SH_MEM_CONFIG.ALIGNMENT_MODE (unmeasured on Scarlett) and HLSL ByteAddressBuffer.Load requires a multiple of four, base_off, offset, and vaddr (align4_v / align4_s) must each be proven 4-byte aligned. Each distinct root parameter binds a ByteAddressBuffer r<i> : register(t<i>) (srv <i> buf root <index> in ComputePipeline.manifest()), captures a = vaddr first (preserving vdst == vaddr aliasing), guards the signed 64-bit view-relative sum zext(a) + base_off + imm against [0, 0xffffffff] before converting to a 32-bit Load offset (a <= 0xffffffff - total_off ? r<i>.Load(a + total_off) : 0u for total_off > 0, a >= -total_off ? r<i>.Load(a - (-total_off)) : 0u for total_off < 0, and r<i>.Load(a) for total_off == 0), and writes v<dst> through Stage.set_v (preserving inactive lanes under partial EXEC).
  • Encoding and stage refusals:
    • check_encoding rejects reserved bit w0[25], nv (w1[23]), and non-zero unused data (w1[15:8]).
    • calculated_pc_proof treats global_ alongside buffer_ / tbuffer_ as preserving SCC.
    • Stage.op_global_load_dword checks modifiers before operand count so the two-operand lds form refuses on global load modifier lds, accepts cache flags (glc, slc, dlc) and 4-byte-aligned signed 12-bit offset (-2048..2044), refuses unaligned immediate/pointer/vaddr offsets and |total_off| > 0xffffffff, and keeps off (saddr = 0x7d), sub-dword and multi-dword GLOBAL loads (ubyte/sbyte/ushort/sshort/dwordx2/dwordx3/dwordx4), GLOBAL stores and atomics, FLAT / SCRATCH loads, non-compute stages (vs/ps/ms), table/heap/descriptor/numeric pairs, and incomplete or mismatched pointer pairs refused.
  • Keeps src/ untouched so it merges cleanly alongside Integrate mesh translation, D3D12 rendering and memory handling #2603 (whose d3d12_compute.inl already binds srv <i> buf root <param>).

Refs #2618, #2022.

Verification

Added tests/startup_compute_global_load_check.py (source-built synthetic gfx1013 words only; wired into CMakeLists.txt, .github/workflows/windows.yml for Linux llvm-mc-15 + libLLVM-15.so.1 and Linux Python checks, AGENTS.md, and docs/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-lane vaddr, scalar base pairs via direct entry s[6:7], s_mov_b64 copy, single and chained s_add_u32 + s_addc_u32 advances, multi-root SRV r0/r1, signed offsets +8, -12, -16, +2044, -2048, 64-bit sum overflow/underflow guards, 4-byte alignment proofs and low-bit refusals including vaddr = 1..3, vdst == vaddr aliasing, partial EXEC masking, encoding/provenance/stage/opcode refusals, and unlowered negative control).
  • startup_compute_global_load_warp (Microsoft Basic Render Driver 1414:008c, driver 10.0.26100.9818, debug_layer=enabled, debug_errors=0 debug_warnings=0): PASSED (9 DXC cs_6_0 --compute-store-sized-case dispatches across 320 nonzero words including positive-offset overflow 0xfffffffc + 8 -> base + 0x100000004, negative-offset underflow 0..12 below 16/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 XT 1002:7550, driver 32.0.32029.2010, debug_layer=enabled, debug_errors=0 debug_warnings=0): PASSED (same 9 DXC cs_6_0 dispatches + 4 reference controls + 10 negative HLSL mutations caught).
  • startup_gfx2hlsl_*, startup_translator, docs_links, and bidi_controls: PASSED.
ctest --test-dir out/build/release --no-tests=error -R "^startup_compute_global_load_(controls|warp|hardware)$" -V

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
consolelogkyo force-pushed the feat/startup-compute-global-load branch from 46aefa4 to fa98827 Compare November 26, 2026 04:12
@consolelogkyo

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto main:

  • 64-bit view-relative sum guard (tools/startup/gfx2hlsl.py): Stage.op_global_load_dword now captures a = vaddr first and guards zext(a) + base_off + sext(offset) against [0, 0xffffffff] before converting to a 32-bit ByteAddressBuffer.Load offset (a <= 0x<limit>u ? r<i>.Load(a + <total_off>u) : 0u for total_off > 0, a >= <mag>u ? r<i>.Load(a - <mag>u) : 0u for total_off < 0, and r<i>.Load(a) for total_off == 0, refusing |total_off| > 0xffffffff).
  • Verification (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 added KERNEL_C covering positive-offset overflow (vaddr = 0xfffffffc with +8 -> base + 0x100000004 and +36 -> base + 0x100000020, plus boundary sweep across 0xfffffff4..0x100000004) and negative-offset underflow (vaddr = 0..12 with -16 and +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.

@consolelogkyo
consolelogkyo requested a review from R0Y00 November 26, 2026 04:29

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
consolelogkyo force-pushed the feat/startup-compute-global-load branch from fa98827 to c61450f Compare November 26, 2026 05:21
@consolelogkyo

Copy link
Copy Markdown
Contributor Author

Constrained the lowering to proven 4-byte-aligned offsets and rebased onto main:

  • 4-byte alignment rule (tools/startup/gfx2hlsl.py): in the RDNA 2 ISA, low-bit GLOBAL_LOAD_DWORD behavior is governed by SH_MEM_CONFIG.ALIGNMENT_MODE (DWORD rounds down, DWORD_STRICT / STRICT raises MEMVIOL, UNALIGNED gathers across neighboring DWORDs; Scarlett's setting is unmeasured), and HLSL ByteAddressBuffer.Load requires a multiple of four. Stage now tracks proven multiple-of-four SGPR/VGPR values (align4_s / align4_v, cleared on unaligned writes, partial-EXEC overwrites of unaligned lanes, and control-flow splits/joins), and Stage.op_global_load_dword refuses unaligned offset, unaligned base_off, or unproven vaddr.
  • Verification (tests/startup_compute_global_load_check.py):
    • Added binary refusal controls for vaddr = 1..3, unshifted v0, v0 << 1, v0 & -2, adding unmasked root constant s4, dropping v_and_b32 -4 from KERNEL_C, partial-EXEC overwrite of v9 = 1, unaligned immediate offsets (1..3, -1..-3, 2047, -2047), and unaligned scalar base advances (1..3).
    • Extended KERNEL_C alongside the existing overflow/underflow controls with c_low_bits_neighbor_dwords (ud0 = 1, ud1 = 5, raw per-lane byte offsets stepping 1 byte per lane across distinct neighboring DWORDs src_low[0] != src_low[1] and aligned via v_and_b32 -4), plus two reference controls (ref_low_bit_unaligned_gather, ref_low_bit_upper_neighbor) and mut_low_bits_unaligned_gather (ldu gather across neighboring DWORDs), verified on WARP and AMD Radeon RX 9070 XT (9 dispatches + 4 reference controls + 10 negative HLSL mutations per adapter, debug_errors=0 debug_warnings=0).

AI-assisted.

@consolelogkyo
consolelogkyo requested a review from R0Y00 November 26, 2026 05:28
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.
@consolelogkyo
consolelogkyo force-pushed the feat/startup-compute-global-load branch from c61450f to d027cbf Compare November 26, 2026 06:14

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit da2a8f6 into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants