Skip to content

Recompiler: use u128 dependency masks for reload invalidation - #2761

Open
amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/recompiler-reload-sgpr-dependency-masks-101316
Open

amazedturnip wants to merge 1 commit into
xcl-dev:mainfrom
amazedturnip:xcl/recompiler-reload-sgpr-dependency-masks-101316

Conversation

@amazedturnip

@amazedturnip amazedturnip commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Precomputes one u128 dependency mask per tracked address in gpu/dxil/reload.rs so fixed-point availability and recording time use a single regs & mask != 0 test instead of a 128-wide per-register scan, with identical emitted reload decisions. New sibling test file pins bitmask agreement with the original reads() scan across base/offset/sentinel shapes and adversarial changes() masks; full 60s retail smoke and the AMD Radeon suite remain green.

Fixes #2747

What is in it

  • crates/xcl/src/gpu/dxil/reload.rs: precompute one u128 dependency mask per tracked address (dep_mask: base pair + offset register, including the SOFFSET=125 sentinel) and replace the 128-wide reads(k, r) scan inside the fixed-point step closure and at recording time with a single regs & m != 0 test. Analysis results, transfer order, memory clobbers and instruction effects are unchanged.
  • crates/xcl/src/gpu/dxil/reload_dep_mask_tests.rs (new sibling test file, declared next to the existing mod tests): dep_mask_agrees_with_reads_for_all_tracked_address_shapes checks per-register-bit agreement across base/offset-sentinel shapes, and mask_intersection_matches_per_register_scan checks the mask decision against the per-register scan for every tracked key against adversarial changes() masks (0, u128::MAX, isolated base/offset bits, sentinel bit, pair bits).

Tested

Regression run
main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 60 44 0
device removals: 0
crashes: 0
peak commit: 13978 MB

PR:

xcl-smoke v1
commit: 0cff1698dc377edc3678550a5cbabb7881528d1f
gpu: AMD Radeon(TM) Graphics
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1496 (PresentX 1496)
presents per 2 s (last 3): 34 0 26
device removals: 0
crashes: 0
peak commit: 14073 MB

Not tested

  • Absolute wall-clock speedup measurement on this Windows host (author's probe on Linux: 99.1ms -> 4.3ms at 16 addrs, 1469ms -> 12ms at 256 addrs); analyzer results verified identical
  • NVIDIA wave32 GPU (verified on AMD Radeon native wave64)
  • Long-horizon shader compile timing across a full title (smoke.ps1 pair handled by gates.py/publish.py)

AI use

  • Local AI (thinkingmachines_inkling-2-mini) assisted with diagnosis, implementation, tests, review, and description; all tests executed locally on AMD Radeon (native wave64).
  • Claude Code (Claude Opus 5.5) updated the test counts under Tested to the run on the current head.

@DarkPanda69

Copy link
Copy Markdown

NVIDIA wave32 run (listed as untested) on an RTX 3060, plus an RX 9070 XT: both new tests pass, and nothing else changes in the direct-DXIL GPU suite.

Head fdbf8bf applied on main b49be18, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, card chosen with XCL_ADAPTER:

main this PR
RTX 3060 (Ampere, 32-lane waves only, 32.0.16.1088) 710 passed, 0 failed, 24 SKIPPED 712 passed, 0 failed, 24 SKIPPED
RX 9070 XT (RDNA4, 32.0.32029.2010) 708 passed, 2 failed, 6 SKIPPED 710 passed, 2 failed, 6 SKIPPED

On both cards, the only result changes against main are the new dep_mask_agrees_with_reads_for_all_tracked_address_shapes and mask_intersection_matches_per_register_scan, both ok, with no new skips. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on main.

Not tested: translation timings on Windows, Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@frenziedcoder

Copy link
Copy Markdown

Checked "identical emitted reload decisions" on a real shader pack: the direct DXIL of every program in the retail title of #505 is byte-for-byte the same with and without this PR.

xcl shaders <shaders.rpf> --direct --sample 0 --threads 12 --dump DIR, release builds of main b49be183 and of fdbf8bf (this PR on that base), Windows 11, RTX 5080 box (CPU-only translation), DXC 1.8.2502.11:

b49be183 fdbf8bf
programs translated 22,445 of 22,445 (CS 1636, GS 390, MS 8724, PS 9511, VS 2184) same
distinct .direct.dxil outputs 21,844 21,844
byte-identical to the other side 21,844 of 21,844 (none differ, none missing)
translation time per program, p50 / p95 11.93 / 75.16 ms 11.94 / 76.07 ms

So the mask form makes the same reload decisions as the per-register scan on this corpus. End-to-end translation time doesn't move measurably here; the fixed-point step isn't a visible share of whole-program translation on these shaders.

AI use: Claude Code (Claude Opus 5.5) built both trees, ran the dumps on my machine, compared them and wrote this comment. The dumps were deleted afterwards.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) verification of exact PR head fdbf8bf69a5f518f02b82f6d52ce96df56e57b7a on Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver 32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC 1.9.2602.17).

