compute: carry descriptor spills through v_writelane_b32 / v_readlane_b32 #3161

Merged
Leyukaka merged 1 commit from upstream-pr/3161 into main 2026-11-27 21:49:59 +00:00
Leyukaka commented 2026-11-27 19:17:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T19:17:18Z.


Fixes #3150. Part of #2935. Target branch main. Follows #2940 (#2950), which lowered numeric SGPR spills through VGPR lanes.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl):

  • The analysis state now keeps, next to the 128 SGPR symbols, a symbol per VGPR and guest lane.
    • A v_writelane_b32 with a constant lane and a non-numeric scalar source records the source symbol and emits nothing. That covers a descriptor dword, a table or root address, and an unbound value.
    • A v_readlane_b32 of the same VGPR and constant lane restores the symbol in its destination SGPR and emits nothing.
    • A write to another constant lane keeps the other lanes' symbols, and a write to the same lane replaces it.
  • An unbound value read back is still unbound, so it is refused where it is used, as before the spill.
  • Numeric spills are lowered as in #2950.
  • Refused:
    • a symbolic lane read through an SGPR or VGPR lane index;
    • a CFG join with different symbols in the same lane;
    • any other read of a VGPR holding symbolic lanes;
    • any other write to it.
  • Indexed descriptors and values that carry a definition are not carried, because they still depend on a runtime SGPR value.
  • constant32 moves from DirectCompute to file scope so the analysis can use it.
  • native_store_replay gains a --direct-warp mode for the WARP variant of the new test. This touches the same device-creation lines as #3155; I will rebase on whichever lands first.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on main 80668b97 plus this commit.

  • native_lane_spill_descriptor_hardware (new) passed.
    • Two 32-thread groups spill a buffer descriptor to lanes 0..3 of a VGPR and numeric values to lanes 4 and 5.
    • They clobber the descriptor SGPRs, refill everything with v_readlane_b32 and load through the refilled descriptor.
    • All 192 result words match a CPU reference, with the guard words intact.
  • The same test checks that compile_dxil refuses five controls:
    • a VGPR lane index (the existing refusal);
    • an SGPR lane index;
    • a VALU write to the spill VGPR;
    • a join with a different descriptor in the same lane;
    • a VALU read of the spill VGPR.
  • native_lane_spill_descriptor_warp skips (77) on this machine.
  • native_lane_access_hardware, native_wave_request_hardware, native_direct_container, the native_dpp* tests and the native_gather* tests pass, 16 tests in all, two of them WARP skips.
  • Mutation checks, run by hand:
    • refilling from the next lane fails the hardware test;
    • keeping a conflicting symbol across a join fails the join control;
    • removing the analysis-side clear on other VGPR writes is not detected, because the emitter refuses any other write to a VGPR holding symbolic lanes first.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on main 80668b97.

  • 41 of 2,689 compute requests stopped first at a v_writelane_b32 with "unbound numeric SGPR". With this change, 40 of them pass every spill and stop later:

    Next refusal Requests Covered by
    s_or_saveexec_b32 33 #3158
    image_sample_lz on a 3D image, sampler at s88 (5) or s104 (1) 6 #3146
    v_permlanex16_b32 1 #3022

    The last one stops at a v_fma_f32 with an unbound SGPR source.

  • The compiled count stays at 403, and no request that compiled before stops compiling. The requests of one start-up run give the same result: 416 before and after, and the same 41.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5531923895 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3161). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T19:17:18Z. --- Fixes #3150. Part of #2935. Target branch `main`. Follows #2940 (#2950), which lowered numeric SGPR spills through VGPR lanes. **Change** (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_compute.inl`): - The analysis state now keeps, next to the 128 SGPR symbols, a symbol per VGPR and guest lane. - A `v_writelane_b32` with a constant lane and a non-numeric scalar source records the source symbol and emits nothing. That covers a descriptor dword, a table or root address, and an unbound value. - A `v_readlane_b32` of the same VGPR and constant lane restores the symbol in its destination SGPR and emits nothing. - A write to another constant lane keeps the other lanes' symbols, and a write to the same lane replaces it. - An unbound value read back is still unbound, so it is refused where it is used, as before the spill. - Numeric spills are lowered as in #2950. - Refused: - a symbolic lane read through an SGPR or VGPR lane index; - a CFG join with different symbols in the same lane; - any other read of a VGPR holding symbolic lanes; - any other write to it. - Indexed descriptors and values that carry a definition are not carried, because they still depend on a runtime SGPR value. - `constant32` moves from `DirectCompute` to file scope so the analysis can use it. - `native_store_replay` gains a `--direct-warp` mode for the WARP variant of the new test. This touches the same device-creation lines as #3155; I will rebase on whichever lands first. **Tests.** The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on `main` `80668b97` plus this commit. - `native_lane_spill_descriptor_hardware` (new) passed. - Two 32-thread groups spill a buffer descriptor to lanes 0..3 of a VGPR and numeric values to lanes 4 and 5. - They clobber the descriptor SGPRs, refill everything with `v_readlane_b32` and load through the refilled descriptor. - All 192 result words match a CPU reference, with the guard words intact. - The same test checks that `compile_dxil` refuses five controls: - a VGPR lane index (the existing refusal); - an SGPR lane index; - a VALU write to the spill VGPR; - a join with a different descriptor in the same lane; - a VALU read of the spill VGPR. - `native_lane_spill_descriptor_warp` skips (77) on this machine. - `native_lane_access_hardware`, `native_wave_request_hardware`, `native_direct_container`, the `native_dpp*` tests and the `native_gather*` tests pass, 16 tests in all, two of them WARP skips. - Mutation checks, run by hand: - refilling from the next lane fails the hardware test; - keeping a conflicting symbol across a join fails the join control; - removing the analysis-side clear on other VGPR writes is not detected, because the emitter refuses any other write to a VGPR holding symbolic lanes first. **Measured on a local capture** (counts and instruction shape only) with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` on `main` `80668b97`. - 41 of 2,689 compute requests stopped first at a `v_writelane_b32` with "unbound numeric SGPR". With this change, 40 of them pass every spill and stop later: | Next refusal | Requests | Covered by | |---|---|---| | `s_or_saveexec_b32` | 33 | #3158 | | `image_sample_lz` on a 3D image, sampler at s88 (5) or s104 (1) | 6 | #3146 | | `v_permlanex16_b32` | 1 | #3022 | The last one stops at a `v_fma_f32` with an unbound SGPR source. - The compiled count stays at 403, and no request that compiled before stops compiling. The requests of one start-up run give the same result: 416 before and after, and the same 41. AI-assisted.
