reprend #1259: d3d12: on Intel the GPU reads a fresh host import before it is handed out (RT-INTEL-IMPORT-SETTLE) #2727

Closed
github-bot wants to merge 3 commits from github-bot/gh-2727 into main AGit
Owner

@⁠OreoFR on GitHub · 2026-11-30 13:38 UTC · original
OreoFR:carry/pr-1259 → main · +155 −1 · 3 files · 3 commits · closed without merging

Carries #1259 by @⁠MalexAson, because it conflicts with main after #2566 and the reminder to merge main (#1259) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped.

Item: RT-INTEL-IMPORT-SETTLE-CARRY (claimed in #2570; original item RT-INTEL-IMPORT-SETTLE).

What this branch is

  • The author's branch at 2702cd33c, unchanged (no rebase, author commits kept).
  • A merge of main (from the carry preparation of 29/11) that resolves the conflict, then a merge of current main f9f3ec4c6 (no new conflict). Both merge commits carry Co-authored-by the author.
  • Nothing else: the change itself is the original PR's; see #1259 for what and why, and the verifications posted there.

What conflicted and how it was resolved

  • docs/d3d12_vulkan.md: main's Images row; the Heaps row gets main's two insertions and the PR's Intel paragraph.
  • runtime/shims/d3d12_vulkan_device.cpp (3 hunks): DeviceState keeps main's host_imports counter and the PR's settle_host_imports flag, and main's allocate_image next to the PR's settle_host_import.
  • The moved call, please read it: in Resource::create_host_buffer, main now holds DeviceState::memory_mutex() around the import's vkAllocateMemory. The PR called device_.settle_host_import(memory_, i) inside that loop, right after the allocation succeeded; settle_host_import allocates its 4-byte scratch buffer through allocate(), which takes the same mutex, so calling it there would re-lock it (the recursion GGandCo pointed out on #1259). The loop now only records the imported memory type (imported_type = i) under the lock, and device_.settle_host_import(memory_, imported_type) runs once, after the loop and the !memory_ check, before vkBindBufferMemory, outside the lock. Same call, same arguments, same point relative to the bind; its return value is ignored as in the PR. The other caller (OpenExistingHeapFromAddress) holds no lock and is unchanged.

The Intel path itself (settle_host_imports true only for vendor 0x8086) was not run here: a verifier with an Intel GPU is the useful one.

Tests

  • On this branch (main f9f3ec4c6 merged), Windows 11, Python 3.12, no GPU used: C++ only: left to this PR's CI (no local C++ build in this run).
  • Earlier merge (older main), Windows 11, RTX 4070 Laptop: d3d12_existing_heap*, d3d12_host_prefix, d3d12_mapped_plane_async 5/5 OK (NVIDIA: the Intel path is not exercised); gta6rt imports identical to main.
  • python -I scripts/check_no_game_data.py on every file this PR changes: clean.
  • CI on this PR covers the rest (C++ build and ctest, the full translator suite).

Depends on: none.

Needs an independent verifier before merge (red/green on another machine), as for any carry.

AI-assisted (Claude Code, oreofr-agent).

🤖 Generated with Claude Code

**@⁠OreoFR** on GitHub · 2026-11-30 13:38 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2727) `OreoFR:carry/pr-1259` → `main` · +155 −1 · 3 files · 3 commits · closed without merging Carries #1259 by @⁠MalexAson, because it conflicts with `main` after #2566 and the reminder to merge `main` (https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1259) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped. Item: `RT-INTEL-IMPORT-SETTLE-CARRY` (claimed in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570; original item `RT-INTEL-IMPORT-SETTLE`). ### What this branch is - The author's branch at `2702cd33c`, unchanged (no rebase, author commits kept). - A merge of `main` (from the carry preparation of 29/11) that resolves the conflict, then a merge of current `main` `f9f3ec4c6` (no new conflict). Both merge commits carry `Co-authored-by` the author. - Nothing else: the change itself is the original PR's; see #1259 for what and why, and the verifications posted there. ### What conflicted and how it was resolved - `docs/d3d12_vulkan.md`: `main`'s Images row; the Heaps row gets `main`'s two insertions and the PR's Intel paragraph. - `runtime/shims/d3d12_vulkan_device.cpp` (3 hunks): `DeviceState` keeps `main`'s `host_imports` counter and the PR's `settle_host_imports` flag, and `main`'s `allocate_image` next to the PR's `settle_host_import`. - **The moved call, please read it:** in `Resource::create_host_buffer`, `main` now holds `DeviceState::memory_mutex()` around the import's `vkAllocateMemory`. The PR called `device_.settle_host_import(memory_, i)` inside that loop, right after the allocation succeeded; `settle_host_import` allocates its 4-byte scratch buffer through `allocate()`, which takes the same mutex, so calling it there would re-lock it (the recursion GGandCo pointed out on #1259). The loop now only records the imported memory type (`imported_type = i`) under the lock, and `device_.settle_host_import(memory_, imported_type)` runs once, after the loop and the `!memory_` check, before `vkBindBufferMemory`, outside the lock. Same call, same arguments, same point relative to the bind; its return value is ignored as in the PR. The other caller (`OpenExistingHeapFromAddress`) holds no lock and is unchanged. The Intel path itself (`settle_host_imports` true only for vendor 0x8086) was not run here: a verifier with an Intel GPU is the useful one. ### Tests - On this branch (`main` `f9f3ec4c6` merged), Windows 11, Python 3.12, no GPU used: C++ only: left to this PR's CI (no local C++ build in this run). - Earlier merge (older `main`), Windows 11, RTX 4070 Laptop: `d3d12_existing_heap*`, `d3d12_host_prefix`, `d3d12_mapped_plane_async` 5/5 OK (NVIDIA: the Intel path is not exercised); `gta6rt` imports identical to `main`. - `python -I scripts/check_no_game_data.py` on every file this PR changes: clean. - CI on this PR covers the rest (C++ build and `ctest`, the full translator suite). Depends on: none. **Needs an independent verifier before merge** (red/green on another machine), as for any carry. AI-assisted (Claude Code, oreofr-agent). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Intel's Windows Vulkan driver (32.0.101.7092, Iris Xe) goes on working with a
host import's pages after vkAllocateMemory has returned, and loses the device
at the next vkQueueSubmit when the pages are freed before it is done, also
when vkFreeMemory came first. d3d12_existing_heap opens existing heaps,
releases them and frees their pages at once, so the device was already lost
when the title-placed buffer's copy was submitted: "ExecuteCommandLists
failed: unsupported", then a failed Signal, three times.

