d3d12_xs: a gate held for a later write opens on the GPU, behind the writer (RT-XS-LATE-RELAY) #2484
Closed
github-bot
wants to merge 1 commit from
github-bot/gh-2484 into main
AGit
pull from: github-bot/gh-2484
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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
github/ubiquitarianism--leonida!2484
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2484"
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?
@j-rally on GitHub · 2026-11-27 17:34 UTC · original
j-rally:rt-xs-late-relay→main· +188 −4 · 6 files · 1 commits · closed without mergingClaimed in the coordination issue as: RT-XS-LATE-RELAY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7224539005). Measurements behind it: #2464 (https://github.com/ubiquitarianism/leonida/issues/2464#issuecomment-7224144108). AI-assisted (Claude Code, Claude Opus 5.5).
What and why
A list value wait (slots 73/74) whose write was submitted after it — the waiter's
ExecuteCommandListscame first, the usual order in the world load here — cannot be relayed at submission, becausePump::relayonly sees writes already in flight. It becomes a gate, and the gate opens only after the writer's part has run on the GPU, the write has landed through the pump, the pump's 1 ms poll has read it back, and the single releaser thread has signalled it (running the held work on the way). On an RTX 4070 Ti SUPER in the world load, every held gate was met by such a later write (1,041 of 1,041 in 300 s, counted by this PR's new counter), and the releaser spent 89.5 s of the 300 s signalling them.LEONIDA_LATE_RELAY=1(off by default) takes those off the CPU. InValueSubmission::flush, right after a queue signals itswrittenfence behind a group of writes,Pump::take_late_relays(writer)returns the first gate still shut on each other queue whose waits are all met in memory or bywriter's writes in flight, and the writer's queue signals that gate's fence to its value next. The waiter's held work is released when that Signal is submitted, and the GPU runs it behind the writer's part, as a relayed wait does today. The write still lands through the pump as before.Invariants kept:
gates_, markedgpu_signalled. It never times out, is never handed to the releaser, and keeps its queue's later gates shut until the gate fence shows its value (take_open). So no CPU Signal of a later value can open it before the writer has run.Also added, always on: the
list valuesline counts the gates a later write meets (and of those, the first shut on their queue), and with the switch, the gates signalled this way and the ones seen open. Exposed throughxs::list_value_stats().Tested
xs_proxy_mockcase 9 (new): the gate of case 2's shape is signalled by the writer's queue right behindSignal(written); the gate stays shut until the GPU reaches it; it goes without a releaser Signal; the write lands. A writer on the waiter's own queue gets no late relay.ctest -R "xs_proxy_mock|list_value_wait_budget": 10/10 pass (Windows, MSVC RelWithDebInfo).tests/test_docs_env_vars.py,test_docs_encoding.py,scripts/check_no_game_data.py: pass.So the CPU round trips behind gates are mostly gone (held time ~14x lower, releaser ~70x), but the frame rate in this phase does not move: something else limits it there (the GPU is still idle about three quarters of the time). That is why it stays opt-in for now; a game run on another GPU, and a longer one, would say whether it should become the default. n=1 per arm.
Not done
🤖 Generated with Claude Code
@lixonik on GitHub · 2026-11-27 21:10 UTC · original · requested changes
Reviewed
020d1dd95and tested on Windows 11 (MSVC 19.44):xs_proxy_mockpassed (2.69 s).The design of
LEONIDA_LATE_RELAYis clear and well-scoped (off by default), but I found three concurrency / edge-case bugs in the new path:pending_releases_(runtime/shims/d3d12_xs_list_values.h:440-441):take_late_relays()checksif (pending_releases_.load(std::memory_order_acquire) != 0) return out;before takingstd::lock_guard lock(mutex_);. Meanwhilepass()pops earlier gates (including action gates) intoopeningand incrementspending_releases_undermutex_(lines 966-970). Ifpass()runs between line 440 and line 441,take_late_relays()enters undermutex_, no longer sees the earlier gate ingates_, treats the following gate on that queue as the first shut gate, and letswritersignal a higher gate value on the GPU before the releaser has run the earlier action. Moving thepending_releases_check insidestd::lock_guard lock(mutex_);closes the window.Signalorforceteardown (runtime/shims/d3d12_xs_device.cpp:3952,runtime/shims/d3d12_xs_list_values.h:897-907):take_late_relays()marksgate.gpu_signalled = truebeforeValueSubmission::flush()callssignal(waiter->gate, gate_value). Ifsignal(...)returnsFAILED, the gate staysgpu_signalled = trueforever, never times out, and permanently blocks all subsequent gates onwaiter. OnFAILED,gpu_signalledshould be cleared (or handed back to the normal gate path).take_open()(d3d12_xs_list_values.h:897-907),if (gate.gpu_signalled)executescontinuebeforebool open = force;. Onforce == true(e.g.,stop()/ teardown after a GPU hang or device loss), agpu_signalledgate whose fence never reachesgate.valueis never drained.writeroverwrites the same address (runtime/shims/d3d12_xs_list_values.h:450-456):take_late_relays()iterateswrites_forward and returnstrueon the first matching write fromwriter. Ifwriterwrites a matching value (e.g.1for== 1) and then overwrites the same address with a non-matching value (e.g.2) in the same or a later in-flightWriteGroup,take_late_relays()still signals the gate after the later write even though the final value atSignaltime does not satisfy the wait. Checking the last in-flight write bywritertowait.address(matchingrelay's semantics) avoids false early signals.AI-assisted (Antigravity, Gemini).
@timbot103 on GitHub · 2026-11-28 00:53 UTC · original
Independently checked head
020d1dd95on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), no game files.Local build & test verification:
xs_proxy_mock_test(zero new warnings ind3d12_xs_device/d3d12_xs_list_valuesbeyond standardC4996 getenv).xs_proxy_mock_test: PASS (12 allocations refused on purpose).Static review findings on
020d1dd95(behind off-by-defaultLEONIDA_LATE_RELAY):Signalfails:take_late_relayssetsgate.gpu_signalled = truebefore the caller submits the fenceSignal. InValueSubmission(~lines 3952–3957), a failedSignalonly logslate relay: the gate Signal failed. Becausegpu_signalledremainstrue, the releaser never releases that gate and it never times out, leaving that queue (and every subsequent gate on it) permanently blocked. Committinggpu_signalled = trueonly afterSignalsucceeds — or clearing it undermutex_on failure so normal release/timeout takes over — closes this.pending_releases_is checked before acquiringmutex_. If the pump opens gate G1 undermutex_(queueing CPUSignal(V1)on the releaser) while a writer relays gate G2 with GPUSignal(V2)(V2 > V1), the releaser's CPUSignal(V1)can arrive afterV2, signaling a timeline semaphore non-monotonically (invalid in Vulkan). Re-checkingpending_releases_undermutex_(or skipping releaser signals<= completed) prevents out-of-order signals.writtencompletes; if the waiter's GPU commands read that label address directly, they could observe the old value. Confirming this matches existingwaits_relayedassumptions (or documenting it) is helpful.count_late_relayable_lockedruns undermutex_on everyadd_writeseven whenLEONIDA_LATE_RELAYis off (O(gates * writes * waits)plus anO(gates^2)scan); gating it behindlate_relay_enabled()or a diagnostics flag keeps the default hot path free.Signalfallback, action gate first on waiter's queue (must not relay), two waiting queues relayed by one write group, andstop()while a relayed gate is still shut.AI-assisted.
@zmasi on GitHub · 2026-11-28 11:36 UTC · original
#2484 | head
020d1dd95b(merged cleanly with main4a54aedcb6) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(xs_proxy_mock.*|list_value_wait_budget)$" --output-on-failure+tests/test_docs_encoding.py| red on main:xs_proxy_mock_test.cppfails compile onmain(C2039:gates_late_relayed/set_list_value_late_relayabsent), and stubbingtake_late_relaysempty fails case 9 atxs_proxy_mock_test.cpp:4287(g_queue_call_count == 2, no GPU gateSignalqueued behinda_written) | green on PR+main: 10/10 CTests pass (all 9xs_proxy_mockvariants +list_value_wait_budget),test_docs_encoding.pypasses,LEONIDA_LATE_RELAYdocumented cleanly intest_docs_env_vars.py,check_no_game_data.py0violations (non-blocking note: ifsignal(waiter->gate, gate_value)ever returnsFAILEDatd3d12_xs_device.cpp:3954,gate.gpu_signalledstaystrueingates_, andtake_openchecksgpu_signalledahead offorce) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes@timbot103 on GitHub · 2026-11-29 01:05 UTC · original · reviewed
I recommend changes on head
020d1dd95. This was a static audit only. I did not run builds, tests, or GPU workloads.runtime/shims/d3d12_xs_list_values.h:475. Submit two unmet gates first, then submit each gate's producer behind the other gate. Both gates get markedgpu_signalledand both queue signals are held behind the waits they need to release. Please leave the CPU timeout active whenever the writer's actual signal point could depend on a pending gate or unresolved fence wait. The existing mutual-cycle budget test provides a starting case.runtime/shims/d3d12_xs_list_values.h:468. The pump can move a ready remap gate to the releaser between the pending-release check and lock acquisition. A higher GPU fence value can then open the wait before the remap runs. Move the check undermutex_and cover a pending remap followed by a matching memory gate.runtime/shims/d3d12_xs_device.cpp:3954. A failed gate signal leaves the gate permanently on the GPU path, including when the Vulkan layer accepts the call and the deferred submission fails later. Please resolve the relay reservation on actual submission or failure and restore CPU release on confirmed failure. On Vulkan, the failed fence claim also needs to be undone to allow a same-value retry.runtime/shims/d3d12_xs_list_values.h:478. For a gate waiting onx == 1, a later group containingx = 1followed byx = 2triggers a relay even though the pump would observe2after landing the group. Base eligibility on the final ordered write touching the waited bytes and cover an overwrite in one group.runtime/test/xs_proxy_mock_test.cpp:4006. WithLEONIDA_LATE_RELAY=1inherited from the environment, case 2 takes the GPU path but advances only the written fence. Set the switch explicitly at test entry so case 2 exercises CPU release and case 9 exercises GPU release.AI-assisted.
Pull request closed