Skip to content

hle/acphal: track cumulative XApu enqueued and dequeued totals - #2041

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1489-xapu-cumulative-counts
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1489-xapu-cumulative-counts

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it

Track cumulative XApu enqueued and dequeued totals separately from the pending result queue length (XCL-BT-043, part of #1489).

Part of #1489

  • Problem: In crates/xcl/src/hle/acphal.rs, XApuEnqueueCommand wrote q.len() as u32 (current pending queue length) into its optional count out-parameter instead of the cumulative total of commands enqueued on the connection, and XApuGetResultCount wrote q.len() as u32 (the same pending queue length it returns) into its optional total out-parameter instead of the cumulative total of results dequeued via XApuDequeueResult. After enqueueing 2 commands and dequeuing 2 results, XApuGetResultCount(h, &mut total) returned 0 with *total = 0 instead of 2, and enqueueing a 3rd command wrote *count = 1 instead of 3.
  • Fix: Wrap the result queue and cumulative wrapping counters (queue: VecDeque<XApuResult>, enqueued: u32, dequeued: u32) in XApuResults under XApu.results: Mutex<XApuResults> so queue mutations and totals update atomically under one lock:
    • XApuEnqueueCommand pushes the result, increments st.enqueued via wrapping_add(1), and writes st.enqueued to *count when non-null.
    • XApuDequeueResult increments st.dequeued via wrapping_add(1) only when pop_front() returns Some(r) (leaving dequeued unchanged on XAPU_NO_RESULTS), releasing the lock before write_unaligned.
    • XApuGetResultCount reads (st.queue.len() as u32, st.dequeued) under the lock, writes dequeued to *total when non-null, and returns pending.
  • Tests: Add xapu_enqueue_and_result_count_report_cumulative_totals and xapu_cumulative_counters_wrap_at_u32_max in crates/xcl/src/hle/acphal.rs covering cumulative counts across enqueue/dequeue cycles, empty dequeues (XAPU_NO_RESULTS), null optional out-parameters / null handle safety, and u32::MAX wraparound.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5 (01b62ad4).
  • Pre-fix failure (unfixed origin/main 656c0e8 with new test added, debug): cargo test -p xcl --lib hle::acphal::tests -- --nocapture -> 7 passed; 1 failed (xapu_enqueue_and_result_count_report_cumulative_totals panicked with left: 2, right: 0 when checking *total after 2 enqueues and 0 dequeues).
  • Post-fix targeted (release, b591ccc7): cargo test --release -p xcl --lib hle::acphal::tests -- --nocapture -> 10 passed; 0 failed; 0 ignored.
  • Full workspace (release, b591ccc7): cargo build --release --workspace + cargo test --release --workspace -- --test-threads=4 --nocapture -> 1104 passed, 0 failed, 46 ignored across 20 test binaries.
  • SKIPPED lines (26 total, all pre-existing on this wave32 Windows host without Graphics Tools / Developer Mode / heap windows):
    • 19 no wave64 skips (4 in gpu::recomp::lower::tests, 13 in gpu::recomp::lower_dxil::tests, 2 in gpu::recomp::tests).
    • 3 pre-existing wave32 per-lane form: refused skips in gpu::recomp::lower_dxil::tests (f16 arithmetic, f16 packed, f32 conversions).
    • 2 D3D12 debug layer skips (test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll; uploads_start_from_each_subresources_state: 0x887A002D).
    • 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable driver cache without Windows Developer Mode.
    • 1 heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.

Regression run

Paired 60 s retail title runs with scripts/smoke.ps1 (release build, same title, clean working tree) on origin/main (8f5fca5b) and this PR (b591ccc7):

main:

xcl-smoke v1
commit: 8f5fca5bb9ad6e695093d75294ad2cec023bba60
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14697 MB

this PR:

xcl-smoke v1
commit: b591ccc73547b072cdf854ebf8e56dfdb0d58b1d
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14676 MB

Not tested

  • AMD / Intel GPUs, wave64 hardware, D3D12 debug layer, heap windows, and Linux/Wine.
  • Whether the retail smoke title inspects the optional *count or *total out-parameters of XApuEnqueueCommand / XApuGetResultCount; the paired smoke run is a regression check only.

AI use

Google Antigravity (Gemini 4 Neon) wrote the fix, unit tests, and this PR description; all builds, tests, and paired retail smoke runs were executed locally on the hardware listed above.

XApuEnqueueCommand previously wrote the current pending queue length into its optional count out-parameter, and XApuGetResultCount wrote the pending queue length into its optional total out-parameter instead of the cumulative dequeued count (XCL-BT-043).

Wrap the result queue with wrapping u32 enqueued and dequeued totals under XApu.results so XApuEnqueueCommand reports cumulative enqueued commands, XApuDequeueResult increments dequeued on S_OK (not XAPU_NO_RESULTS), and XApuGetResultCount returns pending results while writing cumulative dequeued results to *total.

Part of xcl-dev#1489

Assisted-by: Google Antigravity (Gemini 4 Neon)
@raylitebull

Copy link
Copy Markdown
Member

Code review on b591ccc:

  • Introducing XApuResults (queue, enqueued: u32, dequeued: u32) in crates/xcl/src/hle/acphal.rs cleanly separates cumulative enqueue/dequeue counters from the pending queue.len() returned by XApuGetResultCount.
  • XApuEnqueueCommand writes cumulative wrapping_add(1) enqueued, XApuDequeueResult increments dequeued only on Some(r), and XApuGetResultCount returns pending while writing cumulative dequeued to *total.
  • Both unit tests (xapu_enqueue_and_result_count_report_cumulative_totals and xapu_cumulative_counters_wrap_at_u32_max) cover empty dequeue (XAPU_NO_RESULTS), null out-pointers/handles, and u32::MAX wraparound cleanly.
  • PR description is green and Build and test (Windows, no GPU) is running.

Remaining before merge: Build and test finishing green plus dual-vendor (AMD + NVIDIA) verification on b591ccc.

@JJAutoCompare

Copy link
Copy Markdown

PR #2041 verification

Tested live PR head b591ccc73547b072cdf854ebf8e56dfdb0d58b1d from refs/pull/2041/head in a clean detached worktree. Fetched origin/main was cbc296ab65a2661a61e3e2da109134bcd5319f60. git merge-tree --write-tree origin/main HEAD exited 0 and produced tree ef3ee3f8d9a7410d03ecd6af81afe8b01de9a8f5.

What is in it

  • crates/xcl/src/hle/acphal.rs tracks cumulative XApu enqueued and dequeued totals alongside the pending result count. The new tests exercise FIFO order, empty dequeues, optional pointers, and counter wraparound.

Tested

  • STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB driver 32.0.101.9175 (wave range 8–32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5, rustc 1.100.0 (0ef1bc386 2026-11-09). Unoptimized Cargo dev/test profiles with debug info and incremental compilation disabled.
  • cargo build --workspace and cargo test --workspace --no-run succeeded outside the GPU lock.
  • cargo test -p xcl --lib acphal -- --show-output outside the GPU lock reported 10 passed, 0 failed, and 0 ignored. Both new XApu tests also passed in the full suite.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output ran once under the shared Arc lock and exited 101. Across 20 target summaries, libtest reported 1077 passed, 27 failed, 46 ignored. The log also records 26 skip notices across 16 tests, including partial skips that libtest can mark as passed. The skipped paths provide no coverage.
  • The library target had 26 GPU shader failures. The errors included CreateComputePipelineState returning 0x80070057 and mismatches in fused F32 arithmetic, implicit-LOD sampling, an F16 high-half result, and pixel-wave reduction. The e2e target had one failure in test_title_runs_and_game_folder_is_untouched. The RSSetDepthBiasX draw produced a blue pixel where the test expected green.

Skip notices from the full workspace log

SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED shaders::tests::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)
SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
SKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))

