Skip to content

PresentX: device-side WaitFrameEventX and the frame pacer share one token source - #7685

Closed
Cattn wants to merge 1 commit into
ProjectLeonida:mainfrom
Cattn:presentx-shared-frame-tokens
Closed

Cattn wants to merge 1 commit into
ProjectLeonida:mainfrom
Cattn:presentx-shared-frame-tokens

Conversation

@Cattn

@Cattn Cattn commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #7496 (comment), from @rafaelpssz's integration run (#7496 (comment) item 9, and #7496 (comment)), which he left as a finding; @controldebils saw the same on an RX 6900 XT (#7599 (comment)). Thanks to both.

Depends on: none (based on main only). Overlaps: #2490 (builds the per-device XboxPresentation, which should pass device_frame_tokens(device); a one-argument change there), #5701, #5797, #7135 (FramePacer; no shared hunks, expected to merge cleanly), #6230 (PresentX routing; doesn't touch the pacer's tokens).

On its own this does not fix the retail refusal: main has no caller that builds the device's XboxPresentation, so the retail PresentX path only exists with #2490, and #2490 must pass rt::d3d12_xs::device_frame_tokens(device) to it (a one-argument change in its present_state_for). Until both are in, the refusal stays reachable. A local stack with #2490 and that one-argument change builds; the retail run on it has not reached PresentX yet, so the combination is not exercised end to end; thanks to @memorypressure for pointing this out.

What and why

Device slot 80 (WaitFrameEventX, routed by #6935) handed out tokens from a counter of its own (DeviceProxy::frame_next_token), while FramePacer::check_present_token refuses any token above the ones its own wait_frame_event issued. The retail title waits for frame events through the device and presents through PresentX, so once its tokens run ahead of the pacer's, every PresentX is refused with E_INVALIDARG ("never handed out"): rafaelpssz and controldebils each measured every present refused on the retail frame loop.

Now both use one counter:

  • leonida::FrameTokenSource (frame_pacer.h): an atomic counter, issue() returns 1, 2, 3, …; issued() is the highest handed out. FramePacer takes an optional shared source; without one it owns a fresh source, so a standalone pacer numbers exactly as before. Its wait issues from the source, check_present_token refuses a token above issued(), and token_source() exposes it.
  • XboxPresentation takes the same optional source and passes it to its pacer; existing callers are unchanged.
  • The device proxy owns a source, slot 80 issues from it (same values as before, never 0), and rt::d3d12_xs::device_frame_tokens(device) returns it (null for a non-proxy). Whoever builds the device's XboxPresentation passes it; main has no such caller yet, which is the one-argument change for d3d12_xs: console-ABI command lists, upload arena, PC-list fixture path #2490 above.

A token that was never issued by either path is still refused.

Tested

Windows 11, NVIDIA GeForce RTX 4070 (driver 617.42), MSVC 14.43 RelWithDebInfo, rebased on a3f917c7e.

  • frame_pacer_test (CPU): a pacer on a shared source accepts a token issued outside it, refuses issued() + 1, continues the shared numbering on its own wait, and accepts/refuses again after another outside issue.
  • device_proxy_test (CPU): slot 80's tokens come from device_frame_tokens(device); device_frame_tokens(nullptr) is null.
  • xbox_present_test (GPU): the presentation is built with the device's source; a token from device slot 80 equals the pacer's tokens_issued(), PresentX with it is S_OK and shows the frame, and device_token + 1 is E_INVALIDARG and presents nothing.
  • ctest -R "frame_pacer|device_proxy|xbox_present|present|boot_movie": 9/9 (d3d12_boot_movie skips without LEONIDA_GAME_DIR), 3 of 3 runs before the rebase and 2 of 2 after.
  • Negative control on main, the slot-80 path alone in xbox_present_test with the old construction: after waiting through slot 80 until its token passes the pacer's (device token 14, pacer issued 13), PresentX with it returns 0x80070057 (E_INVALIDARG).
  • No game data.

AI-assisted: yes

Checklist

  • 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: no translator change)

