Skip to content

Recompiler: key translations on XCL_RDNA_FLOAT and XCL_WATERFALL_COLLAPSE - #3621

Open
kole07139 wants to merge 1 commit into
xcl-dev:mainfrom
kole07139:recompiler/direct-switches-cache-identity
Open

kole07139 wants to merge 1 commit into
xcl-dev:mainfrom
kole07139:recompiler/direct-switches-cache-identity

Conversation

@kole07139

@kole07139 kole07139 commented Dec 1, 2026 •

Copy link
Copy Markdown

XCL_RDNA_FLOAT and XCL_WATERFALL_COLLAPSE both change the DXIL the direct translator emits, but neither was in the translated cache's identity nor in the warm-pipeline settings key. After a default run, a run with either set to 0 (the obvious thing to try when a float result or a sampled texture looks wrong) loaded the translations made with the switch on, so the switch did nothing. The other way round, a cache filled with =0 served its programs to a default run. Same class as #1409 / #2327 (XCL_SAFE_BARRIER).

Fixes #3520 (reported by @Grimkaaah, whose proposed fix this follows). XCL_WATERFALL_COLLAPSE (added in 4250e76) has the same gap and is not in the issue.

Rebased onto main 38ad22da. The only conflict was the semantic_pipeline_setting line, where #3655 added XCL_WAVE64_IDIOMS beside these names; that switch is already in the translated identity through compact_nest_tag.

What is in it

  • gpu/recomp/pso.rs: translated::direct_switches_tagged tags an identity for each switch that is off (xcl-rdna-float-0, xcl-waterfall-collapse-0), the way XCL_X_LDS_ORDER=0 does. With both on (the default) it adds no tag. It is applied in identity_from_source when the backend is direct, and in direct_output_identity, which keys the enormous programs rerouted to the direct translator on the HLSL path. direct_output_identity takes the two switches as parameters, like nest_tag and split_limit, so a test can reach it.
  • gpu/dxil/waterfall.rs: collapse_enabled(), the switch collapse already read. gpu/dxil/mod.rs: prelude and waterfall are pub(crate), so pso.rs can read both switches.
  • shaders.rs: both names join semantic_pipeline_setting.
  • The other caches downstream of a translation follow without a change. This was checked in a read-only audit of the cache keys, and each conclusion then confirmed in the code:
    • the compute, graphics and two-pass driver blobs and the pipeline-library entries are keyed by the DXIL bytes;
    • the warm library, replay, pack and blob receipts are keyed by the translation identity and warm_settings_key().
  • Tests:
    • direct_output_switches_split_the_disk_cache runs each case as a process of its own on one disk cache (the identities use OnceLock), as rerouted_disk_entries_follow_compact_nesting_policy does:
      • an entry a default run stored is a miss with either switch off, on the direct backend and for the rerouted entries of the HLSL backend;
      • the default and the switch's own entries are hits again later;
      • an HLSL-path entry is shared.
      • It fails without the tag in identity_from_source (XCL_DIRECT_DXIL=all, left: 1, right: 2) and without the switches in direct_output() (=0, same).
    • direct_output_switches_that_are_off_get_their_own_identity: the default keeps the identity, and each combination of switches gives a distinct one.
    • The existing warm_settings_ignore_waits_watchdogs_and_traces_but_keep_pipeline_switches now also checks both names.
    • The warm-settings test fails with the two names taken out (XCL_RDNA_FLOAT stays in the key).

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 32.0.16.2140), Intel Core i9-9900K, 32 GB, Windows 11 Pro N build 26200, Rust 1.99.0 MSVC, debug build for tests, release build for the smoke runs.
  • cargo test --workspace -- --test-threads=4 (with --no-fail-fast) on this head (ac528d09), after cargo clean -p xcl, twice:
    • First run: the library harness aborted in hle::d3d12x::list_x::tests::wait64_flags_do_not_mask_the_recorded_counter ("misaligned pointer dereference" in windows-core, a non-unwinding panic, 0xc0000409). The other 42 binaries: 148 passed, 0 failed, 20 ignored.
      • That test passed alone 5/5, and this PR does not touch list_x.
    • Second run: 2964 passed, 0 failed, 52 ignored (43 test binaries).
  • Before the rebase (head cdb365bd): 2906 passed, 0 failed, 51 ignored, twice on a quiet machine.
  • On an earlier head (cda7d4d3), whose non-test code was the same as cdb365bd's, one of two full runs had title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels fail, plus three PoisonErrors from the mutex it poisoned.
  • SKIPPED GPU tests: 25: 22 no wave64 (wave32 adapter), 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1), 1 pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache without Developer Mode)
  • Each switch on a warm translated cache, on the retail title (60 s each, head cda7d4d3), counting the entries under each translated/v2 identity:
    • main: with either switch at 0, no entry is written anywhere; all 26,008 entries come from the default identity, so the switch has no effect.
    • This PR: XCL_RDNA_FLOAT=0 and XCL_WATERFALL_COLLAPSE=0 each make their own identity (220 and 799 entries), and a default run afterwards goes back to its own.
    • The same programs under the default and the switch's identity, the 32-byte header excluded: 105 of 220 have other DXIL with XCL_RDNA_FLOAT=0, 4 of 799 with XCL_WATERFALL_COLLAPSE=0.
  • The reverse direction, with fresh XCL_DXIL_CACHE folders and a fixed set (xcl shaders <pack> --precompile --only ms|vs --limit 300, plus --only ps on main):
    • main: a default pass after an XCL_RDNA_FLOAT=0 pass reuses those entries. Against a clean default cache, 9,457 of 12,356 programs differ (Pixel 9,341, Mesh 80, Vertex 36).
    • This PR (cdb365bd): the same order leaves the default entries byte for byte equal to a clean default cache (0 of 300 differ), while the =0 identity differs in 116 of 300.
    • XCL_WATERFALL_COLLAPSE=0 changes none of the programs in this set.

