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

Open
opened 2026-11-26 20:20:45 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1259
Author: @MalexAson
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/intel-host-import-settle


📝 Commits (1)

  • 2702cd3 d3d12: on Intel the GPU reads a fresh host import before it is handed out (RT-INTEL-IMPORT-SETTLE)

📊 Changes

3 files changed (+154 additions, -3 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+1 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+75 -2)
📝 runtime/test/d3d12_existing_heap_test.cpp (+78 -0)

📄 Description

Claimed in the coordination issue as: RT-INTEL-IMPORT-SETTLE

What and why

d3d12_existing_heap fails with the layer on an Intel Iris Xe: [rt] d3d12: ExecuteCommandLists failed: unsupported; nothing was submitted, then vulkan slot-133 buffer line 219: SUCCEEDED(queue->Signal(fence.p, 1)), three times. It passes on an RTX 4060 in the same machine. I reported it as a finding in https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142086637 and guessed wrong there: the copy out of the title-placed buffer is not at fault.

Which check says unsupported. None of the replay checks. vkQueueSubmit returns VK_ERROR_DEVICE_LOST for the first copy, VulkanQueue::submit marks the device lost, and execute_now reports a batch that was not submitted as unsupported. The second and third failure are execute_now refusing at its entry because the device is lost.

What loses the device. Not the title-placed buffer. With open_cases skipped the test passes on the Iris Xe; with only its write-combined 64 KiB case or only its 2 MiB case it fails; with all cases but without the VirtualFree at its end it passes. open_cases opens existing heaps, releases them and frees their pages at once. The heap frees its import in Release, as it should, but Intel's driver is not done with the pages yet.

A raw Vulkan program without the layer (vkAllocateMemory with a host pointer, vkFreeMemory, VirtualFree, then a copy between two ordinary buffers), Iris Xe, Intel 32.0.101.7092, runs that lost the device:

import lost
4 KiB 2 of 10
64 KiB 5 of 10
1 MiB, 16 MiB, 64 MiB 10 of 10 each
128 MiB, 256 MiB, 512 MiB 0 of 10 each
64 MiB, pages not freed 0 of 10
64 MiB, pages freed 50 µs later 11 of 20
64 MiB, pages freed 100 µs later 0 of 20 (1 of 20 with every core busy)
64 MiB, pages freed 1 ms later 0 of 20 (also with every core busy)
64 MiB, vkDeviceWaitIdle before the free 19 of 20
64 MiB, a vkQueueSubmit without command buffers and vkQueueWaitIdle before the free 20 of 20
64 MiB, a buffer bound to the import before the free 20 of 20
64 KiB, 1 MiB, 16 MiB, 64 MiB, a copy out of the import completed before the free 0 of 20 each

The delay counts from vkAllocateMemory, not from vkFreeMemory: 100 µs between the import and vkFreeMemory with the pages freed right after is 0 of 20 as well. No buffer has to be bound to the import for this. The memory type does not matter (type 1, flags 0x7, and type 2, flags 0xf, both lose it), nor does VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT or writing to the pages before the import. The RTX 4060 (NVIDIA 621.40) lost its device in 0 of 20 runs at 64 KiB, 1 MiB and 64 MiB. On the Iris Xe's own D3D12 driver, OpenExistingHeapFromAddress, Release, VirtualFree and a submitted copy keep the device in 10 of 10 runs at 1 MiB and at 64 MiB, so a title may do this.

The first copy out of a fresh import takes 0.1 to 0.5 ms for 64 KiB and 1.3 to 2.5 ms for 64 MiB, on both drivers, so that is where a driver takes hold of the pages, and afterwards freeing them loses nothing.

The change. DeviceState::settle_host_import: on an Intel GPU, OpenExistingHeapFromAddress and a title-placed buffer (device slot 133, create_host_buffer) copy four bytes out of the new import into a scratch buffer on the device's queue and wait for it, before the heap or buffer is handed out. It goes through the staging queue, as staged_copy does for WriteToSubresource. In the test it takes 0.3 to 0.8 ms per import on the Iris Xe. Other vendors run the same code as before.

d3d12_existing_heap_test gains check_pages_freed_at_once: three existing heaps and three placed buffers (64 KiB, 1 MiB, 16 MiB), each released with its pages freed at once, then a copy and GetDeviceRemovedReason. docs/d3d12_vulkan.md has the measurements in the "Heaps and placed resources" row.

Two things for a maintainer to decide.

  • The read is gated on the vendor ID (0x8086), because I could measure only Intel and NVIDIA and did not want to add a queue wait to every import on drivers that do not need it. D3D-417 applies its driver workaround on every GPU instead. If you prefer that here, it is one condition to drop; say so and I will.
  • It is a workaround for a driver that breaks the rule of VK_EXT_external_memory_host (the pages only have to stay valid while the VkDeviceMemory lives). I did not find a way to ask the driver whether it is done, so the read is what I measured to be enough, not something the specification promises.

