xbox_present: the first HDR10 present wakes the SDR white reader at once (RT-DISPLAY-WHITE-WORKER-WAKE) #2503

Merged
Tyrannys merged 1 commit from upstream-pr/2503 into main 2026-11-29 01:04:08 +00:00
Tyrannys commented 2026-11-27 21:15:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T21:15:07Z.


Claimed in the coordination issue as: RT-DISPLAY-WHITE-WORKER-WAKE (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7228273864). It comes from @djrolfes' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226719337). Thanks for the precise report. This is an independent implementation; djrolfes' local fix was not shared, so the test here is new.

Depends on: none.

What and why

XboxPresentation::display_white_worker() (runtime/shims/xbox_present.cpp) reads Windows' SDR white level off the present path, about once a second while an HDR10 swapchain is in use. On the first HDR10 present, effective_sdr_white_nits() set white_wanted_ and called worker_wake_.notify_all() so that the level would be read at once. But the worker waited with wait_for(lock, 1s, [this] { return worker_stop_; }). A notify only ends a wait whose predicate is true, so it ended nothing, and the first read came when the second ran out. A request sent before the worker reached its wait would have been lost the same way. Until the first read lands, PresentX composes SDR planes at the 203-nit default.

The worker moves into a small class, leonida::DisplayWhiteCache (new runtime/src/display_white_cache.h), so the wake-up can be tested without a window or a GPU:

  • The first get() sets a read_now_ flag under the lock together with the notify, and the wait's predicate checks that flag. The first read therefore happens at once, also when get() comes before the wait has begun.
  • After that, reads continue once a period. A failed read (0) keeps the last good value, as before.
  • XboxPresentation holds one. It is made at the end of the constructor and reset first in the destructor, where the thread used to be started and joined. effective_sdr_white_nits() keeps its behaviour: the override first, then 203 without HDR10, then the cached value or 203.

Tested

New CPU test display_white_cache (runtime/test/display_white_cache_test.cpp; no window, no GPU, no game data). It covers:

  • With a one-hour period, nothing is read before the first get(), the first get() is read within 2 s, and the value is cached. Later get()s do not read again before the period ends.
  • 50 runs of get() right after construction are each read.
  • With a 20 ms period, reads repeat, and a failed read keeps 180 nits.
  • Destruction during a one-hour wait returns at once.

With the wait's predicate put back to stop_ alone (main's behaviour), the test fails:

FAIL: the first get() wakes the worker to read now
FAIL: and the value it read is cached
FAIL: later get()s do not read again before the period

With the change it passes, 3 of 3 runs.

ctest -R "display_white|present|dxgi_swapchain": 13 of 14 pass. The failure is xbox_present, which fails the same way on main on this machine (line 633: xbox.presenter().composed_presents() == composed_before, checked with and without this change).

