Skip to content

GPU: add an opt-in execution performance census - #509

Open
aycow wants to merge 13 commits into
Marvisak:mainfrom
aycow:gpu/execution-performance-census
Open

aycow wants to merge 13 commits into
Marvisak:mainfrom
aycow:gpu/execution-performance-census

Conversation

@aycow

@aycow aycow commented Nov 24, 2026 •

Copy link
Copy Markdown

What this measures

In a diagnostics build, VICTORY_GPU_CENSUS=1 aggregates D3D12 completion spans by pipeline and shader hash. It reports invocation counts, work sizes, GPU spans, CPU pipeline-build time, and refusals. This complements #130's CPU and frame profiling, #279's DRED diagnostics, and #159's title-facing queries.

Run the census

cargo build --profile diag -p victory --features diagnostics
$env:VICTORY_GPU_CENSUS = '1'
$env:VICTORY_LOG = 'info'

The victory_gpu::census log target reports roughly five-second windows on completed submissions. It flushes pending data when the title thread exits or the host reports a GPU failure.

  • Execution rows are grouped by pipeline key and command kind and sorted by accumulated time. They show stage and shader hash, recorded calls, calls per second, timed calls, and median, maximum, and accumulated milliseconds. Shader rows aggregate across pipelines. Stages in the same graphics pipeline share its span.
  • Direct compute and mesh rows report total groups and maximum dimensions. Draw rows report vertices or indices times instances. Indirect rows report calls, stride, and exact argument-record counts for fixed-count calls. Count-buffer calls report their upper limits. The clamp reports candidate records separately from launched groups.
  • CPU build rows include translation on a miss, root signature work, and PSO loading or creation. Refusal rows count existing runtime classifications.

Each timestamp pair marks two completion points on the direct queue. Work can overlap, and timestamp queries can affect scheduling. Use the spans to rank work for investigation and measure submission or frame time separately. Timestamp results are resolved into list-owned buffers and collected after the existing fence. The first 2,048 operations in a list can receive timestamps. Later operations, duplicate instances in a batch, and unavailable samples still contribute to call counts. The census takes precedence when both timing switches are set, so normal list batching is retained. D3D12 timing · Indirect count semantics

Synthetic reproduction

The original compute and mesh fixture records two lists and verifies reference output, direct and indirect metadata, timestamp coverage, and one native submission even with the legacy timing switch set. The single-record test passed on AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP with the debug layer and full GPU-based validation. NVIDIA and WARP passed the multi-record control. The tested AMD driver produced only the first record, including with profiling off, and also produced the first record in a separate zero-count control. Those observations apply to the synthetic fixture and driver tested.

Run the hardware test manually with Graphics Tools, Agility SDK 1.620.x x64, and a local x64 DXC:

$env:VICTORY_GPU_CENSUS = '1'
$env:VICTORY_GPU_TIMING = '1'
$env:VICTORY_CENSUS_TEST_AGILITY = '<Agility SDK x64 runtime directory>'
$env:VICTORY_CENSUS_TEST_DXC = '<path to x64 dxc.exe>'
foreach ($adapter in 'amd', 'nvidia', 'warp') {
    $env:VICTORY_CENSUS_TEST_ADAPTER = $adapter
    cargo test --locked -p victory-gpu --features diagnostics --lib census::gpu_tests::census_gpu_smoke -- --exact --ignored --nocapture --test-threads=1
}

Set VICTORY_CENSUS_TEST_MULTI_INDIRECT=1 for the three-record probe or VICTORY_CENSUS_TEST_ZERO_INDIRECT=1 for the zero-count probe. Clear both timing switches for an unprofiled control. The hosted diagnostics step runs the census unit test for aggregation and work counts. The hardware test runs through the explicit manual command above.

Matched title measurements

Use an authorized title setup. Match GPU and driver, title build, scene and inputs, PR stack, and cache warm-up. Use the same present-call window and identify incomplete windows or device removal. Establish a stock frame and submission baseline, then compare builds that both use the census and differ only by the optimization under test. Turn listed-frame capture, legacy timing, DRED, the debug layer, and GPU-based validation off during timed runs. Run validation separately.

Share build SHAs, adapter and driver, frame range, and aggregate rows for the expensive compute and mesh pipelines. Include hashes, calls and timed calls, work sizes or indirect limits, median, maximum and accumulated milliseconds, and refusal counts. Title performance remains unmeasured here.

Earlier validation

Updated onto ffe310e. The Windows workflow now runs the census diagnostics unit tests explicitly, with the existing default workspace tests and both Clippy configurations retained. The focused unit command and both Clippy commands passed locally. The hardware smoke remains opt-in. The current-main single-record fixture passed on AMD, NVIDIA, and WARP with full GPU-based validation, reference output and one submission. For async composition, the pending submission must retain the recording-specific timestamp/readback allocation and operation metadata through its fence. Early reset can otherwise pair old timestamps with new metadata. This branch collects synchronously.

fromthemoonx independently validated the single-record, multi-record, zero-count, and unprofiled controls on a desktop RTX 3060 with full GPU-based validation. The profiled variants used one submission. Independent result

Async census validation

The separate async composition retains queries, readback, operation metadata and shader identities as one recording generation. AMD, NVIDIA and WARP passed the held-fence reset/resubmission and replay fixture with full GPU validation. No samples were collected while the 100 ms CPU gate was held. The original smoke still produced one submission; the new test produced exactly three. The synchronous #509 head and its workflow remain independent.

Earlier upstream compatibility

bfc60cf merges main 70564ae while retaining normal submission batching and the diagnostics-specific CI step. Both strict workspace Clippy configurations and the asset policy passed. The matched synthetic census-on/off fixture passed on AMD Radeon Graphics and WARP with full GPU-based validation in a composition with the independent startup-probe sampler-heap correction fcf3f3e. It produced identical ALU, mesh and indirect outputs and one native submission in all four runs. The startup probe change is outside this PR. The workspace shader failures observed on that base also reproduced with stock lowering. Upstream fixed the CI adapter selection in ccfb029.

The exact historical #595 7465030 recording-ownership control is available separately at 6e79490. A contemporary #595 integration requires resolving the changes in main's submission implementation.

For the pathological mesh report in #71, use census windows for pipeline identity, group demand, execution spans and CPU pipeline build cost. #1723 provides primitive and pixel-invocation counters through the separate legacy timing path. Match builds, scene windows and instrumentation settings and use submission-level timing for quantitative comparisons.

AI-assisted with OpenAI Codex.

@fromthemoonx

Copy link
Copy Markdown

Tested 99a24ec merged onto current main (ffe310e; merges cleanly, auto-merges in host.rs and pipeline.rs). This is the desktop-NVIDIA data point for the synthetic fixture.

Environment: Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1 x86_64-pc-windows-msvc. Agility SDK runtime from the Microsoft.Direct3D.D3D12 1.620.2 package (D3D12Core.dll 1.620.2.0, Microsoft-signed), SDK dxc.exe 10.0.26100, Graphics Tools installed.

census_gpu_smoke (VICTORY_CENSUS_TEST_ADAPTER=nvidia, debug layer and full GBV as the test sets them):

variant result outputs spans
single record, VICTORY_GPU_CENSUS=1 + VICTORY_GPU_TIMING=1 pass, 1 submission …[8..10]=1,1 … [16..18]=1,1 direct 2720/5120 ns, indirect 2048/28672, mesh 3072
MULTI_INDIRECT=1 (limit 3, count 2), census + timing pass, 1 submission [8..13]=1,1,1,1,1, [16..19]=1,1,1 direct 3072/5120, indirect 24576/19456, mesh 3072
ZERO_INDIRECT=1 (count 0), census + timing pass, 1 submission counted region [16..] all 0 direct 3520/4096, indirect 2048/14336, mesh 4096
MULTI_INDIRECT=1, census and timing off (control) pass same outputs as the profiled run n/a