Not covered: Intel Arc and Intel on Linux get the read without having been measured, AMD does not get it and was not measured. The 14 GiB whole-region import of RT-TITLE-HOST-REGION is another code path and is not touched.

Overlap: #644, #1100, #1190 and #1192 change the same two source files. This merges cleanly with the current head of each (git merge-tree), and it does not depend on any of them. #1192 reports that d3d12_existing_heap fails on clean main on an Intel UHD at the first aligned copy; that is probably this.

Tested

With MSVC 19.50 (Build Tools 2026), RelWithDebInfo, Windows 11 build 26100.6584, each on both GPUs through LEONIDA_VK_DEVICE. The numbers without the change and the raw-program numbers above were taken on main 58be9cdf8, the numbers with the change on main 66d4f5aa3:

  • d3d12_existing_heap without the change: fails on the Iris Xe in every run (the three lines above), passes on the RTX 4060. With it: 20 of 20 runs pass on each GPU.
  • check_pages_freed_at_once run alone, through a local switch that is not in this pull request: without the read it fails in 10 of 10 runs on the Iris Xe, at its queue->Signal; with it in 0 of 10; on the RTX 4060 it passes 10 of 10.
  • ctest -R "d3d12_existing_heap|d3d12_descriptor|d3d12_console_descriptor_heap|xmem" (xmem, d3d12_existing_heap, d3d12_xmem_placed, d3d12_descriptor, d3d12_console_descriptor_heap): 5 of 5 pass on both GPUs.
  • python -I scripts/check_no_game_data.py on the three changed files, and git diff --check.
  • Not run: the whole ctest (only these five targets were built), LEONIDA_VK_VALIDATION=1 (no validation layer on this PC), an AMD GPU, an Intel Arc, Linux or Wine.

