shader: support partial final waves in native direct compute (Part of #3224, #2935) #3808

Merged
timbot103 merged 1 commit from upstream-pr/3808 into main 2026-12-02 02:38:28 +00:00
timbot103 commented 2026-12-02 01:05:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T01:05:51Z.


## Summary

Supports multi-wave compute threadgroups with a partial final wave (threads > width && threads % width != 0) for both guest wave32 and wave64 in the native direct DXIL compute compiler (Part of #3224, #2935; listed under "No open PR" on #3224, 2 shaders / 9,070 dispatches).

  • Host-wave padding & guest coordinate reconstruction (src/gfx1013_direct_compute.inl): pads the emitted DXIL [numthreads(host_threads, 1, 1)] to complete physical waves (ceil(threads / width) * width), ranks physical waves cleanly, reconstructs the original guest 1D/2D/3D thread coordinates, and computes per-wave valid_exec_lo / valid_exec_hi masks so padded tail lanes participate in barriers and wave64 half-exchange scratch without ever executing guest side effects or appearing active in ballots, v_readfirstlane_b32, lower_permlane, or lower_dpp (even after scalar EXEC writes).
  • Wave64 half-exchange & TG_SIZE_EN: allows converged multi-wave64 groups with partial final waves (including tails with <= 32 lanes where valid_exec_hi == 0), computes rounded-up guest wave count in TG_SIZE_EN, and keeps the runtime manifest on the original guest group shape.
  • Fail-closed controls (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl): keeps single narrow wave64 (threads < 64), divergent barriers / divergent wave64 half-exchange on partial final waves, ds_append, DS lane permutations (ds_swizzle / ds_bpermute / ds_permute), and out-of-range or SGPR v_readlane_b32 / v_writelane_b32 selectors explicitly refused.

Verification

Added source-built fixture suite native_partial_final_wave_{ir,warp,hardware} (tests/native_partial_final_wave_check.py) covering 18 positive readback cases (48x1x1, 70x1x1, 10x5x1, 5x5x2, 80x1x1, 96x1x1, 100x1x1 across ALU, masks/ballots, v_readlane/v_writelane, quad DPP, LDS+barrier, and wave64 half-exchange), a full-EXEC negative control catching unmasked tail count (32 vs 16), and refusal controls, plus updated native_compute_implicit_lod_check.py (36x1x1 positive, 38x1x1 refused).

Tested on Windows 11 (26200.9974), MSVC 19.44, Ninja, Windows SDK 10.0.26100.0, app-local WARP 1.0.22, and NVIDIA GeForce RTX 5080 (driver 32.0.16.2140; D3D12 debug layer unavailable on this host):

  • Debug (dev): ctest --preset dev --no-tests=error -R '^(native_partial_final_wave_|native_compute_implicit_lod_|native_dpp_|native_permlane_)' -V — 13/13 passed (0 failed, 0 skipped).
  • Release (release): ctest --preset release --no-tests=error -R '^(native_partial_final_wave_|native_compute_implicit_lod_|native_dpp_|native_permlane_)' -V — 13/13 passed (0 failed, 0 skipped).
  • All 18 positive readback cases and UAV tail guards matched on both WARP and RTX 5080.
  • git diff --check origin/main..HEAD: clean; zero new MSVC /W4 warnings.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5597690138 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3808). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T01:05:51Z. --- ## Summary Supports multi-wave compute threadgroups with a partial final wave (`threads > width && threads % width != 0`) for both guest wave32 and wave64 in the native direct DXIL compute compiler (Part of #3224, #2935; listed under "No open PR" on #3224, 2 shaders / 9,070 dispatches). - **Host-wave padding & guest coordinate reconstruction (`src/gfx1013_direct_compute.inl`):** pads the emitted DXIL `[numthreads(host_threads, 1, 1)]` to complete physical waves (`ceil(threads / width) * width`), ranks physical waves cleanly, reconstructs the original guest 1D/2D/3D thread coordinates, and computes per-wave `valid_exec_lo` / `valid_exec_hi` masks so padded tail lanes participate in barriers and wave64 half-exchange scratch without ever executing guest side effects or appearing active in ballots, `v_readfirstlane_b32`, `lower_permlane`, or `lower_dpp` (even after scalar `EXEC` writes). - **Wave64 half-exchange & `TG_SIZE_EN`:** allows converged multi-wave64 groups with partial final waves (including tails with <= 32 lanes where `valid_exec_hi == 0`), computes rounded-up guest wave count in `TG_SIZE_EN`, and keeps the runtime manifest on the original guest group shape. - **Fail-closed controls (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_compute.inl`):** keeps single narrow wave64 (`threads < 64`), divergent barriers / divergent wave64 half-exchange on partial final waves, `ds_append`, DS lane permutations (`ds_swizzle` / `ds_bpermute` / `ds_permute`), and out-of-range or SGPR `v_readlane_b32` / `v_writelane_b32` selectors explicitly refused. ## Verification Added source-built fixture suite `native_partial_final_wave_{ir,warp,hardware}` (`tests/native_partial_final_wave_check.py`) covering 18 positive readback cases (`48x1x1`, `70x1x1`, `10x5x1`, `5x5x2`, `80x1x1`, `96x1x1`, `100x1x1` across ALU, masks/ballots, `v_readlane`/`v_writelane`, quad DPP, LDS+barrier, and wave64 half-exchange), a full-EXEC negative control catching unmasked tail count (`32` vs `16`), and refusal controls, plus updated `native_compute_implicit_lod_check.py` (`36x1x1` positive, `38x1x1` refused). Tested on Windows 11 (`26200.9974`), MSVC `19.44`, Ninja, Windows SDK `10.0.26100.0`, app-local WARP `1.0.22`, and NVIDIA GeForce RTX 5080 (driver `32.0.16.2140`; D3D12 debug layer unavailable on this host): - **Debug (`dev`):** `ctest --preset dev --no-tests=error -R '^(native_partial_final_wave_|native_compute_implicit_lod_|native_dpp_|native_permlane_)' -V` — **13/13 passed** (0 failed, 0 skipped). - **Release (`release`):** `ctest --preset release --no-tests=error -R '^(native_partial_final_wave_|native_compute_implicit_lod_|native_dpp_|native_permlane_)' -V` — **13/13 passed** (0 failed, 0 skipped). - All 18 positive readback cases and UAV tail guards matched on both WARP and RTX 5080. - `git diff --check origin/main..HEAD`: clean; zero new MSVC `/W4` warnings. AI-assisted.
R0Y00 commented 2026-12-02 01:56:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T01:56:19Z.


Please rebase this on the merged #3796 (e0db3121). This head rewrites the same TG_SIZE_EN expression with guest_wave << 20, while current main encodes the wave ID in bits [11:6] and has a witness for TG_SIZE & 0xfc0. Please preserve that layout for both padded and full groups and include native_compute_tg_size alongside the partial-wave checks on the rebased head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7332277527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3808#issuecomment-7332277527). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T01:56:19Z. --- Please rebase this on the merged #3796 (`e0db3121`). This head rewrites the same `TG_SIZE_EN` expression with `guest_wave << 20`, while current main encodes the wave ID in bits [11:6] and has a witness for `TG_SIZE & 0xfc0`. Please preserve that layout for both padded and full groups and include `native_compute_tg_size` alongside the partial-wave checks on the rebased head.
timbot103 commented 2026-12-02 02:10:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T02:10:04Z.


@R0Y00 Rebased onto main (3ecfbad7, including merged #3796 e0db3121) as ac3f1d5c:

  • Preserved TG_SIZE[11:6] (guest_wave << 6, bit 31 first-wave, rounded-up wave count) in src/gfx1013_direct_compute.inl for both padded and full groups.
  • Updated tests/native_partial_final_wave_check.py (70x1x1 wave32 and 80x1x1/96x1x1/100x1x1 wave64 entry_masks cases) and docs/experiments/native-compute-partial-final-wave.md to check the [11:6] encoding on padded partial waves as well.
  • Re-verified on Windows 11 (26200.9974), MSVC 19.44 (C++20 / #3794), app-local WARP 1.0.22, and RTX 5080 (32.0.16.2140): 16/16 Debug and 16/16 Release passed (0 failed, 0 skipped), including native_compute_tg_size_{ir,warp,hardware}, native_partial_final_wave_{ir,warp,hardware}, native_compute_implicit_lod_*, native_dpp_*, and native_permlane_*.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7332545724 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3808#issuecomment-7332545724). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T02:10:04Z. --- @R0Y00 Rebased onto `main` (`3ecfbad7`, including merged #3796 `e0db3121`) as `ac3f1d5c`: - Preserved `TG_SIZE[11:6]` (`guest_wave << 6`, bit 31 first-wave, rounded-up wave count) in `src/gfx1013_direct_compute.inl` for both padded and full groups. - Updated `tests/native_partial_final_wave_check.py` (`70x1x1` wave32 and `80x1x1`/`96x1x1`/`100x1x1` wave64 `entry_masks` cases) and `docs/experiments/native-compute-partial-final-wave.md` to check the `[11:6]` encoding on padded partial waves as well. - Re-verified on Windows 11 (`26200.9974`), MSVC `19.44` (C++20 / `#3794`), app-local WARP `1.0.22`, and RTX 5080 (`32.0.16.2140`): **16/16 Debug** and **16/16 Release** passed (0 failed, 0 skipped), including `native_compute_tg_size_{ir,warp,hardware}`, `native_partial_final_wave_{ir,warp,hardware}`, `native_compute_implicit_lod_*`, `native_dpp_*`, and `native_permlane_*`. 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!3808
No description provided.