runtime: export the title GPU registry across DLLs #508

Closed
agilesh08 wants to merge 1 commit from upstream-pr/514 into main
agilesh08 commented 2026-11-22 08:43:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T08:43:15Z.


Change

Exports the process-wide title GPU registry across DLL boundaries from xmem.dll via a clean, fixed-layout C ABI declared in src/era_title_gpu_api.h.

Previously, docs/experiments.md noted:

"A D3D12 client in another DLL cannot reach the registry: a shared registry, with a fixture that loads both DLLs and shows the client sees the real provider's allocations, is left for the first such client."

This change delivers that capability:

  • Exposes X2WTitleGpuAttach, X2WTitleGpuDetach, X2WTitleGpuTranslate, X2WTitleGpuLocate, and X2WTitleGpuGetShaderView in src/xmem_shim.def and src/xmem_shim.cpp with X2W_TITLE_GPU_EXPORTS.
  • Keeps xmem.dll decoupled from direct d3d12.dll imports on load so existing non-D3D12 startup tests (xmem_shim_exports) remain intact.
  • Adds client DLL fixture tests/xmem_gpu_client.cpp and harness tests/xmem_gpu_cross_dll_check.cpp.
  • Registers CTest target xmem_gpu_cross_dll_warp in CMakeLists.txt and documents the cross-DLL contract in docs/experiments.md.

Verification

On Windows x64:

# C++20 header and client/test syntax compilation check
& "D:\DevTools\winlibs\mingw64\bin\g++.exe" -std=c++20 -fsyntax-only -I src tests/xmem_gpu_client.cpp tests/xmem_gpu_cross_dll_check.cpp
# Result: 0 (passes cleanly)

& "D:\DevTools\winlibs\mingw64\bin\g++.exe" -std=c++20 -fsyntax-only -I src -DX2W_TITLE_GPU_EXPORTS src/xmem_shim.cpp
# Result: 0 (passes cleanly)

# Documentation link verification
.\.venv\Scripts\python.exe -B tests/docs_links_check.py
# Result: Self-test passed. Checked 10 Markdown files and 114 links.

# Bidirectional controls check
.\.venv\Scripts\python.exe -B tests/bidi_controls_check.py
# Result: Self-test passed. Checked 478 tracked source, script and build/CI files: no bidirectional controls.

# Whitespace integrity check
git -c core.whitespace=cr-at-eol diff --check
# Result: 0 (clean)

Full MSVC CMake build and xmem_gpu_cross_dll_warp execution will be exercised in GitHub Actions Windows CI (windows.yml).

Evidence and follow-up

The fixture tests/xmem_gpu_client.cpp and runner tests/xmem_gpu_cross_dll_check.cpp exercise the cross-DLL C ABI round trip:

  • Attaching a null device reports E_INVALIDARG.
  • Attaching a valid D3D12 device aliases tracked title allocations.
  • Interior X2WTitleGpuLocate confirms correct resource resolution and byte offset arithmetic; out-of-bounds queries fail with HRESULT_FROM_WIN32(ERROR_NOT_FOUND).
  • X2WTitleGpuGetShaderView confirms two-call capacity checking and table generation matching TitleRange in src/title_va_lookup.hlsli.
  • Double X2WTitleGpuDetach behaves idempotently, followed by clean re-attach.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

Assisted by AI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6540399222 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/514). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T08:43:15Z. --- ## Change Exports the process-wide title GPU registry across DLL boundaries from `xmem.dll` via a clean, fixed-layout C ABI declared in `src/era_title_gpu_api.h`. Previously, `docs/experiments.md` noted: > "A D3D12 client in another DLL cannot reach the registry: a shared registry, with a fixture that loads both DLLs and shows the client sees the real provider's allocations, is left for the first such client." This change delivers that capability: - Exposes `X2WTitleGpuAttach`, `X2WTitleGpuDetach`, `X2WTitleGpuTranslate`, `X2WTitleGpuLocate`, and `X2WTitleGpuGetShaderView` in `src/xmem_shim.def` and `src/xmem_shim.cpp` with `X2W_TITLE_GPU_EXPORTS`. - Keeps `xmem.dll` decoupled from direct `d3d12.dll` imports on load so existing non-D3D12 startup tests (`xmem_shim_exports`) remain intact. - Adds client DLL fixture `tests/xmem_gpu_client.cpp` and harness `tests/xmem_gpu_cross_dll_check.cpp`. - Registers CTest target `xmem_gpu_cross_dll_warp` in `CMakeLists.txt` and documents the cross-DLL contract in `docs/experiments.md`. ## Verification On Windows x64: ```powershell # C++20 header and client/test syntax compilation check & "D:\DevTools\winlibs\mingw64\bin\g++.exe" -std=c++20 -fsyntax-only -I src tests/xmem_gpu_client.cpp tests/xmem_gpu_cross_dll_check.cpp # Result: 0 (passes cleanly) & "D:\DevTools\winlibs\mingw64\bin\g++.exe" -std=c++20 -fsyntax-only -I src -DX2W_TITLE_GPU_EXPORTS src/xmem_shim.cpp # Result: 0 (passes cleanly) # Documentation link verification .\.venv\Scripts\python.exe -B tests/docs_links_check.py # Result: Self-test passed. Checked 10 Markdown files and 114 links. # Bidirectional controls check .\.venv\Scripts\python.exe -B tests/bidi_controls_check.py # Result: Self-test passed. Checked 478 tracked source, script and build/CI files: no bidirectional controls. # Whitespace integrity check git -c core.whitespace=cr-at-eol diff --check # Result: 0 (clean) ``` Full MSVC CMake build and `xmem_gpu_cross_dll_warp` execution will be exercised in GitHub Actions Windows CI (`windows.yml`). ## Evidence and follow-up The fixture `tests/xmem_gpu_client.cpp` and runner `tests/xmem_gpu_cross_dll_check.cpp` exercise the cross-DLL C ABI round trip: - Attaching a null device reports `E_INVALIDARG`. - Attaching a valid D3D12 device aliases tracked title allocations. - Interior `X2WTitleGpuLocate` confirms correct resource resolution and byte offset arithmetic; out-of-bounds queries fail with `HRESULT_FROM_WIN32(ERROR_NOT_FOUND)`. - `X2WTitleGpuGetShaderView` confirms two-call capacity checking and table generation matching `TitleRange` in `src/title_va_lookup.hlsli`. - Double `X2WTitleGpuDetach` behaves idempotently, followed by clean re-attach. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. Assisted by AI.
upstream-sync closed this pull request 2026-11-24 06:43:27 +00:00
alexander-src commented 2026-11-24 06:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-22T08:50:00Z.


