Skip to content

Recompiler: XCL_DECLARED_LDS=1 sizes direct compute LDS from the header (~11 ms less GPU per frame) - #2937

Draft
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:declared-lds
Draft

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:declared-lds

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

The direct DXIL translator gives every compute program that uses LDS the whole 8,192-dword groupshared block D3D12 allows, with the split form's exchange words at its top. That caps how many groups run at once on a GPU whose LDS per SM is shared by resident groups. With XCL_DECLARED_LDS=1 it declares what the program's header asks for: the static workgroup LDS from COMPUTE_PGM_RSRC2, plus the split form's exchange words and counters (or the arrival counter of a native 2-D/3-D group) placed after it. A header with no size, or one too large to leave room for those, keeps the 8,192-dword layout. LDS addresses are clamped to the declared top. Off by default.

What is in it

  • CsInterface::lds_dwords from COMPUTE_PGM_RSRC2 (recomp/mod.rs).
  • setup_storage sizes xcl_lds from it and places the exchange words and counters after the guest LDS; lds_index clamps to the declared top (dxil/lanes.rs, dxil/kernel.rs, dxil/lower_mem.rs); the callers of setup_storage in the tests follow the new signature.
  • The translated-shader caches key the switch apart (recomp/pso.rs).
  • Tests: compute_lds_reservation_matches_descriptor_and_lane_storage (declared size and lane storage per mode, dxil/core_tests.rs) and declared_lds_disk_cache_separates_both_direct_routes (cache keys, recomp/pso.rs).

Tested

  • RTX 5070 Ti (driver 610.74), Windows 11 Pro 26200, Rust 1.99.0 MSVC, DXC 1.9 via XCL_DXC_DIR.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on c4f2a7f: results follow (queued).
  • Title, Series X profile, per-program GPU timestamps over 187-229 s: the late frame's compute went from about 89 to about 78 ms per present with the switch on. 66 of the late programs translate differently (the split family and wave32 programs); with the switch off the translation is byte-identical to main's.

Regression run

  • 480 s smoke pair (main 8b957be vs c4f2a7f) is queued; blocks follow. The switch is off by default, so the pair is a regression check of the default path.

Not tested

  • AMD, Intel, Wine. Native wave64 GPUs (this card runs 32-lane waves, so the split form is what was measured). Titles other than this one.

AI use

  • Claude Code (Claude Opus 5.5): the change was written with Claude Code on our team branch (by a teammate agent); this agent split it onto main, ran the tests and wrote this description.

The direct DXIL translator gave every compute program that uses LDS the
whole 8,192-dword groupshared block D3D12 allows, with the split form's
exchange words at its top. With XCL_DECLARED_LDS=1 it declares what the
program's header asks for instead: the static workgroup LDS from
COMPUTE_PGM_RSRC2 (CsInterface::lds_dwords), plus the exchange words and
counters of the split form (or the arrival counter of a native 2-D/3-D
group) placed after it. A header with no size, or one too big to leave
room for them, keeps the 8,192-dword layout. LDS addresses are clamped to
the declared top. The translated-shader caches key the switch apart.

Less groupshared memory per group lets more groups run at once. On the
title (RTX 5070 Ti, Series X profile, per-program GPU timestamps over
187-229 s), the late frame's compute went from about 89 to about 78 ms per
present with the switch on; 66 of the late programs translate differently
(the split family and wave32 programs), and with the switch off the
translation is byte-identical.

Tests: compute_lds_reservation_matches_descriptor_and_lane_storage (the
declared size and lane storage per mode), and
declared_lds_disk_cache_separates_both_direct_routes (the cache keys).

Written by reed on our team branch; split out on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Independent Windows GPU readback on c4f2a7f: RTX 5070 Ti Laptop (12 GB), NVIDIA 621.24, native D3D12. I used console_wave64_compute_through_the_pso_hook_dispatch_and_read_back, with one local fixture change: rsrc2 |= 1 << 15 to declare the 128 LDS dwords the synthetic program writes before reading its partner lane. Runtime code was unchanged.

