Skip to content

Shaders: adaptive DXC memory budget & direct-DXIL mesh/graphics precompilation - #2950

Open
POMXARK wants to merge 4 commits into
xcl-dev:mainfrom
POMXARK:perf/precompile-direct-mesh-and-graphics
Open

POMXARK wants to merge 4 commits into
xcl-dev:mainfrom
POMXARK:perf/precompile-direct-mesh-and-graphics

Conversation

@POMXARK

@POMXARK POMXARK commented Nov 27, 2026

Copy link
Copy Markdown

Speeds up cold shader precompilation and prevents host OOM / stalled launches by adapting DXC/pipeline concurrency to available host resources, routing Mode::Mesh and direct graphics (Vertex/Pixel) stages through pso during precompile(), and allowing XCL_PIPELINE_MAX_KB-capped compute pipelines to defer cleanly to runtime.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs (0093a63):
    • Estimate DXC memory usage per HLSL compile (estimate_compile_mb) and dynamically scale active compile budget/permits against available host commit/RAM with a 3.0 GB floor (wait_for_memory_for).
  • crates/xcl/src/shaders.rs (0093a63, 2879c5b, 0b3729b):
    • Scale default_pipeline_threads (4..=12) from CPU thread count and host RAM.
    • Route Mode::Mesh (NGG) containers through pso::console_mesh_in so translated/v2 caching and XCL_DIRECT_DXIL match runtime pipeline creation instead of unconditionally falling back to HLSL + DXC (~35% of shader packs).
    • When XCL_DIRECT_DXIL=all is active, route standalone Vertex and Pixel stages through pso::console_to_dxil_in.
    • Allow XCL_PIPELINE_MAX_KB-capped compute pipelines to stay deferred to runtime during startup preparation instead of failing prepare_for_launch with an error after translation finishes cleanly (0 failures, 0 refused pipelines).
  • crates/xcl/src/gpu/recomp/pso.rs (2879c5b):
    • Expose pub fn console_mesh_in(blob, ps, split_wave64, windows) and add unit test console_mesh_in_forwards_windows_and_populates_cache.

Tested

  • Hardware & toolchain: Windows 11, NVIDIA GeForce RTX 5080 (driver 32.0.16.2124), AMD Ryzen 7 5700X (8C/16T), rustc 1.91.1 (ed61e7d7e 2025-11-07), DXC/DXIL 1.8.2502.11, release build --locked.
  • Targeted unit & E2E suites:
    • cargo test -p xcl --lib dxc -- --test-threads=4 (on 0093a63): 45 passed, 0 failed, 3 ignored (dump_dxc_lowering, blob_dxc_cost, dxc_time_levels)
    • cargo test -p xcl --lib pso -- --test-threads=4 (on 2879c5b): 53 passed, 0 failed, 1 ignored (repeated_pso_shader_compile)
    • cargo test -p xcl --lib shaders -- --test-threads=4 (on 0b3729b): 17 passed, 0 failed, 0 ignored
    • cargo test -p xcl --test shaders_e2e -- --test-threads=4 (on 0b3729b): 8 passed, 0 failed, 0 ignored
  • Cold --precompile benchmarks on an anonymized 26,503-record RPF9 corpus (NVMe SSD):
    • --precompile --limit 300 (HLSL default): 18.33 s (main) -> 14.196 s (0093a63, avg 9.39/16 cores, 0 errors)
    • --precompile --limit 500 (XCL_DIRECT_DXIL=all): 23.278 s wall / 22.9 s internal (0093a63, 548 .dxil, 15.68 MB, 0 errors) -> 2.014 s wall / 1.1 s internal (2879c5b, 48 .dxil + 500 translated/v2, 12.31 MB -21.5%, ~20.8x internal speedup, 0 errors)
    • Full cold 26,503-record --precompile (XCL_DIRECT_DXIL=all, empty cache): 311.8 s internal / 322.215 s wall (5m 12s), 26,308 compiled (25,694 translated/v2 + 677 passthrough .dxil, 3,723.93 MB), 0 errors, 390 paired GS skipped, avg 11.32/16 cores, peak 1.72 GB WS / 1.79 GB PM.
    • Direct DXIL coverage (--direct --sample 2000 --max-bytes 0 --validate --threads 12): 2000/2000 (100.0%) translated & validated in 31.0 s (CS 205, GS 35, MS 708, PS 874, VS 178, 0 unsupported/validator errors/panics/timeouts).

Regression run
Draft PR pending clean scripts/smoke.ps1 xcl-smoke v1 runs on main and 0b3729b (earlier 60s launch on warm translated/v2 cache finished shader preparation cleanly and entered the title, then aborted at 47s due to low free space on the host system drive for pagefile.sys).

Not tested

  • Full cargo test --workspace on 0b3729b, non-NVIDIA GPUs, and a completed 60s scripts/smoke.ps1 run.

AI use

  • Antigravity (Google DeepMind) assisted with bottleneck profiling, implementation, unit tests, and benchmark runs.

Роман Бушуев added 3 commits November 26, 2026 21:17
Expose pso::console_mesh_in with explicit memory window count and route
Mode::Mesh containers through it in shaders::precompile so translated/v2
caching and XCL_DIRECT_DXIL apply during precompilation just as at runtime.
Also route standalone Vertex and Pixel stages through pso::console_to_dxil_in
when XCL_DIRECT_DXIL=all is enabled.

Includes unit test console_mesh_in_forwards_windows_and_populates_cache.
Verified on Windows 11 / RTX 5080 (--limit 500 with XCL_DIRECT_DXIL=all):
22.9 s -> 1.1 s internal (23.28 s -> 2.01 s wall), 15.68 MB -> 12.31 MB, 0 errors;
full cold 26,503-record pack precompiled in 311.8 s internal (322.2 s wall), 0 errors.
…eparation

Keep capped compute pipelines deferred to runtime when XCL_PIPELINE_MAX_KB
is set during startup preparation instead of failing precompilation after
translation finishes cleanly (0 failures, 0 refused pipelines).
@andrewDoing

Copy link
Copy Markdown

On 0b3729b1c7ada92b28666d05942c02ea3e7d9ba4, an unused loose pixel shader with one unsupported instruction prevents guest entry when XCL_DIRECT_DXIL=all. The same guest and shader start successfully on the PR’s base, 8b957bec6f82495aec940944c6bf47faa02db590.

I ran six fresh xcl run processes on an RTX 5070 with isolated data and shader caches, using unmodified executables from each revision and the repository’s synthetic title. I placed one pixel shader in the title’s shaders directory. The unsupported variant replaces one instruction with v_cvt_off_f32_i4. The guest does not request that shader.

Loose shader and direct mode Base PR head
Supported, all 1 compiled, exit 0 1 compiled, exit 0
Unsupported, 0 1 skipped, exit 0 1 skipped, exit 0
Unsupported, all 1 skipped, exit 0 1 error, 0 skipped, exit 2 before guest entry

Every exit-0 guest reported zero fixture failures. The failing launch reported incomplete translation, missing: ["v_cvt_off_f32_i4"], with zero refused pipelines and zero pipelines over the size cap. The direct-graphics precompile route counts this incomplete translation as a hard failure. The existing per-program path skips it.

PR #2613 addressed this distinction for graphics warmup by retaining the old per-program fallback for incomplete translations. Its treatment of CompileOutcome::Incomplete is relevant here. Related PR #2613

This test covers launch admission for a synthetic pixel shader. Retail shader incidence, performance and world loading were not measured. AI use: OpenAI Codex with GPT-6.2 Astra adapted the synthetic shader, built both revisions and ran the paired launches; Codex coordinated and prepared this report.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

I checked the reservation boundary in wait_for_memory_for on 0b3729b. The headroom check reads RESERVED_MB before the OS query and later adds to it separately. Multiple workers can all admit themselves using the same pre-reservation state.

In an isolated Windows Rust harness, I used the exact admission code and replaced only the memory query with a synchronized test source. It released eight workers from their first query with 3 GiB reserve plus 128 MiB available. Each job requested the 128 MiB estimate. With no priority bypass and no timeout reached, 8/8 workers entered while the first permits were still held, reserving 1,024 MiB against the 128 MiB budget, in 5/5 trials. Main 8b957bec also admitted 8/8 with the same coordinated snapshots, so the check/reserve race predates the estimates.

A local control sampled memory first, then serialized the headroom check and permit acquisition under one mutex. 1/8 entered before release, 128 MiB reserved, in 5/5 trials. All eight finished and the counters returned to zero in both variants. This is a deterministic admission-policy test with injected headroom. It does not measure actual commit use, a compiler OOM, or retail performance.

OpenAI Codex assisted with verification.

@andrewDoing

Copy link
Copy Markdown

I tested a local fix on #2950 head 0b3729b1. If the runtime graphics translator reports an incomplete vertex or pixel translation, precompilation falls through to the existing per-program path for that shader variant. Successful direct translations retain their current route. Other errors keep their original failure behavior. This follows the incomplete-translation distinction used by #2613.

On native Windows with an RTX 5070 and the repository’s synthetic guest, the unused pixel shader containing v_cvt_off_f32_i4 now produced one skip and exit 0 with XCL_DIRECT_DXIL=all, both cold and when a fresh process read its cached incomplete-translation reason. Unmodified #2950 produced one error and exit 2. The supported direct shader and the unsupported shader with direct graphics disabled also reached guest entry and finished with zero fixture failures. A separate negative control injected a non-incomplete reason into an isolated refusal-cache record. The local fix preserved the hard error and stopped before guest entry with exit 2.

