Skip to content

gpu: settle reader before readback and serialize Gate tests - #81

Open
Lewandox wants to merge 1 commit into
MiamiGame:mainfrom
Lewandox:gpu/fix-raw-views-test-race
Open

Lewandox wants to merge 1 commit into
MiamiGame:mainfrom
Lewandox:gpu/fix-raw-views-test-race

Conversation

@Lewandox

Copy link
Copy Markdown

What and why

descriptor::host::tests::raw_views_a_submission_in_flight_may_read_stay_until_it_has_run called gpu_caught_up(host) after gate.open() and then asserted on dst.words()[..64]. gpu_caught_up loops on while host.completed() < ticket, which checks the D3D12 GPU fence value (ID3D12Fence::GetCompletedValue). When the GPU finishes reader and advances the fence before gpu_caught_up enters its loop, the loop runs zero times and returns before xtp-gpu-finisher finishes Host::complete write-back into dst, leaving the 0xdead_beef sentinel in title memory (crates/xtp-gpu/src/descriptor/host.rs:6603).

Settling reader (reader.settle()) waits for both the GPU fence and timeline.finish write-back before reading dst.words(), without touching the heap, while completed_until still verifies that host completion returns both retired raw views to the pool.

In addition, the four Gate::close tests in crates/xtp-gpu/src/descriptor/host.rs and reserved_textures_map_and_give_back_their_tiles in crates/xtp-gpu/src/resource/pool.rs held the shared host queue without host::submissions::serial(), unlike host::submissions and draw.rs. Serializing them prevents holding the queue concurrently with tests waiting under the host submission lock.

Fixes part of #54 (raw_views_a_submission_in_flight_may_read_stay_until_it_has_run; other tests tracked in #54 are unchanged).
Depends on: none

Area

xtp-gpu unit tests (descriptor::host, resource::pool, host::submissions doc comment).

Tests

  • cargo xtask pr-check passes on my machine (ran fmt, clippy plain + --all-features, xtask policy, xtask conventions, and repeated xtp-gpu WARP + hardware runs; the 17 inline-ray tests requiring Windows SDK dxc were skipped locally because dxc is not installed on this machine)
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot
  • Ran on a title: no

Measured on Windows 11 Pro build 26300.10075, NVIDIA GeForce RTX 3050 Ti Laptop GPU (driver 32.0.16.2140), rustc 1.100.0 (stable-x86_64-pc-windows-gnu; MSVC link.exe not installed locally):

  • Before fix (main 9b822f5): 30 parallel WARP runs (XTP_TEST_ADAPTER=warp, --test-threads=8, skipping the 17 DXC-only RT tests): 29 passed, 1 failed (run 29) in descriptor::host::tests::raw_views_a_submission_in_flight_may_read_stay_until_it_has_run at crates/xtp-gpu/src/descriptor/host.rs:6603 (assertion left == right failed: the old window, untouched, left: [3735928559, ...] = 0xdead_beef).
  • After fix (WARP): 40 consecutive parallel WARP runs (XTP_TEST_ADAPTER=warp, XTP_REQUIRE_GPU=1, --test-threads=8, skipping DXC-only RT tests): 40/40 passed (604 passed, 0 failed per run).
  • After fix (hardware GPU): 10 consecutive parallel runs on RTX 3050 Ti (XTP_TEST_ADAPTER=hardware, XTP_REQUIRE_GPU=1, --test-threads=8) of all 5 modified tests together with host::submissions::: 10/10 passed (25 passed, 0 failed per run).
  • Static checks: cargo fmt --all --check, cargo clippy -p xtp-gpu --no-deps --all-targets --locked (both plain and --all-features, zero warnings in touched files; Rust 1.100 flags pre-existing untouched fetch_update / texture.rs:937), cargo xtask policy, and cargo xtask conventions (commits, title, and PR body) all passed.
  • Not run locally: the 17 DXC-dependent inline-ray tests (dxc unavailable) and XTP_D3D12_DEBUG=1 (Graphics Tools / d3d12SDKLayers.dll not installed on this machine).

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: Antigravity assisted with investigating the failure, implementing the fix, and running the verification checks; I reviewed and verified every changed line and measurement.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

In raw_views_a_submission_in_flight_may_read_stay_until_it_has_run, gpu_caught_up checks only the D3D12 GPU fence value and returns without draining when the fence has already advanced, racing against xtp-gpu-finisher copying dst back to title memory. Settle reader explicitly before asserting on dst.words(). Also serialize the Gate::close tests in descriptor/host.rs and resource/pool.rs with host::submissions::serial(), matching host::submissions and draw.rs.
@github-actions github-actions Bot added area/gpu touches crates/xtp-gpu size/S 10 to 99 changed lines labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/gpu touches crates/xtp-gpu size/S 10 to 99 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant