Skip to content

D3D12.X: track exact per-query byte sizes in ResolveQueryData - #3393

Merged
throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/resolve-query-data-sizes
Dec 1, 2026
Merged

throny merged 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/resolve-query-data-sizes

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What is in it

  • Add query_result_bytes(ty: D3D12_QUERY_TYPE) -> u64 in crates/xcl/src/hle/d3d12x/list_x.rs so resolve_query_data_x passes the exact resolved byte range ((count as u64).saturating_mul(query_result_bytes(ty))) to note_copy_into for every D3D12_QUERY_TYPE:
    • D3D12_QUERY_TYPE_SO_STATISTICS_STREAM0..=3: size_of::<D3D12_QUERY_DATA_SO_STATISTICS>() (16 bytes, previously under-reported as 8 bytes).
    • D3D12_QUERY_TYPE_VIDEO_DECODE_STATISTICS: 32 bytes (previously under-reported as 8 bytes).
    • D3D12_QUERY_TYPE_PIPELINE_STATISTICS: size_of::<D3D12_QUERY_DATA_PIPELINE_STATISTICS>() (88 bytes).
    • D3D12_QUERY_TYPE_PIPELINE_STATISTICS1: size_of::<D3D12_QUERY_DATA_PIPELINE_STATISTICS1>() (112 bytes, previously under-reported as 8 bytes).
    • OCCLUSION, BINARY_OCCLUSION, TIMESTAMP, and other 64-bit queries: 8 bytes.
  • Add a #[cfg(test)] helper real::set_test_console_buffer in crates/xcl/src/hle/d3d12x/real.rs (mirroring set_test_buffer_delta) and an isolated unit test resolve_query_data_x_notes_exact_result_bytes_for_all_query_types in crates/xcl/src/hle/d3d12x/list_x.rs verifying the exact recorded write spans in LISTS for all 10 query types.

Tested

  • Verified resolve_query_data_x_notes_exact_result_bytes_for_all_query_types fails before the fix (SO_STATISTICS_STREAM0 with count = 2 recorded 16 bytes instead of 32 bytes).
  • Targeted tests after the fix (cargo test -p xcl --lib -j 4 -- resolve_query_data --nocapture): 2 passed, 0 failed, 0 ignored.
  • Full workspace suite (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: with XCL_DXC_DIR set to DXC 1.9 on RTX 5070 Ti): 41 test binaries, 2662 passed, 0 failed, 49 ignored, 9 filtered out.
  • SKIPPED breakdown (26 total): 21 no wave64 (RTX 5070 Ti is wave32), 3 refused (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32 #1426 semantics), 2 no heap windows (XCL_HEAP_WINDOWS=1 opt-in).

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: d65aa8963719370f639f3774373306d167a73547
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1547 (PresentX 1547)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33958 MB

Not tested

  • Retail titles resolving SO_STATISTICS_STREAM0..3, VIDEO_DECODE_STATISTICS, or PIPELINE_STATISTICS1 into shadowed committed UMA buffers were not run directly; those paths are covered by the synthetic unit test.
  • test_title_runs_and_game_folder_is_untouched, uma_driver::tests::, wave64 GPU tests, and XCL_HEAP_WINDOWS=1 opt-in unit tests were not run in the workspace suite.

AI use

  • Authored, verified, and tested with an AI coding agent; all changes and test results were verified directly against the local repository, compiler, test suite, and 150 s smoke run.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

Reviewed and tested at d65aa896.

Looks clean and accurate — query_result_bytes matches the exact D3D12 query result struct sizes (including SO_STATISTICS_STREAM0..3 at 16 B, VIDEO_DECODE_STATISTICS at 32 B, and PIPELINE_STATISTICS1 at 112 B) with saturating_mul, and the test verifies all 10 query types through resolve_query_data_x.

Tested locally

  • Windows 11 (build 26300), NVIDIA GeForce RTX 4070 SUPER (driver 32.0.16.2140), AMD Ryzen 7 7800X3D, rustc 1.100.0.
  • cargo test -p xcl --lib hle::d3d12x::list_x::tests::resolve_query_data_x_notes_exact_result_bytes -- --test-threads=1: 1 passed, 0 failed.

AI use

  • Antigravity (Gemini 4 Neon) assisted with code review and drafting; all builds and tests were executed locally on the hardware above.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: d65aa89
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (list_x.rs +82/-2, real.rs +15). No change to what a title runs by default: note_copy_into returns early unless a committed window fell back to shadowed mode or view windows exist (XCL_HEAP_WINDOWS=1). The per-type sizes match the D3D12 structures: pipeline statistics 88, PIPELINE_STATISTICS1 112, stream-output statistics 16, video decode statistics 32, occlusion / binary occlusion / timestamp / unknown 8. Main recorded 8 bytes for everything but pipeline statistics, so stream-output, video-decode and PIPELINE_STATISTICS1 resolves were under-reported. The test fails on main (stream 0, count 2: 16 bytes instead of 32). Findings: (1) the new test runs in a child process whose output is dropped when it succeeds, so a "no UMA" skip_test there shows as a plain pass (~11826). (2) AI use names no tool or model ("an AI coding agent"); the PR's suite run skipped uma_driver::tests:: and test_title_runs_and_game_folder_is_untouched (the run above covers them). No smoke run: the default path doesn't reach this code.
performance: no smoke run (the default path doesn't reach this change); not measured.
verdict: safe to merge (the description should name the AI model)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny

throny commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: d65aa89
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; failing: none (25 SKIPPED lines, all GPU tests on this adapter, e.g. no wave64)
review: Read the whole diff (list_x.rs, real.rs test helper). ResolveQueryData now notes the exact result size per query type (pipeline statistics, SO statistics, video decode, pipeline statistics 1) instead of 8 or 88 bytes, with saturating multiplication. The test checks the recorded write span for ten query types against a fake command list vtable (a no-op function replaces the PC call; the flagged code-loading line is that test stub) in a child process. The video decode size 32 is a hard-coded constant, not checked here against the SDK struct; the test would not catch a wrong value as it uses the same number. The real.rs helper is #[cfg(test)].
performance: no cost by default: a match per ResolveQueryData call; the noted span can be larger for pipeline statistics 1 (more tracked bytes), reasoned, not measured.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report (the diff review is Sonnet's)

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny
throny merged commit 99a0451 into xcl-dev:main Dec 1, 2026
3 checks passed
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merged at the checked head after a combined trial of #3400, #3386, #3393 and #3535 on main d0832e61 (RTX 4080 16 GB, cargo test --workspace --no-fail-fast -- --test-threads=4: 2896 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks: Foniass and ours.

AI use: Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants