Skip to content

startup: back off the retry for an absent shader cache manifest - #2925

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
JB2WIN:startup/compute-manifest-retry
Nov 27, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
JB2WIN:startup/compute-manifest-retry

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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 by run.ps1 -Translate during the run is picked up. Until now each absent key was looked up again once per second, and each lookup opens a cache file while draw_lock is 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 old retry_manifest_at keeps its meaning (pending() is the old != 0, so the first-miss log, translation_missing and previously_missing are 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_text and in waiting for draw_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).

ctest --test-dir out\build\release --no-tests=error -R "^startup_manifest_retry$|desktop_root_signature|startup_compute_dispatch_array_warp|startup_compute_translate|startup_shader_cache_key"
100% tests passed, 0 tests failed out of 9

startup_manifest_retry is new. Without manifest_retry.h it 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):

main 6ee878d this branch
frames presented from 105 s to the end of the run 682 in ~127 s (~5.4 fps) 897 in ~132 s (~6.8 fps)
time per Dispatch (list slot 14) in the last 5 s report 59 µs 23 µs
time per ExecuteIndirect (list slot 61) 28 µs 16 µs
compute Dispatch calls handled in the run 1,227,316 1,780,307
device removed no no

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

  • The unit test covers the schedule, not the two call sites; the call sites were checked by review and by the runs above.
  • A translation published during a run is now used up to 32 s after it appears instead of up to 1 s.
  • The lookup still happens under draw_lock; it is only rarer. Moving the file I/O out of the lock would be a larger change.
  • Single runs; frame rates vary between runs.

AI-assisted.

🤖 Generated with Claude Code

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 KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@R0Y00
R0Y00 merged commit 6aa5944 into R0Y00:main Nov 27, 2026
5 checks passed
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.

3 participants