mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:50:52 +01:00
[PR #1756] d3d12: finish CompileActivity before checkpointing and retry deferred cache snapshots #1770
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1770
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1756
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/startup-cache-checkpoint-race📝 Commits (2)
de3c463d3d12: finish CompileActivity before checkpointing and retry deferred cache snapshots9050645d3d12: schedule startup cache checkpoints at 30s/priority-1 and yield only to priority-0 waiters📊 Changes
6 files changed (+172 additions, -32 deletions)
View changed files
📝
docs/d3d12_vulkan.md(+3 -2)📝
runtime/shims/d3d12_pipeline_checkpoint.h(+13 -2)📝
runtime/shims/d3d12_pipeline_compile.h(+3 -1)📝
runtime/shims/d3d12_vulkan_device.cpp(+38 -26)📝
runtime/src/pipeline_cache_store.h(+57 -0)📝
runtime/test/pipeline_cache_store_test.cpp(+58 -1)📄 Description
Item ID:
RT-STARTUP-CACHE-CHECKPOINT-RACEClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7160859893
Addresses finding: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157762911 (
LEONIDA_STARTUP_CACHE_CHECKPOINTS=1wrote nothing during a 200 s run reaching world start)Root cause
Two bugs in
runtime/shims/d3d12_vulkan_device.cppprevented startup cache checkpoints from saving during active world-start compilation bursts:maybe_checkpoint(cache)ran whileCompileActivitystill helddevice_.active_compiles >= 1: bothPipelineState::build_compute()(lines 8038, 8091) andPipelineState::build()(lines 8202, 8386) keptCompileActivity activity(device_.active_compiles)alive acrossmaybe_checkpoint(cache). When the build ran on a submitting orPipelineWorkersthread, thePipelineCompilerworker woke up before the caller returned, sawactive_compiles != 0, and skippedsave_session_pipeline_cache().active_compiles != 0orhas_compile_waiter()(either beforesave_session_pipeline_cache()at line 8110 or after the size query at line 1348),maybe_checkpoint()unconditionally pushednext_checkpointout by another 120,000 ms (2 minutes). A single deferral att = 120 spushed the next attempt tot = 240 s— past the world-start crash at~195–200 s, leaving the cache directory empty.Changes
runtime/src/pipeline_cache_store.h:CheckpointOutcome(saved,deferred,skipped) and portable atomicCheckpointSchedule(try_claim,complete,abort_claim). Deferred checkpoints and queue-submission aborts stay immediately eligible on the next compile completion instead of burningdefault_checkpoint_interval_ms(120 s);savedandskipped(empty/over-cap/I/O error) advance the deadline by the full interval with saturation below thein_flightsentinel.runtime/shims/d3d12_pipeline_checkpoint.h:CompileActivity::finish()(withacq_relordering) so callers can release their active-compile count before queueing a checkpoint while keeping RAII cleanup on early returns.runtime/shims/d3d12_vulkan_device.cpp:next_checkpointatomic withCheckpointSchedule checkpoint_schedule.build_compute(), publishpipeline_.pipeline, unlockvariants_mutex_, and callactivity.finish()beforemaybe_checkpoint(cache); inbuild(), callactivity.finish()beforemaybe_checkpoint(cache).save_session_pipeline_cache()to returnCheckpointOutcome(returningdeferredifactive_compilesorhas_compile_waiter()became active during the size query) and wiredmaybe_checkpoint()tocheckpoint_schedule.complete(..., outcome).runtime/test/pipeline_cache_store_test.cpp:test_checkpoint_schedule()covering due-time gating, in-flight coalescing, deferred immediate retry,abort_claim, saved/skipped 120 s cooldown, and near-UINT64_MAXsaturation.Verification
clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=address,undefined runtime/test/pipeline_cache_store_test.cpp: PASS.clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/pipeline_cache_store_test.cpp: PASS.python3 -I scripts/check_no_game_data.py runtime/src/pipeline_cache_store.h runtime/shims/d3d12_pipeline_checkpoint.h runtime/shims/d3d12_vulkan_device.cpp runtime/test/pipeline_cache_store_test.cpp: PASS.python3 -I tests/test_text_write_line_endings.py: 3/3 OK.runtime/shims/d3d12_pipeline_checkpoint.handruntime/shims/d3d12_vulkan_device.cppare Windows/Vulkan shims and rely on Windows CI / a retail boot run withLEONIDA_STARTUP_CACHE_CHECKPOINTS=1.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.