shader: lower root-pointer global_load_dword in the direct C++ compute path #2966

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/2966 into cpp-migration 2026-11-27 00:34:21 +00:00
legacy-code-archaeologist commented 2026-11-27 00:07:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T00:07:30Z.


Change

The direct C++ compute frontend now lowers global_load_dword in the saddr form. Before, it refused it with unsupported instruction global_load_dword. Refs #2962 (part of the "global loads" item in #2935).

  • Address. ADDR = SADDR + zext(VADDR) + sext(OFFSET[11:0]). SADDR must be the unadvanced root address of a root SRV with its matching high half. That is the same symbol and root_buffer_srv binding the scalar root loads in memory() already use. The load becomes a raw buffer load from that view.
  • Wrap guard. The 32-bit byte offset is guarded to [0, 2^32), the rule gfx2hlsl.py op_global_load_dword uses. A VADDR near 2^32 plus a positive offset reads 0 instead of wrapping into an in-bounds word.
  • Alignment. The low two address bits are dropped, as for buffer_load_dword in this path (DWORD alignment mode). gfx2hlsl.py refuses an unproven alignment instead; the console's ALIGNMENT_MODE is not measured.
  • Refused by name. The off form, the FLAT and scratch segments, other opcodes (wider loads, stores, atomics), the lds form, a non-root SADDR, a replaced high half, and an unaligned immediate offset. A pointer advanced by scalar arithmetic is refused earlier, as an unbound numeric SGPR. gfx2hlsl.py accepts a pointer advanced by a known literal; that is not done here.

Files: src/gfx1013_compute_native.cpp (decode), src/gfx1013_direct_compute.inl (global_load), tests/native_global_load_check.py, tests/cmake/native_global_load.cmake and docs/experiments/native-direct-global-load.md.

Verification

Run on cpp-migration f934df52 plus this commit, Windows 10.0.26100.9711, dev preset, NVIDIA Quadro M1000M (driver 32.0.15.7371), debug layer unavailable.

  • ctest --preset dev --no-tests=error -R '^native_global_load_hardware$' -V reports a skip (77). The 11 refusals and the dxc -dumpbin module checks passed: 6 raw buffer loads, 2 upper-bound guards and 1 lower-bound guard. The dispatch readback is not measured. native_store_replay needs shader model 6.6 with wave32, which this Maxwell GPU lacks; native_scalar_lds_hardware and native_shift64_hardware skip here for the same reason. A run on an SM 6.6 wave32 adapter would be very welcome.
  • With the frontend change reverted, the first refusal check fails on unsupported instruction global_load_dword.
  • ctest --preset dev -R '^native_' -j 2 on e3670100 plus the change: 97/99 passed, 9 skipped (77). The two failures are graphics PSO creations that return 0x80070057 on this adapter: native_graphics_vertex_vcc_join_hardware (it failed the same way before the change on e97c5c7c) and native_startup_request_cache_hardware (a desktop graphics pipeline; not compared against a baseline). This change only adds a compute-stage decode.
  • After the rebase onto f934df52, native_direct_container, native_shift64_controls and native_global_load_hardware (skip) were rerun.
  • python -B tests/docs_links_check.py: ok.

Evidence and follow-up

Fixture. All words are source-built and assembled with LLVM 15.0.7 (clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding). The dispatch has two groups of 32 lanes. It reads the root SRV that native_store_replay fills with 0x51aa0000 + dword index, sized to 64 dwords by a scalar load at byte 252. Each lane stores five words:

  • offset 0, offset 16 and offset -8 (0 below byte 0);
  • a VADDR of 0xfffffff0 or above with offset 16, which the guard turns into 0;
  • an unaligned VADDR.

References with the offset dropped or the upper guard dropped must differ from the readback. The lower guard is not observable under a view below 4 GiB: the wrapped value lies outside the view either way.

