Skip to content

shims: find_title_window, the title's own window that PresentX shows its frames in - #8591

Open
NiiRoZz wants to merge 1 commit into
ItsNotRexed:mainfrom
NiiRoZz:d3d12-xs/presentx-title-window
Open

NiiRoZz wants to merge 1 commit into
ItsNotRexed:mainfrom
NiiRoZz:d3d12-xs/presentx-title-window

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

What and why

On the console, PresentX puts a frame on the display and names no window. A GDKX title still makes its own top-level Win32 window, with its own class and a message loop on its own thread, before it presents. On the PC the frames belong in that window.

Measured on a retail executable (Vulkan device, integration stack with #2490):

  • By the first PresentX, the process has exactly one visible, unowned top-level window, on a thread of its own. Every other window of the process is hidden: the IME windows Windows adds, and a driver's dummy window.
  • d3d12_xs: console-ABI command lists, upload arena, PC-list fixture path #2490's present_state_for built a hidden window of its own (WS_OVERLAPPEDWINDOW, never shown, no message loop) and presented there. The title's window stayed white for the whole run (~3,000 PresentX calls in 44 s).
  • A first lookup read window titles with GetWindowTextW. That sends WM_GETTEXT across threads, and it stopped the title at its first PresentX because the title's window thread was not pumping at that moment.

The change

runtime/shims/title_window.h: rt::d3d12::find_title_window(process_id, exclude) returns the visible, unowned, non-tool top-level window of the process with the largest client area, or null. It only reads window-manager state (EnumWindows, GetWindowThreadProcessId, IsWindowVisible, GetWindow(GW_OWNER), GetWindowLongPtrW, GetClientRect) and sends no message.

On its own it changes nothing on main, because main has no PresentX queue wiring. #2490's present_state_for should present into find_title_window(GetCurrentProcessId()) when it finds one, keep its own window only for a title that has none, and not destroy the title's window. The local integration does exactly that. With #7685 applied there too (PresentX's tokens), the presents go to the title's window.

Test

title_window_test (ctest title_window) makes five windows on a thread that never pumps its messages: the title window, a smaller visible one, and larger hidden, owned and tool windows. It checks that:

  • the lookup returns the title window in under 100 ms and skips the larger hidden, owned and tool windows;
  • with the title window excluded, it returns the smaller one;
  • another process id gives null, and so does the process once the windows are gone.

Negative control: a WM_GETTEXT sent to the title window times out (200 ms), so a lookup that sent messages would block there. Dropping the owner check makes the test fail (found == windows.title).

🤖 Generated with Claude Code

…its frames in

A GDKX title makes its own top-level Win32 window before its first PresentX, and PresentX names no window: on the PC
the frames belong in that window. Measured on a retail executable: by the first PresentX the process has one visible,
unowned top-level window on a thread of its own, and only hidden windows besides (IME, a driver's dummy window). The
PresentX wiring (ItsNotRexed#2490) built a hidden window of its own instead, so a running title showed a blank window.

find_title_window picks the visible, unowned, non-tool top-level window of the process with the largest client area.
It sends no message: a lookup that read window titles with GetWindowTextW (a WM_GETTEXT sent across threads) stopped
the retail title at its first PresentX, because the title's window thread was not pumping at that moment.

title_window_test makes the windows on a thread that never pumps; the negative control shows a sent WM_GETTEXT times out
there, while the lookup answers at once and skips the larger hidden, owned and tool windows.

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

Copy link
Copy Markdown

Tested commit ec41c2201c4881d9ee7760a6e6c9e7d02c3cb48f on native Windows 11 x64 (MSVC 19.44.35230.0, Windows SDK 10.0.26100.0, Ninja Release build, NVIDIA GeForce RTX 3050 8 GB, driver 591.86 / Vulkan 1.4.363.1). Synthetic test only, zero game data.

Build & Test Verification

  • cmake --build build --target title_window_test -j 6 -> built cleanly with /W4 /permissive- /utf-8 (0 warnings).
  • title_window_test.exe -> title_window: ok (exit code 0):
    • Verified that the negative control SendMessageTimeoutW(windows.title, WM_GETTEXT, ..., SMTO_BLOCK, 200, ...) times out on the non-pumping window thread.
    • Verified that rt::d3d12::find_title_window(GetCurrentProcessId()) returns windows.title in < 100 ms without sending window messages, skipping the larger hidden (900x700), owned (800x600), and tool (800x600) windows.
    • Verified that passing exclude = windows.title selects windows.small (160x120), and querying a different PID or after window destruction returns nullptr.
  • python -I scripts/check_no_game_data.py runtime/CMakeLists.txt runtime/shims/title_window.h runtime/test/title_window_test.cpp -> clean (exit code 0).

Code Review

  • EnumWindows callback in runtime/shims/title_window.h queries only window-manager state (GetWindowThreadProcessId, IsWindowVisible, GetWindow(GW_OWNER), GetWindowLongPtrW(GWL_EXSTYLE), GetClientRect), avoiding any cross-thread SendMessage deadlock when the presentation thread queries the window while the title's UI thread is blocked.

AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested ec41c2201 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8599, #8589, #8591, #8620, #8569 and #8622 (no conflicts): pass.

@Marukooh

Copy link
Copy Markdown
Contributor

Tested ec41c22 on Wine 11.22 with RTX 5070 Ti (NVIDIA 620.73.04). The synthetic title_window CTest passed. A local integration with #7685 and #7448 selected the title's own visible window and recorded over 1,000 successful one-plane PresentX calls to it. Two sampled frames in that window remained black. The command-list diagnostics point to a separate RTV-handle recording failure covered by #7880, which is being tested separately.

AI-assisted verification. No game files, screenshots or traces attached.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

The present_state_for side, measured on the retail boot (Windows 11, RTX 5060 Ti, ASTROWwwW:ladder-frame@a1751a9f0 + #7604 + this PR). Without it, this PR changes nothing at run time: the frames still go to the hidden LeonidaPresentX window, and the title's window stays white. With it, the log shows PresentX presents into the title's window, the title's window shows a black 1920x1080 frame at 31 s, and the whole window is black at 62 s (A33: #7154 (comment)). @ASTROWwwW, this applies on ladder-frame as is (it sits where #2490's present_state_for is):

diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp
index af7f22599..efc4d1d68 100644
--- a/runtime/shims/d3d12_xs_device.cpp
+++ b/runtime/shims/d3d12_xs_device.cpp
@@ -25,6 +25,7 @@
 // for a trace that disagrees. The frame-event calls answer from a per-device token counter: there is no vblank source
 // behind the device before a presenter exists, so WaitFrameEventX returns at once with a fresh non-zero token.
 #include "d3d12_xs_device.h"
+#include "title_window.h"
 #include "d3d12_trace.h"
 #include "d3d12_xs_alloc_size.h"
 #include "d3d12_xs_desc_clean.h"
@@ -1294,9 +1295,10 @@ LONG CALLBACK table_overrun_handler(EXCEPTION_POINTERS* info) {
 
 struct PresentState {
     ~PresentState() {
-        if (window) DestroyWindow(window);  // the presentation and its window die with the device proxy
+        if (window && owns_window) DestroyWindow(window);  // the title's own window is never destroyed (#8591)
     }
     HWND window = nullptr;
+    bool owns_window = false;
     std::unique_ptr<rt::d3d12::XboxPresentation> xbox;
     bool tried = false;  // creation is attempted once; a null xbox means this device cannot present
 };
@@ -1317,17 +1319,25 @@ PresentState* present_state_for(DeviceProxy* device) {
     if (!state) return nullptr;
     device->present_state = state;
     state->tried = true;
+    // The title's own top-level window, when it has one (#8591): frames go where the player looks.
+    if (HWND title = rt::d3d12::find_title_window(GetCurrentProcessId())) {
+        state->window = title;
+        std::fprintf(stderr, "[rt] d3d12_xs: PresentX presents into the title's window %p\n", static_cast<void*>(title));
+    }
     WNDCLASSW window_class{};
     window_class.lpfnWndProc = present_window_proc;
     window_class.hInstance = GetModuleHandleW(nullptr);
     window_class.lpszClassName = L"LeonidaPresentX";
-    if (!RegisterClassW(&window_class) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
+    if (!state->window && !RegisterClassW(&window_class) && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
         std::fprintf(stderr, "[rt] d3d12_xs: PresentX window class failed (error %lu)\n", GetLastError());
         return state;
     }
-    state->window = CreateWindowExW(0, window_class.lpszClassName, L"Leonida", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
-                                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr,
-                                  window_class.hInstance, nullptr);
+    if (!state->window) {  // a title without a window of its own: the runtime's, hidden as before
+        state->window = CreateWindowExW(0, window_class.lpszClassName, L"Leonida", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
+                                        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr,
+                                        window_class.hInstance, nullptr);
+        state->owns_window = state->window != nullptr;
+    }
     if (!state->window) {
         std::fprintf(stderr, "[rt] d3d12_xs: PresentX window failed (error %lu)\n", GetLastError());
         return state;

AI-assisted (Claude Code).

@akimfomin

Copy link
Copy Markdown

A33 integration follow-up for #8591. On Windows 11 28000.3501, I tested the exact ec41c2201 window finder with the PresentState block from ladder-frame@a1751a9f0, using real synthetic Win32 windows on a private inactive desktop and a fake Vulkan presenter.

Simple local wiring of the finder into the existing once-per-device latch, with borrowed-window teardown fixed, passed 14/19 checks. A visible 0×0 placeholder could be selected on the first call and stay pinned when a different, usable title window appeared. If the same HWND resized, the direct wiring worked.

A local candidate passed 19/19. It distinguishes a ready client area, an existing but transient client, and a truly absent candidate. On transient it defers before caching any state. On absent it keeps the existing fallback. Teardown destroys only the runtime-owned fallback and leaves the title window alive. These checks cover binding and ownership before the Vulkan constructor. No full Vulkan or retail run. AI-assisted (Codex).

@RAINighty

Copy link
Copy Markdown

Tested ec41c2201 merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, MSVC 19.44.35228, RelWithDebInfo (Ninja), CPU-only tests: pass.

  • title_window passes with this PR.
  • Control is not clean here: runtime/shims/title_window.h is new in this PR, so there is no main version to put back and the title_window test passes as before; there is nothing to compare against.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

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.

7 participants