Skip to content

d3d12_compile_pool_test: submit the demand after the checkpoint's first look (TEST-COMPILE-POOL-LOAD-FLAKE) - #2510

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
Tyrannys:test-compile-pool-load-flake
Nov 29, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
Tyrannys:test-compile-pool-load-flake

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Package TEST-COMPILE-POOL-LOAD-FLAKE. Claim: #1608 (comment). This is a test-only change to runtime/test/d3d12_compile_pool_test.cpp (the test from #2233).

The flake

test_a_checkpoint_sees_a_demand_that_started_during_it checks its first look, EXPECT(!pool.has_compile_waiter()) (line 379 on main), inside the checkpoint job, right after log.start("checkpoint"). The test thread waits on that same log.start (log.wait_started(1)) and then submits the demanded build. On a loaded machine the checkpoint's worker can be preempted between log.start and the look. The demanded build is then already queued or running when the look happens, and the check fails. This was found while verifying #2505: with 16 copies running at once, the check failed in 1 of 64 runs of main's test, and the same check failed in 1 of 48 runs with #2505.

The fix

The job stores its first look in an atomic and opens a gate. The test waits for that gate with Gate::wait_for(10s) (new; no fixed sleep), checks the stored look, and only then submits the demanded build. The rest of the test is unchanged.

Tested

Profile M: RTX 4070 SUPER, Windows 11, Ryzen 7 9800X3D, MSVC RelWithDebInfo. CPU only.

  • 16 copies of d3d12_compile_pool_test.exe at once, 13 rounds:
    • with the fix: 0 of 208 runs failed.
    • main's test: 0 of 208 also failed this time. The race is rare (about 1 in 50 to 60 before), so the run count alone does not prove the fix.
  • Forced race: a temporary sleep_for(200ms) after log.start("checkpoint") stands in for a preempted worker. It is not committed.
    • main's test with it: 3 of 3 runs fail at the first-look check.
    • the fixed test with it: 3 of 3 runs pass.
  • git diff --check and scripts/check_no_game_data.py are clean. No game files used.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…st look (TEST-COMPILE-POOL-LOAD-FLAKE)

test_a_checkpoint_sees_a_demand_that_started_during_it checked its first
look (!has_compile_waiter()) inside the checkpoint job, after log.start.
The test thread woke on that log.start and submitted the demanded build,
so on a loaded machine the build could be queued or running before the
checkpoint's thread reached its first look, and the check failed (seen
1 in 64 runs with 16 copies running at once).

The job now records the first look and opens a gate; the test waits for
that gate (10 s limit, no fixed sleep) before it submits the build, and
checks the recorded look.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timbot103

Copy link
Copy Markdown
Contributor

Reviewed at head db477857f on Windows 11 (MSVC 2022 19.44).

Verification

  • Built d3d12_compile_pool_test.
  • d3d12_compile_pool_test (5 consecutive runs): 5/5 passed.

Notes

  • Adding the looked gate after storing the first has_compile_waiter() result and waiting on it before submitting demand (d3d12_compile_pool_test.cpp:26-58, 372-399) cleanly eliminates the test scheduling race where demand could arrive before the checkpoint took its first look, while preserving the intended two-look production test semantics. (Also confirmed disjoint from #2505's hunks in the same file.)

Approve.

AI-assisted review + local MSVC verification.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2510 | head db47785 (merged cleanly with main 3ca0707) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^d3d12_compile_pool$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: under worker preemption between log.start("checkpoint", false) and !pool.has_compile_waiter() (reproduced deterministically with a 20 ms delay), the demanded build arrives before the checkpoint's first look and fails d3d12_compile_pool_test.cpp (!pool.has_compile_waiter()) | green on PR+main: 1/1 CTest passes (1.74s) plus 20/20 consecutive stress runs on RTX 3090 with LEONIDA_VK_VALIDATION=1 (0 Khronos validation errors); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

@OreoFR

OreoFR commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR

  • Base: main c1ecf04ed + PR head db477857f; green run in a merge package of 11 PRs, no new ctest failure vs main
  • Test: ctest -R "^d3d12_compile_pool$"
  • Red on main: OK
  • Green with the PR: OK
  • Verdict: NO RED (test-only PR: fixes a rare race (1 in 50-60 per the author), not reproduced here)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

@enlight3d

Copy link
Copy Markdown
Contributor

Run of #2510 (d3d12_compile_pool): green at the PR head; the flake is only reproduced by a forced race (a temporary sleep), not by the plain test.

  • PR head: db47785 (base 39f52f3). Current main: 1bc055e. git merge-tree --write-tree main <head> merges cleanly. The test file and runtime/shims/d3d12_pipeline_compile.h are identical on main and at the PR base, so "main's test" below is the base version.
  • GPU/driver: NVIDIA GeForce RTX 3090 24 GB, driver 621.40 (not used by this CPU-only test). OS: Windows 11 Pro 10.0.26300. MSVC 19.44, Ninja, RelWithDebInfo.
  • Only the test target was built, not the whole runtime. The PR is test-only: there is no non-test change to revert.

Commands (in a vcvars64 shell, build folder inside the worktree):

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON -DSDL3_DIR=<installed SDL3 3.4.20 static>/cmake
cmake --build runtime/build --target d3d12_compile_pool_test -j 8
ctest -R "^d3d12_compile_pool$" --output-on-failure

Green (PR head): d3d12_compile_pool Passed (1.7 s); the executable run 20 times in a row: 0 failures. Main's test (base version) without any change: Passed, 20 runs: 0 failures (the race is rare; I did not try to catch it under load).

Red (forced race, as in the description): a temporary std::this_thread::sleep_for(200ms); right after log.start("checkpoint", false); in the test, never committed:

  • main's test (base version) with it: Failed at d3d12_compile_pool_test.cpp:380: !pool.has_compile_waiter() (the first-look check); 3 of 3 executable runs fail.
  • the PR's test with it: Passed; 3 of 3 executable runs pass.
    The red is therefore a simulated one (the sleep stands in for a preempted worker), on the test and not on the runtime.
    Link check: merged into main 1bc055e, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

@MoonEyes
MoonEyes merged commit 5d0a501 into ProjectLeonida:main Nov 29, 2026
8 of 12 checks passed
@MoonEyes

Copy link
Copy Markdown
Collaborator

Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and gta6rt.exe still links) and a re-check here: no conflict with main 7e06a02, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

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.

6 participants