Skip to content

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

Open
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1766
Open

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1766

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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: xcl-dev#1065 (XCL_GPU_TIMING) times ExecuteCommandLists on the CPU; xcl-dev#1323 (XCL_GPU_CULPRIT) marks dispatches to name the ones a stalled queue has not finished; xcl-dev#1592 names the pipeline at a DRED fault; xcl-dev#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).
  • 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 (c433edb on main 85e3826): 877 passed, 0 failed, 42 ignored (no new build warnings);
    • main 85e3826: 875 passed, 0 failed, 42 ignored.
    • SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), 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: 85e38262ff94aecd75d6f83fa8156a8b7697bd13
gpu: NVIDIA GeForce RTX 5090
title: retail
seconds: 60
exit: 0x0
frames shown: 1663 (PresentX 1663)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16216 MB
xcl-smoke v1
commit: c433edbe8d7565b3d8c4413374bba2804a3f66e7
gpu: NVIDIA GeForce RTX 5090
title: retail
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16350 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. The title runs are ours, on the hardware above.

Mirror of xcl-dev#1766 (auto-synced, do not edit).

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.

2 participants