Skip to content

D3D12.X: XCL_GPU_PROFILE logs the console programs that take GPU time - #1766

Open
wondercrash wants to merge 1 commit into
xcl-dev:mainfrom
wondercrash:pr/gpu-profile
Open

wondercrash wants to merge 1 commit into
xcl-dev:mainfrom
wondercrash:pr/gpu-profile

Conversation

@wondercrash

@wondercrash wondercrash commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Diagnostics only, off by default. Nothing in XCL measures GPU time per draw or dispatch, so a run where the GPU is busy but the title crawls cannot say which console programs the time goes to. With XCL_GPU_PROFILE=1 every draw, dispatch and ExecuteIndirect of console code gets a GPU timestamp pair, and every 2 s the log names the 15 console programs that took the most GPU time.

This is how we found why a retail title's intro cutscene ran at 0.3-0.5 fps with the GPU at 98-100 %: full-screen compute passes of 150-580 ms each (e.g. CS 79d178afa02abd49 Dispatch; 8x8x1 threads, wave32, ...: 1 call(s), longest 161.6 ms (320x180x1 groups)), which led to the cause (a separate change).

Related, and different: #1065 (XCL_GPU_TIMING) times ExecuteCommandLists on the CPU; #1323 (XCL_GPU_CULPRIT) marks dispatches to name the ones a stalled queue has not finished; #1592 names the pipeline at a DRED fault; #996 is about timestamps on hosts without GPU timestamps. None measures GPU time per program.

What is in it

  • crates/xcl/src/hle/d3d12x/gpu_profile.rs (new): begin / end record EndQuery(TIMESTAMP) before and after the op and a ResolveQueryData of the pair into a readback ring (2^17 pairs; one query heap and one readback buffer, made at the first timed op); a reporter thread takes the written pairs every 100 ms and logs every 2 s (every 20 s also the totals since the start): hash, kind, calls, total and longest ms, the group counts of the longest call, and for compute the thread group size, wave64 / split form, code and DXIL size. Ticks are converted with a title queue's GetTimestampFrequency (note_queue). Tests: a_pair_counts_once_both_stamps_are_written_and_in_order, programs_are_ranked_by_their_total_and_keep_their_longest_call.
  • bind.rs, console_list.rs: the timed call sites (Dispatch, console-list Dispatch, both ExecuteIndirect paths, DrawInstanced, DrawIndexedInstanced). The ExecuteIndirect span includes D3D12.X: an ExecuteIndirect reads the arguments written before it #1791's fresh_indirect_arguments.
  • real.rs: with the profile on, a translated pipeline's console shader hashes are kept (PSO_SHADERS, as for the frame trace) and a compute program's shape is noted; title queues are noted at submit (list_x.rs kickoff_x too).
  • gpu/recomp/pso.rs: compute_shape (thread group size, wave64, code size of a console CS).
  • With the profile off, each op pays one LazyLock read.

Limits (in the module doc): queues that overlap on the GPU are each charged in full, so the sum can exceed wall time; bundles get no stamps; a recording run again without a Reset is counted once; the resolve waits on the GPU for the op to finish, so with the profile on a queue runs its ops one after the other (the numbers are per op, not the frame time).

