Skip to content

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

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

POMXARK wants to merge 3 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.

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.

3 participants