shader: lower global_load_*_d16 in native compute #3783

Merged
R0D4X merged 1 commit from upstream-pr/3783 into main 2026-12-02 01:54:30 +00:00
R0D4X commented 2026-12-01 21:43:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-12-01T21:43:40Z.


Refs #3224, #2935

Summary

Lowers the six GFX10 D16 sub-DWORD GLOBAL load instructions (global_load_{ubyte,sbyte,short}_d16{,_hi}, opcodes 0x20..0x25) in the direct C++ compute frontend (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl), reusing global_subdword_load for alignment, cross-DWORD halfword extraction, and 32-bit wrap guards while preserving the untouched 16-bit half of v_dst.

Changes

  • src/gfx1013_compute_native.cpp:
    • Admit opcodes 0x20..0x25 alongside 0x08..0x0b in subdword_load decoding.
    • Clear VGPR spill tracking (s.clear_spills(256 + i.dst)) for all global_load_* sub-DWORD and D16 variants.
  • src/gfx1013_direct_compute.inl:
    • Extend global_subdword_load to support d16 (low half) and d16_hi (high half): read old_dst before vector_write, apply the 32-bit wrap guard to the loaded value (so a wrapped lane zeroes only the target 16-bit half), mask to 16 bits, and merge into the low or high half of old_dst.
  • tests/native_global_subdword_d16_load_check.py, tests/cmake/native_global_subdword_d16_load.cmake, and tests/checks/python-linux/native-global-subdword-d16-load.txt:
    • Pure-Python encodings check verifying exact RDNA 2 disassembly of all 6 opcodes and reference-model wrap/sign-extension invariants (registered in Linux CI).
    • Hardware replay check (native_global_subdword_d16_load_hardware): 28 cases per lane across 64 lanes (1,792 32-bit outputs) covering all 6 opcodes, non-zero untouched half preservation, sign-extension on negative bytes (0x80, 0xaa, 0xff), cross-DWORD halfwords (addr & 3 == 3), 32-bit wrap guards, chained low+high loads into one VGPR, self-aliasing (v_dst == v_addr), and both root SRV and root UAV bases.
  • tests/native_global_subdword_load_check.py:
    • Remove global_load_ubyte_d16 (0x20) and global_load_short_d16 (0x24) from the unsupported-opcode refusal list while keeping byte/short stores (0x18, 0x1a), atomics (0x32), and all other refusal controls intact.

Verification

  • Commit: c59fddae (based on main 158ef794)
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK / DXC 10.0.26100.0, NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2140).

Commands and results

ctest --preset dev --no-tests=error -R '^native_global_subdword_' -V
ctest --preset release --no-tests=error -R '^native_global_subdword_' -V
  • dev (Debug): 4/4 Passed (native_global_subdword_d16_load_encodings, native_global_subdword_d16_load_hardware 0.48 s, native_global_subdword_load_encodings, native_global_subdword_load_hardware 1.19 s).
  • release (/O2): 4/4 Passed (native_global_subdword_d16_load_encodings, native_global_subdword_d16_load_hardware 0.56 s, native_global_subdword_load_encodings, native_global_subdword_load_hardware 1.19 s).

Fail-first / mutation control

Mutating the preserved-high-half mask (4294901760 -> 0) in src/gfx1013_direct_compute.inl and rebuilding compile_dxil + native_store_replay fails native_global_subdword_d16_load_hardware (exit 8) with readback mismatches ([(2072, '0x0', '0xabcd0000'), (2073, '0xaa', '0xaafa00aa'), ...]).

Pure-Python checks

.\out\pe-env\Scripts\python.exe -B tests\native_global_subdword_d16_load_check.py encodings
.\out\pe-env\Scripts\python.exe -B tests\docs_links_check.py
.\out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py
  • All PASS.

Scope note