Tested

  • cargo build --workspace (debug): passed (0 errors).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1435 passed, 2 failed, 47 ignored (8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1 heap_window_out_of_memory_falls_back_to_the_switch_form no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record Windows Developer Mode off).
    • Both new tests passed:
      • gpu::dxil::reload::reload_dep_mask_tests::dep_mask_agrees_with_reads_for_all_tracked_address_shapes
      • gpu::dxil::reload::reload_dep_mask_tests::mask_intersection_matches_per_register_scan
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and fuzz_validate_and_gpu_3) are pre-existing on unmodified main on this RX 9060 XT / driver 32.0.31044.16.
  • cargo build --release -p xcl + 60 s retail-title smoke test (scripts/smoke.ps1, offline):
xcl-smoke v1
commit: fdbf8bf69a5f518f02b82f6d52ce96df56e57b7a
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18774 MB

(Compare against main b49be183 on this machine: 1603 frames, 18576 MB peak, 0 device removals, 0 crashes.)

Not tested

  • NVIDIA / Intel GPUs, Linux / Wine.

AI use

  • Verification run and report prepared with Antigravity (Gemini 4 Neon); all build, test, and smoke results are from live runs on this machine.

@CryingLaughing

Copy link
Copy Markdown

A synthetic case where reload analysis takes a large share of translation time shows where the masks help. The fixture uses 8,199 instructions, 4,097 blocks and 128 tracked addresses. I used the same test-only overlay on parent b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 and exact head fdbf8bf69a5f518f02b82f6d52ce96df56e57b7a, with separate release builds and confirmed different test binary hashes.

Median of three timed samples after warm-up Parent PR head
Reload analysis 224.582 ms 3.595 ms
Whole ordinary DXIL translation 316.679 ms 95.435 ms

The large fixture and a second 11-load fixture both produced byte-identical reload-decision traces (36,448 and 137 bytes) and DXIL (99,608 and 3,420 bytes). The focused test was 1 passed, 0 failed, 0 ignored per revision. Both upstream mask tests passed on the head with zero failures or ignores. No capability skips.

Tested on an i5-13600K, Windows 11 25H2 26200.9974, Rust 1.100.0 x64 MSVC, and DXC 1.8.2502.11. The host has an RTX 4080 with driver 621.01. Translation ran on the CPU. XCL_DIRECT_COMPACT=0 XCL_DIRECT_SPLIT_INSTRUCTIONS=0 cargo test --release -p xcl --lib --locked -j 2 gpu::dxil::reload_comparison_tests::ordinary_reload_analysis_and_dxil_comparison -- --exact --test-threads=1 --nocapture.

These times describe the synthetic input with all 128 addresses in play. The retail pack results above show no measurable overall translation speedup on that corpus.