No game files.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (the new test needs no GPU)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5533186999 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-27T21:15:07Z. --- Claimed in the coordination issue as: RT-DISPLAY-WHITE-WORKER-WAKE (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7228273864). It comes from @djrolfes' finding (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226719337). Thanks for the precise report. This is an independent implementation; djrolfes' local fix was not shared, so the test here is new. Depends on: none. ### What and why `XboxPresentation::display_white_worker()` (`runtime/shims/xbox_present.cpp`) reads Windows' SDR white level off the present path, about once a second while an HDR10 swapchain is in use. On the first HDR10 present, `effective_sdr_white_nits()` set `white_wanted_` and called `worker_wake_.notify_all()` so that the level would be read at once. But the worker waited with `wait_for(lock, 1s, [this] { return worker_stop_; })`. A notify only ends a wait whose predicate is true, so it ended nothing, and the first read came when the second ran out. A request sent before the worker reached its wait would have been lost the same way. Until the first read lands, PresentX composes SDR planes at the 203-nit default. The worker moves into a small class, `leonida::DisplayWhiteCache` (new `runtime/src/display_white_cache.h`), so the wake-up can be tested without a window or a GPU: - The first `get()` sets a `read_now_` flag under the lock together with the notify, and the wait's predicate checks that flag. The first read therefore happens at once, also when `get()` comes before the wait has begun. - After that, reads continue once a period. A failed read (0) keeps the last good value, as before. - `XboxPresentation` holds one. It is made at the end of the constructor and reset first in the destructor, where the thread used to be started and joined. `effective_sdr_white_nits()` keeps its behaviour: the override first, then 203 without HDR10, then the cached value or 203. ### Tested New CPU test `display_white_cache` (`runtime/test/display_white_cache_test.cpp`; no window, no GPU, no game data). It covers: - With a one-hour period, nothing is read before the first `get()`, the first `get()` is read within 2 s, and the value is cached. Later `get()`s do not read again before the period ends. - 50 runs of `get()` right after construction are each read. - With a 20 ms period, reads repeat, and a failed read keeps 180 nits. - Destruction during a one-hour wait returns at once. With the wait's predicate put back to `stop_` alone (main's behaviour), the test fails: ``` FAIL: the first get() wakes the worker to read now FAIL: and the value it read is cached FAIL: later get()s do not read again before the period ``` With the change it passes, 3 of 3 runs. `ctest -R "display_white|present|dxgi_swapchain"`: 13 of 14 pass. The failure is `xbox_present`, which fails the same way on `main` on this machine (`line 633: xbox.presenter().composed_presents() == composed_before`, checked with and without this change). No game files. GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (the new test needs no GPU) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timbot103 commented 2026-11-28 00:53:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T00:53:31Z.


Independently checked head 0db8ddb8c on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, no game files.

Local build & dual-GPU verification:

  • Clean MSVC build of display_white_cache_test and xbox_present_test (zero warnings in PR files).
  • display_white_cache_test: 5/5 consecutive stress runs PASS (display_white_cache_test: PASS).
  • xbox_present_test (LEONIDA_PRESENT_PLANE1=0, LEONIDA_VK_VALIDATION=1):
    • AMD Radeon(TM) Graphics (25.10.30.02): xbox_present_test: all cases pass (exit 0, 0 validation errors).
    • NVIDIA GeForce RTX 5080 (616.64): SDR white-level queries and all HDR10 compose cases passed (0 validation errors); hit the same unrelated swapchain-resize failure at line 1304 seen on #2508.

Code review notes:

  • Wake/shutdown synchronization in runtime/src/display_white_cache.h is clean with no missed-wakeup window (get() sets read_now_ under mutex_ and notifies; the worker holds mutex_ until wait_for with predicate stop_ || read_now_; thread_ is declared last and joined in the destructor after setting stop_).
  • Lifecycle ordering in XboxPresentation (display_white_ created last and reset() first in ~XboxPresentation) ensures the worker never outlives presenter_, and a failed read (0) preserves the last good white level.

Looks clean and ready. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231267180 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503#issuecomment-7231267180). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T00:53:31Z. --- Independently checked head `0db8ddb8c` on Windows 11 Pro 26200, MSVC 2022 (`19.44.35230.0`, RelWithDebInfo, Ninja), Vulkan SDK `1.4.363.0`, no game files. **Local build & dual-GPU verification:** - Clean MSVC build of `display_white_cache_test` and `xbox_present_test` (zero warnings in PR files). - `display_white_cache_test`: **5/5 consecutive stress runs PASS** (`display_white_cache_test: PASS`). - `xbox_present_test` (`LEONIDA_PRESENT_PLANE1=0`, `LEONIDA_VK_VALIDATION=1`): - **AMD Radeon(TM) Graphics** (`25.10.30.02`): **`xbox_present_test: all cases pass`** (exit 0, 0 validation errors). - **NVIDIA GeForce RTX 5080** (`616.64`): SDR white-level queries and all HDR10 compose cases **passed** (0 validation errors); hit the same unrelated swapchain-resize failure at `line 1304` seen on `#2508`. **Code review notes:** - Wake/shutdown synchronization in `runtime/src/display_white_cache.h` is clean with no missed-wakeup window (`get()` sets `read_now_` under `mutex_` and notifies; the worker holds `mutex_` until `wait_for` with predicate `stop_ || read_now_`; `thread_` is declared last and joined in the destructor after setting `stop_`). - Lifecycle ordering in `XboxPresentation` (`display_white_` created last and `reset()` first in `~XboxPresentation`) ensures the worker never outlives `presenter_`, and a failed read (`0`) preserves the last good white level. Looks clean and ready. AI-assisted.
zmasi commented 2026-11-28 10:22:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T10:22:43Z.