This verifies source-built gfx1013 compute fixtures through compile_dxil and native_store_replay --direct on the RTX 5080; it does not establish full-title startup or frame rate.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5595102776 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3783). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-12-01T21:43:40Z. --- Refs #3224, #2935 ## Summary Lowers the six GFX10 D16 sub-DWORD GLOBAL load instructions (`global_load_{ubyte,sbyte,short}_d16{,_hi}`, opcodes `0x20..0x25`) in the direct C++ compute frontend (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_compute.inl`), reusing `global_subdword_load` for alignment, cross-DWORD halfword extraction, and 32-bit wrap guards while preserving the untouched 16-bit half of `v_dst`. ### Changes - `src/gfx1013_compute_native.cpp`: - Admit opcodes `0x20..0x25` alongside `0x08..0x0b` in `subdword_load` decoding. - Clear VGPR spill tracking (`s.clear_spills(256 + i.dst)`) for all `global_load_*` sub-DWORD and D16 variants. - `src/gfx1013_direct_compute.inl`: - Extend `global_subdword_load` to support `d16` (low half) and `d16_hi` (high half): read `old_dst` before `vector_write`, apply the 32-bit wrap guard to the loaded value (so a wrapped lane zeroes only the target 16-bit half), mask to 16 bits, and merge into the low or high half of `old_dst`. - `tests/native_global_subdword_d16_load_check.py`, `tests/cmake/native_global_subdword_d16_load.cmake`, and `tests/checks/python-linux/native-global-subdword-d16-load.txt`: - Pure-Python `encodings` check verifying exact RDNA 2 disassembly of all 6 opcodes and reference-model wrap/sign-extension invariants (registered in Linux CI). - Hardware replay check (`native_global_subdword_d16_load_hardware`): 28 cases per lane across 64 lanes (1,792 32-bit outputs) covering all 6 opcodes, non-zero untouched half preservation, sign-extension on negative bytes (`0x80`, `0xaa`, `0xff`), cross-DWORD halfwords (`addr & 3 == 3`), 32-bit wrap guards, chained low+high loads into one VGPR, self-aliasing (`v_dst == v_addr`), and both root SRV and root UAV bases. - `tests/native_global_subdword_load_check.py`: - Remove `global_load_ubyte_d16` (`0x20`) and `global_load_short_d16` (`0x24`) from the unsupported-opcode refusal list while keeping byte/short stores (`0x18`, `0x1a`), atomics (`0x32`), and all other refusal controls intact. ## Verification - **Commit:** `c59fddae` (based on `main` `158ef794`) - **Environment:** Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK / DXC `10.0.26100.0`, NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2140`). ### Commands and results ```powershell ctest --preset dev --no-tests=error -R '^native_global_subdword_' -V ctest --preset release --no-tests=error -R '^native_global_subdword_' -V ``` - `dev` (Debug): 4/4 **Passed** (`native_global_subdword_d16_load_encodings`, `native_global_subdword_d16_load_hardware` 0.48 s, `native_global_subdword_load_encodings`, `native_global_subdword_load_hardware` 1.19 s). - `release` (`/O2`): 4/4 **Passed** (`native_global_subdword_d16_load_encodings`, `native_global_subdword_d16_load_hardware` 0.56 s, `native_global_subdword_load_encodings`, `native_global_subdword_load_hardware` 1.19 s). ### Fail-first / mutation control Mutating the preserved-high-half mask (`4294901760` -> `0`) in `src/gfx1013_direct_compute.inl` and rebuilding `compile_dxil` + `native_store_replay` fails `native_global_subdword_d16_load_hardware` (exit 8) with readback mismatches (`[(2072, '0x0', '0xabcd0000'), (2073, '0xaa', '0xaafa00aa'), ...]`). ### Pure-Python checks ```powershell .\out\pe-env\Scripts\python.exe -B tests\native_global_subdword_d16_load_check.py encodings .\out\pe-env\Scripts\python.exe -B tests\docs_links_check.py .\out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py ``` - All **PASS**. ## Scope note This verifies source-built gfx1013 compute fixtures through `compile_dxil` and `native_store_replay --direct` on the RTX 5080; it does not establish full-title startup or frame rate. AI-assisted.
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!3783
No description provided.