@KOLESNiii

Copy link
Copy Markdown

I’m happy with the implementation at fdbf8bf for #2747. The mask is equivalent to the old scan for every key the analyzer accepts, including the SOFFSET=125 sentinel. Both analysis passes share the same transfer function, and slot numbering, memory clobbers, and instruction effects are preserved.

I ran the analyzer tests in a standalone Linux harness with rustc --edition=2024 --test and the gpu::reload:: filter. Baseline b49be183 passed 5 tests and fdbf8bf passed 7, with zero failures, ignores, or skips. The harness excluded the Windows DXIL emitter test. I did not run the workspace suite or retail smoke.

One test improvement would be to cover two load slots with distinct bases and a write that invalidates only one. All seven current analyzer tests passed when I deliberately reversed the mask vector in the harness. The two-slot fixture passed on the PR and failed with the reversed vector.

AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for review, the standalone harness, and this comment.

@amazedturnip

Copy link
Copy Markdown
Contributor Author

Thanks for the careful reports. Added the requested two-slot fixture (a_write_to_one_slot_base_invalidates_only_that_slot): two loads with distinct bases (s[4:5] vs s[20:21]), a write to the first base's low dword, and assertions that the first slot becomes unavailable while the second stays available (negative control: it fails with the mask deliberately reversed). Analyzer tests: 9 passed. Other review comments were passing test reports; no code changes needed for them.

@KOLESNiii

Copy link
Copy Markdown

Re-review of head 0cff1698dc377edc3678550a5cbabb7881528d1f. The only change since fdbf8bf is the two-slot test I asked for, and it looks good to me.

  • a_write_to_one_slot_base_invalidates_only_that_slot is correct. The second load's base is s[20:21], neither load writes into the other's address registers, and the s_mov to s4 kills only the first slot.
  • Negative control: with the mask vector reversed (by_slot.iter().rev().map(dep_mask)), the new test fails and the other 8 still pass. So the gap I described is covered now.
  • The mask still matches the old scan exactly. key() limits the base register to 123 or less and the offset register to 124 or less, or the 125 sentinel. So no shift goes past bit 125, and dep_mask sets exactly the registers reads() checks.

One note on the description: Tested still shows the counts from before the push, run with --test-threads=2. CONTRIBUTING.md asks for a run with --test-threads=4.

Tested

  • NVIDIA GeForce RTX 2070 SUPER (wave32 only), Windows 11 Home 26300, stable-x86_64-pc-windows-msvc, DXC 1.9.2609
  • cargo test -p xcl --lib gpu::dxil::reload (debug) at 0cff1698: 9 passed, 0 failed, 0 ignored, 0 skipped
  • the same filter with the mask vector reversed: 8 passed, 1 failed (a_write_to_one_slot_base_invalidates_only_that_slot)
  • scripts/smoke.ps1 on a retail game, 60 s, release builds of main's b49be183 and this PR's head, both with no uncommitted changes, run on an otherwise idle machine:

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1401 (PresentX 1402)
presents per 2 s (last 3): 57 60 60
device removals: 0
crashes: 0
peak commit: 17718 MB

PR:

xcl-smoke v1
commit: 0cff1698dc377edc3678550a5cbabb7881528d1f
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1397 (PresentX 1397)
presents per 2 s (last 3): 33 42 59
device removals: 0
crashes: 0
peak commit: 17869 MB

The PR's run reached 99.7 % of main's frames and 100.9 % of its peak commit, with no device removals and no crashes.

Not tested

  • the full workspace suite on this revision
  • AMD / wave64
  • any speedup on the retail game: this was only a regression check

AI use

  • Claude Code (Claude Opus 5.5) did the review, ran the tests and the negative control, ran the smoke runs and wrote this comment. I checked each point.

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.

Recompiler: use SGPR masks for scalar-load availability invalidation

6 participants