A new regression test builds a single synthetic container with two pixel shader variants, placing the incomplete variant first and a supported one second. Stock #2950 compiled zero variants and reported two errors. The local fix compiled the supported variant and reported zero errors. All nine tests in shaders_e2e passed on the candidate.

These results cover graphics precompilation with synthetic inputs. The patch has not been submitted or tested on a retail title. AI use: OpenAI Codex with GPT-6.2 Astra adapted and independently reviewed the fallback and fixtures and ran the tests; Codex coordinated and prepared this report.

@andrewDoing

Copy link
Copy Markdown

PR #2950 changes startup handling of an incomplete mesh translation

A synthetic guest reached its entry point on parent 8b957bec and exited successfully. On PR head 0b3729b1, the same guest exited 2 during shader precompilation. This reproduced with XCL_DIRECT_DXIL unset, set to 0, and set to all.

The input was a loose 128-thread mesh shader with its PSV0 metadata intact. The unsupported variant changed one instruction to v_cvt_off_f32_i4. Each run used fresh data and DXIL caches on Windows with the RTX 5070 selected.

Input Direct DXIL setting Parent PR head
Supported mesh control 0 2 compiled, guest exit 0 1 compiled, guest exit 0
Incomplete mesh shader unset, 0, all Guest exit 0 in all three runs Exit 2 before guest entry in all three runs

With explicit settings, the parent counted one unsupported translation as skipped. The head counted one error and zero skips, with the missing opcode in its diagnostic. The mesh branch calls pso::console_mesh_in independently of the direct vertex/pixel setting. Handling incomplete translation in the vertex/pixel branch alone leaves this startup failure reproducible.

The test covers startup classification and guest entry. It contains no retail game data and measures no game performance. AI use: OpenAI Codex with GPT-6.2 Astra generated and ran the fixtures; Codex coordinated and prepared this follow-up.

@andrewDoing

Copy link
Copy Markdown

Follow-up to the incomplete-mesh report: a local candidate treats only the explicit incomplete-translation result as a request to continue through the existing per-program path. Other mesh translation failures remain errors. It also keeps mesh variants out of the direct VS/PS-only filter during that fallback.

The synthetic two-variant mesh container has an incomplete first program and a supported second program. With direct DXIL both 0 and all, the candidate compiled the compute/pass-through pair, skipped the incomplete program, and reached guest exit 0. The unmodified head exited 2 on the same input. Supported-only and incomplete-only controls passed with their expected compile/skip counts. A genuine undecodable instruction and a separate cached hard refusal remained fatal, each with one error and exit 2. Fresh and cached incomplete reasons both took the skip path.

The repository shader integration suite passed 10/10, including the graphics and mixed-mesh regressions. The local combined patch was independently checked against the pristine head. This is synthetic startup evidence; GTA VI behavior and performance were not measured.

AI use: OpenAI Codex with GPT-6.2 Astra implemented, tested and independently reviewed the candidate; Codex coordinated and prepared this follow-up.

…ranslations

- Serialize availability checks against WORKING and RESERVED_MB updates inside MemoryGateState mutex in dxc::wait_for_memory_for so concurrent DXC workers cannot over-admit against the commit budget
- Treat incomplete translation errors from console_mesh_in and direct VS/PS console_to_dxil_in as non-fatal fallbacks into the per-program translation loop so unsupported programs are skipped cleanly while supported FSSM variants in mixed containers still compile and real decode/compile errors remain fatal
- Add unit and e2e tests covering tight-budget concurrent memory admission, loose/mixed VS/PS/Mesh incomplete fallbacks (cold and warm), startup preparation, and hard decode errors

Tests (Windows release): wait_for_memory 1/1, memory_budget 1/1, console_mesh_in 1/1, startup_preparation_skips_incomplete 1/1, shaders_e2e 9/9 PASS
@POMXARK

POMXARK commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks for catching both blockers @andrewDoing @ettehn — both are fixed and verified, marking this ready for review:

  1. Serialize wait_for_memory_for admission + reservation (@ettehn):
    Guarded availability checks, WORKING, and RESERVED_MB updates under MEMORY_GATE (MemoryGateState::try_admit / release) in crates/xcl/src/gpu/recomp/dxc.rs so concurrent DXC workers cannot read the same uncommitted budget and over-admit past reserve + job_mb. Added wait_for_memory_serializes_concurrent_admission_at_budget_boundary testing 8 threads at the exact boundary (peak_active == 1).

  2. Non-fatal incomplete-translation fallback for direct graphics & Mesh (@andrewDoing):
    Added is_incomplete_translation_error in crates/xcl/src/shaders.rs. When console_mesh_in or direct console_to_dxil_in returns "incomplete translation..." (cold or cached XCLTERR1), precompile() falls back into the per-FSSM / per-program loop instead of incrementing failed (preventing early exit 2 before guest startup on loose incomplete shaders, and allowing remaining supported FSSM variants in mixed containers to compile). Real decode/compile errors still increment failed as fatal. Covered by startup_preparation_skips_incomplete_and_fails_on_decode_error and shaders_precompile_skips_incomplete_and_keeps_hard_errors_for_graphics_and_mesh.

