shader: lower direct MTBUF packed half stores #3353

Merged
RonLogic merged 1 commit from upstream-pr/3353 into main 2026-11-29 00:04:34 +00:00
RonLogic commented 2026-11-28 12:23:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T12:23:28Z.


Refs #2935 and #3302.

The direct gfx1013 Compute path accepts packed D16 buffer stores through MUBUF, but rejected the corresponding MTBUF instructions. On clean main 052abe6f all six source-built MTBUF requests stopped at MTBUF requires a non-D16 load without index, cache modifiers or TFE, before DXIL or manifest publication.

Admit tbuffer_store_format_d16_x, _xy and _xyzw when the instruction carries the exact-width FLOAT format. Both an element index and element zero reuse the existing packed-half lowering and published typed buffer UAV binder. Keep unsupported widths, other numeric formats, byte offsets, cache modifiers and TFE refused. The explicit instruction format follows the AMD RDNA 2 ISA MTBUF contract.

At 6a7923c232a742e7ef08db7dff94f3e0ede8021d, all six MTBUF combinations assembled and validated as DXIL, published their typed manifest, created a PSO, and ran through the ordinary slot 67/14 path with fenced output readback. Each run compares all 320 dwords. The indexed tests write 13 distinct records at byte 8. The element-zero tests use a single writer and a nonzero value in the unused address VGPR. They match the packed binary16 reference and preserve the guards. Toggling only IDXEN in a one-writer control moved the stored pair from output word 2 to word 5 on both adapters. The existing three MUBUF widths still match. Negative inputs cover byte-offset forms, SLC, a mismatched numeric format, and XYZ, plus mismatched or out-of-range runtime views that leave the output untouched.

RTX 4070 and app-local WARP passed 9/9 CTest cases in Debug and 9/9 in Release, with no skips. Windows 26300.10075, NVIDIA driver 32.0.16.2124, DXC 1.9.2602.17, Agility 1.620.2 and WARP 1.0.22. Both adapters had the D3D12 debug layer enabled.

cmake --build --preset <dev-or-release> --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay
ctest --preset <dev-or-release> --no-tests=error -j 1 -V -R '^(startup_compute_(half_buffer_uav_.*|dispatch_(entry|output)_(warp|hardware))|native_(mtbuf_hardware|direct_container))$'

The results cover the source-built Compute fixtures. I used Codex to prepare the change and ran the verification locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5540083156 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3353). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-28T12:23:28Z. --- Refs #2935 and #3302. The direct gfx1013 Compute path accepts packed D16 buffer stores through MUBUF, but rejected the corresponding MTBUF instructions. On clean main `052abe6f` all six source-built MTBUF requests stopped at `MTBUF requires a non-D16 load without index, cache modifiers or TFE`, before DXIL or manifest publication. Admit `tbuffer_store_format_d16_x`, `_xy` and `_xyzw` when the instruction carries the exact-width FLOAT format. Both an element index and element zero reuse the existing packed-half lowering and published typed buffer UAV binder. Keep unsupported widths, other numeric formats, byte offsets, cache modifiers and TFE refused. The explicit instruction format follows the [AMD RDNA 2 ISA MTBUF contract](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture). At `6a7923c232a742e7ef08db7dff94f3e0ede8021d`, all six MTBUF combinations assembled and validated as DXIL, published their typed manifest, created a PSO, and ran through the ordinary slot 67/14 path with fenced output readback. Each run compares all 320 dwords. The indexed tests write 13 distinct records at byte 8. The element-zero tests use a single writer and a nonzero value in the unused address VGPR. They match the packed binary16 reference and preserve the guards. Toggling only IDXEN in a one-writer control moved the stored pair from output word 2 to word 5 on both adapters. The existing three MUBUF widths still match. Negative inputs cover byte-offset forms, SLC, a mismatched numeric format, and XYZ, plus mismatched or out-of-range runtime views that leave the output untouched. RTX 4070 and app-local WARP passed 9/9 CTest cases in Debug and 9/9 in Release, with no skips. Windows 26300.10075, NVIDIA driver 32.0.16.2124, DXC 1.9.2602.17, Agility 1.620.2 and WARP 1.0.22. Both adapters had the D3D12 debug layer enabled. ```powershell cmake --build --preset <dev-or-release> --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay ctest --preset <dev-or-release> --no-tests=error -j 1 -V -R '^(startup_compute_(half_buffer_uav_.*|dispatch_(entry|output)_(warp|hardware))|native_(mtbuf_hardware|direct_container))$' ``` The results cover the source-built Compute fixtures. I used Codex to prepare the change and ran the verification locally.
R0D4X commented 2026-11-28 14:03:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-28T14:03:56Z.

