startup: lower compute global_load_dword saddr form in gfx2hlsl #2707

Merged
consolelogkyo merged 2 commits from upstream-pr/2715 into main 2026-11-26 06:27:26 +00:00
consolelogkyo commented 2026-11-26 03:15:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-26T03:15:21Z.


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 #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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618714098 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715). Originally posted by [consolelogkyo](https://github.com/consolelogkyo) on 2026-11-26T03:15:21Z. --- ## 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 #2603 (whose `d3d12_compute.inl` already binds `srv <i> buf root <param>`). Refs #2618, #2022. ## Verification Added [`tests/startup_compute_global_load_check.py`](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**. ```powershell ctest --test-dir out/build/release --no-tests=error -R "^startup_compute_global_load_(controls|warp|hardware)$" -V ``` ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
R0Y00 commented 2026-11-26 04:04:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T03:43:32Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068258560 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715#pullrequestreview-6068258560). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T03:43:32Z. **Review:** CHANGES_REQUESTED --- 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.
R0Y00 commented 2026-11-26 05:02:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:32:34Z.

Review: CHANGES_REQUESTED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068582188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715#pullrequestreview-6068582188). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T04:32:34Z. **Review:** CHANGES_REQUESTED --- 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](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-byteaddressbuffer-load)
consolelogkyo commented 2026-11-26 05:02:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-26T04:12:15Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182386987 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715#issuecomment-7182386987). Originally posted by [consolelogkyo](https://github.com/consolelogkyo) on 2026-11-26T04:12:15Z. --- 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 commented 2026-11-26 06:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-26T05:21:31Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183413928 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715#issuecomment-7183413928). Originally posted by [consolelogkyo](https://github.com/consolelogkyo) on 2026-11-26T05:21:31Z. --- 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.
upstream-sync closed this pull request 2026-11-26 07:00:17 +00:00
R0Y00 commented 2026-11-26 07:00:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T06:27:16Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069492949 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2715#pullrequestreview-6069492949). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T06:27:16Z. **Review:** APPROVED --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2707
No description provided.