So on Ampere, as on your RTX 5070 Laptop and WARP, the counted call writes nothing with a zero count and stops at the GPU count otherwise. The AMD result in the description (first record written even with count 0) doesn't reproduce here, which fits a driver issue on that adapter. Profiling on or off doesn't change the outputs, and census plus timing still makes one submission.

CI's commands, on the merge: both clippy runs (-D warnings, with and without --all-features) clean; cargo test --workspace --locked: 342 passed, 0 failed, 6 ignored, the same as main.

One note on coverage. mod census is #[cfg(all(windows, feature = "diagnostics"))]. CI's test step (cargo test --workspace --locked) runs without features, so summarizes_timed_and_untimed_calls_and_indirect_limits never runs there; only the --all-features clippy compiles it. It passes with --features diagnostics (1 passed, the GPU smoke ignored as intended). If CI should keep it from regressing, the test step would need --features diagnostics (or --all-features) for victory-gpu.

Not tested: title measurements; the AMD case (no AMD GPU here); no game data used.

AI-assisted (Claude Code) ran the checks and drafted this comment.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

@fromthemoonx Thanks for the RTX 3060 control and for catching the test-coverage gap. 9c1c691 updates the branch to ffe310e and adds a Windows CI step that runs the census unit test with diagnostics. That command and both workspace Clippy configurations passed locally. The hardware fixture remains explicitly opt-in. I linked your four-way validation in the description.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

I published the isolated #509/#595 integration against exact #509 and current #595 plus its confirmed-fence guard. It has no #387 or #562 dependency. Query heaps, readback and operation metadata stay with each recording through native completion. Held-fence reset/replay and the standalone semantic smoke passed with full GBV on AMD, RTX 5070 Laptop and WARP. There was no collection while gated, and the standard smoke retained one native submission. Both Clippy configurations and asset policy passed locally. This makes the async integration independently reviewable while preserving this standalone PR's scope.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

I independently recomposed the timestamp ownership work with #595's 7465030 revision, which gives repeated lists their own preludes. The standard one-native-submission smoke and held-fence reset/resubmit passed on AMD and WARP with full GBV. The new #595 repeated-prelude regression also passed on WARP. NVIDIA was absent from DXGI enumeration in this session. The composition is local and the standalone PR remains scoped to the existing census.

AI-assisted using Codex.

@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown
Author

I validated repeated recording ownership against #595 7465030 with a test and reproduction. AMD Radeon Graphics and WARP both passed with the debug layer and full GPU-based validation. The normal smoke still used one native submission. In the gated test, resetting the list while its old recording was pending preserved the original operation identities and readback. With both timing flags enabled, a later batch containing the same recording at both ends counted both executions and suppressed the ambiguous spans. The distinct peer kept its span. #595 issued the same two native calls for that batch, with zero additional census calls. These timings are synthetic GPU spans.

AI-assisted using Codex.

Keep current title capture and pipeline-library diagnostics. Record census spans around the native GPU commands, collect after the original fence, and release the submission lock before capture and reporting.
@aycow

aycow commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

I ran a held-native-fence control against the current census revision bfc60cf with the separate startup probe fix. With both timing flags set, AMD Radeon Graphics and WARP passed with the debug layer and full GPU-based validation. Both recorded zero early samples during the 100 ms host gate, kept one native submission, and returned the expected shader outputs. The wall times were 103.7 and 106.7 ms, while the largest timestamp spans were 13 µs and 3.60 ms respectively. That control puts the gate before the first timestamp. Operations that overlap or contend after a start timestamp can still contribute to the measured span, so operation totals should be read alongside whole-submission timing. The existing async recording-ownership test stays separate while #595 updates its ownership and wait handling for current main.

AI-assisted using Codex.