Tests on Windows (release): cargo check -p xcl --all-targets, wait_for_memory 1/1, memory_budget 1/1, console_mesh_in 1/1, startup_preparation_skips_incomplete_and_fails_on_decode_error 1/1, shaders_e2e 9/9 PASS.

@POMXARK
POMXARK marked this pull request as ready for review November 27, 2026 11:29
@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA full-suite check of #2950 head 897f0924. This is the current revision with the serialized memory gate and incomplete-translation fallback; the checkout was clean.

Windows 11 build 26300, RTX 3080 Ti (12 GiB, NVIDIA 621.35), Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC available. XCL_DXIL_CACHE pointed to a writable scratch cache.

  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quiet: 1,452 passed, 0 failed, 47 ignored across 38 targets. The log contained 25 GPU skip notices: 21 no native wave64, three refused per-lane f16/packed cases, and one no heap windows. These skips are not GPU coverage.

The full-suite pass did not include a title or a cold full-pack precompile, nor AMD or Intel testing. The PR description still names older commits for its measured runs and has no clean-head smoke pair for 897f0924; this test report does not satisfy that runtime merge gate.

AI use: Codex (GPT-6.2 Sol) ran the clean-head build and suite and checked the counts.
Update on the same head, against current main �6f90c1: I built clean release binaries from both commits and ran scripts/smoke.ps1 -Seconds 60 -Title retail-title under a 16 GiB process-tree commit guard and 12 GiB minimum system commit headroom, with separate copies of the same profile and DXIL cache seed. The first main attempt with default preparation timed out during startup before the guest timer; no smoke block was produced. With the documented XCL_PREPARE=0 setting, main completed the 60-second run. The guard exited normally, peaking at 15.91 GiB with at least 22.67 GiB system headroom.

Generated clean-main smoke block
xcl-smoke v1
commit: 06f90c1986f43698d0405eff3c2ab0af230e1ed9
gpu: NVIDIA GeForce RTX 3080 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16182 MB

The same XCL_PREPARE=0 setting on clean #2950 head 897f092 still entered mandatory preparation of 26,503 shaders and reached the script's 120-second startup limit before producing a log or valid smoke block. Its outer guard exited normally at 2.19 GiB peak; this is a smoke setup blocker, not a measured guest crash. That head predates main's XCL_PREPARE=0 preparation opt-out. Please rebase onto current main (or include the equivalent opt-out), then rerun the full suite and clean-head paired smoke after the push. I can retest the new head. The generated main block alone does not satisfy the PR's two-block gate. This run did not cover cold full-pack preparation or world load.

AI use: Codex (GPT-6.2 Sol) built both clean revisions, ran the guarded smoke attempts, checked the generated block and traced the preparation difference.

@LocranKing

Copy link
Copy Markdown

Tested PR #2950 (897f0924) on Windows 11 (Ryzen 5 5500 6C/12T, 32 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB, driver 32.0.16.2140).

Unit & E2E tests

  • cargo test --locked -p xcl --lib -- wait_for_memory memory_budget console_mesh_in --nocapture:
    • gpu::recomp::dxc::cache_tests::memory_budget_scales_with_hlsl_size_and_restores_on_drop — ok
    • gpu::recomp::dxc::cache_tests::wait_for_memory_serializes_concurrent_admission_at_budget_boundary — ok
    • gpu::recomp::pso::shader_cache_tests::console_mesh_in_forwards_windows_and_populates_cache — ok
    • 3 passed, 0 failed
  • cargo test --locked -p xcl --test shaders_e2e -- --nocapture:
    • 9 passed, 0 failed (including shaders_precompile_skips_incomplete_and_keeps_hard_errors_for_graphics_and_mesh).

xcl shaders --precompile --pipelines --limit 1500 check

Ran cold-cache --precompile --pipelines --limit 1500 (XCL_DEVICE_TYPE=lockhart, XCL_DIRECT_DXIL=all):

  • Output: compiled 1500, already cached 0, errors 0, skipped (GS – paired at pipeline creation) 31, time 5.0 s (wall_s=6.58), rc=0.
  • Scope note: In the first 1500 records of this title's pack, pipelines made on the GPU was 0 (all compute GPU pipelines sit past that range), so this run exercised DXIL/graphics precompile cleanly while GPU compute pipeline gating was not exercised here.

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.

5 participants