#2503 | head 0db8ddb8c9 (merged cleanly with main 33db04a701) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^display_white_cache$" --output-on-failure + xbox_present_test (LEONIDA_PRESENT_PLANE1=0, LEONIDA_VK_VALIDATION=1) | red on main: display_white_cache.h absent (C1083), and restoring main's stop-only wait_for predicate (return stop_;) fails display_white_cache_test (FAIL: the first get() wakes the worker to read now) | green on PR+main: display_white_cache CTest passes (39/40 stress runs pass; note: in display_white_cache.h:42-67, get() runs wanted_.exchange(true) outside mutex_ before setting read_now_ = true under mutex_, so if run() checks wanted_.load() while holding mutex_ in between, it performs the first read while get() sets read_now_ = true, causing wait_for to fire a second immediate read and transiently hit reads() == 2 in the startup loop — setting wanted_ under mutex_ alongside read_now_ closes that window); xbox_present_test SDR-white/compose checks pass on RTX 3090 with 0 Khronos validation errors (SDR monitor hits pre-existing VkResult -11 on forced HDR10 swapchain recreate); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237857241 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503#issuecomment-7237857241). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T10:22:43Z. --- #2503 | head 0db8ddb8c97ed06f250999c0afbeb0ca2251daf7 (merged cleanly with main 33db04a7010e81c40a7a6a15624525aa0c4a3a58) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^display_white_cache$" --output-on-failure` + `xbox_present_test` (`LEONIDA_PRESENT_PLANE1=0`, `LEONIDA_VK_VALIDATION=1`) | red on main: `display_white_cache.h` absent (`C1083`), and restoring `main`'s stop-only `wait_for` predicate (`return stop_;`) fails `display_white_cache_test` (`FAIL: the first get() wakes the worker to read now`) | green on PR+main: `display_white_cache` CTest passes (`39/40` stress runs pass; note: in `display_white_cache.h:42-67`, `get()` runs `wanted_.exchange(true)` outside `mutex_` before setting `read_now_ = true` under `mutex_`, so if `run()` checks `wanted_.load()` while holding `mutex_` in between, it performs the first read while `get()` sets `read_now_ = true`, causing `wait_for` to fire a second immediate read and transiently hit `reads() == 2` in the startup loop — setting `wanted_` under `mutex_` alongside `read_now_` closes that window); `xbox_present_test` SDR-white/compose checks pass on RTX 3090 with `0` Khronos validation errors (SDR monitor hits pre-existing `VkResult -11` on forced HDR10 swapchain recreate); `check_no_game_data.py` `0` violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes
lixonik commented 2026-11-28 10:38:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T10:38:12Z.

Review: APPROVED


Reviewed 0db8ddb8c and verified display_white_cache_test and gta6rt build.

Code audit:

  • runtime/src/display_white_cache.h: cleanly extracts DisplayWhiteCache with a read_now_ flag guarded by mutex_ so the first HDR10 get() wakes the background reader immediately without lost-wakeup races, and handles shutdown (stop_) cleanly.
  • runtime/shims/xbox_present.cpp: delegates SDR white-level caching cleanly to leonida::DisplayWhiteCache.