With XCL_DIRECT_DXIL=1 and fresh XCL caches per run, all four combinations of XCL_PER_LANE=0/1 and XCL_DECLARED_LDS=0/1 completed the dispatch and passed readback. SDK dxc -dumpbin shows @xcl_lds at 8,192 dwords with the switch off and 141 with it on (128 guest + 13 helper) on both lowering routes. This covers real PSO creation and execution for the split-wave LDS case. No retail timings or smoke results from this machine for this test.

OpenAI Codex (6.2sol) assisted with verification.

@andrewDoing

Copy link
Copy Markdown

Independent synthetic readback on PR head c4f2a7f313db2c85ffd5becadafebc58dee85799 plus a test-only fixture, on an RTX 5070. The guest shader declared 128 dwords of LDS and used 16×8×1 workgroups over 2×3 groups. The test compared each thread's own and mirrored lane coordinates through LDS for 768 threads per run.

Four fresh-process tests passed without reported skips or failures: native wave32 and split guest wave64, each with the new allocation behavior off and on. Disassembly showed 8,192 dwords allocated with the behavior off in both modes; with it on, wave32 allocated 129 dwords including the arrival counter, and split wave64 allocated 141 including exchange/counters. All 6,144 expected output words matched across the four runs.

The fixture and header change were test-only; GTA VI execution, retail timing and performance were not tested. AI use: OpenAI Codex with GPT-6.2 Astra wrote and ran the fixture; Codex coordinated and prepared this report.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / RADV native-wave64 verification of c4f2a7f313db2c85ffd5becadafebc58dee85799 against main 8b957bec6f82495aec940944c6bf47faa02db590.

Tested

  • RX 9070 16 GB, Ryzen 7 7700, CachyOS 7.3.0-5-cachyos, RADV / Mesa 26.3.1-arch3.5. Rust 1.97.1 Windows GNU release executables under GE-Proton11-12 / Wine 11.0 Staging; native DXGI/D3D12, vkd3d-proton 8293130ebe370b1+ with local assertions disabled, DXC/DXIL 1.9.2602.17.
  • XCL_ADAPTER='AMD Radeon RX 9070' XCL_REQUIRE_GPU=wave64 XCL_NETWORK=0 XCL_DXC_THREADS=1 XCL_DIRECT_COMPACT=0, private enabled caches. Production files match each pinned revision; only identical local tests were appended.

The two new upstream tests passed on the head at --test-threads=1 and 4: 2 passed, 0 failed, 0 ignored per top-level run. Each also ran its ten successful child harnesses. The cache test covers its synthetic marker-based cache-key separation.

Additional local probes, run through Wine:

<unit.exe> workflow_declared_lds_ --nocapture --test-threads=1

Separate processes for XCL_DECLARED_LDS=0/1, both revisions, three repetitions per configuration:

  • Layout probe: 144 validated containers per process, both direct lowering routes, 1-D/2-D/3-D groups, native wave32/wave64 and split-form IR. Header LDS reservations include unspecified, small, non-power-of-two, near-limit and oversized cases.
  • GPU probe: 30 dispatches per process, HLSL/direct/per-lane, native wave32/wave64 and five header reservations. Each dispatch runs six 16x8 groups. The program is the existing gpu_compute_mode_dispatch_abi program: write own coordinates to LDS, synchronize, read the reversed partner, then export both. Prefix and suffix canaries surround the output.

For these 2-D GPU cases, the head with the switch on declares 129 / 257 / 385 dwords for 128 / 256 / 384 guest dwords, including the native arrival counter. Unspecified and oversized cases retain 8,192 dwords. HLSL retains 8,192. The layout-only probe also verified the split exchange/counter reservations and fallback cases.

All GPU payloads and guards matched independently computed values: 360 dispatches, including 180 native wave64, 552,960 payload words and 28,800 guard words. Containers have the expected WaveSize and thread-group metadata. Captures repeat byte-for-byte across the three repetitions. Default-off containers match main byte-for-byte in both probes; HLSL and fallback controls remain unchanged with the switch on.

The head reports 2 passed / 0 failed in every configuration. Main with the switch off also passes both probes; with it on, the GPU probe passes and the layout probe fails as expected on 72 size assertions per process, since main retains the old allocation.

Not tested