Regression run
Same title, 60 s each, release builds of this head and of the main it is rebased on, run one after the other on a quiet machine. Both builds have new translated-cache identities: main changed the direct translator's sources since the earlier runs, and this PR edits them too. So both runs started with a cold translated cache for the title.

main:

xcl-smoke v1
commit: 38ad22daa624b0fe415889f480016099a9aae390
gpu: NVIDIA GeForce RTX 3070
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1567 (PresentX 1567)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15614 MB

This PR's head:

xcl-smoke v1
commit: ac528d092ae0368dd4a56ddcd6044f6f2bd3d233
gpu: NVIDIA GeForce RTX 3070
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1598 (PresentX 1598)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15861 MB

Not tested

  • AMD and Intel GPUs.
  • Linux / Wine.

Noticed, not changed

  • XCL_PER_LANE_MAX_INSTS (the per-lane form's instruction limit) is in no cache key either. It only matters with XCL_PER_LANE=1, so it is left out here.
  • ComputePolicyKey (pso.rs, "output-affecting process policy") lists neither switch, nor XCL_X_LDS_ORDER. It only keys in-flight builds within one process, where the environment does not change, so nothing goes wrong.
  • With XCL_DIRECT_DXIL=0, whether a compute program takes the huge direct route depends on the size of its direct output, which the switches change. The HLSL entry stored under the untagged HLSL identity is found first, so a run with a switch at 0 can leave an HLSL translation that later default runs keep using.
    • That translation is valid output, so this costs only speed.
    • XCL_DIRECT_COMPACT and XCL_DIRECT_SPLIT_INSTRUCTIONS are in the same position: they also tag the identity only when the backend is direct.
  • The edit of two files under gpu/dxil changes XCL_DIRECT_DXIL_SOURCE_ID, so the first run after this PR translates the direct programs again (expected, as for every such merge). That also drops any entries made before it with a switch at 0.

AI use

  • Claude Code (Claude Opus 5.5) found the second switch, wrote the code, the tests and this description, and ran the tests and the smoke runs.
  • Two Claude Code subagents of the same session reviewed the diff and audited the cache keys, read-only. The process-level test and the notes under Noticed come from that review, and were checked in the code before they went in.
  • I read the diff and the results.

🤖 Generated with Claude Code

@kole07139

Copy link
Copy Markdown
Author

More local tests, beyond the description. Heads: this PR's cdb365bd, and the previous head cda7d4d3, which has the same non-test code (only the new test and a line wrap in shaders.rs differ). Base: main 6bfb5c51.

Machine: RTX 3070 8 GB (driver 32.0.16.2140), i9-9900K, 32 GB, Windows 11 Pro N 26200, Rust 1.99.0 MSVC.

1. Each switch on a warm translated cache (retail title, release, scripts/smoke.ps1, 60 s each, one after the other, previous head; the entries under each translated/v2 identity were counted before and after each run)

run build switch frames removals / crashes peak commit translated/v2 after the run
main-rdna0 main XCL_RDNA_FLOAT=0 1578 0 / 0 18988 MB no new identity; main's 26,008 entries, all hits
main-wf0 main XCL_WATERFALL_COLLAPSE=0 1600 0 / 0 16679 MB no new identity; 26,008, all hits
pr-rdna0 PR XCL_RDNA_FLOAT=0 1599 0 / 0 16260 MB new identity, 220 entries
pr-wf0 PR XCL_WATERFALL_COLLAPSE=0 1577 0 / 0 18731 MB another new identity, 799 entries
pr-default2 PR none 1591 0 / 0 17183 MB back on the PR's default identity (819 → 2,455); the two switch identities untouched

The same programs under each switch's identity and the default one, the 32-byte header (which holds the identity) excluded:

  • XCL_RDNA_FLOAT=0: 105 of 220 have other DXIL.
  • XCL_WATERFALL_COLLAPSE=0: 4 of 799.

2. The reverse direction, deterministic (fresh XCL_DXIL_CACHE per case, CPU only: xcl shaders <pack> --precompile --only ms|vs --limit 300, and --only ps on main)

case build passes identities default entries vs a clean default cache
A main XCL_RDNA_FLOAT=0, then default one (11d4bba9…); the default pass took the PS set in 9.7 s against 680.7 s, all hits 9,457 of 12,356 differ (Pixel 9,341, Mesh 80, Vertex 36)
A' main XCL_WATERFALL_COLLAPSE=0, then default one 0 of 12,356 differ (no collapsible loop in this set)
C this PR XCL_RDNA_FLOAT=0, then default two (6af2e0c3… for =0, be5f11cb… default) 0 of 300 differ; the =0 identity differs in 116 of 300

So on main a default run is served what a =0 run translated. With this PR it is not.

3. Test suite

  • This head, cargo test --workspace --no-fail-fast -- --test-threads=4, quiet machine:
    • two runs, the second after cargo clean -p xcl: 2906 passed, 0 failed, 51 ignored (25 SKIPPED) both times;
    • the new test direct_output_switches_split_the_disk_cache passes, and fails with either wiring point removed.
  • Previous head, two full runs: 2905 passed, 0 failed, 51 ignored; then 2901 passed, 4 failed, 51 ignored.

4. Long runs, default settings (600 s asked, one pair, previous head)

run exit removals / crashes peak commit ended at
main 0x887a0005 1 / 1 35982 MB ~199 s
PR 0x887a0005 1 / 1 35629 MB ~307 s

AI use: Claude Code (Claude Opus 5.5) ran these tests and wrote this report.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head cdb365b, diff read, not a merge-check):

