Repository navigation
startup: back off the retry for an absent shader cache manifest - #2925
Conversation
The graphics and compute translation paths looked for a missing <key>.txt again once per second per key, each time opening a cache file while holding draw_lock. With many keys that never get a translation, every draw and Dispatch waited on that file I/O. The wait now starts at 1 s after the first miss and doubles up to 32 s; a found manifest resets it. Both paths share x2w_startup::ManifestRetry. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KelboLive
left a comment
There was a problem hiding this comment.
PR #2925 by @JB2WIN — startup: back off the retry for an absent shader cache manifest
What works
- Exponential backoff (1s, 2s, 4s, 8s, 16s, 32s...) dramatically reduces lock contention on draw_lock for keys that never get translated
- ManifestRetry struct cleanly encapsulates the schedule with pending(), due(), missed(), found() — each operation is noexcept
- unsigned shift prevents overflow: manifest_retry_delay_ms(~0u) caps at 32000, not undefined behavior
- Unit test covers boundary cases: large miss counts, wrapping, reset via found()
- Both graphics (d3d12_draw.inl) and compute (d3d12_compute_dispatch.inl) paths are updated in one change
- ManifestRetry is 12 bytes (ULONGLONG + unsigned), same footprint as the replaced fields plus negligible state
Issues
- GetTickCount64 wraps every ~50 days. The due() check (now >= at) handles unsigned wrap correctly, but if the system is up >50 days and at wraps near 0 while now is near MAX, the comparison works by unsigned semantics. Worth documenting this assumption in manifest_retry.h comments
- The watcher (mentioned in docs/startup-runtime.md retry text) also scans for absent manifests. The interaction between watcher retries and ManifestRetry backoff between runs is not documented — confirm they do not double-poll the cache between runs
Recommendations
- Add a TODO or constexpr comment noting the GetTickCount64 wrap period (~50 days) and that unsigned wrap makes the comparison correct by construction
- Add a test case crossing the GetTickCount64 boundary: missed at MAX-1000, found at MAX+1, verify state resets cleanly
Overall
A small, focused PR that addresses a real performance issue. The ManifestRetry struct is well-designed with clean transitions between pending/found states. The test coverage is thorough for the arithmetic. Ready to merge.
KelboLive
left a comment
There was a problem hiding this comment.
PR #2925 by @JB2WIN -- startup: back off the retry for an absent shader cache manifest
What works
- Solid foundational work establishing the 0x100 linear layout in gfx10_layout.h with careful derivation from AMD addrlib
- The linear_mode = 0 constant elegantly extends block_log2() to accept mode 0 without changing the tiled modes switch logic
- supports() check is correct: mode == linear_mode bypasses the block_log2 >= 12 requirement since linear has no tail
- Test infrastructure is excellent -- linear_order_control (expected failure with largest mip first), linear_addrlib (338K element addresses), and the unpadded negative control all add strong coverage
- Documentation accurately restates addrlib's linear mode algorithm in clear, testable terms
Issues
- supports() currently allows block-compressed formats (BC1-BC7) in linear mode via the fallthrough -- BC formats are block-based and don't have linear row semantics; consider gating them out explicitly like 1D does in #2929
- The check script in startup_address_console_check.py builds linear backing bytes from addrlib equations. This is correct but the linear path could break if the hardcoded equations drift from addrlib; a comment linking to the Mesa commit that derives these equations would help
Recommendations
- Good discipline in including the negative control (unpadded rows test) to verify the 256-byte pitch requirement
- Consider adding a TODO or assert in supports() that blocks linear mode for BC formats until explicitly validated against addrlib
Overall
A well-researched, well-tested implementation. The linear layout extension is cleanly separated from tiled modes. Minor concern about BC format handling in linear mode, but the existing refusal behavior is safe. Ready for merge.
R0Y00
left a comment
There was a problem hiding this comment.
Reviewed 36d82780012e6617b5ca9de00400621047abdb8b in a clean integration tree. The shared state resets after finding a manifest and caps repeated-miss delays at 32 s. On Windows 11 26200.9974 I built startup_manifest_retry_check startup_stream_consumer d3d12_xs_shim in Release /O2. Eight CTest entries passed: startup_manifest_retry, startup_shader_cache_key, startup_compute_request_offline, both startup_stream_draw_*, both startup_compute_dispatch_*, and startup_compute_root_srv_dispatch_warp. On WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 the stream fixture's first draw stayed clear and the same guest pipeline drew pixels after publishing the manifest. The compute entries matched 320 words. Required Windows CI passed.
What
The graphics and compute translation paths of the D3D12 stand-in look for an absent shader cache manifest (
<key>.txt) again on a later draw or Dispatch, so a translation published byrun.ps1 -Translateduring the run is picked up. Until now each absent key was looked up again once per second, and each lookup opens a cache file whiledraw_lockis held, the lock that every draw and Dispatch takes.This change makes the retry back off: 1 s after the first miss, doubling with each further miss up to 32 s, reset when the manifest is found. Both paths share
x2w_startup::ManifestRetry(src/startup_stubs/manifest_retry.h). Every place that used the oldretry_manifest_atkeeps its meaning (pending()is the old!= 0, so the first-miss log,translation_missingandpreviously_missingare unchanged).Why
In a local title run with a cache that holds requests for ~850 compute keys, ~630 of them without a translation, a stack-sampling probe of the list-recording threads showed most stand-in time in
record_translated_dispatch→load_compute_translation→read_textand in waiting fordraw_lock. An independent read-only diagnosis from symptom only reached the same cause.How tested
Build:
cmake --preset release,cmake --build out\build\release(0 errors).startup_manifest_retryis new. Withoutmanifest_retry.hit fails to compile (C1083). It checks the delays (1, 2, 4, 8, 16, 32, 32 s, no shift overflow), that a found manifest resets the schedule, and that one key that never appears is looked up 23 times in ten minutes instead of ~600.Local title runs (not reproducible from the repository; same cache, same switches, 240 s, input at 60 s, one run each, NVIDIA GeForce RTX 3080 driver 32.0.16.2124, Windows 11 build 26200, no debug layer):
On a stack with more translated draws the same change took the scene from ~0.4 fps to ~7.8 fps (measured with a fixed 60 s retry probe, not with this exact schedule).
Limits
draw_lock; it is only rarer. Moving the file I/O out of the lock would be a larger change.AI-assisted.
🤖 Generated with Claude Code