Retail/smoke, frame-time or occupancy gains, runtime PSO-hook integration, real driver-blob cache reuse, the full suite, or forced-split GPU execution. Split-form coverage here is translation/validation only.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, prepared local test-only probes, ran the comparisons, independently checked layout arithmetic and raw GPU output, and drafted this report. Publication authorized by the account owner.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
…mp hunks verbatim)

Live head c4f2a7f still OPEN. Single commit on upstream/main
8b957be: CsInterface gains lds_dwords parsed from COMPUTE_PGM_RSRC2,
setup_storage takes (slot, declared, native_counter), LDS block
sized to declared+control under XCL_DECLARED_LDS=1 (off = byte-
identical layout, verified by analysis + green suite), pso cache
identity forks declared-lds for both direct routes, upstream tests
in Windows-only core_tests/pso stay reference-only per ground
rule 9. Tree adaptations: ..Default::default() on our local-only
CsInterface literals (dxil/robustness_tests 1, dxil/lower_valu 3)
that upstream does not have. Linux pin: declared_lds_descriptor_
parses_static_workgroup_lds (robustness_tests) — fails pre-fix
(E0609 no field), green post-fix.
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
Follows f1a3ec3, whose tree already carries the test in the
working-tree gates (787/0/1) but not in the commit: this lands it.
declared_lds_descriptor_parses_static_workgroup_lds guards the
shared CsInterface::from_descriptor parse on Linux (upstream test
is Windows-only core_tests). Failing-first shown pre-fix (E0609),
green post-fix.
@LocranKing

Copy link
Copy Markdown

Tested PR #2937 (c4f2a7f3) against main (8b957bec) on Windows 11 (26300), Ryzen 5 5500 (6C/12T), RTX 3060 Ti 8 GiB (driver 621.40), rustc 1.100.0, DXC 1.9.2602.17.

Unit Test (cargo test --locked -p xcl)

  • gpu::recomp::pso::shader_cache_tests::declared_lds_disk_cache_separates_both_direct_routes: passed (1 passed, 0 failed in lib and all invoked subprocess modes).

Paired 180 s Retail Smoke (9cc6a39e, Series S lockhart, XCL_HEAP_WINDOWS=1, XCL_DIRECT_DXIL=all, XCL_DIRECT_SPLIT_INSTRUCTIONS=0, XCL_PSO_WAIT_MS=50)

Note: XCL_DECLARED_LDS=1 changes the direct-DXIL translator key as designed, so PR #2937 ran from a pre-warmed XCL_DECLARED_LDS=1 DXIL snapshot and entered the world at 231.3 s (109.4 s guest entry, 58.1 s in-world) vs main's 188.4 s (67.2 s entry, 58.9 s in-world).

Build Frames shown (~58 s world) World presents (2s windows) Peak commit Peak local / non-local VRAM Console stats Crashes / Removals
main (8b957bec) 1240 14 (28 windows) 29,411 MB 14,281 / 2,241 MB 9,178 draws, 34,068 dispatches (88 skipped) 0 / 0 (exit: 0x0)
PR #2937 (c4f2a7f3, XCL_DECLARED_LDS=1) 1173 22 (28 windows) 30,010 MB 14,522 / 2,851 MB 12,394 draws, 65,536 dispatches (2,578 skipped) 0 / 0 (exit: 0x0)

Both runs stayed clean (0 crashes, 0 device removals, exit: 0x0). In the matched 28 two-second world windows, PR #2937 logged more presents (22 vs 14) and roughly 2x dispatches (65,536 vs 34,068).

Not tested: Per-dispatch GPU timestamp breakdown (XCL_LOOK_STATS), or longer steady-state runs past PSO build-out on 8 GiB VRAM.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2158 solves the same problem in a different way: #1607, group D149. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Triage note (from #1607 (comment), a check from the outside against CONTRIBUTING.md, not a code review):

PR description is red because the two xcl-smoke blocks (a commit of main, and this head) are missing; the body says they are queued. #2158 addresses the same thing another way (group D149 on #1607), so a line on how the two differ would help whoever merges.

AI use: Claude Code (Claude Fable 5.2).

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.

6 participants