runtime: fix MSVC build failures in acphal and console descriptor heap shims #122

Closed
github-bot wants to merge 1 commit from gh-pr/122/head into gh-pr/122/base
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:23 UTC · original
ubiquitarianism:old-pr/9857 → main · +45 −17 · 5 files · 1 commits · closed without merging

Carried over from old PR 9857 by liamhob in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9857, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
This branch conflicts with the current main and needs a rebase.
liamhob: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

What and why

On \main\ (\2d53a8055), building the runtime on Windows with MSVC 19.44 fails in four files introduced by commits \ccd36246f\ and \3630610ca:

  1. **
    untime/shims/acphal.cpp**: \SHAPE_XMA_CONTEXT\ (60 bytes) and \SHAPE_PCM_CONTEXT\ (28 bytes) were each one \uint32_t\ short of their GDK \static_assert\ sizes (64 and 32 bytes). Updated
    eserved[10]\ ->
    eserved[11]\ and
    eserved[1]\ ->
    eserved[2].
  2. **
    untime/shims/d3d12_xs_device.h\ / \d3d12_xs_device.cpp**:
    • \proxy_create_descriptor_heap\ called
      t::d3d12::create_console_descriptor_heap\ directly without declaring it and broke linking in targets that compile \d3d12_xs_device.cpp\ without \gta6rt_d3d12_com\ (
      oot_sig_test, \device_proxy_test, \xs_proxy_mock_test, \pe_loader_test, etc.). Replaced with a registered \ConsoleDescriptorHeapHandler\ (\set_console_descriptor_heap_handler), matching the existing \PlacedAtVaHandler\ pattern.
    • Tightened the slot-14 console-extended desc check to require a plausible aligned canonical VA and matching non-zero heap byte size rather than any non-zero 64-bit word after the 16-byte struct—reading stack memory immediately after normal 16-byte PC \D3D12_DESCRIPTOR_HEAP_DESC\ structs was triggering false positives and causing 17+ D3D12 proxy tests to fail/segfault.
  3. **
    untime/shims/d3d12_vulkan_device.cpp**:
    • Registered \create_console_descriptor_heap\ in \Device::Device().
    • Added a non-const \DeviceState& state()\ overload and used \d->holder()\ instead of private \d->identity()\ in \create_console_descriptor_heap.
  4. **
    untime/test/d3d12_console_descriptor_heap_test.cpp**:
    • Added \operator->\ to \Ref, fixed \IID_PPV_ARGS\ + \AddRef()\ ownership when calling \create_device_proxy, and invoked Xbox heap proxy slot 9 via the Xbox-ABI RAX return convention.

Verification

  • Windows 11, MSVC 19.44, Ninja, Vulkan SDK 1.4.363.0, AMD Radeon RX 9070 XT (driver 26.10.1):
    • Full runtime build (\cmake --build runtime/build --parallel): 100% targets compile and link cleanly (exit 0).
    • ^Gcphal_test.exe: PASS (65/65 checks, 0 failures).
    • \d3d12_console_descriptor_heap_test.exe: PASS (\ok).
    • Full \ctest\ suite: 280/301 passed, 12 skipped, 0 segfaults (all 17 proxy-related regressions resolved).
    • \git diff --check\ and \python scripts/check_no_game_data.py: clean.
  • Synthetic tests only; no game files. AI-assisted.