Review: COMMENTED


Commit 6a7923c232a742e7ef08db7dff94f3e0ede8021d (shader: lower direct MTBUF packed half stores).

Verified on Windows 11 Pro 26H2, NVIDIA GeForce RTX 5080 (driver 32.0.16.2140, nvidia-smi), MSVC 19.44, DXC 10.0.26100.0/x64, CMake/Ninja dev+release builds in out/build/dev and out/build/release.

Built targets before testing:
cmd /c ""C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 >nul && cmake --build --preset dev --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay"
cmd /c ""C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 >nul && cmake --build --preset release --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay"

CTest (dev): ctest --preset dev --no-tests=error -j 1 -V -R "^(startup_compute_(half_buffer_uav_.*|dispatch_(entry|output)_(warp|hardware))|native_(mtbuf_hardware|direct_container))$" -> 8 passed, 1 skipped out of 9. startup_compute_half_buffer_uav_warp skipped (77): WARP adapter lacks SM 6.6/WaveOps/32-lane wave required by the shader-wave32 fixture on this machine; not a pass/fail.
CTest (release): same pattern -> 8 passed, 1 skipped out of 9, same WARP capability skip.

Passed tests include native_mtbuf_hardware, native_direct_container, startup_compute_dispatch_entry_warp/hardware, startup_compute_dispatch_output_warp/hardware, startup_compute_half_buffer_uav_controls, and startup_compute_half_buffer_uav_hardware.

Targeted mutations (reverted cleanly with git checkout -- src/gfx1013_compute_native.cpp after each): (1) removed MTBUF D16 format-equality check (format != half_formats[count]) -> startup_compute_half_buffer_uav_controls failed as expected (bad store accepted/compiled). (2) replaced MTBUF D16 addressing/modifier guard with if (false) -> startup_compute_half_buffer_uav_controls failed as expected. No blocking defect found in the PR as-is.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6098269476 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3353#pullrequestreview-6098269476). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-28T14:03:56Z. **Review:** COMMENTED --- Commit `6a7923c232a742e7ef08db7dff94f3e0ede8021d` (`shader: lower direct MTBUF packed half stores`). Verified on Windows 11 Pro 26H2, NVIDIA GeForce RTX 5080 (driver 32.0.16.2140, `nvidia-smi`), MSVC 19.44, DXC `10.0.26100.0/x64`, CMake/Ninja dev+release builds in `out/build/dev` and `out/build/release`. Built targets before testing: `cmd /c ""C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 >nul && cmake --build --preset dev --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay"` `cmd /c ""C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 >nul && cmake --build --preset release --target offscreen_check compile_dxil startup_stream_consumer d3d12_xs_shim native_store_replay"` CTest (dev): `ctest --preset dev --no-tests=error -j 1 -V -R "^(startup_compute_(half_buffer_uav_.*|dispatch_(entry|output)_(warp|hardware))|native_(mtbuf_hardware|direct_container))$"` -> 8 passed, 1 skipped out of 9. `startup_compute_half_buffer_uav_warp` skipped (77): WARP adapter lacks SM 6.6/WaveOps/32-lane wave required by the shader-wave32 fixture on this machine; not a pass/fail. CTest (release): same pattern -> 8 passed, 1 skipped out of 9, same WARP capability skip. Passed tests include `native_mtbuf_hardware`, `native_direct_container`, `startup_compute_dispatch_entry_warp/hardware`, `startup_compute_dispatch_output_warp/hardware`, `startup_compute_half_buffer_uav_controls`, and `startup_compute_half_buffer_uav_hardware`. Targeted mutations (reverted cleanly with `git checkout -- src/gfx1013_compute_native.cpp` after each): (1) removed MTBUF D16 format-equality check (`format != half_formats[count]`) -> `startup_compute_half_buffer_uav_controls` failed as expected (bad store accepted/compiled). (2) replaced MTBUF D16 addressing/modifier guard with `if (false)` -> `startup_compute_half_buffer_uav_controls` failed as expected. No blocking defect found in the PR as-is. AI-assisted; commands listed were executed locally.
JB2WIN commented 2026-11-28 20:09:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-28T20:09:22Z.


