xbox_present: the first HDR10 present wakes the SDR white reader at once (RT-DISPLAY-WHITE-WORKER-WAKE) #2503
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2503
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-display-white-worker-wake"
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 successfully merged and closed
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()setwhite_wanted_and calledworker_wake_.notify_all()so that the level would be read at once. But the worker waited withwait_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(newruntime/src/display_white_cache.h), so the wake-up can be tested without a window or a GPU:get()sets aread_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 whenget()comes before the wait has begun.XboxPresentationholds 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:get(), the firstget()is read within 2 s, and the value is cached. Laterget()s do not read again before the period ends.get()right after construction are each read.With the wait's predicate put back to
stop_alone (main's behaviour), the test fails:With the change it passes, 3 of 3 runs.
ctest -R "display_white|present|dxgi_swapchain": 13 of 14 pass. The failure isxbox_present, which fails the same way onmainon 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code
Independently checked head
0db8ddb8con Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK1.4.363.0, no game files.Local build & dual-GPU verification:
display_white_cache_testandxbox_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):25.10.30.02):xbox_present_test: all cases pass(exit 0, 0 validation errors).616.64): SDR white-level queries and all HDR10 compose cases passed (0 validation errors); hit the same unrelated swapchain-resize failure atline 1304seen on#2508.Code review notes:
runtime/src/display_white_cache.his clean with no missed-wakeup window (get()setsread_now_undermutex_and notifies; the worker holdsmutex_untilwait_forwith predicatestop_ || read_now_;thread_is declared last and joined in the destructor after settingstop_).XboxPresentation(display_white_created last andreset()first in~XboxPresentation) ensures the worker never outlivespresenter_, and a failed read (0) preserves the last good white level.Looks clean and ready. AI-assisted.
#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.habsent (C1083), and restoringmain's stop-onlywait_forpredicate (return stop_;) failsdisplay_white_cache_test(FAIL: the first get() wakes the worker to read now) | green on PR+main:display_white_cacheCTest passes (39/40stress runs pass; note: indisplay_white_cache.h:42-67,get()runswanted_.exchange(true)outsidemutex_before settingread_now_ = trueundermutex_, so ifrun()checkswanted_.load()while holdingmutex_in between, it performs the first read whileget()setsread_now_ = true, causingwait_forto fire a second immediate read and transiently hitreads() == 2in the startup loop — settingwanted_undermutex_alongsideread_now_closes that window);xbox_present_testSDR-white/compose checks pass on RTX 3090 with0Khronos validation errors (SDR monitor hits pre-existingVkResult -11on forced HDR10 swapchain recreate);check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesReviewed
0db8ddb8cand verifieddisplay_white_cache_testandgta6rtbuild.Code audit:
runtime/src/display_white_cache.h: cleanly extractsDisplayWhiteCachewith aread_now_flag guarded bymutex_so the first HDR10get()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 toleonida::DisplayWhiteCache.Verification (Windows 11, MSVC 19.44, Ninja Release):
display_white_cache_testandgta6rt.ctest -R '^display_white_cache$': 1/1 passed.python -I scripts/check_no_game_data.py: passed.AI-assisted (Antigravity, Gemini).
Run on PR head
0db8ddb8c(base39f52f39c), checked against main1bc055e6c(and origin/mainc7753ed98):git merge-tree --write-treefinds 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.hback tostop_alone (main's behaviour), rebuilt the same target, same ctest -> failed (5.00 s):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_testandgameinput_host_testbuild, andctest -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.
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.exestill links) and a re-check here: no conflict withmainc9f2e41f6, same head as run,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.