On an Intel GPU, OpenExistingHeapFromAddress and a title-placed buffer
(device slot 133) now copy four bytes out of the new import on the device's
queue and wait for that (DeviceState::settle_host_import) before the object
is handed out. Other vendors take the same path as before.

d3d12_existing_heap gains check_pages_freed_at_once: three existing heaps and
three placed buffers released with their pages freed at once, then a copy.
On the Iris Xe it fails 10 of 10 times without the layer change and passes
with it; an RTX 4060 passes either way.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
runtime/shims/d3d12_vulkan_device.cpp: DeviceState keeps main's host_imports
counter and the PR's settle_host_imports flag, and main's allocate_image next
to the PR's settle_host_import. In Resource::create_host_buffer (slot 133)
main now holds DeviceState::memory_mutex around the import's
vkAllocateMemory; settle_host_import allocates its scratch buffer through
allocate(), which takes that mutex, so the import records its memory type
under the lock and settle_host_import runs once the loop has left it (the
recursion GGandCo noted on the PR).
docs/d3d12_vulkan.md: main's Images row; the Heaps row gets main's two
insertions and the PR's Intel paragraph.

Co-authored-by: MalexAson <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Current main after #2566; no new conflicts on top of the earlier carry merge.

Co-authored-by: MalexAson <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 13:40:26 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-30 15:47 UTC · original

Verified by MoonEyes (another owner than OreoFR) on head a6b421f74 merged with main be7690805: Windows 11, MSVC 2022 x64, RelWithDebInfo, RTX 4060 8 GB (NVIDIA). ctest -R ^d3d12_existing_heap$: 1/1 passed. With d3d12_vulkan_device.cpp of main the same test passes too (1/1), so on this NVIDIA card it shows no regression but does not show the Intel defect.

Unit test only: no run of the title (this is the Vulkan path).

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-11-30 15:47 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2727#issuecomment-7283593787) Verified by MoonEyes (another owner than OreoFR) on head `a6b421f74` merged with `main` `be7690805`: Windows 11, MSVC 2022 x64, RelWithDebInfo, RTX 4060 8 GB (NVIDIA). `ctest -R ^d3d12_existing_heap$`: 1/1 passed. With `d3d12_vulkan_device.cpp` of `main` the same test passes too (1/1), so on this NVIDIA card it shows no regression but does not show the Intel defect. Unit test only: no run of the title (this is the Vulkan path). AI-assisted (Claude Code).
Author
Owner

@⁠KelboLive on GitHub · 2026-12-01 15:44 UTC · original · reviewed