Verification (Windows 11, MSVC 19.44, Ninja Release):

  • Built display_white_cache_test and gta6rt.
  • ctest -R '^display_white_cache$': 1/1 passed.
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6097270415 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503#pullrequestreview-6097270415). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T10:38:12Z. **Review:** APPROVED --- Reviewed `0db8ddb8c` and verified `display_white_cache_test` and `gta6rt` build. Code audit: - `runtime/src/display_white_cache.h`: cleanly extracts `DisplayWhiteCache` with a `read_now_` flag guarded by `mutex_` so the first HDR10 `get()` wakes the background reader immediately without lost-wakeup races, and handles shutdown (`stop_`) cleanly. - `runtime/shims/xbox_present.cpp`: delegates SDR white-level caching cleanly to `leonida::DisplayWhiteCache`. Verification (Windows 11, MSVC 19.44, Ninja Release): - Built `display_white_cache_test` and `gta6rt`. - `ctest -R '^display_white_cache$'`: 1/1 passed. - `python -I scripts/check_no_game_data.py`: passed. AI-assisted (Antigravity, Gemini).
enlight3d commented 2026-11-29 00:46:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:46:21Z.


Run on PR head 0db8ddb8c (base 39f52f39c), checked against main 1bc055e6c (and origin/main c7753ed98): git merge-tree --write-tree finds no conflict with either.

Environment: NVIDIA GeForce RTX 3090 (24 GB), driver 621.40, Windows 11 Pro (build 26300), MSVC 14.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, SDL3 3.4.20 static installed. The new test is CPU only.

Configure (as scripts/build_runtime.ps1 does, own build folder): cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON. Only the test target was built, not the whole runtime: cmake --build runtime/build -j 8 --target display_white_cache_test.

Green (PR head): ctest -R "^display_white_cache$" --output-on-failure -> 1/1 passed (1.03 s).

Red (behavioural): kept the PR's header and test, put the worker's wait predicate in display_white_cache.h back to stop_ alone (main's behaviour), rebuilt the same target, same ctest -> failed (5.00 s):

FAIL: the first get() wakes the worker to read now
FAIL: and the value it read is cached
FAIL: later get()s do not read again before the period

Red (literal revert, header removed, test kept): does not compile (missing display_white_cache.h), so this one is only "the header is missing".

Also checked: with SDL3 installed, gameinput_test and gameinput_host_test build, and ctest -R "^gameinput" passes 3/3.
Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248340001 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503#issuecomment-7248340001). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T00:46:21Z. --- Run on PR head `0db8ddb8c` (base `39f52f39c`), checked against main `1bc055e6c` (and origin/main `c7753ed98`): `git merge-tree --write-tree` finds no conflict with either. Environment: NVIDIA GeForce RTX 3090 (24 GB), driver 621.40, Windows 11 Pro (build 26300), MSVC 14.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, SDL3 3.4.20 static installed. The new test is CPU only. Configure (as scripts/build_runtime.ps1 does, own build folder): `cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON`. Only the test target was built, not the whole runtime: `cmake --build runtime/build -j 8 --target display_white_cache_test`. **Green** (PR head): `ctest -R "^display_white_cache$" --output-on-failure` -> 1/1 passed (1.03 s). **Red** (behavioural): kept the PR's header and test, put the worker's wait predicate in `display_white_cache.h` back to `stop_` alone (main's behaviour), rebuilt the same target, same ctest -> failed (5.00 s): ``` FAIL: the first get() wakes the worker to read now FAIL: and the value it read is cached FAIL: later get()s do not read again before the period ``` Red (literal revert, header removed, test kept): does not compile (missing `display_white_cache.h`), so this one is only "the header is missing". Also checked: with SDL3 installed, `gameinput_test` and `gameinput_host_test` build, and `ctest -R "^gameinput"` passes 3/3. Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
MoonEyes commented 2026-11-29 01:04:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:04:11Z.


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 c9f2e41f6, 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248538089 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2503#issuecomment-7248538089). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T01:04:11Z. --- Merged after **enlight3d** (Thib)'s red/green run ([RUN](https://github.com/ProjectLeonida/mandy/pull/2503#issuecomment-7248340001), 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` c9f2e41f6, 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 in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2503
No description provided.