Full log L:\XclTooling\neon-slot-5\tmp\pr2041-suite.log.

Not tested

  • The full suite was run on the PR head only. Reproduction of the failures on origin/main is unverified.
  • Retail-title smoke runs on main and the PR head, sample-data paths (XCL_SAMPLE_* unset), and other GPU adapters.

AI use

Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr2041-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tested head b591ccc73547b072cdf854ebf8e56dfdb0d58b1d (merge-base 8f5fca5bb9ad6e695093d75294ad2cec023bba60) on Windows 11 Pro 26100, rustc 1.100.0 MSVC, debug, CPU only (no GPU opened).

cargo test -p xcl --lib acphal:: -- --test-threads=1: head 10 passed, 0 failed, 0 ignored; merge-base 8 passed, 0 failed. The 2 extra on head are xapu_enqueue_and_result_count_report_cumulative_totals and xapu_cumulative_counters_wrap_at_u32_max. The new tests live inline in acphal.rs, so they cannot be run against base code.

Not tested: the full suite, GPU, retail title. AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: b591ccc

@github-actions github-actions Bot added area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 29, 2026
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: b10cc4c
head: b591ccc
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2607 passed, 2 failed, 49 ignored on the merge result with main b10cc4c (27 SKIPPED lines). The two failures are uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom and mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment ("Map gave A, wanted B" for a 64 MB segment): the address-space-hungry tests that #3187 moves into a child process, in a file this PR does not touch. The four other trees of this batch on the same base had 0 failures, so I count them as that known instability and not against this PR.
review: the mechanics are sound (one mutex, wrapping counters, counters per handle so a reconnect starts at zero, and it builds with main's newer audio code). What holds it back is meaning, not code: it changes what a title reads back from two calls, from "results waiting" to "total ever enqueued" and from a count to "total ever dequeued", and the only source for that meaning is a static audit that cites another project's code. Nobody has shown a title's calls (a trace) that need the cumulative meaning, and a title that uses the returned count to decide how many results to take would behave differently. The reviews in the thread checked the mechanics only.
performance: none.
verdict: not yet: one trace of a title's use of these out-parameters (or another first-hand source) that confirms the cumulative meaning.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@github-actions github-actions Bot removed the needs-1st-check Passes gates; needs first independent merge-check (#3041) label Nov 29, 2026
@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check claim
head: b591ccc

@brainhay5

Copy link
Copy Markdown

merge-check claim
head: b591ccc

1 similar comment
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: b591ccc

@coolpersonnn

Copy link
Copy Markdown
Contributor

merge-check
base: ff0c364
head: b591ccc
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored (25 SKIPPED lines: 22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); both new acphal tests passed (xapu_enqueue_and_result_count_report_cumulative_totals, xapu_cumulative_counters_wrap_at_u32_max); failing: two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (gpu_two_pass_cache_e2e.rs:584, releasing the title PSOs releases their two-pass state: left 1, right 0) — fails on the base ff0c364 alone too (1 passed, 3 failed across 4 runs with the same assertion), unrelated to acphal.rs
review: Code mechanics, locking, wrapping arithmetic, null-pointer handling, scope (+119/-13 in crates/xcl/src/hle/acphal.rs), and unit tests are clean and match the PR description; no duplicate PR found in open/merged PRs or #1607. However, agreeing with the earlier check, the behavioral change to the two optional out-parameters (XApuEnqueueCommand's *count from pending queue length to cumulative enqueued total, and XApuGetResultCount's *total from pending queue length to cumulative dequeued total) rests only on a static audit in #1489 (XCL-BT-043) referencing another project's code, with no title trace or first-hand verification confirming those semantics.
performance: Negligible (reasoned): adds two u32 counters (+8 B per XApu handle) and one wrapping_add(1) under the existing results mutex on enqueue/dequeue.
verdict: not yet: needs first-hand confirmation (e.g. a title trace or hardware/runtime evidence) that XApuEnqueueCommand's count and XApuGetResultCount's total out-parameters are cumulative enqueued/dequeued totals rather than pending queue length.
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 621.01 / 32.0.16.2101), AMD Ryzen 9 9950X3D, Windows 11 Pro build 26300, Rust 1.100.0 (debug); T3 Code (Antigravity), Gemini 4 Neon (Medium)

@brainhay5

Copy link
Copy Markdown

merge-check
base: ff0c364
head: b591ccc
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored; 29 SKIPPED lines; failing: test_title_runs_and_game_folder_is_untouched (also fails on the base alone, verified by running it there)
review: automated check: diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no line-by-line review and no duplicate search performed.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@github-actions github-actions Bot added the checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head b591ccc

No open or merged PR makes the same change: the other #1489 PRs touch unrelated code, and the other open XApu PRs (#1715, #1283, #2700) do not change the enqueue/result counters. XApuEnqueueCommand / XApuGetResultCount in hle/acphal.rs on main still report the queue length.
No problems found in the diff. The counters and queue share one lock, and an empty dequeue does not count. The cumulative-total semantics come from XCL-BT-043 (VIctory's apu.rs), not from a console measurement.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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

Labels

area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants