Skip to content

DXC: compute programs are linked with their memory accessors (window switches no longer dominate DXC time) - #174

Draft
gefydev wants to merge 1 commit into
ivall:mainfrom
gefydev:mem-accessor-cost
Draft

gefydev wants to merge 1 commit into
ivall:mainfrom
gefydev:mem-accessor-cost

Conversation

@gefydev

@gefydev gefydev commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Lane L6 of the compile-time handoff (DXC cost). Draft. About −14 % DXC time on retail compute programs (measured below); the tests pass on AMD (RX 7800 XT, comment below). #187 removes the window switch itself (windows from the descriptor heap, VS / PS too, and much faster on its own synthetic CS). If it lands, this PR only matters where that one falls back to the switch (XCL_HEAP_WINDOWS=0, a failed view); I would prefer it over this one.

What is slow

With several memory windows every mem access is a call to an accessor that switches between the windows. DXC inlines it when it compiles, before it optimises, so a program gets one switch per access, and DXC's time grows much faster than their number. HANDOFF (956a476) measured it at about double DXC + driver time on one large CS; #172 measured about 26 % of DXC time on its 1-in-100 pack sample. The first table below is the worst case, programs made of memory accesses only; the second is real ones.

Change

  • emit::linked_form turns such a program into two DXIL libraries: the program, with its accessors only declared, and the accessors. DXC cannot inline a declaration.
  • dxc::compile_linked compiles both and links them with IDxcLinker, which inlines the accessors after the program was optimised. The compiled accessor library is kept.
  • Only cs_* (which is also what MS and GS programs run as), only with 2–4 windows, only from 100 places that use an accessor. VS and PS are unchanged.
  • If anything in this path fails, the program is compiled whole as before, and the first failure is logged.
  • XCL_LINK_MEM=0 turns it off. It shares the DXIL cache, so compare with another XCL_DXIL_CACHE.

The HLSL the translator emits is unchanged (the accessor text is byte-identical to main for 2, 3 and 4 windows), so cache keys do not change: programs already in a DXIL cache stay as they were compiled.

Measured, synthetic worst case

GTX 1650 (driver 32.0.16.2124, 32-lane waves), Ryzen 5 1600, 16 GB RAM, ~13.5 GB commit free, Windows 11 26300, DXC 1.9.2602.17, debug build. bench_memory_window_accessors (ignored test, in this PR): synthetic split-wave64 CS, 3 rounds, the forms one after the other in every round, a different program each time so that the driver cannot answer from its cache. Medians:

accesses form DXC DXIL pipeline (driver) 2048 groups
400 1 window 0.62 s 21 KB 0.16 s 0.185
400 4, whole (main) 2.61 s 48 KB 0.44 s 0.222
400 4, linked (this PR) 0.90 s 48 KB 0.47 s 0.221
1600 1 window 3.13 s 73 KB 0.83 s 1.253
1600 4, whole (main) 36.05 s 188 KB 3.48 s 1.653
1600 4, linked (this PR) 4.37 s 189 KB 3.84 s 1.653

Measured on a retail pack

GTX 1650 machine above (16 GB RAM), release build, one binary, XCL_LINK_MEM=0 / 1. Cold --precompile --only cs --limit 22300 (143 compute programs, 4 windows, split wave64), 4 DXC threads, a new empty cache for every run, order off-on, on-off, off-on:

XCL_LINK_MEM=0 linked (this PR) medians
wall 212.2 / 213.5 / 214.3 s 181.2 / 183.8 / 183.3 s 213.5 → 183.3 s (−14 %)
CPU 730.8 / 732.6 / 733.6 s 644.0 / 644.5 / 645.7 s 732.6 → 644.5 s (−12 %)
peak commit 2.57 / 2.49 / 2.55 GB 2.70 / 2.69 / 2.68 GB 2.55 → 2.69 GB (+5 %)
  • 143 of 143 compile in every run, 0 errors. 53 were linked and 90 have the same DXIL as without; the 53 take 20.36 MB either way. The output is the same in repeated runs of each form.
  • All 143 pipelines of the linked cache are made by the NVIDIA driver, 0 refused (--pipelines, one at a time, in two runs). Driver time off / on was not compared.
  • Foniass measured about −15 % on another sample (1 in 100, RTX 5070 Ti machine, native 64-lane form, DXC only): see the comment below.

Tried and dropped

  • [noinline] accessors in the program itself: the same DXC gain and a smaller DXIL, but NVIDIA keeps them as calls and the dispatch is 4.5–6× slower. (DXC's validator also takes only scalars in such functions.)
  • The same compiled as a library and linked: the linker keeps noinline.

Checked

  • gpu_linked_memory_accessors: one program with 1–4 dword loads and stores, scalar loads, 32- and 64-bit atomics, in two windows, odd and even lanes in different ones. Registers and memory are the same whole and linked, and loads match what is in memory.
  • linked_programs_keep_their_declarations: wave size (32 and 64), thread count, the windows' registers, globallycoherent (resource properties) and the number of functions are those of the whole program.
  • cargo test --workspace: 538 lib tests pass, 0 fail, 2 SKIPPED (no wave64); other suites pass.
  • The same with the threshold at 0, so that every cs_* program with windows is linked: 538 pass, 0 fail.

Not tested

  • AMD: TheHoracio ran the tests on an RX 7800 XT (RDNA3), native and split: the two new tests pass, no driver crash; the one failure also fails on main. No AMD timings, and no retail program on AMD.
  • A title: none has been run with this PR. Whether the linked retail programs give the same results on the GPU is only checked by the synthetic test.
  • Older DXC versions than the one above.

Textually it conflicts with #172 only at the end of tests.rs; the two are independent.

Gate A passed at 2026-11-23 18:21 UTC on main 956a476; Gate B passed at 18:54 UTC on main 956a476. PRs read: #113, #123, #138, #139, #162, #166, #172: none changes how accessors are compiled. The tests use synthetic programs only; no game material is in this PR.

With several memory windows every access is a switch between them. DXC
inlines the accessors before it optimises, so a program gets one switch per
access and its time grows much faster than their number. Compute programs
with 100 accesses or more are now compiled with the accessors only declared
and linked with them afterwards (IDxcLinker inlines them): 1600 accesses
36 s -> 4.4 s, the same DXIL size and GPU time. The generated HLSL is
unchanged. XCL_LINK_MEM=0 turns it off; a program that cannot be linked is
compiled whole.
@TheHoracio

Copy link
Copy Markdown
Contributor

AMD run, as asked under "Not tested": RDNA3 Radeon RX 7800 XT (16 GB, native 64-lane waves, amdxc64), driver 32.0.32015.7029, Windows 11 Pro 10.0.26300, Rust 1.100.0 x86_64-pc-windows-msvc, DXC 1.9.2602.17, debug build, PR head 328cf29.

Run Result
cargo test --workspace --no-fail-fast 570 passed, 1 failed, 40 ignored, 0 SKIPPED
XCL_SPLIT_WAVE64=1 cargo test -p xcl --lib gpu:: 256 passed, 0 failed
  • gpu_linked_memory_accessors and linked_programs_keep_their_declarations pass natively (64-lane) and split. No driver crash, no TDR or device removal.
  • The one failure is gpu_wave64_ps_whole_wave_reductions. It fails the same way on main 956a476 on RDNA2/RDNA3 and is fixed by VS / PS: the 32-lane form on every GPU that can run 32-lane waves (RD… #155. It is unrelated to this PR.
  • I did not run bench_memory_window_accessors or a retail pack, so there are no AMD timings here.

@Foniass

Foniass commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Retail-pack measurement, as asked under "Not tested": about −15 % DXC time on a 1-in-100 sample, 0 errors.

Machine: Ryzen 7 7800X3D (16 threads), 32 GB RAM, ~17 GB commit free, RTX 5070 Ti (driver 32.0.16.2114, 32-lane waves), Windows 11 26300, DXC 1.9.2602.17, release build. Measured at 8bca7cb; the PR head 328cf29 has the same tree.

Method: retail_translation_survey on a retail title's shader pack with XCL_SURVEY_EVERY=100, XCL_SURVEY_DXC=1, XCL_SURVEY_WINDOWS=4, two seeds. One binary, with XCL_LINK_MEM=0 and without, runs interleaved, nothing else running. The numbers are the total DXC time the test prints (4 threads).

Sample XCL_LINK_MEM=0 linked (this PR)
seed 1, 294 programs 336 / 323 / 332 s 288 / 282 / 275 s
seed 2, 261 programs 363 / 353 s 309 / 251 s
  • Seed 1 medians: 332 → 282 s. The 251 s run of seed 2 was fast throughout (median per program 0.24 s against 0.30 s in the other runs), so I would not read more than the −15 % of the other pairs into it.
  • 0 DXC errors in every run. No "could not be linked" warning in the output; I did not check that the test would show one.
  • The gain is in the large compute / mesh programs. The five slowest of seed 1, one run each: 21.7 → 14.7 s, 17.9 → 13.8 s, 16.1 → 11.7 s, 15.7 → 11.6 s, 12.7 → 8.6 s.
  • Pixel shaders do not change, as the PR says. With it they are 5 of the 10 slowest programs of the sample (4.4–8.2 s each), so they are what is left of the window switches' cost.
  • Wall time of the survey (seed 1): 86–89 s → 72–75 s.

Not measured: the split wave64 form (the survey translates the native 64-lane form), the driver's pipeline time, DXC's peak memory, and the GPU tests on this card.

No game material: timings and counts only. Measured with an AI assistant (Claude Code).

@RemingtonWilcox

Copy link
Copy Markdown
Contributor

Tested 328cf29 (main 956a476 + this PR) on an RTX 3090 (driver 616.92), Windows 11 26300, Ryzen 9 5950X.
cargo test --workspace --no-fail-fast -- --test-threads=2: 571 passed, 0 failed, 40 ignored (main: 569 / 0 / 39). gpu_linked_memory_accessors (linked vs whole: same registers and memory on the GPU) and linked_programs_keep_their_declarations pass on NVIDIA. bench_memory_window_accessors was not run. No regressions.

AI-assisted test report (Claude); tests run locally as stated; the diff was read in full before running.

@ethandepstein-del

Copy link
Copy Markdown

Independent Windows + RTX 5080 GPU verification of 328cf2963 (merge-base 956a476bf) on NVIDIA GeForce RTX 5080 (Blackwell desktop, driver 617.42, D3D12 SM 6.6 + mesh shaders, 32-wide waves, Windows 11, Ryzen 7 9800X3D, Rust 1.100.0, DXC 1.9.2602.17, no XCL_SAMPLE_*, no game files):

Build & Tests

  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 573 passed, 0 failed, 39 ignored (git diff --check clean; 2 expected no wave64 skips).
  • New GPU & unit tests passed on RTX 5080: gpu_linked_memory_accessors and linked_programs_keep_their_declarations.

Code check

(AI-assisted)

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review (Claude Code). Windows 11 (10.0.26200), Ryzen 9 9950X, RTX 5070 Ti (NVIDIA 610.74, 32-lane waves), Rust 1.99.0 MSVC, debug build. Synthetic programs only, no game files.

Tested 328cf29 (one commit directly on main 956a476, so the PR head is the merge result), with main as the control.

With the Windows SDK's DXC, the linked path never works. The README names the Windows SDK as the DXC source. The newest SDK, 10.0.26100, ships dxcompiler.dll 1.7.2308.16. That version rejects [WaveSize] on a library entry: error: attribute WaveSize only valid on entry point function, in either attribute order (checked with the SDK's dxc.exe -T lib_6_6 on a 5-line file). Every compute program the translator emits has [WaveSize], so with the SDK DXC:

  • every linked attempt fails and the program is compiled whole. The warning is logged once, but the cost is paid every time.
  • that costs an extra library compile per program. On the bench below, shape C goes from 1.3 s on main to 1.6 s with this PR.
  • the PR's own gpu_linked_memory_accessors and linked_programs_keep_their_declarations fail (2/2, same error). With DXC 1.9.2602.17 they pass (2/2).

DXC 1.8.2505 and 1.9.2602 (GitHub releases) accept it. Everyone who measured above used 1.9.2602.17, so nobody has run the SDK case yet.

Suggestions:

  • Stop trying for the rest of the process after the first linking failure, or check the DXC version once (IDxcVersionInfo) and skip linking below 1.8.
  • Say in the README that the gain needs DXC ≥ 1.8.

Measured with DXC 1.9.2602.17. I used xcl-pso's synthetic E/F bench from #156 (a copy in my tree; translated compute programs, one creator, fresh seeds so the driver hasn't seen them). DXC time is with 2 compiles at a time. The driver column is the first CreateComputePipelineState (median of 2).

shape DXC main DXC this PR DXIL driver main driver this PR
C: wave32, 4 windows, 2000 rounds 3.0–3.2 s 1.6–1.8 s 178 KB both 6.24 s 5.96 s
D: wave64 split, 4 windows, 2000 rounds 5.0–5.4 s 2.6–2.9 s 179 / 180 KB 6.00 s 5.64 s
E: D plus a divergent block every 4 rounds 3.8–3.9 s 3.4–3.8 s 261 / 262 KB 7.36 s 7.26 s
F: wave32, 1 window, 4000 rounds (control, not linked) 4.4–4.7 s 4.3–4.5 s 235 KB both 4.19 s 4.25 s

The DXC columns are from a CPU-only run with 4 programs. The driver run's own DXC times agree (C 2.9–3.0 → 1.6 s, D 4.7–4.9 → 2.0–2.1 s).

  • DXC time roughly halves for C and D. It does not change for E: with branches in the program, the linked form gives no gain here. I haven't looked into why.
  • On this card the driver is not slower. It is within ±6 % and slightly faster in C and D. The PR's GTX 1650 run measured 7–10 % slower. Two programs per cell, so I read both as "about equal".
  • XCL_LINK_MEM=0 on the PR binary gives the same DXIL sizes as main in every shape, and DXC times within this run's noise (D 5.3–6.0 vs 5.0–5.4 s; the other shapes within 0.4 s).