Reviewed 5990953 by reading the diff against src/era_title_gpu.{h,cpp} (static code review on Linux, did not build/run Windows tests). A few concrete issues in the C ABI and test harness:

  1. CMakeLists.txt sets only TIMEOUT 30 on xmem_gpu_cross_dll_warp without SKIP_RETURN_CODE 77, even though tests/xmem_gpu_cross_dll_check.cpp returns 77 when WARP creation fails. Also, if WARP does not support D3D12_FEATURE_EXISTING_HEAPS, X2WTitleGpuAttach() returns E_NOTIMPL and ClientTitleGpuRoundTrip() turns that into exit code 3 instead of a capability skip (77), unlike gpu_alias_registry_warp.
  2. In tests/xmem_gpu_cross_dll_check.cpp, MultiByteToWideChar(CP_UTF8, 0, argv[1], -1, path_buffer, MAX_PATH) does not check the return value. On a path longer than MAX_PATH (or invalid UTF-8), it returns 0 and LoadLibraryW gets an empty string instead of sizing a std::wstring via the two-call length query.
  3. In src/xmem_shim.cpp, X2WTitleGpuLocate() leaves *resource and *offset untouched on ERROR_NOT_FOUND. Zeroing *resource = nullptr; *offset = 0; before the lookup (after the null check) avoids exposing an uninitialized out-pointer across the C ABI on a miss.
  4. src/era_title_gpu.h (lines 20-22) still states that xmem.dll keeps only its four XMem* exports and cannot be reached from another DLL, which now contradicts docs/experiments.md.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7076764196 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/514#issuecomment-7076764196). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-22T08:50:00Z. --- Reviewed `5990953` by reading the diff against `src/era_title_gpu.{h,cpp}` (static code review on Linux, did not build/run Windows tests). A few concrete issues in the C ABI and test harness: 1. `CMakeLists.txt` sets only `TIMEOUT 30` on `xmem_gpu_cross_dll_warp` without `SKIP_RETURN_CODE 77`, even though `tests/xmem_gpu_cross_dll_check.cpp` returns `77` when WARP creation fails. Also, if WARP does not support `D3D12_FEATURE_EXISTING_HEAPS`, `X2WTitleGpuAttach()` returns `E_NOTIMPL` and `ClientTitleGpuRoundTrip()` turns that into exit code `3` instead of a capability skip (`77`), unlike `gpu_alias_registry_warp`. 2. In `tests/xmem_gpu_cross_dll_check.cpp`, `MultiByteToWideChar(CP_UTF8, 0, argv[1], -1, path_buffer, MAX_PATH)` does not check the return value. On a path longer than `MAX_PATH` (or invalid UTF-8), it returns `0` and `LoadLibraryW` gets an empty string instead of sizing a `std::wstring` via the two-call length query. 3. In `src/xmem_shim.cpp`, `X2WTitleGpuLocate()` leaves `*resource` and `*offset` untouched on `ERROR_NOT_FOUND`. Zeroing `*resource = nullptr; *offset = 0;` before the lookup (after the null check) avoids exposing an uninitialized out-pointer across the C ABI on a miss. 4. `src/era_title_gpu.h` (lines 20-22) still states that `xmem.dll` keeps only its four `XMem*` exports and cannot be reached from another DLL, which now contradicts `docs/experiments.md`.
agilesh08 commented 2026-11-24 06:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T09:46:23Z.


Closing for now to keep active review focused; will revisit after current PRs land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7077360388 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/514#issuecomment-7077360388). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T09:46:23Z. --- Closing for now to keep active review focused; will revisit after current PRs land.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!508
No description provided.