No problems found in the diff. Checked the new tags against how translated::identity_from_source, direct_output / rerouted_identity, the mesh and geometry cached_for callers, compile_console_shader's huge and enormous reroutes (pso.rs ~825-866), and the warm library and replay keys use these identities; the switches are read only in gpu/dxil (prelude.rs, kernel.rs ~329), the tags apply only when the direct translator can run, and with both switches at their defaults direct_switches_tagged returns the identity unchanged (pso.rs ~350-353), so existing caches stay valid. The subprocess test follows the existing rerouted_disk_entries_follow_compact_nesting_policy pattern.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

…APSE

Both switches change the DXIL the direct translator emits
(XCL_RDNA_FLOAT=0: v_fract_f32 and the legacy multiplies keep their
general form; XCL_WATERFALL_COLLAPSE=0: sampler waterfall loops are not
collapsed), but neither was in the translated cache's identity nor in
the warm-pipeline settings key. A run with either set to 0 after a
default run loaded the translations made with it on, so the switch did
nothing; the other way round, a cache filled with =0 served its programs
to a default run.

A switch that is off now tags the direct identity (identity_from_source
under XCL_DIRECT_DXIL, and direct_output_identity for the enormous
programs rerouted to the direct translator), the way XCL_X_LDS_ORDER=0
does. With both on, the default, no tag is added. Both names join
semantic_pipeline_setting.

Fixes xcl-dev#3520

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kole07139
kole07139 force-pushed the recompiler/direct-switches-cache-identity branch from cdb365b to ac528d0 Compare December 2, 2026 14:26
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head ac528d0, since cdb365b, diff read, not a merge-check):

  • Earlier review (no problems found): still holds; this push is a rebase onto the current main, which only moves the new warm-setting names next to XCL_WAVE64_IDIOMS in shaders.rs.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@fromthemoonx

fromthemoonx commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 5ad98ad
head: ac528d0
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3007 passed, 0 failed, 52 ignored (3004 / 0 / 52 on 817eb1f, plus this PR's 2 tests and 1 that main gained since); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: read the whole diff (4 files, +122 -7). No blocking findings.

  1. Each of the three places has a test that needs it. I took them out one at a time:
taken out test that fails
the tag in identity_from_source direct_output_switches_split_the_disk_cache (a run with the switch off gets the default run's entry: left 1, right 2)
the tag in direct_output_identity the same test, and direct_output_switches_that_are_off_get_their_own_identity
the two names in semantic_pipeline_setting warm_settings_ignore_waits_watchdogs_and_traces_but_keep_pipeline_switches
  1. Both switches are read only in the direct translator, so leaving HLSL entries untagged is right. With both at their default the identity stays as it was.
  2. I listed every XCL_* name in gpu/dxil/*.rs. The other ones that change the output are already in a key, so I found no third switch with this gap there. I did not repeat that for gpu/recomp.
  3. The first run after the merge translates the direct programs again, because two files under gpu/dxil change. The description says so. It also drops entries an earlier =0 run left behind.
  4. Not tested: a retail title (none on this machine), so the counts of changed programs in the description are the author's.
    performance: two tags when an identity is computed, none by default; one retranslation after the merge as in 4 (reasoned, not measured)
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: XCL_RDNA_FLOAT changes the direct DXIL but is in no cache key, so a run with =0 can load translations made with it on

5 participants