KelboLive commented 2026-11-27 21:12:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:12:25Z.


LGTM. The refactoring of State to track lane spills cleanly separates symbolic descriptor tracking from scalar state. The handling in both the analysis pass and direct compute lowering is consistent, and the new test covers the critical edge cases (conflicts, overwrites). Ready to merge.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228232867 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3161#issuecomment-7228232867). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T21:12:25Z. --- LGTM. The refactoring of `State` to track lane spills cleanly separates symbolic descriptor tracking from scalar state. The handling in both the analysis pass and direct compute lowering is consistent, and the new test covers the critical edge cases (conflicts, overwrites). Ready to merge.
pigalot commented 2026-11-27 21:49:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T21:49:23Z.

Review: APPROVED


I reviewed 9a8c3478 merged over main 2b7ebf18. The merge is clean (tree ce82c8af) and git diff --cached --check is clean.

What I traced.

  • Analysis: with a constant lane, v_writelane_b32 records a non-numeric, non-indexed, definition-free SGPR symbol under (VGPR, guest lane) and emits nothing. Any other source erases that key. v_readlane_b32 of the same key restores the symbol into its SGPR. At a join, a key whose symbol differs, or is present on only one side, becomes nullopt, and a later readlane of it is refused. Both join orders are handled: the reset() loop covers keys present in in, and the emplace(..., nullopt) loop covers keys present only in after.
  • Emitter guard: read() and write() refuse any VGPR access to a register whose before-state holds a spill key. The one exception is the lane write itself (lane_write). read_storage is used only by the readlane/writelane lowering and write_active. Every VGPR store goes through write(), so clear_vector_spills is a second line of defence, not the guard. That matches the PR's note on its third mutation.
  • Operand helper: constant32 moved to file scope with the same nine float words, and operand() now uses it. The emitted constants are unchanged.
  • Scope of the new transfer: it runs only when parse is called with graph and not graphics. The only such caller is the direct_dxil compute path.

