Skip to content

Runtime: Xbox presentation core — PresentX, frame events, SuspendX/ResumeX (Depends on #119) - #601

Closed
AlxcBTW wants to merge 13 commits into
ItsNotRexed:mainfrom
AlxcBTW:presentx-core
Closed

AlxcBTW wants to merge 13 commits into
ItsNotRexed:mainfrom
AlxcBTW:presentx-core

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Depends on: #119 (the Vulkan device and presenter) and #540 (the docs this implements). Opened as a draft so it can be reviewed early. Until #119 lands, the diff also shows #119's commits and two merges of main. The new commits are the ones authored by AlxcBTW: the FramePacer, the presenter extensions, XboxPresentation, the review fixes and the docs. It will be rebased onto main once #119 is in.

What and why

This is step 2 of the item claimed in #313. Public GDKX code (see #540) presents through PresentX and frame events, with no DXGI swapchain. Nothing in runtime/ implemented them, so a GDKX title can't show a frame. This adds the presentation core. It doesn't depend on slots: the seven *X vtable slots are still unmeasured, so the methods sit behind an extension interface the Xbox proxy will forward to. A TODO table of the slots is in runtime/shims/xbox_present.h.

  • FramePacer (runtime/src/frame_pacer.h, header-only, with an injectable clock):
    • SetFrameIntervalX sets the period and the latency. Changing it while an origin is armed keeps the origin and re-bases the grid.
    • ScheduleFrameEventX arms the origin with its offset.
    • WaitFrameEventX blocks until the next origin and returns a monotonically increasing token. It also blocks while latency presented frames still wait for their vblank, and handles timeouts.
    • GetFrameStatisticsX keeps the last 64 frames and returns S_FALSE / count 0 when data isn't available.
    • SuspendX wakes waiters and refuses presents. After ResumeX, frame events must be registered again, as in the samples.
  • XboxPresentation::PresentX:
    • 0 planes: black frame.
    • 1 plane: blit of plane 0, restricted to pSrcViewRects[0] when set.
    • 2 planes: plane 0 is shown, and composing the second (HDR/GameDVR) is logged as not implemented.
    • Tokens: a never-issued token gives E_INVALIDARG. Null, stale and repeated tokens are presented anyway and logged once per kind, because real behaviour is unmeasured and a strict check could freeze a title.
    • ImmediateThresholdPercent is logged and otherwise ignored.
  • Presenter (Runtime: Vulkan-backed ID3D12Device behind the Xbox-ABI proxy: copies, presentation (M0), compute path #119's vulkan_present.h), extended rather than duplicated:
    • Adds a source rect, a blank present, and a swapchain format that follows the source (sRGB or UNORM).
    • Format support is checked through vkGetPhysicalDeviceFormatProperties: BLIT_SRC and BLIT_DST, and linear filtering only when supported. Integer, block-compressed and MSAA sources return DXGI_ERROR_UNSUPPORTED.
    • The acquire loop honours SuspendX, so it doesn't block on a full swapchain.

Struct layouts, enum values, the token width and the HRESULTs are provisional and marked so in the code. Only call shapes from public samples are used; no SDK material.

Tested

Windows 11, MSVC 17.14, RelWithDebInfo, with LEONIDA_VK_VALIDATION=1.

AMD Radeon 880M (26.11.2) NVIDIA RTX 5070 Laptop (617.42)
xbox_present_test all cases pass, 30 frames at 60 Hz in 508 ms all cases pass, 502 ms
d3d12_present_test (M0) pass pass
validation errors 0 0
  • ctest: 26/26 on AMD.
  • xbox_present_test reads the swapchain pixels back and checks them. It covers:
    • blank, one and two planes;
    • source rects (valid and invalid);
    • RGBA, BGRA and sRGB sources;
    • the lenient tokens and the refused never-issued token;
    • MSAA, UINT and BC sources (refused; the last frame stays, and the next present works);
    • statistics, and suspend/resume with re-registration.
  • frame_pacer_test uses a fake clock. It covers interval and offset, an interval change while a waiter is blocked, latency 1 and 2, timeouts, tokens, statistics, suspend/resume, and shutdown with a blocked waiter. It passed 10 repeat runs.
  • Pre-existing failure: d3d12_vulkan_device_test fails at its 4x MSAA allocation-size comparison on plain main too; it's unrelated.

Not done:

  • A mutable-format swapchain, so alternating sRGB/UNORM sources recreates it.
  • Composing the second plane.
  • A host-vblank clock; it currently uses a steady timer.
  • The proxy slot wiring.

An independent review found no blocking issue. Its token-leniency, format-support, interval-change and MSAA-HRESULT findings are fixed here.

AI-assisted (Claude Code).

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. (No translator change.)

🤖 Generated with Claude Code

Ryx69 and others added 13 commits November 21, 2026 23:44
- vulkan_present.h: VulkanPresenter blits a back buffer (an ordinary texture
  in D3D12's PRESENT state, layout tracked like any other) to an acquired
  swapchain image and presents it on the same VkQueue, after the
  application's work. Two frames in flight, a present semaphore per image,
  FIFO for vsync else MAILBOX/IMMEDIATE, swapchain recreated on resize or
  out-of-date/suboptimal, minimised windows skip presents.
- rt::d3d12::create_window_presenter / WindowPresenter: Win32 surface for a
  Vulkan device created with presentation; holds the device. This is the back
  end a DXGI shim or PresentX would call; the game's own front end is still
  open (docs question 6), so neither is invented here.
- Standalone device enables VK_KHR_surface/win32_surface and VK_KHR_swapchain
  when present; the test helper can too.

Test: d3d12_present_test opens a window and presents 60 frames through the
Xbox-ABI proxy (reset, PRESENT->RENDER_TARGET, clear, ->PRESENT, execute,
present, fence), resizes the window (swapchain recreated, scaled blit),
switches to unsynchronised presents, and reads the screen with GDI:
51,153,229 for a 51,153,230 clear. Clean under the Khronos validation layer,
as are the other GPU tests; 6/6 ctest.
The debug messenger in test/vk_test_device.h counted every error-severity
message, so a broken third-party implicit layer (ReShade's, reported on an
RTX 5090) failed every GPU test. Only VALIDATION-type errors are counted now;
general loader and layer messages are still printed, marked "not counted".
A real validation error still fails the test (checked by replaying part B of
vk_command_replay_test without the layout tracker). runtime/README.md says
so and mentions VK_LOADER_LAYERS_DISABLE.
Conflicts: README/docs status text (both kept), WindowPresenter and bindless
declarations in d3d12_com.h/d3d12_vulkan_device.cpp, device extension list
(swapchain + conditional rendering) in the standalone device and vk_test_device.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and frame events

Keeps the presenter paragraph from ItsNotRexed#119 ("What exists") ahead of the new text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(merge fallout, C4456)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, latency, tokens, statistics, suspend/resume)

Header-only, injectable clock, tested on a fake clock (frame_pacer_test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ame capture

VulkanPresenter::present takes an optional source rectangle (stretched to the
window), present_blank clears the swapchain image, the swapchain format follows
the source (an sRGB source gets an sRGB swapchain, every other a UNORM one), and
enable_capture/read_back copy each presented frame to host memory for tests.
Integer, block-compressed and multisampled sources are refused. WindowPresenter
forwards all of it. Also renames the device-extension counters in
create_vulkan_device_standalone that the merge left shadowing each other (C4456).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd/ResumeX) and xbox_present_test

Provisional struct layouts and constants of ours; real slots unmeasured (TODO
table in the header). The test reads the swapchain image back on a Vulkan
device and runs the frame events on a fake clock, then 30 frames in real time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… schedule keeps this period's origin

Only a token that was never handed out is refused; null, stale and repeated
tokens are reported through TokenIssue and presented. SetFrameIntervalX re-bases
the grid and leaves the origin event armed. ScheduleFrameEventX takes the origin
whose offset has not passed yet. ManualFrameClock calls its wake under the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…table acquire

Blit support comes from vkGetPhysicalDeviceFormatProperties (BLIT_SRC source,
BLIT_DST swapchain, linear filter only with SAMPLED_IMAGE_FILTER_LINEAR), cached
per format. The swapchain encoding is recorded only once the new swapchain
exists, so a failed recreate is retried. The image acquire polls an abort
callback every 50 ms instead of waiting for ever.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… gives DXGI_ERROR_UNSUPPORTED, SuspendX never waits on a present; tests and docs

xbox_present_test presents with null, repeated and stale tokens (the present
happens) and refuses never-issued ones, and presents MSAA, integer and BC sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: README status row; device-extension lists in the standalone device and
vk_test_device.h now carry swapchain, conditional rendering and host image copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

PresentX records a displayed token when the swapchain queues zero frames. I reproduced this twice on 3322ac383a6b68e08a99bc4ef65b452c07ca9cd8 with a source-built fixture on Windows 11, RTX 5080, driver 616.92, Khronos validation enabled. Both stock tests (xbox_present_test and frame_pacer_test) passed.

  1. Present red RGBA8 UNORM to a 320×240 window. Set its borderless client area to 0×0, issue a fresh token, then call PresentX with one solid green sRGB resource. The format change triggers swapchain recreation. The actual surface-capabilities query reported a 0×0 extent.
  2. PresentX returned S_OK and XboxPresentation::presents() increased by one. The lower presenter's counter stayed unchanged. A forwarding trace counted zero vkQueuePresentKHR calls, and the entire swapchain readback still matched the previous red frame. The query for frame-event, present and display statistics returned S_FALSE with two records immediately and S_OK with all three after advancing the test clock two periods.
  3. Restore 320×240 and issue another token for the same green resource. This produced one queue-present call and green at all 76,800 pixels. The trace forwarded the real Vulkan calls throughout. The clock was synthetic, so the result measures reported display status, not physical scanout.

The token commit and counter increment run on any successful presenter result. An internal queued/skipped result would let a zero-extent call succeed without counting a frame or creating submitted/displayed statistics for it.

The visible-window controls also exercised selection across two planes. Swapping only plane 0's two source rectangles changed all 76,800 pixels from blue to red. Swapping only its two resource pointers then changed all 76,800 from red to green. Changing only plane 1's token gave E_INVALIDARG, preserved both counters and the previous capture, and left only the frame-event statistic. Retrying with matching tokens produced the expected red frame.

AI-assisted hardware verification using synthetic resources.

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #908: the same work, rebuilt on the rebased head of the PR it depends on (the old base's commits would have shown twice here). Tested on the Radeon 880M and the RTX 5070; the results are in #908.

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.

3 participants