shader: lower flat_load_dword through TitleLookup in pixel_aot #694

Manually merged
github merged 4 commits from gh-pr/694/head into gh-pr/694/base 2026-11-26 22:12:21 +00:00
Owner

@⁠Its3rr0rsWRLD on GitHub · 2026-11-22 20:40 UTC · original
Its3rr0rsWRLD:flat-load-dword → main · +424 −30 · 5 files · 4 commits · merged 2026-11-23 07:20 UTC

This is Claude Opus 5.5. It is the first flat-load step for #319, built on the design notes thepatrickworld posted there. flat_load_dword, and global_load_dword with off, now read one DWORD through TitleLookup from #284. The address is the VGPR pair plus the offset, sign-extended to 64 bits with the carry or borrow taken into the high word. Ranges are a StructuredBuffer<TitleRange> at t0, space1 and the aliased buffers are ByteAddressBuffer TitleAliases[8] at t1, space1 with NonUniformResourceIndex, on ps_6_0. A miss, a DWORD not inside a single range, a misaligned address or a slot past 8 reads 0xdeadbeef. The global off form is included because it is the same lowering, and LLVM 15 only accepts gfx1013 flat offsets from 0 to 2047, so the borrow case can only be tested through it. Wider, sub-DWORD and D16 loads, stores, atomics, scratch, the saddr and lds forms and cache bits stay refused, each by a control.

One program reads two addresses from the constant buffer. Six cases cover the first and last word of a range, carry and borrow across the 32-bit boundary, misses, a straddling DWORD and four slots. Eight wrong references must report pixel_mismatch, each followed by a passing draw: 22 draws in one batch. The program is also in the LLVM 15 round trip.

Test: ctest --preset dev --no-tests=error -R '^pixel_aot_title_loads_(warp|hardware)$' -V. Passed on an RTX 4070 Ti (1.4 s) and on WARP (0.8 s); pixel_aot_hardware and pixel_aot_warp still pass.

Questions for R0Y00:

  1. Should the range count be fixed at translation time (title_ranges=N, as now), or read at run time from a root constant or GetDimensions?
  2. Is a limit of 8 alias slots right, and should a slot of 8 or more read the sentinel, as it does now?
  3. Is 0xdeadbeef the right result for a miss, a straddling DWORD and a misaligned address, or should translation refuse instead?
  4. Is it right for flat and global to share one lowering? Flat addresses are treated as global, with no check for the private or LDS apertures.
  5. Should gfx1013 flat offsets with bit 11 set (LLVM prints them as 2048 to 4095) stay refused?
  6. Should tools/scan_unsupported_shaders.py count these forms as supported? This PR leaves it unchanged.
  7. Is the order of the next steps right: dwordx2/x3/x4, then 8- and 16-bit loads, then the global saddr form?

🤖 Generated with Claude Code

https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc

**@⁠Its3rr0rsWRLD** on GitHub · 2026-11-22 20:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/694) `Its3rr0rsWRLD:flat-load-dword` → `main` · +424 −30 · 5 files · 4 commits · merged 2026-11-23 07:20 UTC This is Claude Opus 5.5. It is the first flat-load step for #319, built on the design notes thepatrickworld posted there. `flat_load_dword`, and `global_load_dword` with `off`, now read one DWORD through `TitleLookup` from #284. The address is the VGPR pair plus the offset, sign-extended to 64 bits with the carry or borrow taken into the high word. Ranges are a `StructuredBuffer<TitleRange>` at `t0, space1` and the aliased buffers are `ByteAddressBuffer TitleAliases[8]` at `t1, space1` with `NonUniformResourceIndex`, on `ps_6_0`. A miss, a DWORD not inside a single range, a misaligned address or a slot past 8 reads `0xdeadbeef`. The global `off` form is included because it is the same lowering, and LLVM 15 only accepts gfx1013 flat offsets from 0 to 2047, so the borrow case can only be tested through it. Wider, sub-DWORD and D16 loads, stores, atomics, scratch, the `saddr` and `lds` forms and cache bits stay refused, each by a control. One program reads two addresses from the constant buffer. Six cases cover the first and last word of a range, carry and borrow across the 32-bit boundary, misses, a straddling DWORD and four slots. Eight wrong references must report `pixel_mismatch`, each followed by a passing draw: 22 draws in one batch. The program is also in the LLVM 15 round trip. Test: `ctest --preset dev --no-tests=error -R '^pixel_aot_title_loads_(warp|hardware)$' -V`. Passed on an RTX 4070 Ti (1.4 s) and on WARP (0.8 s); `pixel_aot_hardware` and `pixel_aot_warp` still pass. Questions for R0Y00: 1. Should the range count be fixed at translation time (`title_ranges=N`, as now), or read at run time from a root constant or `GetDimensions`? 2. Is a limit of 8 alias slots right, and should a slot of 8 or more read the sentinel, as it does now? 3. Is `0xdeadbeef` the right result for a miss, a straddling DWORD and a misaligned address, or should translation refuse instead? 4. Is it right for flat and global to share one lowering? Flat addresses are treated as global, with no check for the private or LDS apertures. 5. Should gfx1013 flat offsets with bit 11 set (LLVM prints them as 2048 to 4095) stay refused? 6. Should `tools/scan_unsupported_shaders.py` count these forms as supported? This PR leaves it unchanged. 7. Is the order of the next steps right: `dwordx2`/`x3`/`x4`, then 8- and 16-bit loads, then the global `saddr` form? 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
pixel_aot lowered no vector memory. flat_load_dword, and global_load_dword
with `off`, now read one DWORD at a 64-bit title address through TitleLookup
(src/title_va_lookup.hlsli), as proposed in #319:

- the address is the VGPR pair plus the instruction offset, sign-extended to
  64 bits with the carry or borrow taken into the high word; LLVM 15 prints
  gfx1013 flat offsets as 11-bit unsigned and global offsets as 12-bit
  signed, so the borrow is only reachable through the global form;
- the range table is StructuredBuffer<TitleRange> at t0, space1 and the
  aliased buffers ByteAddressBuffer TitleAliases[8] at t1, space1, indexed
  with NonUniformResourceIndex; the range count is fixed at translation
  time (lower(title_ranges=N)) and both forms are refused without it;
- an address in no range, a DWORD not inside a single range, a misaligned
  address and a slot past the eighth read 0xdeadbeef, never zero;
- the word is ready after a vmcnt wait that covers it, counted in issue
  order with image samples.

Wider, sub-DWORD and D16 loads, stores, atomics, scratch, the global saddr
and lds forms, cache-policy bits and out-of-range offsets stay refused, each
by a control. The scratch-base writes still translate as no-ops before a
flat load.

The case trailer's flag bit 2 carries the ranges and slot buffers, and the
renderer binds them after the two textures. One program reads two addresses
from the constant buffer; six cases cover first and last words, carry and
borrow across the 32-bit boundary, misses, a straddling DWORD and four
slots. Eight wrong references (high word dropped, immediate ignored or
masked, carry dropped, sentinel dropped, straddle accepted, slot masked to
one bit, range count one short) must mismatch, each followed by a passing
draw: 22 draws in one batch, pixel_aot_title_loads_(warp|hardware). The
program is part of the LLVM 15 round trip.

Refs #319

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:12:18 +00:00
github manually merged commit 143479fbfc into gh-pr/694/base 2026-11-26 22:12:21 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 04:36 UTC · original

For the first DWORD-only profile, keep the fixed range count, eight bound aliases and existing TitleLookup miss sentinel. Document those as properties of the explicit binding profile. global_load_dword ... off fits directly. Accept flat_load_dword only when that profile explicitly guarantees a global address and excludes scratch/LDS apertures. Keep bit-11 flat offsets outside this slice until there is an independent encoding and effective-address comparison. Please keep these forms out of generic scanner coverage unless the scanner can establish the profile’s binding and address preconditions. Wider, sub-DWORD and saddr forms can remain separate. The existing carry/borrow, alignment, straddle and wrong-slot cases should stay in the DWORD fixture.

**@⁠R0Y00** on GitHub · 2026-11-23 04:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7091719885) For the first DWORD-only profile, keep the fixed range count, eight bound aliases and existing TitleLookup miss sentinel. Document those as properties of the explicit binding profile. `global_load_dword ... off` fits directly. Accept `flat_load_dword` only when that profile explicitly guarantees a global address and excludes scratch/LDS apertures. Keep bit-11 flat offsets outside this slice until there is an independent encoding and effective-address comparison. Please keep these forms out of generic scanner coverage unless the scanner can establish the profile’s binding and address preconditions. Wider, sub-DWORD and saddr forms can remain separate. The existing carry/borrow, alignment, straddle and wrong-slot cases should stay in the DWORD fixture.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 06:29 UTC · original

I pushed 7ec6337 with the explicit flat_global_only=True binding option and resolved the renderer and lowerer conflicts. The new static control rejects a flat load when only the range table is supplied, while the global off form still lowers in that mode. Windows Release passed title-load readbacks on hardware and WARP, plus the existing WARP buffer-color and compressed-export checks. The LLVM and Windows CI results for the pushed commit are pending.

**@⁠R0Y00** on GitHub · 2026-11-23 06:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7093388519) I pushed `7ec6337` with the explicit `flat_global_only=True` binding option and resolved the renderer and lowerer conflicts. The new static control rejects a flat load when only the range table is supplied, while the global `off` form still lowers in that mode. Windows Release passed title-load readbacks on hardware and WARP, plus the existing WARP buffer-color and compressed-export checks. The LLVM and Windows CI results for the pushed commit are pending.
Author
Owner

@⁠MatyEjsr on GitHub · 2026-11-23 06:52 UTC · original

Verdict: Approve (static, Python, offline DXC, and ISA review of head 7ec6337ba6c3677ddb7479479e40958b7396d65a, compared against main 20e4357).

Verification

Environment: Windows 11 x64, Python 3.12.10, DXC 1.9.0.5512 (C:\VulkanSDK\1.4.363.0\Bin\dxc.exe) for offline HLSL-to-DXIL compile checks, and WSL Arch llvm-mc 23.1.5 (-triple=amdgcn--amdpal -mcpu=gfx1013) for ISA offset bounds. Zero-GPU review (no WARP or hardware draw executed locally; all 4 CI jobs including Windows dev and /O2 passed on 7ec6337).

Commands and results on 7ec6337:

  • python -B tests/pixel_aot_check.py: passed (exit 0).
  • python -B tests/rdna2_tools_check.py: 64 passed, 1 skipped (test_llvm_comparison, skipped because LLVM_LIB is not set on Windows).
  • python -B tests/docs_links_check.py (13 files, 154 links) and python -B tests/bidi_controls_check.py (654 files): both passed.
  • git merge-tree --write-tree main 7ec6337: clean against 20e4357 (exit 0).

Independent ISA, DXC, and negative-control checks:

  • Offset bounds (llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding): Confirmed flat_load_dword accepts 0..2047 and rejects 2048/4095/-4 (expected a 11-bit unsigned offset), and global_load_dword ..., off accepts -2048..2047 and rejects 2048/-2049 (expected a 12-bit signed offset), matching TITLE_OFFSETS.
  • Offline DXC (-T ps_6_0 -E main -WX and -T ps_6_6 -E main -WX): Both flat_load_dword (title_ranges=2, flat_global_only=True) and global_load_dword ... off (title_ranges=2) lowered HLSL compiled cleanly (exit 0, 0 warnings/errors).
  • Profile guards & edge cases:
    • Rejected: flat_load_dword without flat_global_only=True, flat_load_dword without title_ranges, title_ranges in {0, -1, True}, flat_load_dword exported without s_waitcnt, glc modifier, and offset:2048.
    • Accepted: self-overwriting address pair (flat_load_dword v18, v[18:19]).
    • Confirmed scan_unsupported_shaders.is_instruction_supported("flat_load_dword v12, v[18:19]") == False (and is_opcode_recognized("flat_load_dword") == True), matching the explicit binding-profile requirement.

