Skip to content

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 into
ProjectLeonida:mainfrom
OreoFR:carry/pr-1259
Closed

OreoFR wants to merge 3 commits into
ProjectLeonida:mainfrom
OreoFR:carry/pr-1259

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Carries #1259 by @MalexAson, because it conflicts with main after #2566 and the reminder to merge main (#1259 (comment)) 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 (comment); original item RT-INTEL-IMPORT-SETTLE).

What this branch is

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 d3d12: on Intel the GPU reads a fresh host import before it is handed out (RT-INTEL-IMPORT-SETTLE) #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

MalexAson and others added 3 commits November 24, 2026 21:55
… out (RT-INTEL-IMPORT-SETTLE)

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 <noreply@anthropic.com>
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 <360820579+MalexAson@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Current main after ProjectLeonida#2566; no new conflicts on top of the earlier carry merge.

Co-authored-by: MalexAson <360820579+MalexAson@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MoonEyes

Copy link
Copy Markdown
Collaborator

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 KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

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 aslan2142 closed this Dec 1, 2026
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.

5 participants