GPUs tested: Intel Iris Xe (Raptor Lake-P, 8086:a7a0), Intel 32.0.101.7092, Windows 11 build 26100.6584; NVIDIA GeForce RTX 4060 Laptop GPU, NVIDIA 621.40, Windows 11 build 26100.6584

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not applicable: no translator change)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1259 **Author:** [@MalexAson](https://github.com/MalexAson) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/intel-host-import-settle` --- ### 📝 Commits (1) - [`2702cd3`](https://github.com/ubiquitarianism/leonida/commit/2702cd33cbbe3d9eb655bb30f1436dbfb7fbe0e5) d3d12: on Intel the GPU reads a fresh host import before it is handed out (RT-INTEL-IMPORT-SETTLE) ### 📊 Changes **3 files changed** (+154 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+1 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+75 -2) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+78 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-INTEL-IMPORT-SETTLE ### What and why `d3d12_existing_heap` fails with the layer on an Intel Iris Xe: `[rt] d3d12: ExecuteCommandLists failed: unsupported; nothing was submitted`, then `vulkan slot-133 buffer line 219: SUCCEEDED(queue->Signal(fence.p, 1))`, three times. It passes on an RTX 4060 in the same machine. I reported it as a finding in https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142086637 and guessed wrong there: the copy out of the title-placed buffer is not at fault. **Which check says `unsupported`.** None of the replay checks. `vkQueueSubmit` returns `VK_ERROR_DEVICE_LOST` for the first copy, `VulkanQueue::submit` marks the device lost, and `execute_now` reports a batch that was not submitted as `unsupported`. The second and third failure are `execute_now` refusing at its entry because the device is lost. **What loses the device.** Not the title-placed buffer. With `open_cases` skipped the test passes on the Iris Xe; with only its write-combined 64 KiB case or only its 2 MiB case it fails; with all cases but without the `VirtualFree` at its end it passes. `open_cases` opens existing heaps, releases them and frees their pages at once. The heap frees its import in `Release`, as it should, but Intel's driver is not done with the pages yet. A raw Vulkan program without the layer (`vkAllocateMemory` with a host pointer, `vkFreeMemory`, `VirtualFree`, then a copy between two ordinary buffers), Iris Xe, Intel 32.0.101.7092, runs that lost the device: | import | lost | | --- | --- | | 4 KiB | 2 of 10 | | 64 KiB | 5 of 10 | | 1 MiB, 16 MiB, 64 MiB | 10 of 10 each | | 128 MiB, 256 MiB, 512 MiB | 0 of 10 each | | 64 MiB, pages not freed | 0 of 10 | | 64 MiB, pages freed 50 µs later | 11 of 20 | | 64 MiB, pages freed 100 µs later | 0 of 20 (1 of 20 with every core busy) | | 64 MiB, pages freed 1 ms later | 0 of 20 (also with every core busy) | | 64 MiB, `vkDeviceWaitIdle` before the free | 19 of 20 | | 64 MiB, a `vkQueueSubmit` without command buffers and `vkQueueWaitIdle` before the free | 20 of 20 | | 64 MiB, a buffer bound to the import before the free | 20 of 20 | | 64 KiB, 1 MiB, 16 MiB, 64 MiB, a copy out of the import completed before the free | 0 of 20 each | The delay counts from `vkAllocateMemory`, not from `vkFreeMemory`: 100 µs between the import and `vkFreeMemory` with the pages freed right after is 0 of 20 as well. No buffer has to be bound to the import for this. The memory type does not matter (type 1, flags 0x7, and type 2, flags 0xf, both lose it), nor does `VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT` or writing to the pages before the import. The RTX 4060 (NVIDIA 621.40) lost its device in 0 of 20 runs at 64 KiB, 1 MiB and 64 MiB. On the Iris Xe's own D3D12 driver, `OpenExistingHeapFromAddress`, `Release`, `VirtualFree` and a submitted copy keep the device in 10 of 10 runs at 1 MiB and at 64 MiB, so a title may do this. The first copy out of a fresh import takes 0.1 to 0.5 ms for 64 KiB and 1.3 to 2.5 ms for 64 MiB, on both drivers, so that is where a driver takes hold of the pages, and afterwards freeing them loses nothing. **The change.** `DeviceState::settle_host_import`: on an Intel GPU, `OpenExistingHeapFromAddress` and a title-placed buffer (device slot 133, `create_host_buffer`) copy four bytes out of the new import into a scratch buffer on the device's queue and wait for it, before the heap or buffer is handed out. It goes through the staging queue, as `staged_copy` does for `WriteToSubresource`. In the test it takes 0.3 to 0.8 ms per import on the Iris Xe. Other vendors run the same code as before. `d3d12_existing_heap_test` gains `check_pages_freed_at_once`: three existing heaps and three placed buffers (64 KiB, 1 MiB, 16 MiB), each released with its pages freed at once, then a copy and `GetDeviceRemovedReason`. `docs/d3d12_vulkan.md` has the measurements in the "Heaps and placed resources" row. **Two things for a maintainer to decide.** - The read is gated on the vendor ID (0x8086), because I could measure only Intel and NVIDIA and did not want to add a queue wait to every import on drivers that do not need it. D3D-417 applies its driver workaround on every GPU instead. If you prefer that here, it is one condition to drop; say so and I will. - It is a workaround for a driver that breaks the rule of `VK_EXT_external_memory_host` (the pages only have to stay valid while the `VkDeviceMemory` lives). I did not find a way to ask the driver whether it is done, so the read is what I measured to be enough, not something the specification promises. Not covered: Intel Arc and Intel on Linux get the read without having been measured, AMD does not get it and was not measured. The 14 GiB whole-region import of RT-TITLE-HOST-REGION is another code path and is not touched. Overlap: #644, #1100, #1190 and #1192 change the same two source files. This merges cleanly with the current head of each (`git merge-tree`), and it does not depend on any of them. #1192 reports that `d3d12_existing_heap` fails on clean `main` on an Intel UHD at the first aligned copy; that is probably this. ### Tested With MSVC 19.50 (Build Tools 2026), RelWithDebInfo, Windows 11 build 26100.6584, each on both GPUs through `LEONIDA_VK_DEVICE`. The numbers without the change and the raw-program numbers above were taken on `main` 58be9cdf8, the numbers with the change on `main` 66d4f5aa3: - `d3d12_existing_heap` without the change: fails on the Iris Xe in every run (the three lines above), passes on the RTX 4060. With it: 20 of 20 runs pass on each GPU. - `check_pages_freed_at_once` run alone, through a local switch that is not in this pull request: without the read it fails in 10 of 10 runs on the Iris Xe, at its `queue->Signal`; with it in 0 of 10; on the RTX 4060 it passes 10 of 10. - `ctest -R "d3d12_existing_heap|d3d12_descriptor|d3d12_console_descriptor_heap|xmem"` (`xmem`, `d3d12_existing_heap`, `d3d12_xmem_placed`, `d3d12_descriptor`, `d3d12_console_descriptor_heap`): 5 of 5 pass on both GPUs. - `python -I scripts/check_no_game_data.py` on the three changed files, and `git diff --check`. - Not run: the whole `ctest` (only these five targets were built), `LEONIDA_VK_VALIDATION=1` (no validation layer on this PC), an AMD GPU, an Intel Arc, Linux or Wine. GPUs tested: Intel Iris Xe (Raptor Lake-P, 8086:a7a0), Intel 32.0.101.7092, Windows 11 build 26100.6584; NVIDIA GeForce RTX 4060 Laptop GPU, NVIDIA 621.40, Windows 11 build 26100.6584 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (not applicable: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#1291
No description provided.