shader: lower flat_load_dword through TitleLookup in pixel_aot #688

Merged
Its3rr0rsWRLD merged 4 commits from upstream-pr/694 into main 2026-11-23 07:20:15 +00:00
Its3rr0rsWRLD commented 2026-11-22 20:40:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-22T20:40:57Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547517467 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/694). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-22T20:40:57Z. --- 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
upstream-sync closed this pull request 2026-11-24 06:44:22 +00:00
R0Y00 commented 2026-11-24 06:49:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T04:36:27Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7091719885 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7091719885). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T04:36:27Z. --- 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 commented 2026-11-24 06:49:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T06:29:43Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7093388519 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7093388519). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T06:29:43Z. --- 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.
MatyEjsr commented 2026-11-24 06:49:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MatyEjsr on 2026-11-23T06:52:53Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7093767251 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/694#issuecomment-7093767251). Originally posted by [MatyEjsr](https://github.com/MatyEjsr) on 2026-11-23T06:52:53Z. --- **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).*
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!688
No description provided.