**@⁠Andretuta** on GitHub · 2026-11-24 02:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/122) `ubiquitarianism:old-pr/9857` → `main` · +45 −17 · 5 files · 1 commits · closed without merging > Carried over from **old PR 9857** by `liamhob` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9857`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > This branch conflicts with the current `main` and needs a rebase. > `liamhob`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): ### What and why On \main\ (\2d53a8055\), building the runtime on Windows with MSVC 19.44 fails in four files introduced by commits \ccd36246f\ and \3630610ca\: 1. **\ untime/shims/acphal.cpp\**: \SHAPE_XMA_CONTEXT\ (60 bytes) and \SHAPE_PCM_CONTEXT\ (28 bytes) were each one \uint32_t\ short of their GDK \static_assert\ sizes (64 and 32 bytes). Updated \ eserved[10]\ -> \ eserved[11]\ and \ eserved[1]\ -> \ eserved[2]\. 2. **\ untime/shims/d3d12_xs_device.h\ / \d3d12_xs_device.cpp\**: - \proxy_create_descriptor_heap\ called \ t::d3d12::create_console_descriptor_heap\ directly without declaring it and broke linking in targets that compile \d3d12_xs_device.cpp\ without \gta6rt_d3d12_com\ (\ oot_sig_test\, \device_proxy_test\, \xs_proxy_mock_test\, \pe_loader_test\, etc.). Replaced with a registered \ConsoleDescriptorHeapHandler\ (\set_console_descriptor_heap_handler\), matching the existing \PlacedAtVaHandler\ pattern. - Tightened the slot-14 console-extended desc check to require a plausible aligned canonical VA and matching non-zero heap byte size rather than any non-zero 64-bit word after the 16-byte struct—reading stack memory immediately after normal 16-byte PC \D3D12_DESCRIPTOR_HEAP_DESC\ structs was triggering false positives and causing 17+ D3D12 proxy tests to fail/segfault. 3. **\ untime/shims/d3d12_vulkan_device.cpp\**: - Registered \create_console_descriptor_heap\ in \Device::Device()\. - Added a non-const \DeviceState& state()\ overload and used \d->holder()\ instead of private \d->identity()\ in \create_console_descriptor_heap\. 4. **\ untime/test/d3d12_console_descriptor_heap_test.cpp\**: - Added \operator->\ to \Ref<T>\, fixed \IID_PPV_ARGS\ + \AddRef()\ ownership when calling \create_device_proxy\, and invoked Xbox heap proxy slot 9 via the Xbox-ABI RAX return convention. ### Verification - Windows 11, MSVC 19.44, Ninja, Vulkan SDK 1.4.363.0, AMD Radeon RX 9070 XT (driver 26.10.1): - Full runtime build (\cmake --build runtime/build --parallel\): **100% targets compile and link cleanly** (exit 0). - \^Gcphal_test.exe\: **PASS** (65/65 checks, 0 failures). - \d3d12_console_descriptor_heap_test.exe\: **PASS** (\ok\). - Full \ctest\ suite: **280/301 passed**, 12 skipped, 0 segfaults (all 17 proxy-related regressions resolved). - \git diff --check\ and \python scripts/check_no_game_data.py\: clean. - Synthetic tests only; no game files. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:45:12 +00:00
github-bot closed this pull request 2026-11-26 08:45:12 +00:00
Author
Owner

@⁠wavehs on GitHub · 2026-11-24 02:28 UTC · original

macOS arm64 verification — close this as superseded: current main already contains every change, four times over, and the branch conflicts with main in all five files

Head 58a4b58dd (one commit, base 2d53a8055), main 9ec34cdff. git merge-tree --write-tree main 58a4b58dd exits 1 and conflicts in all five files (acphal.cpp, d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_vulkan_device.cpp, d3d12_console_descriptor_heap_test.cpp), so there is no merged tree to run; the branch cannot go in as it stands.

It also does not need to. Each of its five changes is already on main, from four commits dated 2026-11-24, each verified with git merge-base --is-ancestor <c> main:

This PR's change Already on main in
acphal.cpp: reserved[11] / reserved[2], both static_asserts db761be31 "give acphal's SHAPE contexts their GDK trailing words" — git diff main 58a4b58dd -- acphal.cpp is two comment lines, no code
slot 14 delegates through a registered ConsoleDescriptorHeapHandler; registration in Device::Device() a7ffc53c1 "route console slot-14 heap creation through a registered handler" (registered as &rt::d3d12::create_console_descriptor_heap, same place in the constructor)
the slot-14 layout gate 37246f11d "only take the console slot-14 layout when the descriptor size agrees", as console_heap_range_plausible()
test: AddRef() before create_device_proxy (the proxy takes ownership of one reference and releases it at refcount 0 — proxy_release, d3d12_xs_device.cpp:274) a7ffc53c1; main's test has the same AddRef/Release pair with the same comment
test: heap slot 9 called through the vtable in the RAX convention main reads the wrapped real heap instead (heap_proxy_real_heap, d3d12_console_descriptor_heap_test.cpp:96), but the RAX call itself is already in about ten runtime tests (d3d12_compute_test.cpp:39, d3d12_descriptor_test.cpp:46, d3d12_depth24_draw_test.cpp:42, d3d12_bindless_churn_test.cpp:50, …), so nothing is lost

That leaves exactly one substantive difference, the gate itself, and main's is the version I would keep. I extracted both rules into one C++ harness (clang++ -std=c++17 -fsanitize=undefined) and ran 14 boundary inputs: they agree on the two synthetic descs this PR's test uses (va=0x556677880000, size=128, n=4 and va=0x112233440000, size=256, n=8), and disagree on 8 of the other 12. The disagreements are the two shapes that matter:

  • main accepts a genuine call whatever the address (va=0x8000, va=0x12345, va=0x800000000000 with size == n*32); this PR rejects all three because it adds address >= 0x10000, < 2^47 and 256-byte alignment, none of which is measured anywhere in the repo.
  • this PR accepts any 16-aligned size in [n*16, n*128] (n=4, size=64, 144, 160, 512); main requires exactly n*32. main's exact stride is the stricter false-positive rule, and a title whose descriptor stride is not 32 (if there is one) fails loudly instead of being half-admitted by a window.

Neither rule is measured against a real title's (address, size) pair — the only pair in the tree is the synthetic one in the test — so don't rebase this branch to swap one guess for another. If the old PR's log captured the retail pair, post it on console_heap_range_plausible instead; that is the measurement both versions are missing.

What could not be tested here, and why that is not a gap for this PR: all five files sit inside if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) (runtime/CMakeLists.txt:19-20), so the macOS portable configure never compiles any of them — no MSVC, no VirtualQuery, no COM here. Because of that, the suites are unchanged by construction, and I confirmed the baselines on main 9ec34cdff itself: translator suite 463 files, 6,075 tests, 2 failed (test_exec_computed, test_image_atomics_guard, both known), GPU suite 248 fixtures (MoltenVK 182 passed/61 skipped/5 failed, KosmicKrisp 177/64/7, the same rows as before). Nothing this PR touches is read by the translator, the semantic tests or the GPU harness.

Negative control: the usual "run the new test against the base" is unavailable for MSVC-only code, so the control here is the other direction — the fix is already proved present on main by ancestry (db761be31, a7ffc53c1, 37246f11d are all ancestors of 9ec34cdff) and by the near-empty main → 58a4b58dd diffs above, plus the predicate harness that shows the two versions are not interchangeable.

Recommendation: close as superseded (main's a7ffc53c1 + 37246f11d + db761be31 carry it, and f9c68577e on main builds on top in the same file). Thank liamhob — the diagnosis was right; it landed through the other PRs. If anything is worth salvaging, it is the retail (address, size) measurement, not the code.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-24 02:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/122#issuecomment-7120187499) **macOS arm64 verification — close this as superseded: current `main` already contains every change, four times over, and the branch conflicts with `main` in all five files** Head `58a4b58dd` (one commit, base `2d53a8055`), `main` `9ec34cdff`. `git merge-tree --write-tree main 58a4b58dd` exits 1 and conflicts in **all five** files (`acphal.cpp`, `d3d12_xs_device.cpp`, `d3d12_xs_device.h`, `d3d12_vulkan_device.cpp`, `d3d12_console_descriptor_heap_test.cpp`), so there is no merged tree to run; the branch cannot go in as it stands. It also does not need to. Each of its five changes is already on `main`, from four commits dated 2026-11-24, each verified with `git merge-base --is-ancestor <c> main`: | This PR's change | Already on `main` in | |---|---| | `acphal.cpp`: `reserved[11]` / `reserved[2]`, both `static_assert`s | `db761be31` "give acphal's SHAPE contexts their GDK trailing words" — `git diff main 58a4b58dd -- acphal.cpp` is **two comment lines**, no code | | slot 14 delegates through a registered `ConsoleDescriptorHeapHandler`; registration in `Device::Device()` | `a7ffc53c1` "route console slot-14 heap creation through a registered handler" (registered as `&rt::d3d12::create_console_descriptor_heap`, same place in the constructor) | | the slot-14 layout gate | `37246f11d` "only take the console slot-14 layout when the descriptor size agrees", as `console_heap_range_plausible()` | | test: `AddRef()` before `create_device_proxy` (the proxy takes ownership of one reference and releases it at refcount 0 — `proxy_release`, `d3d12_xs_device.cpp:274`) | `a7ffc53c1`; `main`'s test has the same `AddRef`/`Release` pair with the same comment | | test: heap slot 9 called through the vtable in the RAX convention | `main` reads the wrapped real heap instead (`heap_proxy_real_heap`, `d3d12_console_descriptor_heap_test.cpp:96`), but the RAX call itself is already in about ten runtime tests (`d3d12_compute_test.cpp:39`, `d3d12_descriptor_test.cpp:46`, `d3d12_depth24_draw_test.cpp:42`, `d3d12_bindless_churn_test.cpp:50`, …), so nothing is lost | That leaves exactly one substantive difference, the gate itself, and `main`'s is the version I would keep. I extracted both rules into one C++ harness (`clang++ -std=c++17 -fsanitize=undefined`) and ran 14 boundary inputs: they agree on the two synthetic descs this PR's test uses (`va=0x556677880000, size=128, n=4` and `va=0x112233440000, size=256, n=8`), and **disagree on 8 of the other 12**. The disagreements are the two shapes that matter: - `main` accepts a genuine call whatever the address (`va=0x8000`, `va=0x12345`, `va=0x800000000000` with `size == n*32`); this PR rejects all three because it adds `address >= 0x10000`, `< 2^47` and 256-byte alignment, none of which is measured anywhere in the repo. - this PR accepts any 16-aligned size in `[n*16, n*128]` (`n=4, size=64`, `144`, `160`, `512`); `main` requires exactly `n*32`. `main`'s exact stride is the stricter false-positive rule, and a title whose descriptor stride is not 32 (if there is one) fails loudly instead of being half-admitted by a window. Neither rule is measured against a real title's `(address, size)` pair — the only pair in the tree is the synthetic one in the test — so don't rebase this branch to swap one guess for another. If the old PR's log captured the retail pair, post it on `console_heap_range_plausible` instead; that is the measurement both versions are missing. **What could not be tested here, and why that is not a gap for this PR:** all five files sit inside `if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)` (`runtime/CMakeLists.txt:19-20`), so the macOS portable configure never compiles any of them — no MSVC, no `VirtualQuery`, no COM here. Because of that, the suites are unchanged by construction, and I confirmed the baselines on `main` `9ec34cdff` itself: translator suite **463 files, 6,075 tests, 2 failed** (`test_exec_computed`, `test_image_atomics_guard`, both known), GPU suite **248 fixtures** (MoltenVK 182 passed/61 skipped/5 failed, KosmicKrisp 177/64/7, the same rows as before). Nothing this PR touches is read by the translator, the semantic tests or the GPU harness. **Negative control:** the usual "run the new test against the base" is unavailable for MSVC-only code, so the control here is the other direction — the fix is already proved present on `main` by ancestry (`db761be31`, `a7ffc53c1`, `37246f11d` are all ancestors of `9ec34cdff`) and by the near-empty `main → 58a4b58dd` diffs above, plus the predicate harness that shows the two versions are not interchangeable. Recommendation: close as superseded (main's `a7ffc53c1` + `37246f11d` + `db761be31` carry it, and `f9c68577e` on main builds on top in the same file). Thank `liamhob` — the diagnosis was right; it landed through the other PRs. If anything is worth salvaging, it is the retail `(address, size)` measurement, not the code. No game files. AI-assisted.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:49 UTC · original

Thank you for this fix. The diagnosis was right, and current main already has it, so I'm closing this draft as superseded:

  • acphal.cpp: the SHAPE XMA/PCM contexts are 64 and 32 bytes (#2, db761be31, and the XMA context was reworked since then), so both static_asserts hold.
  • Slot 14: the proxy reaches the Vulkan layer through set_console_descriptor_heap_handler, the same way slot 133 does. Every Vulkan Device registers it, and a Device member builds the heap (#2, a7ffc53c1). #4 (37246f11d) takes the console layout only when the trailing size equals NumDescriptors * 32, so PC callers are no longer caught by the stack bytes after their desc.
  • d3d12_console_descriptor_heap_test compiles and passes (operator->, the reference handling of create_device_proxy, the start read through heap_proxy_real_heap).

The Runtime windows job compiles all of these files with MSVC 14.52 again. The remaining slot-14 false positive (a stray 32 after a one-descriptor desc) is handled in #1148. If anything from this branch is still missing, please open a new PR from current main. The old-pr/* branch stays, and #17 lists the carried-over drafts.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/122#issuecomment-7142645286) Thank you for this fix. The diagnosis was right, and current `main` already has it, so I'm closing this draft as superseded: - `acphal.cpp`: the SHAPE XMA/PCM contexts are 64 and 32 bytes (#2, `db761be31`, and the XMA context was reworked since then), so both `static_assert`s hold. - Slot 14: the proxy reaches the Vulkan layer through `set_console_descriptor_heap_handler`, the same way slot 133 does. Every Vulkan `Device` registers it, and a `Device` member builds the heap (#2, `a7ffc53c1`). #4 (`37246f11d`) takes the console layout only when the trailing size equals `NumDescriptors * 32`, so PC callers are no longer caught by the stack bytes after their desc. - `d3d12_console_descriptor_heap_test` compiles and passes (`operator->`, the reference handling of `create_device_proxy`, the start read through `heap_proxy_real_heap`). The Runtime `windows` job compiles all of these files with MSVC 14.52 again. The remaining slot-14 false positive (a stray `32` after a one-descriptor desc) is handled in #1148. If anything from this branch is still missing, please open a new PR from current `main`. The `old-pr/*` branch stays, and #17 lists the carried-over drafts. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.