…oken source

Device slot 80 (WaitFrameEventX, from ItsNotRexed#6935) numbered its tokens with a
counter of its own, while XboxPresentation's pacer refuses any token above
the ones it issued itself. A title that waits through the device and
presents through the device's XboxPresentation therefore had every
PresentX refused with E_INVALIDARG once its tokens ran ahead of the
pacer's.

leonida::FrameTokenSource is now the counter both use: a pacer takes an
optional shared source (a standalone pacer still owns its own and numbers
as before), the device proxy owns one and exposes it through
rt::d3d12_xs::device_frame_tokens, and XboxPresentation passes a given
source to its pacer. A token that was never issued is still refused.

Reported by rafaelpssz in ItsNotRexed#7496.
@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent Windows + GPU test of afb14d56c: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24), Vulkan SDK 1.4.363.1, no game files.

  • xs_proxy_mock_test.exe: PASS (exit 0).
  • xbox_present_test.exe: PASS (exit 0).

AI-assisted review/test.

@GustawMatuszewski

Copy link
Copy Markdown
Contributor

Tested afb14d56c on AMD Radeon RX 9060 XT (RDNA4, gfx1200), RADV Mesa 26.0.8, Ubuntu 26.04 LTS, Linux (clang 21, Vulkan 1.4.335), built from this head in its own tree:

  • ctest -j 12: 64/64 passed, 0 failed (two skipped by design: shader_library_corpus, vk_sync_validation)
  • of those, the ones this PR touches: frame_pacer Passed (0.90 s), xbox_present_readback_size Passed, vk_presenter_capture_colour Passed

So the token-source change builds and passes on a RADV RDNA4 device as well, not only on the Windows/NVIDIA setup you tested. Caveat: the Windows-only present/pacer tests in your 9/9 are outside what this machine can run, so this is an independent second platform, not a replacement for that run.

No game files used. AI-assisted (Claude Code): it built the head on that machine, ran the suite and wrote this.

@memorypressure

Copy link
Copy Markdown

Tested head afb14d5 against main dde82f2 (merges clean, tree 6634c30bc). C++ — review only here; CI is the execution gate, and NO CI checks are reported on the branch. FrameTokenSource threading is sound (atomic issue/issued, standalone pacer unchanged), and your overlap self-declaration checks out — pairwise merge-tree against #2490 and #7135 is CLEAN both ways. Integration note, as your body says: on current main nobody wires device_frame_tokens into XboxPresentation, so until #2490's one-argument change lands, this alone leaves the retail refusal reachable — correct ordering, just don't let it read as the fix shipped. The negative control (device token 14 vs pacer 13 → 0x80070057 on main) is exactly the proof the finding needs. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@venetanji

Copy link
Copy Markdown
Contributor

Tested the device-to-presenter wiring on Arch Linux, Wine 11.20, Intel i9-10900K, RTX 3080 Ti, NVIDIA 615.78.08. This was an A/B on a private integration with #2490 and the boot dependencies, using the same local retail copy, Vulkan backend, shader inputs, and first-present readback in both runs. Title asserts were enabled.

  • Before PresentX: device-side WaitFrameEventX and the frame pacer share one token source #7685, the device handed out a frame token and the title called the queue's one-plane PresentX. It returned E_INVALIDARG with the present counter still at zero. The window presenter had initialized successfully.
  • With afb14d56c and d3d12_xs: console-ABI command lists, upload arena, PC-list fixture path #2490's presenter constructed with device_frame_tokens(device), the one-plane call returned S_OK and the counter advanced from zero to one. The completed Vulkan swapchain readback was uniformly zero in all four channels. I reproduced that first present in two later builds while testing independent allocation fixes.
  • This verifies the token handoff through the retail caller on this host. The command list had a failed Close and the first readback contained no visible content.

Only aggregate results. AI-assisted with Codex.

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Data point from the retail 1.0.2.1 executable on Windows 11 (RTX 4090, NVIDIA 617.42, LEONIDA_D3D12=vulkan). This PR is cherry-picked onto my local boot stack, which also carries #2490's queue PresentX wiring (present_state_for / queue_present_x, the newer layout's queue slot 32).

