[PR #1957] [MERGED] runtime: work-aware timeout clock for console command-list value waits #1964

Closed
opened 2026-11-26 21:19:33 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1957
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: fix/rt-list-value-wait-work-aware-timeout


📝 Commits (2)

  • ec95c3c runtime: pause list value wait timeouts while submitted or held work can still satisfy them
  • 9520db5 runtime: cap all list-value wait pauses, scale demoted caps, and test Pump

📊 Changes

5 files changed (+814 additions, -33 deletions)

View changed files

📝 runtime/CMakeLists.txt (+2 -0)
📝 runtime/shims/d3d12_xs_list_values.h (+134 -33)
➕ runtime/src/list_value_wait_budget.h (+251 -0)
➕ runtime/test/list_value_wait_budget_test.cpp (+348 -0)
📝 runtime/test/xs_proxy_mock_test.cpp (+79 -0)

📄 Description

Claim: RT-LIST-VALUE-WAIT-WORK-AWARE-TIMEOUT (claim comment #7168326837 on #1608, taking @DadaCap's world-phase finding #7167966834).

Problem

In retail world-phase testing (#1608 #7167966834), the default 200 ms wall-clock timeout in runtime/shims/d3d12_xs_list_values.h (which demotes to 4 ms after 4 timeouts in a row) cuts short all 122 command-list memory waits (0 met) whenever the releaser is busy running multi-second held work or an in-flight producer write has not yet finished on the GPU. That lets dependent queues run out of order and turns lit world frames into silhouettes/black frames, whereas raising LEONIDA_VALUE_WAIT_TIMEOUT_MS=30000 let 68–82 waits be met and produced lit buildings, windows, interiors, trees, and lamp glow.

Fix

Extract a portable, sanitizer-verifiable timeout & producer dependency policy into runtime/src/list_value_wait_budget.h and wire it into rt::d3d12_xs::list_values::Pump (runtime/shims/d3d12_xs_list_values.h):

  1. Work-aware pausable timeout clock (GateTimeoutState): tracks idle elapsed_us separately from paused time instead of comparing wall-clock now >= deadline, with finite pause caps scaled to the gate's own timeout budget (default_pause_caps(gate_ms, cut_short)):
    • PauseReason::releaser_busy: pauses while writes just landed, gates are opening in this pass, or the releaser thread still has queued/active Signal() releases (pending_releases_ atomic counter with RAII PendingReleaseGuard), bounded by max_pause_cap_us.
    • PauseReason::matching_producer: pauses while an in-flight WriteGroup has a final write (overwrite-aware back-to-front scan, including timestamp writes) that can satisfy an unmet wait of the gate, provided every pending gate <= after_gate on the producer's queue is cycle-free with respect to the waiting queue, bounded by max_pause_cap_us.
    • PauseReason::active_work: pauses while unrelated unblocked GPU work (an unblocked WriteGroup or unblocked action gate on another queue) is still executing, bounded by active_pause_cap_us (and sharing total_paused_us <= max_pause_cap_us).
    • Finite caps & demoted-gate scaling (default_pause_caps(gate_ms, cut_short)):
      • Normal gates: active_us = 300x (60 s at 200 ms) and max_us = 1500x (300 s / 5 min at 200 ms, capped at 10 min) — covers multi-minute world-phase pipeline builds while guaranteeing a finite exit if a producer is held behind an untracked dependency (e.g. a title fence wait or stuck Signal()).
      • Demoted (cut_short) gates: active_us = 1x (4 ms) and max_us = 4x (16 ms) of the gate's short 4 ms budget, so unmodelled waits pay only a few milliseconds rather than inheriting the full timeout's cap.
    • PauseReason::none: ticks normally once no submitted or held work can still satisfy the gate (or when a direct/indirect multi-queue cycle is detected).
  2. Lazily built dependency snapshot in take_open(): only constructs the flat PendingWriteGroup / PendingGate view when a non-forced front memory gate is still unmet and !releaser_busy.
  3. Minor consistency fixes in Pump:
    • add_writes() records after_gate = max_pending_gate_locked(queue.get()).
    • watch_late() watches cut-short waits for now + full rather than the stale gate.since + full (which could already be expired after a long pause).
    • note_outcome() guards gate.waits.front() with !gate.waits.empty().

Overlap notes

  • Independent of #1944 (watch_releaser, untouched) and #1868 (only 2 lines inside add_writes record after_gate, and the xs_proxy_mock_test.cpp addition is at section 11 right before stop_list_values).

Verification

  • AI-assisted: yes (Antigravity agent by Google DeepMind).
  • GPUs tested: none locally (host is macOS arm64; no retail files). Independent Windows/GPU verification reported below by @DadaCap (RTX 5080 retail world phase) and @kawaii-shakal (RTX 5070 Ti Blackwell full CTest 424/424 on earlier head ec95c3c0b).
  • Added portable CTest target list_value_wait_budget (runtime/test/list_value_wait_budget_test.cpp, 11 test groups including finite max_pause_cap_us, demoted-gate cap scaling, alternating pause reasons, and a 1 ms mock-Pump tick driver).
  • Added real-Pump regression tests in runtime/test/xs_proxy_mock_test.cpp (section 11a–d: matching producer pause, busy releaser pause, demoted gate cap under unrelated active work, and finite cap on a stuck matching producer).
  • Ran list_value_wait_budget_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror
  • Executed the real rt::d3d12_xs::list_values::Pump (runtime/shims/d3d12_xs_list_values.h) directly under a scratch POSIX-backed Win32 harness running all four scenarios (11a–d) under ASan+UBSan and TSan (4/4 passed, 0 warnings/races), and confirmed the same test fails against main's d3d12_xs_list_values.h (times out at 40 ms while the matching producer is in flight).
  • Ran python3 -I scripts/check_no_game_data.py on all 5 changed files and python3 -I tests/test_text_write_line_endings.py: all passed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1957 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/rt-list-value-wait-work-aware-timeout` --- ### 📝 Commits (2) - [`ec95c3c`](https://github.com/ubiquitarianism/leonida/commit/ec95c3c0b451ae10e84da2f9f0150aec5a7ee56f) runtime: pause list value wait timeouts while submitted or held work can still satisfy them - [`9520db5`](https://github.com/ubiquitarianism/leonida/commit/9520db518779080a5a7a9a1b7cc1d4c42fe3b41a) runtime: cap all list-value wait pauses, scale demoted caps, and test Pump ### 📊 Changes **5 files changed** (+814 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+2 -0) 📝 `runtime/shims/d3d12_xs_list_values.h` (+134 -33) ➕ `runtime/src/list_value_wait_budget.h` (+251 -0) ➕ `runtime/test/list_value_wait_budget_test.cpp` (+348 -0) 📝 `runtime/test/xs_proxy_mock_test.cpp` (+79 -0) </details> ### 📄 Description Claim: `RT-LIST-VALUE-WAIT-WORK-AWARE-TIMEOUT` (claim comment `#7168326837` on #1608, taking @DadaCap's world-phase finding `#7167966834`). ### Problem In retail world-phase testing (#1608 `#7167966834`), the default 200 ms wall-clock timeout in `runtime/shims/d3d12_xs_list_values.h` (which demotes to 4 ms after 4 timeouts in a row) cuts short all 122 command-list memory waits (`0 met`) whenever the releaser is busy running multi-second held work or an in-flight producer write has not yet finished on the GPU. That lets dependent queues run out of order and turns lit world frames into silhouettes/black frames, whereas raising `LEONIDA_VALUE_WAIT_TIMEOUT_MS=30000` let 68–82 waits be met and produced lit buildings, windows, interiors, trees, and lamp glow. ### Fix Extract a portable, sanitizer-verifiable timeout & producer dependency policy into `runtime/src/list_value_wait_budget.h` and wire it into `rt::d3d12_xs::list_values::Pump` (`runtime/shims/d3d12_xs_list_values.h`): 1. **Work-aware pausable timeout clock (`GateTimeoutState`)**: tracks idle `elapsed_us` separately from paused time instead of comparing wall-clock `now >= deadline`, with finite pause caps scaled to the gate's own timeout budget (`default_pause_caps(gate_ms, cut_short)`): - **`PauseReason::releaser_busy`**: pauses while writes just landed, gates are opening in this pass, or the releaser thread still has queued/active `Signal()` releases (`pending_releases_` atomic counter with RAII `PendingReleaseGuard`), bounded by `max_pause_cap_us`. - **`PauseReason::matching_producer`**: pauses while an in-flight `WriteGroup` has a final write (overwrite-aware back-to-front scan, including timestamp writes) that can satisfy an unmet wait of the gate, **provided** every pending gate `<= after_gate` on the producer's queue is cycle-free with respect to the waiting queue, bounded by `max_pause_cap_us`. - **`PauseReason::active_work`**: pauses while unrelated unblocked GPU work (an unblocked `WriteGroup` or unblocked action gate on another queue) is still executing, bounded by `active_pause_cap_us` (and sharing `total_paused_us <= max_pause_cap_us`). - **Finite caps & demoted-gate scaling (`default_pause_caps(gate_ms, cut_short)`)**: - Normal gates: `active_us = 300x` (`60 s` at `200 ms`) and `max_us = 1500x` (`300 s` / 5 min at `200 ms`, capped at 10 min) — covers multi-minute world-phase pipeline builds while guaranteeing a finite exit if a producer is held behind an untracked dependency (e.g. a title fence wait or stuck `Signal()`). - Demoted (`cut_short`) gates: `active_us = 1x` (`4 ms`) and `max_us = 4x` (`16 ms`) of the gate's short 4 ms budget, so unmodelled waits pay only a few milliseconds rather than inheriting the full timeout's cap. - **`PauseReason::none`**: ticks normally once no submitted or held work can still satisfy the gate (or when a direct/indirect multi-queue cycle is detected). 2. **Lazily built dependency snapshot in `take_open()`**: only constructs the flat `PendingWriteGroup` / `PendingGate` view when a non-forced front memory gate is still unmet and `!releaser_busy`. 3. **Minor consistency fixes in `Pump`**: - `add_writes()` records `after_gate = max_pending_gate_locked(queue.get())`. - `watch_late()` watches cut-short waits for `now + full` rather than the stale `gate.since + full` (which could already be expired after a long pause). - `note_outcome()` guards `gate.waits.front()` with `!gate.waits.empty()`. ### Overlap notes - Independent of #1944 (`watch_releaser`, untouched) and #1868 (only 2 lines inside `add_writes` record `after_gate`, and the `xs_proxy_mock_test.cpp` addition is at section 11 right before `stop_list_values`). ### Verification - **AI-assisted**: yes (Antigravity agent by Google DeepMind). - **GPUs tested**: none locally (host is macOS arm64; no retail files). Independent Windows/GPU verification reported below by @DadaCap (RTX 5080 retail world phase) and @kawaii-shakal (RTX 5070 Ti Blackwell full CTest 424/424 on earlier head `ec95c3c0b`). - Added portable CTest target `list_value_wait_budget` (`runtime/test/list_value_wait_budget_test.cpp`, 11 test groups including finite `max_pause_cap_us`, demoted-gate cap scaling, alternating pause reasons, and a 1 ms mock-`Pump` tick driver). - Added real-`Pump` regression tests in `runtime/test/xs_proxy_mock_test.cpp` (section 11a–d: matching producer pause, busy releaser pause, demoted gate cap under unrelated active work, and finite cap on a stuck matching producer). - Ran `list_value_wait_budget_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror` - Executed the real `rt::d3d12_xs::list_values::Pump` (`runtime/shims/d3d12_xs_list_values.h`) directly under a scratch POSIX-backed Win32 harness running all four scenarios (11a–d) under ASan+UBSan and TSan (4/4 passed, 0 warnings/races), and confirmed the same test fails against `main`'s `d3d12_xs_list_values.h` (times out at 40 ms while the matching producer is in flight). - Ran `python3 -I scripts/check_no_game_data.py` on all 5 changed files and `python3 -I tests/test_text_write_line_endings.py`: all passed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:33 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1964
No description provided.