For the "tests already fail on main" note: startup_compute_half_buffer_uav_{controls,hardware} fail on main without this PR. I bisected it locally between ee3347d3 (pass) and f5a6f6ba (fail). The first bad commit is 86cf5aa8 ("shader: merge main 3926a289 into the native shader stack"), from the native shader stack that came in with #3091. There a one-channel D16 store compiles to packed_d16_x_uav, which has no manifest line, so compile_dxil prints UAV kind unknown and nothing is published. Not-Saii described the same cause on #3224. SimSalabimse has claimed publishing that kind there, and #3395 names it in the reason.

startup_compute_dispatch_output_{warp,hardware} fail on f5a6f6ba too ("an output token does not identify a slot-19 UAV"). My bisect checked both tests together, so I can't say whether that one broke at the same commit. As far as I can see, nobody has claimed it yet.

So this PR's own MTBUF cases can't be checked through that file on main until the packed_d16_x_uav publishing lands.

Windows 11 26200, RTX 3080 (32.0.16.2124), WARP. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7245076182 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3353#issuecomment-7245076182). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-28T20:09:22Z. --- For the "tests already fail on main" note: `startup_compute_half_buffer_uav_{controls,hardware}` fail on `main` without this PR. I bisected it locally between `ee3347d3` (pass) and `f5a6f6ba` (fail). The first bad commit is `86cf5aa8` ("shader: merge main 3926a289 into the native shader stack"), from the native shader stack that came in with #3091. There a one-channel D16 store compiles to `packed_d16_x_uav`, which has no manifest line, so `compile_dxil` prints `UAV kind unknown` and nothing is published. Not-Saii described the same cause on #3224. SimSalabimse has claimed publishing that kind there, and #3395 names it in the reason. `startup_compute_dispatch_output_{warp,hardware}` fail on `f5a6f6ba` too ("an output token does not identify a slot-19 UAV"). My bisect checked both tests together, so I can't say whether that one broke at the same commit. As far as I can see, nobody has claimed it yet. So this PR's own MTBUF cases can't be checked through that file on main until the `packed_d16_x_uav` publishing lands. Windows 11 26200, RTX 3080 (32.0.16.2124), WARP. AI-assisted.
KelboLive commented 2026-11-28 20:54:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T20:54:42Z.

Review: APPROVED


LGTM — clean MTBUF D16 store lowering.

Parses explicit buffer_store_format_d16_x/xy/xyzw MTBUF opcodes (0x0c-0x0f), validates exact-width FLOAT formats (13, 29, 71), enforces index or element-zero with zero byte offsets, and reuses the MUBUF typed buffer UAV path. The test extension covers indexed, element-zero, and 4 invalid descriptor shapes via compile refusal.

Ready to land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6100049647 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3353#pullrequestreview-6100049647). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-28T20:54:42Z. **Review:** APPROVED --- LGTM — clean MTBUF D16 store lowering. Parses explicit buffer_store_format_d16_x/xy/xyzw MTBUF opcodes (0x0c-0x0f), validates exact-width FLOAT formats (13, 29, 71), enforces index or element-zero with zero byte offsets, and reuses the MUBUF typed buffer UAV path. The test extension covers indexed, element-zero, and 4 invalid descriptor shapes via compile refusal. Ready to land.
KelboLive commented 2026-11-28 21:57:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-28T21:57:35Z.

Review: APPROVED


LGTM — clean MTBUF D16 store lowering.

Parses explicit buffer_store_format_d16_x/xy/xyzw MTBUF opcodes (0x0c-0x0f), validates exact-width FLOAT formats (13, 29, 71), enforces index or element-zero with zero byte offsets, and reuses the MUBUF typed buffer UAV path. The test extension covers indexed, element-zero, and 4 invalid descriptor shapes via compile refusal.

Ready to land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6100254571 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3353#pullrequestreview-6100254571). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-28T21:57:35Z. **Review:** APPROVED --- LGTM — clean MTBUF D16 store lowering. Parses explicit buffer_store_format_d16_x/xy/xyzw MTBUF opcodes (0x0c-0x0f), validates exact-width FLOAT formats (13, 29, 71), enforces index or element-zero with zero byte offsets, and reuses the MUBUF typed buffer UAV path. The test extension covers indexed, element-zero, and 4 invalid descriptor shapes via compile refusal. Ready to land.
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!3353
No description provided.