The queue's XboxPresentation needs the device's token source too. present_state_for still builds it as std::make_unique<rt::d3d12::XboxPresentation>(std::move(presenter)), so its pacer owns a fresh FrameTokenSource that never issues anything. The title waits through device slot 80 (so the tokens come from the device's source) and then presents through queue slot 32. check_present_token sees token > issued() == 0 and returns invalid_arg, so every PresentX failed with E_INVALIDARG (token 1, 2, 3…). Measured locally:

  • Before: 0 of about 7,000 PresentX calls succeed. The plane's Token is exactly the count WaitFrameEventX has handed out, while the queue pacer has issued 0.
  • After, one line in present_state_for: std::make_unique<rt::d3d12::XboxPresentation>(std::move(presenter), nullptr, device->frame_tokens). Every PresentX returns S_OK: over 7,000 in a 240 s run, with the frame loop alive to the timeout and no crash.

Whichever of #2490 and this PR lands second needs that line. A mock test could create the presentation through a queue proxy, wait on the device, and present that token. Counts only, no game files.

AI-assisted (Claude Code).

@TripleJ160

Copy link
Copy Markdown

I exercised the #2490 + #7685 integration through the production queue proxy on an RTX 5090 (616.92, Windows 11 build 26200, MSVC 19.44, Vulkan SDK 1.4.363). The fixture clears a synthetic RGBA render target, selects the newer queue layout with slot 16, then sends a token from device slot 80 to queue slot 32. The stock merge (ef9d0759d + afb14d56c) creates the presenter but returns E_INVALIDARG (0x80070057) for the issued token. Passing device->frame_tokens into the lazy XboxPresentation makes it return S_OK. The next unissued token still returns E_INVALIDARG. After the separate ownership fix described below, this passed 5/5 runs.

The production route also exposed a reference cycle because the device proxy owns the presenter and the presenter retains the proxy. Validation showed 29 leaked device objects and one surface. Having just this presenter retain the underlying device removed both teardown reports. The full presentation test still hits its existing NVIDIA sRGB validation skip.

Tested integration commit. Ownership finding and claim. Synthetic inputs only. AI-assisted.

@AAyberkU

Copy link
Copy Markdown
Contributor

Measured on the retail title with this PR stacked on #2490 (and #7880, #7286, #7111 and the other boot PRs): the queue-side PresentX path in #2490 (present_state_for in d3d12_xs_device.cpp) still builds its XboxPresentation with the one-argument constructor, so its pacer has handed out no tokens. Every PresentX (queue slot 32, about 100 per second) then came back E_INVALIDARG ("never handed out"), because the title takes its tokens from device slot 80, which this PR now serves from device->frame_tokens.

Passing the shared source at that call site fixed it:

state->xbox = std::make_unique<rt::d3d12::XboxPresentation>(std::move(presenter), nullptr, device->frame_tokens);

With that one-argument change every PresentX returns S_OK for a 90 s run (about 100 per second). Whichever of the two lands second needs this line. I can push it to either branch if that helps.

A related question for whoever owns the presenter: present_state_for creates its own "Leonida" window and never shows it, while the title has already created and shown its own top-level window. Locally I present into the title's window (the largest visible unowned top-level window of the process), with the own window as the fallback. Is the title's window the intended target, or is the separate window deliberate?

on: Windows 11, MSVC RelWithDebInfo, RTX 5060 Ti, LEONIDA_D3D12=vulkan, LEONIDA_SKIP_INT3=1. AI-assisted (Claude Code).

@Cattn

Cattn commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@AAyberkU, @TripleJ160, thanks; both match what the PR text says: #7685 only provides the shared source, and the one line in #2490's present_state_for (std::make_unique<rt::d3d12::XboxPresentation>(std::move(presenter), nullptr, device->frame_tokens)) is what connects it on the retail path. Since present_state_for only exists on #2490's branch, that branch is the natural home for the line: @AAyberkU, please do push it there (to @NolanCotter's #2490, or next to @TripleJ160's NolanCotter#4, which fixes the proxy/presenter reference cycle but does not add the token argument), so there is one place for it whichever order #2490 and #7685 land in. If #2490 lands first without it, I will add the line to this PR instead.

On the window question: the separate "Leonida" window comes from #2490's present_state_for, not from this PR, so that is @NolanCotter's call.

AI-assisted: yes

tibzejoker added a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
… PresentX); includes and declarations side by side
std::atomic<std::uint32_t> frame_latency{1};
std::atomic<bool> frame_event_scheduled{false};
std::atomic<std::uint64_t> frame_next_token{1};
std::shared_ptr<leonida::FrameTokenSource> frame_tokens = std::make_shared<leonida::FrameTokenSource>();

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.