Update after @wbkepler’s dfac3b4 rebase. The local composition with bfc60cf passes the census smoke and held-fence reset/replay on AMD and WARP with full GPU-based validation. The smoke still uses one native submission. The repeated recording contributes four calls with no spans, and its distinct peer keeps one timed sample. The broader #595 suite has a separate AMD upload-visibility failure, reproduced on dfac3b4 with census disabled. Matched comparison on #595.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. The new head (a940992) merges main again and now merges cleanly. The host.rs conflict from the last triage is gone, and docs/gpu-execution-census.md is now short, as asked.

The census itself is diagnostics-only. It is under cfg(all(windows, feature = "diagnostics")) and opt-in through VICTORY_GPU_CENSUS. Its hooks in draw.rs (State::census, dispatch/mesh/draw/indirect) and pipeline/make.rs (Pending::make) don't change the default build.

The two open questions are still for the maintainer, and only they can settle them:

  • the new step in .github/workflows/ci.yml;
  • census::gpu_tests::census_gpu_smoke (ignored by default), which runs a local dxc.exe through std::process::Command, with the path taken from VICTORY_CENSUS_TEST_DXC.

If either one is unwanted, dropping it (or changing the test to compile its fixture with the repo's own shader path) would leave a diagnostics-only change. CI: passing (check).


Generated by Claude Code

@aycow

aycow commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Merged upstream 42363ab into the PR at 2968f48. The census counts one launched group per nonempty indirect clamp and records its argument count separately. Diagnostics Clippy, the census aggregation test, and all five clamp tests passed. The full-GPU-validation smoke passed on AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP with the existing local FMad startup sampler-heap workaround. The workaround is outside this PR. Each smoke run reported one submission and the expected readback. GitHub reports a clean merge.

Follow-up daebb52 runs the census-specific check before the workspace suite. The previous workflow was stopped by the same gather and wave-32 permute failures seen on upstream 42363ab. Upstream CI

@aycow

aycow commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

@Marvisak The repository guide is now a short enablement and output reference at 06824d2. The PR description holds the reproduction, timing limitations, hardware findings, and matched title measurement instructions. The repository policy test passed locally.

Could you confirm whether the dedicated diagnostics workflow step and the ignored fixture's explicit local dxc.exe invocation are acceptable? The hosted step runs only the census aggregation unit test. The hardware fixture uses a local DXC path when explicitly invoked.

Rebase follow-up 2ea5bcb preserves upstream traced indirect readback and the new native clamp output buffer. The census aggregation test and strict diagnostics Clippy passed. The one-submission native smoke passed on AMD, GeForce RTX 5070 Laptop GPU, and WARP with full GPU-based validation and the separate local startup sampler workaround. The two earlier maintainer decisions remain open.

…cca4

# Conflicts:
#	crates/victory-gpu/src/host.rs
Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…d at every check (the opening video no longer cycles through old frames)

The opening video decodes into a ring of three plane sets in view memory,
which the title writes through another view: the guards never see a write
to them, and the hash that finds the change was taken on the texture's
eighth-frame turn only (HASH_EVERY). A set's use and its turn lined up
about every 24 frames, so two presented frames in three showed video from
up to two seconds before.

Now a texture whose hash finds it changed while its guard saw no write is
hashed at every check from then on, and a guarded texture's first three
checks hash it whatever the turn, so such a texture is found at its second
use (its memory moves from run to run; it cannot be known by address).
Textures that do not change cost three hashes more each, once. The log's
texture line counts the textures found so.

Source: fxceless/victory-fork pull request Marvisak#701 (on an RTX 5070: the planes
uploaded every frame of the video, 12.7 MB and about 4 ms of refresh a
frame; 0 of 318 frames out of order, none doubled). Of the cluster it is
the one that holds: Marvisak#602 hashes again only while the hash keeps finding a
change, which a ring of three defeats (each set is unchanged for two checks
out of three); Marvisak#489 covers linear one-layer R8 textures only; Marvisak#509/Marvisak#456 are
the same as a timed "hot" window. Without a switch: a fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants