Skip to content

compute: carry descriptor spills through v_writelane_b32 / v_readlane_b32 - #3161

Merged
pigalot merged 1 commit into
R0Y00:mainfrom
Leyukaka:desc-lane-spill
Nov 27, 2026
Merged

pigalot merged 1 commit into
R0Y00:mainfrom
Leyukaka:desc-lane-spill

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

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 shader: lower v_readlane_b32 and v_writelane_b32 in the direct C++ compute path #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 tests: honor hardware adapter selection in native Compute replay #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.

AI-assisted.

…_b32

Titles spill buffer descriptors, table pointers and unknown entry SGPRs
to fixed lanes of a VGPR and read them back with v_readlane_b32 at the
same constant lane. The analysis now keeps the scalar symbol per VGPR and
guest lane: a symbolic v_writelane_b32 emits nothing, and the matching
v_readlane_b32 restores the symbol in the destination SGPR. A write to
another lane keeps the other lanes; a CFG join with a different symbol,
a VGPR lane index, any other read of that VGPR, or any other write to it
is refused. Numeric spills are lowered as before.

native_lane_spill_descriptor_hardware spills a buffer descriptor to lanes
0..3 next to numeric lanes, clobbers the SGPRs, refills them and loads
through the descriptor; five controls cover the refusals.

Closes R0Y00#3150.

AI-assisted.
@KelboLive

Copy link
Copy Markdown
Contributor

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 pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pigalot
pigalot merged commit c45bf9a into R0Y00:main Nov 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

direct compute: carry descriptor spills through v_writelane_b32 / v_readlane_b32

3 participants