If the device proxy allocation succeeds but this new shared allocation fails, std::make_shared throws std::bad_alloc. The new (std::nothrow) DeviceProxy at line 1634 only handles failure to allocate the outer object. Its null check never runs when a member initializer throws. Before this change the token counter was an inline atomic.

That exception can escape D3D12XboxCreateDevice. The Vulkan and native D3D12 branches release their caller-owned device reference only after a failing HRESULT returns. Could the factory translate this allocation failure to E_OUTOFMEMORY while leaving *out == nullptr and the reference with the caller? A deterministic mock check could allow proxy allocation, fail just the token-source allocation, then check the HRESULT, output pointer and unchanged mock refcount. Factory · Export cleanup

Source review at afb14d56c. No runtime or allocation-failure test run. Neither GPU was exercised.

AI-assisted by GPT-6.2 Astra.

@NolanCotter

Copy link
Copy Markdown
Contributor

Reviewed on its head (clang-cl 20 + xwin cross-build, Wine): frame_pacer_test all cases pass, xs_proxy_mock_test PASS. xbox_present_test/device_proxy_test can't run here (no Vulkan display under headless Wine).

Correctness reads clean:

  • Token semantics preserved exactly: frame_next_token starting at 1 with fetch_add ≡ FrameTokenSource::issue() returning fetch_add(1)+1 from 0 — first token is 1, and 0 can never be issued, so the old skip-zero branch is covered by construction.
  • issued() going lock-free is safe — it's an atomic load where the mutex no longer needs to order it; tokens_issued() and the token > issued() validation read the shared counter consistently.
  • nullptr-default keeps every existing XboxPresentation/FramePacer caller creating its own source — the sharing is strictly opt-in, which is the right shape for a staged integration (the #2490 present_state_for line is queued on my side for when this lands).
  • device_frame_tokens(nullptr) → nullptr → pacer makes its own source: graceful on a non-proxy device.

Measured on retail by AAyberkU stacked with #2490 + the device->frame_tokens arg: PresentX E_INVALIDARG → S_OK every frame (~100/s, 90 s). That's the combination this PR exists for.

AI-assisted (Devin); no game files used.

@Marukooh

Copy link
Copy Markdown
Contributor

Independent retail check of the shared-token path on CachyOS x86-64, Wine 11.22 and RTX 5070 Ti / NVIDIA 620.73.04, Vulkan, offline with a local 1.0.2.1 package. I applied afb14d56 to an integration stack (including #2490) and passed the device's token source to the three-argument XboxPresentation constructor.

An instrumented run recorded at least 1,198 one-plane PresentX calls returning S_OK. The synthetic xbox_present CTest passed. The presenter-owned window is hidden (IsWindowVisible returned false on each sampled call). Mapping it separately on XWayland shows black output; successful PresentX does not establish that the title reached its menu. The window lifecycle work is tracked as D3D-857.

Only call outcomes and counts. AI-assisted (Codex).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

checked: #7685 at afb14d5, merged onto main 867d922 (clean merge, 8 files, +81/-13) | on: Wine 11 on RunPod RTX 4090 (Linux), clang-cl cross-build; not native Windows, host D3D12/WARP comparisons do not run | ran: frame_pacer_test EXIT 0 (includes the new shared-token case); xs_proxy_mock_test EXIT 0 (PASS (9 allocations refused on purpose)) plus its five ctest modes by hand (--fail-virtualalloc, --fail-virtualprotect, --fail-veh, --env-slots, --env-slots-invalid), all EXIT 0; device_proxy_test EXIT 77 SKIP: no WARP adapter; xbox_present_test EXIT 1. That last one is not the PR: on a clean origin/main copy the same target also exits 1, with the same present failed (VkResult -11) lines and the same stop at real time: centre 255,0,0, presented 0,255,0 (main line 1329, this head line 1347, which is the 18 lines the PR adds earlier in the file). So the new device-token block in xbox_present_test and the new device_proxy_test check did not run here; only frame_pacer_test exercised the new FrameTokenSource logic. No negative control run (the new frame_pacer_test case uses the new API, so it cannot even build against main's header).

diff review: FrameTokenSource is one atomic counter (issue() returns last+1, issued() reads it); FramePacer takes an optional shared_ptr (a private source when none is passed, so existing callers keep their behaviour), check_present_token compares against the shared issued(), and the device's slot-80 WaitFrameEventX now draws from the same source instead of its own frame_next_token. The old "skip token 0" branch is gone because the new counter starts at 1. Tokens still run in one sequence per device and the pacer reads the atomic under its own mutex, so I see no ordering problem. The new frame_pacer_test case checks an outside token is valid, token+1 is refused, a pacer-issued token continues the sequence and that the next outside token is valid. Scope: this PR only provides the shared source; the call that hands it to the queue-side presenter (present_state_for in #2490) still has to change, as the author and other testers state, so this alone does not unblock PresentX on the title. I found no defect.

Not verified: the real PresentX path (needs a display and Vulkan present, which fails under this Wine setup even on main), native Windows, retail boot.

agent: yes
AI-assisted.

@fever308

Copy link
Copy Markdown

checked: #7685afb14d5 | with: cmake -S runtime -B runtime/build -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.26100.0 -DLEONIDA_VULKAN_HEADERS_FETCH=ON -DLEONIDA_REQUIRE_VULKAN=ON, cmake --build runtime/build --config Release --target frame_pacer_test device_proxy_test xbox_present_test -- /nr:false /m:1, frame_pacer_test.exe, device_proxy_test.exe, xbox_present_test.exe, python -I scripts/check_no_game_data.py ... | on: Windows 11 x64, MSVC 19.44.35222.0, Windows SDK 10.0.26100.0, NVIDIA GeForce RTX 5090 (driver 617.42), synthetic tests only (no game files) | result: pass (frame_pacer_test: all cases pass; device_proxy_test: 0 failures; xbox_present_test: all cases pass on RTX 5090 including a token from device slot 80 (WaitFrameEventX) presents: ok; check_no_game_data.py: clean)

Details

  • Base / merge: afb14d56c merges cleanly onto main (867d922f0) with zero conflicts.
  • Negative control: Temporarily ignoring the shared tokens argument in FramePacer::FramePacer (runtime/src/frame_pacer.h) causes frame_pacer_test.exe to fail at line 94: pacer.token_source() == tokens (exit 1).
  • Code review (afb14d56c):
    • FrameTokenSource uses fetch_add(1, std::memory_order_acq_rel) + 1 and load(std::memory_order_acquire), guaranteeing non-zero monotonically increasing tokens visible across threads between device slot 80 (proxy_wait_frame_event_x) and FramePacer::check_present_token.
    • Default tokens = nullptr preserves standalone FramePacer and XboxPresentation behavior, and device_frame_tokens(nullptr) safely returns nullptr.

AI-assisted.

@thedarkcr0w

Copy link
Copy Markdown

Tested on the retail boot with this PR merged into a local integration (main + the boot-chain PRs, #2490's queue-side PresentX among them). Own 1.0.2.1 copy, Windows 11, NVIDIA GeForce RTX 4090 (driver 32.0.16.1062), LEONIDA_D3D12=vulkan.

With this PR alone, every PresentX was refused: 17,119 of 17,119 returned E_INVALIDARG. The token the title passes is the one WaitFrameEventX (device slot 80) handed out, but the queue-side XboxPresentation is built without the device's FrameTokenSource, so its pacer does not know the token. The plane words the title passes match xbox_present.h (token 1, ResourceCount 1, ppResources, source rect, destination placement, the rest 0).

One line fixes it, in present_state_for: construct the presentation with the device's token source,

cpp state->xbox = std::make_unique<rt::d3d12::XboxPresentation>(std::move(presenter), nullptr, device->frame_tokens);

After it: 12,857 of 12,857 PresentX ok over a 70 s run, with the title in its frame loop (queue slot 35 submissions, fence slot 12). No draw reaches those frames yet (device slot 57 graphics pipelines are the next gap), so this shows the present path and pacing, not an image.

No game-free test for it here: queue_proxy_test builds the proxy without the Vulkan device, where PresentX is the S_OK stub and never reaches a presenter; a test needs a Vulkan-device proxy with a swapchain.

AI-assisted (Claude Code).

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
PresentX: device-side WaitFrameEventX and the frame pacer share one token source

Preserve the existing device slot handlers while integrating PresentX frame tokens.

Fork integration. AI-assisted (Codex).
@Ty0x7

Ty0x7 commented Nov 23, 2026

Copy link
Copy Markdown

checked: #7685afb14d5 | base: forge main@70bc8a25e1c69c3f058cf550a8db9397c6a89d0c (includes #2490), plus #7685 and the one-line constructor wiring to pass the device's shared token source | on: Wine 11.20, Omarchy/Hyprland XWayland, RTX 3060 Ti, NVIDIA 615.78.08, clang-cl/lld 23.1.3, xwin SDK 10.0.26100 | result: 3 issued tokens presented, 3 deliberately unissued tokens refused with E_INVALIDARG, exact RGB readback in both window modes.

The local synthetic xbox_present_test probe compiled the production Vulkan queue route, used a test-owned window for capture, registered the frame interval and origin event through slots 78/79, and obtained tokens from slot 80. It cleared a 320×240 GPU render target to red, green and blue and called queue PresentX through slot 30. The unpatched base refused the first issued token with E_INVALIDARG and presented zero frames. With #7685 wired in, each refused token left the present count unchanged. The three valid frames each matched every RGB pixel at the measured client area and swapchain extent: 1,941,504/1,941,504 at 1896×1024 with default tiling and 76,800/76,800 at 320×240 with explicit floating on the same scale-1 output. The frame_pacer and xs_proxy_mock CTests also passed.

Separate forge follow-up. Forge main@097e9f46ec97b57cbb28950bb9051c8bc842d037 uses its own token handoff. With only the pre-present registration, it accepted the first valid token and rendered an exact first frame. The second WaitFrameEventX returned 0x8007139F (ERROR_INVALID_STATE) in both modes, including when the very first PresentX used the valid token. Re-registering the same interval and origin event after the first present restored waits for tokens 2 and 3, and all three frames matched exactly. The evidence points to registration being lost when the presenter takes over. All checks used synthetic inputs. Retail boot, native Windows, Proton and the newer queue layout remain unverified by this run.

agent: yes

@sodove

sodove commented Nov 23, 2026

Copy link
Copy Markdown

Native Windows follow-up to the forge overlap check and the Wine slot-30 result. Tested forge main 097e9f46 on Windows 11 x64 build 26100, MSVC 19.44, SDK 10.0.26100, RTX 5070 Ti, NVIDIA 610.74 and Vulkan loader 1.4.341.

A local synthetic fixture used the real Vulkan queue path (LEONIDA_VULKAN_DEVICE). It selected the newer queue layout with slot 16, registered 60 Hz and the origin event through device slots 78/79, and issued two tokens at slot 80 before the first queue slot-32 PresentX. The fixture counted successful vkQueuePresentKHR calls through the test's Vulkan dispatch.

  • First present passes 3/3. The latest issued token returned S_OK and reached Vulkan once. The next unissued token returned E_INVALIDARG with zero additional Vulkan presents.
  • The next wait loses registration 3/3. With slots 78/79 called only before the first present, slot 80 returned ERROR_INVALID_STATE (0x8007139F). Repeating 78/79 on the same device restored waits. The next token followed the pre-present sequence and reached Vulkan once.
  • Negative control. Omitting the local call to adopt_frame_tokens rejected the first issued token with E_INVALIDARG and produced zero Vulkan presents. Restoring the call reproduced both results.

On the restored stock build, xbox_present and frame_pacer passed. The HDR10 swapchain subcase skipped because the surface offered no ST.2084 format. The stock device_proxy test reported one failure in the PC-form queue slot 18 GetDesc check. Synthetic inputs only. AI-assisted.

@Roy-0406

Copy link
Copy Markdown

checked: #7685afb14d5 | with: merged into main@867d922f0, scripts\build_runtime.ps1 (MSVC 19.51, CMake 4.4.4 + Ninja 1.13.2, Vulkan SDK 1.4.363.0, RelWithDebInfo); ctest -R "^(device_proxy|device_proxy_trace|frame_pacer|xbox_present|xbox_present_readback_size)$" 10 rounds, then the full ctest | on: native Windows 11 Pro 26200, AMD Radeon RX 7800 XT (RDNA3), AMD 26.11.2 (driver 32.0.32029.2010, LLPC, Vulkan 1.4.359), VK_LOADER_LAYERS_DISABLE=~implicit~, no game copy | result: pass. The five tests pass 10/10 each with the PR, including the checks it adds to device_proxy_test, frame_pacer_test and xbox_present_test (main: also 10/10 each). Full ctest: 259 passed, 5 failed of 275, the same five as main without the PR (vk_queue_query_sync, d3d12_vulkan_device, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; each has its own fix PR). | agent: yes

AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

checked: #7685 | with: clang-cl/lld cross-build (xwin SDK, Ninja, ccache) of d3d12_boot_movie_test and queue_proxy_test, two targets that include the changed headers and that no earlier check ran; plus a read of the diff against docs/d3d12_xs_surface.md | on: Wine on Linux (RunPod, headless X), main@6312c057f + #7685 (clean merge, 8 files, +81/-13); not native Windows | result: both targets compile and link with the PR (default-constructed XboxPresentation, null tokens argument, still builds). d3d12_boot_movie_test EXIT 77 (SKIP: no package/movie, so it proves compile only). queue_proxy_test fails under Wine at queue_proxy_test.cpp:1041 (run.end == ChildEnd::exited && run.exit_code != 0 && run.printed == 100, child-runner unhandled exception), and fails identically on a clean main copy, so it is not caused by this PR. Read against docs: tokens are 64-bit with 0 as the null token (docs/d3d12_xs_surface.md, token row); FrameTokenSource::issue() starts at 1 and never returns 0 before a 2^64 wrap, so the old "skip the null token" branch is correctly gone; grep finds no remaining frame_next_token or issued_ in runtime/. Observation: on this main, device_frame_tokens() is passed to XboxPresentation only by xbox_present_test; no production code constructs XboxPresentation yet, so the shared source is exercised by tests only until the consumer PR lands (the third earlier check mentions that wiring line). Not covered: native Windows, a controlled negative on the new device_proxy_test checks (that target SKIPs without WARP here).

agent: yes

ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
@danzig666

Copy link
Copy Markdown
Contributor

Rebased afb14d56c onto forge main@1812e0bd1, retaining your authorship. One-commit diff at 081fdf51.

The lazy presenter uses the device's token source immediately, replacing the first-PresentX adoption step. This keeps the forge's interval and event-offset replay and preserves the flag-2 current-token path. The test interleaves an external issuance, a regular wait, another external issuance, and a flag-2 poll. The proxy's allocation failure still returns E_OUTOFMEMORY.

frame_pacer_test passed on both the clean forge base and the rebase on Windows 11 with Zig 0.15.2 C++20 targeting x86_64-windows-gnu. The available headers lack newer D3D12 types and Vulkan headers, so the native device/PresentX tests and retail run remain unverified. This branch is based on forge history.

AI-assisted (Codex).

@YaBulochka

Copy link
Copy Markdown
Contributor

checked: the rebase at 081fdf512 (danzig666's fix/forge-present-token-source on forge main@1812e0bd1), not the old afb14d56c | with: clang-cl 23.1.5 + xwin 10.0.26100, -DLEONIDA_D3D12_SHIM_TESTS=ON, then Wine 11.13 (GE-Proton 11-13), RDNA2 gfx1036, LEONIDA_D3D12=vulkan, the 28,359-entry work folder | on: Linux, and the retail title for the run | result:

check result
build clean, 0 errors, gta6rt + the three test binaries
frame_pacer_test all cases pass, natively and under Wine (5 origins at 10 ms took 50 and 51 ms)
xbox_present_test all cases pass under Wine; the five present failed (VkResult -11) lines are the resize cases (VK_ERROR_OUT_OF_DATE_KHR), and the minimised/restored cases ("2 of 3 presents skipped and not read back") behave
device_proxy_test exit 77 (skip) under Wine, as designed: no DXGI factory with vkd3d-proton
retail run, 130 s 81,139 D3D12 calls, 10 PresentX, 0 ExecuteCommandLists failures, 0 int3 (with LEONIDA_SKIP_INT3=1 left on as a safety net), and no WaitFrameEventX failure line at all

So the token sharing does not change what the frame loop does on the forge base: the run still has no soft assert and presents, and the presenter no longer needs the first-PresentX adoption step to get a token. The only thing I could not check is the Windows-side path (no Windows machine here), and device_proxy_test staying a skip on Wine means its PresentX half is not exercised there.

@sodove

sodove commented Nov 23, 2026

Copy link
Copy Markdown

checked: native Windows follow-up for danzig666’s #7685 rebase 081fdf51204c7dd0b0f010d63b8772d061718806 against its exact parent 1812e0bd1ee1bfc54006edcc1e400e91d5cdd57f. Windows 11 x64 build 26100, MSVC 19.44.35220, SDK 10.0.26100, Release, RTX 5070 Ti / NVIDIA 610.74, Vulkan loader 1.4.341.

  • Stock frame_pacer and xbox_present passed on both revisions. The rebase’s new shared-token checks also passed in both device_proxy modes. Each mode still reports the same single queue slot 18 PC GetDesc assertion on both revisions. The HDR10 swapchain subcase skipped on this display.
  • A local extension of xbox_present_test, built with the runtime’s LEONIDA_VULKAN_DEVICE path enabled, drove the lazy queue-slot-32 PresentX and counted successful vkQueuePresentKHR calls. On each revision, 3/3 runs accepted the token issued before the first present and reached Vulkan once. The unissued next token returned E_INVALIDARG with zero additional presents. A subsequent flag-2 wait issued that token and it produced a second Vulkan present.
  • Control on the rebase: giving the lazy presenter a separate token source made the first issued token return E_INVALIDARG, with zero Vulkan presents.

Synthetic inputs only. AI-assisted verification.

@ramenbellic

Copy link
Copy Markdown

Tested afb14d5 under Wine: Proton Experimental (wine 11), runtime cross-built with clang-cl 23.1.6 + xwin SDK 10.0.26100 (RelWithDebInfo), merged onto main dfe4e4ad3: pass

  • Build: OK with clang-cl.
  • The tests this PR adds or touches, under Proton: 11 passed, 2 skipped, 0 failed (of 13).
  • Skipped under Wine, on main too: device_proxy, device_proxy_trace (for example device_proxy needs a WARP adapter, which Wine doesn't have).

AI-assisted run (Claude Code); no game files used.

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.