What I ran. I built compile_dxil native_store_replay in dev and release, then ran

python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_lane_spill_descriptor|native_lane_access|native_dpp[a-z0-9_]*|native_gather[a-z0-9_]*)_hardware$'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_lane_spill_descriptor_warp|native_direct_container)$'
  • dev: 8/8 hardware tests pass. native_lane_spill_descriptor_hardware matched all 192 descriptor-spill and numeric-spill words and the guards.
  • release: the new test, native_lane_access_hardware and native_direct_container pass.
  • Skips: native_lane_spill_descriptor_warp skips (77) in both presets, so the five compile controls ran but the WARP readback didn't.
  • Negative control: on main 2dde49a8, compiling the fixture's positive program refuses it at +0x38: unbound numeric SGPR s32, the first descriptor spill.

Mutants. I rebuilt compile_dxil native_store_replay in dev for each, then ran the new test (WARP for the compile controls, hardware for the readback):

Mutant Result
join keeps a conflicting symbol (drop the !(other->second == value) term) killed (join control compiles)
read() symbolic-lane refusal removed killed (valu)
write() symbolic-lane refusal removed killed (overwrite)
SGPR-lane has_spill refusal removed killed (sgpr_selector)
transfer refills from the next lane killed (hardware readback)
one-sided join key not added (emplace(..., nullopt) removed) survives
numeric v_writelane_b32 does not erase the key survives
identity_spill also carries indexed_descriptor survives
the refill also emits the physical waveReadLaneAt survives (equivalent here: descriptor uses go through the symbol)

Restored and rebuilt afterwards; git diff --quiet is clean.

I then compiled four extra programs built from the test's own helpers.

  • One-sided joins: one path spills the descriptor to lanes 0..3 and the other writes numeric values there or writes nothing, in both branch orders. All four are refused on this head with symbolic VGPR lane read has conflicting incoming values. Under the one-sided-join mutant three of them are still refused, later, as unproven resource descriptor s32, so that mutant moves the refusal but doesn't produce wrong code here.
  • Numeric overwrite: a program that spills the descriptor, then writes numeric values to the same four lanes, then refills, is refused on this head (unproven resource descriptor s32). Under the no-erase mutant it compiles, restoring the overwritten descriptor.

Non-blocking. "A write to the same lane replaces it" is implemented correctly, but no test pins it. A sixth control in native_lane_spill_descriptor_check.py would kill that mutant: a numeric v_writelane_b32 over a symbolic lane, followed by the refill and the load, expected to be refused. The indexed-descriptor exclusion is likewise unpinned.

Verdict: approve on 9a8c3478.