Limits:

  • Addresses outside the bound view read 0, while the console reads the memory there. gfx2hlsl.py has the same limit. I did not check how the runtime sizes the root view on this branch.
  • Only the one-dword load is lowered.

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.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518918711 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2966). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T00:07:30Z. --- ## Change The direct C++ compute frontend now lowers `global_load_dword` in the `saddr` form. Before, it refused it with `unsupported instruction global_load_dword`. Refs #2962 (part of the "global loads" item in #2935). - **Address.** ADDR = SADDR + zext(VADDR) + sext(OFFSET[11:0]). SADDR must be the unadvanced root address of a root SRV with its matching high half. That is the same symbol and `root_buffer_srv` binding the scalar root loads in `memory()` already use. The load becomes a raw buffer load from that view. - **Wrap guard.** The 32-bit byte offset is guarded to [0, 2^32), the rule `gfx2hlsl.py` `op_global_load_dword` uses. A VADDR near 2^32 plus a positive offset reads 0 instead of wrapping into an in-bounds word. - **Alignment.** The low two address bits are dropped, as for `buffer_load_dword` in this path (DWORD alignment mode). `gfx2hlsl.py` refuses an unproven alignment instead; the console's `ALIGNMENT_MODE` is not measured. - **Refused by name.** The `off` form, the FLAT and scratch segments, other opcodes (wider loads, stores, atomics), the `lds` form, a non-root SADDR, a replaced high half, and an unaligned immediate offset. A pointer advanced by scalar arithmetic is refused earlier, as an unbound numeric SGPR. `gfx2hlsl.py` accepts a pointer advanced by a known literal; that is not done here. Files: `src/gfx1013_compute_native.cpp` (decode), `src/gfx1013_direct_compute.inl` (`global_load`), `tests/native_global_load_check.py`, `tests/cmake/native_global_load.cmake` and `docs/experiments/native-direct-global-load.md`. ## Verification Run on `cpp-migration` `f934df52` plus this commit, Windows 10.0.26100.9711, `dev` preset, NVIDIA Quadro M1000M (driver 32.0.15.7371), debug layer unavailable. - `ctest --preset dev --no-tests=error -R '^native_global_load_hardware$' -V` reports a **skip (77)**. The 11 refusals and the `dxc -dumpbin` module checks passed: 6 raw buffer loads, 2 upper-bound guards and 1 lower-bound guard. **The dispatch readback is not measured.** `native_store_replay` needs shader model 6.6 with wave32, which this Maxwell GPU lacks; `native_scalar_lds_hardware` and `native_shift64_hardware` skip here for the same reason. A run on an SM 6.6 wave32 adapter would be very welcome. - With the frontend change reverted, the first refusal check fails on `unsupported instruction global_load_dword`. - `ctest --preset dev -R '^native_' -j 2` on `e3670100` plus the change: 97/99 passed, 9 skipped (77). The two failures are graphics PSO creations that return `0x80070057` on this adapter: `native_graphics_vertex_vcc_join_hardware` (it failed the same way before the change on `e97c5c7c`) and `native_startup_request_cache_hardware` (a desktop graphics pipeline; not compared against a baseline). This change only adds a compute-stage decode. - After the rebase onto `f934df52`, `native_direct_container`, `native_shift64_controls` and `native_global_load_hardware` (skip) were rerun. - `python -B tests/docs_links_check.py`: ok. ## Evidence and follow-up **Fixture.** All words are source-built and assembled with LLVM 15.0.7 (`clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding`). The dispatch has two groups of 32 lanes. It reads the root SRV that `native_store_replay` fills with 0x51aa0000 + dword index, sized to 64 dwords by a scalar load at byte 252. Each lane stores five words: - offset 0, offset 16 and offset -8 (0 below byte 0); - a VADDR of 0xfffffff0 or above with offset 16, which the guard turns into 0; - an unaligned VADDR. References with the offset dropped or the upper guard dropped must differ from the readback. The lower guard is not observable under a view below 4 GiB: the wrapped value lies outside the view either way. **Limits:** - Addresses outside the bound view read 0, while the console reads the memory there. `gfx2hlsl.py` has the same limit. I did not check how the runtime sizes the root view on this branch. - Only the one-dword load is lowered. ## 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MasterDomino commented 2026-11-27 00:34:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T00:34:18Z.

Review: APPROVED