Tested

  • NVIDIA GeForce RTX 5090 (driver 621.14, 32-lane waves), AMD Ryzen 7 9800X3D, Windows 11 10.0.22631, Rust 1.96.0 MSVC, debug; DXC 1.8.2502 (Windows SDK 10.0.26100).
  • cargo build --workspace && cargo test --workspace -- --test-threads=4:
    • this PR (5a3fc0c on main 6020a33, --no-fail-fast): 1151 passed, 5 failed, 46 ignored (no new build warnings);
    • main 6020a33: 1150 passed, 4 failed, 46 ignored.
    • The 4 failures on both: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState: 0x8007000E, seeds 70, 545, 1019, 1507), the same when run alone on main. The fifth on this PR, offline_compute_pipeline_is_reused_by_a_second_process, failed once in the full run and passed when run alone on this PR and on main.
    • SKIPPED on both (24, identical): 20 no wave64, 3 refused gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 forms (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Retail title with XCL_GPU_PROFILE=1, on our integration branch (main + other PRs) with the same code: GPU timestamps at 1000000000 Hz; from 60 s the 2 s blocks read 1.9-2.1 s of GPU time per 2 s (e.g. last 2.0 s: 1920.5 ms of GPU time in 2905 op(s) of console code (3253 in flight, 0 lost, 0 out of order)), with the programs above at the top. In a later run with those programs changed, the same blocks showed 79d178 going from ~156 ms to a few ms.

Regression run
.\scripts\smoke.ps1 -Game <retail title> -Seconds 60, no input (both runs stay on the start screen), profile off as in any run without the variable, main first, same machine:

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: NVIDIA GeForce RTX 5090
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1548 (PresentX 1548)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16158 MB
xcl-smoke v1
commit: 5a3fc0cee469d5f39afb2c86589f1ca4d86fbefb
gpu: NVIDIA GeForce RTX 5090
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1650 (PresentX 1650)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16047 MB

Not tested

  • The title runs above were on our integration branch (this profile code plus other changes, including our own breadcrumbs, which are not in this PR), not on main + this PR alone; on this PR's head the profile was only checked by the suite. The regression pair runs with the profile off.
  • AMD / Intel GPUs (timestamp frequency and resolve behaviour), bundles, the overhead with the profile on.

AI use

  • omp with Claude Opus 5.5 wrote the change, the tests and this description, ported it onto main and ran the suite; omp with Claude Sonnet 5.5 rebased it onto 6020a33; omp with Claude Opus 5.5 reran the suite and the regression pair. The title runs are ours, on the hardware above.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head c433edb (on its base 85e3826).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record: 875 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: a_pair_counts_once_both_stamps_are_written_and_in_order, programs_are_ranked_by_their_total_and_keep_their_longest_call.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 877 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)).
  • Two tests were skipped with --skip on NVIDIA. Both fail on main 7f7e768 too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. heap_window_out_of_memory_falls_back_to_the_switch_form skips when XCL_HEAP_WINDOWS is unset (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record skips because Developer Mode is off on this PC (it cannot disable the driver cache). The AMD run does not set XCL_REQUIRE_GPU, so there both just print SKIPPED.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@JJAutoCompare

Copy link
Copy Markdown

PR #1766 compatibility verification on Intel Arc A770

Tested

Clean detached head c433edbe8d7565b3d8c4413374bba2804a3f66e7 on STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB, driver 32.0.101.9175 (no FP64, wave range 8–32). Rust 1.100.0 (0ef1bc386), DXC/DXIL 1.9.2609.5, unoptimized profiles with debug info disabled. cargo build --workspace and cargo test --workspace --no-run succeeded. All test execution used the shared Arc lock.

  • cargo test -p xcl --lib gpu_profile::tests -- --nocapture passed 2 tests covering timestamp-pair validation and program ranking by total ticks with longest-call tracking.
  • cargo test -p xcl --test gpu_compute_e2e console_wave64_compute_through_the_pso_hook_dispatch_and_read_back -- --nocapture passed on Arc with XCL_GPU_PROFILE=1. The translated shader's readback matched and the queue hook logged 19.2 MHz.
  • cargo test -p xcl --lib timestamps_outside_unified_memory_land_after_the_queue -- --nocapture passed.
  • cargo test -p xcl --test e2e test_title_runs_and_game_folder_is_untouched -- --nocapture with profiling enabled initialized the profiler and logged the timestamp clock. The title failed its RSSetDepthBiasX pixel check and exited before the first two-second reporting window. The same pixel failure occurred with profiling disabled.

Full workspace suite

cargo test --workspace --no-fail-fast -- --test-threads=4 with profiling disabled exited 101. The 20 summaries in pr1766-suite.log total 859 passed, 18 failed, 42 ignored. The log contains 4 SKIPPED lines, excluded from coverage.

  • 13 compute PSO refusals (0x80070057), including FP64 cases. Four GPU result mismatches involved FMA, FP16, mip LOD, and wave reduction. The remaining failure was the synthetic title's depth-bias pixel check.
  • Logged skips covered native wave64 (2), disabling the driver cache (1, requires Developer Mode), and heap windows (1).

Not tested

Per-program timing rows and long-run profiling, retail-title smoke or a main-branch baseline, sample-data paths, the D3D12 debug layer (DLL absent), and other adapters.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1766-suite.log and published this report.

A retail title's intro cutscene ran at 0.3-0.5 fps with the GPU at
98-100 %, and nothing in XCL measured GPU time per draw or dispatch: the
logs could not say which console programs the GPU time went to.

With XCL_GPU_PROFILE=1 each translated draw, dispatch and ExecuteIndirect
(and an ExecuteIndirect with a PC pipeline) gets a timestamp query on its
PC list before and after it, resolved right behind it into a readback
ring of 2^17 pairs. Nothing on the CPU waits: a reporter thread takes
the written pairs every 100 ms, and every 2 s logs the 15 console
programs with the most GPU time (every 20 s also since the start):
hash, kind, calls, total and longest ms, group counts of the longest
call, and for compute the thread group size, wave64 / split form, code
and DXIL size. Ticks are converted with a title queue's
GetTimestampFrequency. Off by default; with it off each op pays one
LazyLock read.

Overlapping queues are each charged in full, so the sum can exceed wall
time; bundles get no stamps; a recording run again without a Reset is
counted once. The resolve waits on the GPU for the op to finish, so with
the profile on a queue runs its ops one after the other. The unit tests
cover the pair states and the ranking.

Assisted-by: omp (Claude Opus 5.5)
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