Environment: NVIDIA GeForce RTX 5090 driver 610.88, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer off. WARP variant skipped (77).
CI: Build and test on Windows passes on 9a8c3478.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093644872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3161#pullrequestreview-6093644872). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T21:49:23Z. **Review:** APPROVED --- I reviewed `9a8c3478` merged over `main` `2b7ebf18`. The merge is clean (tree `ce82c8af`) and `git diff --cached --check` is clean. **What I traced.** - **Analysis:** with a constant lane, `v_writelane_b32` records a non-numeric, non-indexed, definition-free SGPR symbol under (VGPR, guest lane) and emits nothing. Any other source erases that key. `v_readlane_b32` of the same key restores the symbol into its SGPR. At a join, a key whose symbol differs, or is present on only one side, becomes `nullopt`, and a later readlane of it is refused. Both join orders are handled: the `reset()` loop covers keys present in `in`, and the `emplace(..., nullopt)` loop covers keys present only in `after`. - **Emitter guard:** `read()` and `write()` refuse any VGPR access to a register whose before-state holds a spill key. The one exception is the lane write itself (`lane_write`). `read_storage` is used only by the readlane/writelane lowering and `write_active`. Every VGPR store goes through `write()`, so `clear_vector_spills` is a second line of defence, not the guard. That matches the PR's note on its third mutation. - **Operand helper:** `constant32` moved to file scope with the same nine float words, and `operand()` now uses it. The emitted constants are unchanged. - **Scope of the new transfer:** it runs only when `parse` is called with `graph` and not `graphics`. The only such caller is the `direct_dxil` compute path. **What I ran.** I built `compile_dxil native_store_replay` in `dev` and `release`, then ran ```powershell python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_lane_spill_descriptor|native_lane_access|native_dpp[a-z0-9_]*|native_gather[a-z0-9_]*)_hardware$' ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_lane_spill_descriptor_warp|native_direct_container)$' ``` - **`dev`:** 8/8 hardware tests pass. `native_lane_spill_descriptor_hardware` matched all 192 descriptor-spill and numeric-spill words and the guards. - **`release`:** the new test, `native_lane_access_hardware` and `native_direct_container` pass. - **Skips:** `native_lane_spill_descriptor_warp` skips (77) in both presets, so the five compile controls ran but the WARP readback didn't. - **Negative control:** on `main` `2dde49a8`, compiling the fixture's positive program refuses it at `+0x38: unbound numeric SGPR s32`, the first descriptor spill. **Mutants.** I rebuilt `compile_dxil native_store_replay` in `dev` for each, then ran the new test (WARP for the compile controls, hardware for the readback): | Mutant | Result | |---|---| | join keeps a conflicting symbol (drop the `!(other->second == value)` term) | killed (`join` control compiles) | | `read()` symbolic-lane refusal removed | killed (`valu`) | | `write()` symbolic-lane refusal removed | killed (`overwrite`) | | SGPR-lane `has_spill` refusal removed | killed (`sgpr_selector`) | | transfer refills from the next lane | killed (hardware readback) | | one-sided join key not added (`emplace(..., nullopt)` removed) | survives | | numeric `v_writelane_b32` does not erase the key | **survives** | | `identity_spill` also carries `indexed_descriptor` | survives | | the refill also emits the physical `waveReadLaneAt` | survives (equivalent here: descriptor uses go through the symbol) | Restored and rebuilt afterwards; `git diff --quiet` is clean. I then compiled four extra programs built from the test's own helpers. - **One-sided joins:** one path spills the descriptor to lanes 0..3 and the other writes numeric values there or writes nothing, in both branch orders. All four are refused on this head with `symbolic VGPR lane read has conflicting incoming values`. Under the one-sided-join mutant three of them are still refused, later, as `unproven resource descriptor s32`, so that mutant moves the refusal but doesn't produce wrong code here. - **Numeric overwrite:** a program that spills the descriptor, then writes numeric values to the same four lanes, then refills, is refused on this head (`unproven resource descriptor s32`). Under the no-erase mutant it **compiles**, restoring the overwritten descriptor. **Non-blocking.** "A write to the same lane replaces it" is implemented correctly, but no test pins it. A sixth control in `native_lane_spill_descriptor_check.py` would kill that mutant: a numeric `v_writelane_b32` over a symbolic lane, followed by the refill and the load, expected to be refused. The indexed-descriptor exclusion is likewise unpinned. **Verdict:** approve on `9a8c3478`. Environment: NVIDIA GeForce RTX 5090 driver 610.88, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer off. WARP variant skipped (77). CI: `Build and test on Windows` passes on `9a8c3478`. This reply was 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!3161
No description provided.