Non-blocking note: on gfx1013 hardware, flat_load_dword increments both vmcnt and lgkmcnt, whereas lower() tracks it only via sample_dest (vmcnt), so s_waitcnt vmcnt(0) alone clears it here. That is acceptable for the explicit flat_global_only=True global-address slice, and worth keeping in mind if a future profile models non-global flat apertures.

AI-assisted review (local Python, offline DXC, and llvm-mc checks executed locally).

**@⁠MatyEjsr** on GitHub · 2026-11-23 06:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7093767251) **Verdict: Approve** (static, Python, offline DXC, and ISA review of head `7ec6337ba6c3677ddb7479479e40958b7396d65a`, compared against `main` `20e4357`). ### Verification Environment: Windows 11 x64, Python 3.12.10, DXC `1.9.0.5512` (`C:\VulkanSDK\1.4.363.0\Bin\dxc.exe`) for offline HLSL-to-DXIL compile checks, and WSL Arch `llvm-mc` 23.1.5 (`-triple=amdgcn--amdpal -mcpu=gfx1013`) for ISA offset bounds. Zero-GPU review (no WARP or hardware draw executed locally; all 4 CI jobs including Windows `dev` and `/O2` passed on `7ec6337`). Commands and results on `7ec6337`: - `python -B tests/pixel_aot_check.py`: passed (exit 0). - `python -B tests/rdna2_tools_check.py`: **64 passed, 1 skipped** (`test_llvm_comparison`, skipped because `LLVM_LIB` is not set on Windows). - `python -B tests/docs_links_check.py` (13 files, 154 links) and `python -B tests/bidi_controls_check.py` (654 files): both passed. - `git merge-tree --write-tree main 7ec6337`: clean against `20e4357` (exit 0). Independent ISA, DXC, and negative-control checks: - **Offset bounds (`llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding`):** Confirmed `flat_load_dword` accepts `0..2047` and rejects `2048`/`4095`/`-4` (`expected a 11-bit unsigned offset`), and `global_load_dword ..., off` accepts `-2048..2047` and rejects `2048`/`-2049` (`expected a 12-bit signed offset`), matching `TITLE_OFFSETS`. - **Offline DXC (`-T ps_6_0 -E main -WX` and `-T ps_6_6 -E main -WX`):** Both `flat_load_dword` (`title_ranges=2, flat_global_only=True`) and `global_load_dword ... off` (`title_ranges=2`) lowered HLSL compiled cleanly (exit 0, 0 warnings/errors). - **Profile guards & edge cases:** - Rejected: `flat_load_dword` without `flat_global_only=True`, `flat_load_dword` without `title_ranges`, `title_ranges` in `{0, -1, True}`, `flat_load_dword` exported without `s_waitcnt`, `glc` modifier, and `offset:2048`. - Accepted: self-overwriting address pair (`flat_load_dword v18, v[18:19]`). - Confirmed `scan_unsupported_shaders.is_instruction_supported("flat_load_dword v12, v[18:19]") == False` (and `is_opcode_recognized("flat_load_dword") == True`), matching the explicit binding-profile requirement. Non-blocking note: on `gfx1013` hardware, `flat_load_dword` increments both `vmcnt` and `lgkmcnt`, whereas `lower()` tracks it only via `sample_dest` (`vmcnt`), so `s_waitcnt vmcnt(0)` alone clears it here. That is acceptable for the explicit `flat_global_only=True` global-address slice, and worth keeping in mind if a future profile models non-global flat apertures. *AI-assisted review (local Python, offline DXC, and `llvm-mc` checks executed locally).*
This discussion has been locked. Commenting is limited to contributors.
No description provided.