The vendor gate, both call sites and the memory_mutex move check out, and the new path is functional on this machine when force-enabled (settle_host_imports = true builds, 3/3 ctests pass, no validation errors). On NVIDIA the feature is inert, as intended.

One blocker for Intel, though, and it is in the queue the new path creates. settle_host_import builds the shared device_.staging_queue as a plain VulkanQueue(*context, info.queue, info.queue_family) (d3d12_vulkan_device.cpp:13941-13942) with neither make_synchronous() nor set_skip_before_execute(true), while staged_copy only configures that queue when it creates it (:16471-16484). Whichever path creates it first wins, and the first host import normally happens at load, so on a real Intel title:

  • every later WriteToSubresource/ReadFromSubresource copy lands on info.queue, the title's own direct queue, instead of the spare queue the D9 note deliberately picked (:16463-16466);
  • before_execute_/after_execute_ (frame write-back and shadow refresh, :22020) now run for every internal staging copy — exactly what the flag at :16483 exists to forbid;
  • with LEONIDA_SUBMIT_ASYNC>0, execute() only enqueues (:3302, :3312) and staged_copy's wait_submitted() (:16491) can read a stale submitted_gpu_ (:3553-3555) and return before the copy ran, so ReadFromSubresource may unpack() (:16500) stale bytes.

Create the queue exactly as staged_copy does (or use a dedicated one), and prefer make_synchronous() + wait_submitted() over idle() (:13946) — that is vkQueueWaitIdle on the title's shared queue, which the same file notes blocks every submission (:3550-3552).

Test gap worth stating in the body: the new check_pages_freed_at_once passes with the feature on or off on this machine — replacing settle_host_import's body with return true still passes 3/3 — so it guards Intel CI only. One real Intel run before merge would cover what this box cannot.

Everything else here is clean: ctest -R d3d12_existing_heap 3/3, the LEONIDA_SUBMIT_ASYNC=2 run, the docs tests, check_no_game_data, and merge-tree against current main (685 commits behind, clean).

**@⁠KelboLive** on GitHub · 2026-12-01 15:44 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2727#pullrequestreview-6134668913) · **reviewed** The vendor gate, both call sites and the `memory_mutex` move check out, and the new path is functional on this machine when force-enabled (`settle_host_imports = true` builds, 3/3 ctests pass, no validation errors). On NVIDIA the feature is inert, as intended. **One blocker for Intel, though, and it is in the queue the new path creates.** `settle_host_import` builds the *shared* `device_.staging_queue` as a plain `VulkanQueue(*context, info.queue, info.queue_family)` (`d3d12_vulkan_device.cpp:13941-13942`) with neither `make_synchronous()` nor `set_skip_before_execute(true)`, while `staged_copy` only configures that queue **when it creates it** (`:16471-16484`). Whichever path creates it first wins, and the first host import normally happens at load, so on a real Intel title: - every later `WriteToSubresource`/`ReadFromSubresource` copy lands on `info.queue`, the title's own direct queue, instead of the spare queue the D9 note deliberately picked (`:16463-16466`); - `before_execute_`/`after_execute_` (frame write-back and shadow refresh, `:22020`) now run for every internal staging copy — exactly what the flag at `:16483` exists to forbid; - with `LEONIDA_SUBMIT_ASYNC>0`, `execute()` only enqueues (`:3302`, `:3312`) and `staged_copy`'s `wait_submitted()` (`:16491`) can read a stale `submitted_gpu_` (`:3553-3555`) and return before the copy ran, so `ReadFromSubresource` may `unpack()` (`:16500`) stale bytes. Create the queue exactly as `staged_copy` does (or use a dedicated one), and prefer `make_synchronous()` + `wait_submitted()` over `idle()` (`:13946`) — that is `vkQueueWaitIdle` on the title's shared queue, which the same file notes blocks every submission (`:3550-3552`). Test gap worth stating in the body: the new `check_pages_freed_at_once` passes with the feature on *or* off on this machine — replacing `settle_host_import`'s body with `return true` still passes 3/3 — so it guards Intel CI only. One real Intel run before merge would cover what this box cannot. Everything else here is clean: `ctest -R d3d12_existing_heap` 3/3, the `LEONIDA_SUBMIT_ASYNC=2` run, the docs tests, `check_no_game_data`, and `merge-tree` against current main (685 commits behind, clean).
Author
Owner

@⁠aslan2142 on GitHub · 2026-12-01 16:46 UTC · original

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

**@⁠aslan2142** on GitHub · 2026-12-01 16:46 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2727#issuecomment-7318212634) Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
github-bot closed this pull request 2026-12-01 16:56:29 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2727
No description provided.