Skip to content

D3D12.X: add opt-in gameplay graphics PSO frame budget, scale workers, and log slow compile hashes - #2988

Open
Saksukella wants to merge 2 commits into
xcl-dev:amd-devfrom
Saksukella:perf/pso-dynamic-frame-budget
Open

Saksukella wants to merge 2 commits into
xcl-dev:amd-devfrom
Saksukella:perf/pso-dynamic-frame-budget

Conversation

@Saksukella

Copy link
Copy Markdown

Introduces a dynamic boot-to-gameplay graphics PSO frame wait budget, scales default PSO compile worker threads on high-core / high-RAM hosts, and logs shader record hashes for slow driver compiles (>= 500 ms).

Motivation & summary of changes

On AMD RDNA 4 (RX 9070 XT), world entry hits hundreds of uncached 3D graphics PSOs. Because DEFAULT_FRAME_BUDGET_MS was 12,000 ms across all frames, a single 3D gameplay frame hitting 10–13 unready graphics PSOs stalled the title thread for 5–6.5 seconds per frame (237.8 s total in a 240 s run) before falling back to stand-ins anyway. Meanwhile, pso_worker_threads() remained capped at 6 even on 16–24 thread / 32+ GiB systems, and slow driver compiles (>= 500 ms) did not log the shader record hash without XCL_PSO_TRACE=1.

  1. Dynamic gameplay graphics PSO frame budget (crates/xcl/src/hle/d3d12x/pso_async.rs):
    • Adds FrameBudgetPolicy::{Explicit, Dynamic} with GAMEPLAY_FRAME_BUDGET_MS = 32 starting at GAMEPLAY_FRAME_BUDGET_START_FRAME = 60.
    • Boot/menu frames (frame < 60) keep the existing 12,000 ms budget; once active rendering is flowing (frame >= 60), graphics PSO bind waits cap at 32 ms/frame while background workers finish compiling them in parallel.
    • Explicit XCL_PSO_FRAME_BUDGET_MS (or XCL_GFX_PSO_FRAME_BUDGET_MS) always overrides uniformly across all frames.
    • Producer compute pipelines (p.compute == true / wait_for_submit) are completely untouched (fcap = None).
  2. High-core / high-RAM PSO worker scaling (crates/xcl/src/hle/d3d12x/pso_async.rs):
    • Adds pso_worker_threads_for(logical_cpus, total_ram_gib): hosts with < 16 logical CPUs or < 24 GiB RAM keep the existing 2..=6 cap; hosts with >= 16 CPUs and >= 24 GiB RAM scale to (logical_cpus / 2).clamp(6, 10) (protected by 81c04142 commit-headroom gating). Explicit XCL_PSO_THREADS / XCL_DXC_THREADS always override.
  3. Slow-compile shader record hash logging (crates/xcl/src/hle/d3d12x/real.rs):
    • driver_compile_identified now logs any compile >= 500 ms with its 64-bit record hash and driver blob status without requiring XCL_PSO_TRACE=1, and finish_two_pass supplies the two-pass console shader hash on all 3 call sites.

Tested

  • Unit tests on amd-dev (bf7c82ee + dd0b65f1, --test-threads=1, 0 new warnings):
    • cargo test -p xcl --lib pso_async -- --test-threads=1: 38 passed; 0 failed, including new pure-CPU unit tests:
      • dynamic_frame_budget_transitions_after_boot_and_honors_explicit_override
      • pso_worker_threads_scales_with_cpus_and_ram
    • cargo test -p xcl --lib big_compile -- --test-threads=1: 15 passed (1 pre-existing unrelated failure giant_driver_compiles_have_their_own_lane on bf7c82ee base).

Not tested

  • Non-AMD GPUs (NVIDIA / Intel).
  • Systems with < 16 logical CPUs or < 24 GiB RAM (verified via pso_worker_threads_scales_with_cpus_and_ram unit test).

