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

Closed
OreoFR wants to merge 3 commits from upstream-pr/2727 into main
OreoFR commented 2026-11-30 13:38:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:38:14Z.


Carries #1259 by @MalexAson, because it conflicts with main after #2566 and the reminder to merge main (https://github.com/ProjectLeonida/mandy/pull/1259#issuecomment-7259384920) 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://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; 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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5566371014 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2727). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:38:14Z. --- Carries #1259 by @MalexAson, because it conflicts with `main` after #2566 and the reminder to merge `main` (https://github.com/ProjectLeonida/mandy/pull/1259#issuecomment-7259384920) 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://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; 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)
MoonEyes commented 2026-11-30 15:47:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T15:47:31Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283593787 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2727#issuecomment-7283593787). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T15:47:31Z. --- 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).
KelboLive commented 2026-12-01 15:44:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T15:44:01Z.

Review: COMMENTED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6134668913 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2727#pullrequestreview-6134668913). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T15:44:01Z. **Review:** COMMENTED --- 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).
aslan2142 commented 2026-12-01 16:46:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:46:40Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318212634 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2727#issuecomment-7318212634). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:46:40Z. --- 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.

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
ProjectLeonida/mandy!2727
No description provided.