Related, and bigger than this PR on NVIDIA. The same main binary was run with the SDK DXC and with DXC 1.9 (fresh seeds, same session):

shape DXC DXIL DXC time driver
F SDK 1.7.2308 633 KB 2.8–3.0 s 10.12 s
F 1.9.2602 235 KB 3.8–3.9 s 4.61 s
C SDK 1.7.2308 371 KB 1.3 s 7.66 s
C 1.9.2602 178 KB 2.4–2.8 s 5.32 s

DXC 1.9 emits DXIL half the size or less, and the 5070 Ti's driver then compiles it 1.4–2.2× faster. DXC's own time goes up for a whole compile. Linking (this PR) takes that back for windowed programs. The driver times in #156's synthetic table were taken with the SDK DXC.

Not tested:

  • AMD (TheHoracio's run above covers correctness there);
  • a retail pack (Foniass's run above);
  • DXC 1.8 timings;
  • dispatch time;
  • more than 2 programs per cell.

@ryosen0

ryosen0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A data point for the SDK-DXC boundary, measured on this machine (Ryzen 7 9800X3D, RTX 3060 Ti, Windows 11):

  • The SDK 10.0.26100.0 installed here ships dxcompiler.dll 1.8.2502.11, not 1.7.2308.16 (dxc.exe --version: dxcompiler.dll: 1.8 - 1.8.2502.11). So "SDK 26100" is not one fixed DXC version - the revision of the SDK matters.
  • With that dxc.exe, lib_6_6 accepts [WaveSize(64)] and [WaveSize(32)] on a [shader("compute")] entry placed before [shader] (the order the translator emits, e.g. emit.rs [WaveSize(64)] [numthreads(64, 1, 1)]): both compile, exit 0, valid DXIL out. The 5-line repro from the review was not run against this revision.
  • The linked-compute path this review covers (DXC: compute programs are linked with their memory accessors (window switches no longer dominate DXC time) #174) is not on our main checkout yet, so this is only the attribute-acceptance half of the finding, not a linked-path run.

Suggests the version check / README note would be more precise as "DXC >= 1.8" rather than "SDK DXC fails": a 26100 SDK with 1.8.2502 passes the attribute probe here.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A follow-up to the review above, on how this fits with #187 and on the driver's part for access-dense programs.

With #187. The two merge with one conflict, in emit.rs::mem_accessors (keep this PR's mem_methods() split and put #187's heap branch at the top of mem_accessors(windows, heap); linked_form then calls mem_accessors(w, None)). linked_form looks for the switch accessors' text and finds none in a heap-window program, so that program is compiled whole once and nothing is done twice. With #187 on, this PR serves the programs still in the switch form: XCL_HEAP_WINDOWS=0, no shared heap, and the pipelines #187 rebuilds in the switch form when the driver refuses the heap form (603f546).

Driver time when accesses are dense. The review's shapes had a memory access every 8 rounds. With a load and a store every round (split wave64, 1000 rounds, an exec-masked block every 4 rounds, 2 never-seen programs per row):

form DXIL DXC driver, first creation
1 window 202 KB 3.0 s 3.8 / 4.4 s
4 windows, switch, whole 447 KB 5.0–5.6 s 139.5 / 159.6 s
4 windows, switch, linked (this PR) 450 KB 4.0–4.1 s 156.3 / 167.4 s
4 windows, heap (#187) 274 KB 3.7–3.8 s 3.6 / 3.6 s

So the PR does what it says for DXC, and on such programs the driver's part, which it leaves as it is, is the larger one by far.

In your own bench with a heap form added (1600 accesses, 2 rounds): DXC 1.0 s (1 window) / 11.0 s (whole) / 1.6 s (linked) / 1.2 s (heap), and GPU time for 2048 groups 0.237 / 0.273 / 0.271 / 0.243 ms.

Tested

Not tested

  • AMD, graphics pipelines, a retail pack, DXC 1.7 or 1.8.
  • Each row is 2 programs (2 rounds in the accessor bench).

AI use: Claude Code, Claude Fable 5.2.

Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Nov 23, 2026
…ong SDKs first

Nobody running XCL could tell which dxcompiler.dll it had loaded, and it
matters: with DXC 1.7.2308 (what Windows SDK 10.0.26100.4654 installs;
other revisions of that SDK have 1.8.2502) the DXIL of translated
compute programs was 2-2.7 times the size of DXC 1.9.2602's and an
NVIDIA driver took 1.4-2.2 times as long to build pipelines from it
(ivall#156); 1.7 also rejects [WaveSize] on library entries (ivall#174).

- dxc.rs: after loading, dxcompiler.dll and dxil.dll are asked for
  IDxcVersionInfo and IDxcVersionInfo2 (commit), and their version
  resources are read. One info line with versions and folder; below
  1.8 one warning with the measured cost and XCL_DXC_DIR.
  The release number is taken from the file: IDxcVersionInfo gives the
  DXIL version the library knows, and release 1.8.2505 answers 1.9.
- report.json: `dxc` (folder, both libraries). Filled by the game
  process when it compiled something, else by the launcher from its
  checks.
- xcl run's checks print the version, and a note with the fix when it
  is below 1.8.
- Windows SDK folders are tried in the order of their DXC's version,
  then of the SDK's, compared as numbers (old SDKs' compilers carry
  their Windows build number and go last). XCL_DXC_DIR and the folder
  of xcl.exe come first as before.
- README: DXC 1.8 or newer is recommended, and where to get it.

Co-Authored-By: Claude <noreply@anthropic.com>

@shdann shdann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In dxc.rs:249–254, two different compute shaders can request the same accessor library at startup. Each thread can see an empty cache before either stores its result. Both then compile the same library. The result is correct, but the extra DXC work happens during the cold start this change aims to shorten. Consider storing a per-key initialization cell under the map lock, then compiling outside the map lock. Preserve retry after a compile failure. A test with two distinct programs sharing one library can count library compilations and check that both programs link. Static review of 328cf29 with OpenAI Codex (GPT-6); I did not measure the timing impact.

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.

8 participants