Regression run
Baseline (main, b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB

This PR (dd0b65f1 on amd-dev bf7c82ee):

xcl-smoke v1
commit: dd0b65f13e28ed5015e00407ff3e04dafbd8ebcf
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 63 60 60
device removals: 0
crashes: 0
peak commit: 13014 MB

AI use

  • Profiling analysis, implementation, and unit tests were assisted by AI; all unit tests and the 60 s hardware smoke run were executed and verified locally on AMD Radeon RX 9070 XT.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent check of #2988 head dd0b65f1 against its exact parent bf7c82ee on Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC:

  • cargo test --offline --locked -j 4 -p xcl --lib pso_async -- --test-threads=1 on head: 38 passed, 0 failed, 0 ignored. These are policy/queue tests, not GPU coverage.
  • With XCL_SAMPLE_RPF set to my locally owned shader pack and XCL_REQUIRE_GPU=1, cargo test --offline --locked -j 4 -p xcl --test gpu_pso_e2e -- --test-threads=1 on head: 3 passed, 4 failed, 0 ignored. The exact parent gives the same 3/4/0 result and the same failing test names. Three mesh pairs report “PSO without a compute pass”; later tests also hit the shared PSO-count assertion. An isolated VS/PS draw reads clear color at pixel (25,17) on both revisions. I cannot attribute these NVIDIA failures to this PR. No title executable was run.

One policy point: resolve_wait_for uses the count of successful Present calls, and frame_budget_for switches the default from 12 s to 32 ms at count 60. Menu and loading presents count too; at 30 FPS the threshold is reached about two seconds after the first presentation, even if world loading is still ahead. The new unit test proves the numeric threshold, but not the described boot/menu-to-gameplay transition. If the 12 s budget must protect loading menus, the 32 ms default needs an explicit phase signal; until then, an opt-in budget is the bounded option. A regression should present more than 60 loading/menu frames, bind a cold graphics PSO, and verify the intended wait while producer compute remains uncapped. If 60 presents is intentionally just a responsiveness heuristic, the description and a measured visual-correctness run should say so.

Not tested: full workspace suite, Intel/AMD hardware, or a paired title smoke run. AI use: Codex (GPT-6.2 Sol) ran the exact-head and exact-parent tests and traced the frame counter; Codex (GPT-6.2 Astra) reviewed the attribution and wait policy.

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up to my earlier NVIDIA report: I isolated the two pack-backed failures on the exact amd-dev parent bf7c82ee, so they should not be read as mesh translation failures introduced by #2988.

On Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, with XCL_SAMPLE_RPF set to my locally owned shader pack and XCL_REQUIRE_GPU=1, I ran each test in a separate process using cargo test --offline --locked -j 4 -p xcl --test gpu_pso_e2e <test> -- --exact --nocapture --test-threads=1:

  • retail_vs_ps_through_the_pso_hook_render_and_read_back: 1 passed, 0 failed, 0 ignored with XCL_HEAP_WINDOWS=0 on the parent. The parent defaults heap windows on. #1743 already addresses the graphics test runner's missing heap-window descriptors; this result supports handling that through the existing PR.
  • retail_mesh_pipelines_through_the_hook: 1 passed, 0 failed, 0 ignored, 7/7 MS+PS pairs with XCL_PSO_FRAME_BUDGET_MS=off on the parent (heap windows left at their default). With the default 12-second per-frame cap, later pairs instead receive stand-ins and the test reports missing compute passes. This synthetic test creates seven PSOs before any Present, so they share frame 0's budget. Disabling heap windows did not fix it: 0 passed, 1 failed, 0 ignored, 2/7 pairs.
  • On current main 83b00818, with its default settings, each isolated test passed (1/0/0; mesh 7/7). main and amd-dev have diverged, so this is a baseline comparison, not an attribution to D3D12.X: add opt-in gameplay graphics PSO frame budget, scale workers, and log slow compile hashes #2988.

The mesh test should give each synthetic PSO its own frame budget or explicitly disable the frame cap while measuring translation. That would distinguish a stand-in from an actual failure to build the two-pass PSO. No title executable was run; no full workspace suite or paired smoke run was done in this follow-up. AI use: Codex (GPT-6.2 Sol) traced the wait path and ran these GPU tests.

@Saksukella Saksukella changed the title D3D12.X: use dynamic gameplay graphics PSO frame budget, scale workers, and log slow compile hashes D3D12.X: add opt-in gameplay graphics PSO frame budget, scale workers, and log slow compile hashes Nov 27, 2026
@Saksukella

Copy link
Copy Markdown
Author

Thanks @thehollowedone for the thorough check and great policy catch!

You're right that switching from 12 s to 32 ms at Present count 60 triggers during menu/loading screens and can skip cold graphics PSOs on world entry. Pushed an update keeping the default graphics frame budget at \12_000 ms\ (identical to \�md-dev, zero premature draw skips), while making \XCL_GFX_PSO_FRAME_BUDGET_MS\ strictly opt-in (caps graphics-only bind waits from frame 60 onward while leaving producer compute uncapped, with \XCL_PSO_FRAME_BUDGET_MS\ overriding all frames). High-core/high-RAM worker scaling (\6 -> 10\ on >=16T / >=24GiB) and >= 500 ms\ slow-compile shader record hash logging remain enabled by default. Updated \ rame_budget_keeps_default_12s_and_honors_opt_in_gfx_and_explicit_overrides\ (\38/38\ passed in \pso_async).

@fromthemoonx

Copy link
Copy Markdown

Full suite on NVIDIA (listed under Not tested) on the new head 6f5e03c: no new failure compared with amd-dev itself. Every failure here also fails on bf7c82e, or is a parallel-only flake that passes alone on both.

Tested: 6f5e03c (its base is current amd-dev bf7c82e, so head = merged), and bf7c82e itself for comparison. RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X (16 threads), 16 GB RAM (GlobalMemoryStatusEx reads 15 GiB, so this host keeps the old 2..=6 worker cap and does not reach the new scaling), Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, 6f5e03c the lib binary aborted part-way; the other binaries: 121 passed, 6 failed, 20 ignored, 20 SKIPPED lines, the same 6 as on bf7c82e
lib binary, --test-threads=4, 2 more runs on 6f5e03c / 7 runs on bf7c82e one run completed: 1657 passed, 12 failed, 27 ignored; the other aborted with thread 'xcl-pso-0' panicked at … windows-core-0.62.2\src\interface.rs:41:18: null reference produced / non-unwinding panic. aborting., which bf7c82e does too (in 2 of its 7 runs, plus 1 segfault)
the 19 tests that failed in any run on 6f5e03c, compared with bf7c82e 17 fail on bf7c82e too (e.g. the 3 e2e title tests, giant_driver_compiles_have_their_own_lane)
compositor_releases_root_sig_and_rejects_invalid_planes (psos_for leaked root_sig COM refs) failed 1 of 3 runs here; flaky on bf7c82e too (1 of 7, same assertion)
hle::kernelx::guards::tests::writes_from_many_threads_are_all_caught_and_kept (guards.rs:411, caught pages differ) failed 1 of 3 runs here, passed in the 4 bf7c82e runs that reached it; alone, 10 of 10 on both. This PR does not touch guards.rs, so this looks like a parallel-only flake
hle::d3d12x::pso_async:: (38 tests), --test-threads=8 38 passed

From reading: total_physical_ram_gib rounds down (ullTotalPhys >> 30), and Windows reports a little less than the installed size (16 GB reads as 15 here). So a 24 GB machine would likely read 23 and stay on the old cap. If 24 GB hosts are meant to scale, the threshold could compare in MiB, or use 23.

Not tested: a title on NVIDIA with this branch, a 24 GB+ host with 16+ threads (the new worker scaling), a release build, Intel.

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

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