Review of head c5776536, tested merged onto cpp-migration 8946fb16 (after #2964). It auto-merges cleanly, and CI on the head is green. This is the dispatch readback you asked for, on an SM 6.6 wave32 adapter. Approving and merging.

Code read:

  • Decode matches gfx10 FLAT/GLOBAL: 0x37 in [31:26], SEG = 2, opcode 12, the LDS bit refused, SADDR 125 (off) refused, a 12-bit signed offset, VADDR in word 1 [7:0] and VDST in [31:24].
  • Base: the unadvanced root address pair, with a matching high half, bound as the existing root_buffer_srv, and required_bytes widened to the positive offset.
  • Wrap guard: applied as in gfx2hlsl.op_global_load_dword, but only when the offset is non-zero, which is the only case that can wrap.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release.

  • native_global_load_hardware passed:
    • global_load_dword: 320 words of two groups matched (offsets 0, 16, -8, the 2^32 guard and an unaligned address); the offset-dropped and wrap-guard-dropped references differ;
    • refusals: off, a table pointer, offset:2, dwordx2, store, a replaced high half, an advanced pointer, lds, flat and scratch segments, an atomic.
  • ctest --preset release --no-tests=error -R '^native_': 48 tests, 47 passed and 1 skipped (77, native_comparison_pso_warp). The two graphics PSO failures you saw on the Quadro M1000M (0x80070057) do not happen here: native_graphics_vertex_vcc_join_hardware and native_startup_request_cache_hardware both pass. So they look specific to that adapter or driver.

Mutation here: ignoring the immediate offset (addr = vaddr) fails the readback, for example (9, '0x51aa0000', '0x51aa0004'). With it restored, it passes.

Open, as you note, not blocking: dropping the low two address bits assumes DWORD alignment mode for global loads. The console's SH_MEM_CONFIG.ALIGNMENT_MODE is not measured, and gfx2hlsl.py refuses an unproven alignment instead. The fixture's unaligned case pins the current choice, so a later measurement will show up as a fixture change.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6081991098 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2966#pullrequestreview-6081991098). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T00:34:18Z. **Review:** APPROVED --- Review of head `c5776536`, tested merged onto `cpp-migration` `8946fb16` (after #2964). It auto-merges cleanly, and CI on the head is green. **This is the dispatch readback you asked for**, on an SM 6.6 wave32 adapter. Approving and merging. **Code read:** - **Decode** matches gfx10 FLAT/GLOBAL: `0x37` in [31:26], SEG = 2, opcode 12, the LDS bit refused, SADDR 125 (`off`) refused, a 12-bit signed offset, VADDR in word 1 [7:0] and VDST in [31:24]. - **Base:** the unadvanced root address pair, with a matching high half, bound as the existing `root_buffer_srv`, and `required_bytes` widened to the positive offset. - **Wrap guard:** applied as in `gfx2hlsl.op_global_load_dword`, but only when the offset is non-zero, which is the only case that can wrap. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. - `native_global_load_hardware` **passed**: - `global_load_dword: 320 words of two groups matched (offsets 0, 16, -8, the 2^32 guard and an unaligned address); the offset-dropped and wrap-guard-dropped references differ`; - refusals: `off, a table pointer, offset:2, dwordx2, store, a replaced high half, an advanced pointer, lds, flat and scratch segments, an atomic`. - `ctest --preset release --no-tests=error -R '^native_'`: 48 tests, 47 passed and 1 skipped (77, `native_comparison_pso_warp`). The two graphics PSO failures you saw on the Quadro M1000M (`0x80070057`) do **not** happen here: `native_graphics_vertex_vcc_join_hardware` and `native_startup_request_cache_hardware` both pass. So they look specific to that adapter or driver. **Mutation here:** ignoring the immediate offset (`addr = vaddr`) fails the readback, for example `(9, '0x51aa0000', '0x51aa0004')`. With it restored, it passes. **Open, as you note, not blocking:** dropping the low two address bits assumes DWORD alignment mode for global loads. The console's `SH_MEM_CONFIG.ALIGNMENT_MODE` is not measured, and `gfx2hlsl.py` refuses an unproven alignment instead. The fixture's unaligned case pins the current choice, so a later measurement will show up as a fixture change. AI-assisted; the commands above were run locally.
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!2966
No description provided.