runtime: fall back to staging copies when a HOST_TRANSFER image has no memory type (OLD-4682) #1364

Manually merged
github merged 3 commits from gh-pr/1364/head into gh-pr/1364/base 2026-11-26 09:48:55 +00:00
Owner

@⁠qhukz13 on GitHub · 2026-11-24 22:35 UTC · original
qhukz13:cont/old-4682 → main · +81 −17 · 5 files · 3 commits · merged 2026-11-24 23:15 UTC

Claimed in the coordination issue as: OLD-4682 (claim)

Carries #37 (old-pr/4682, TEST-995) onto current main. The three commits are cherry-picked unchanged with their
authors: ray3242 (the fallback), Gustavo Rafael Schmidt (the forced retry the tests use) and Rayhan Robin (log
wording, stale doc row). The only conflict was in docs/testing.md, where the first commit added a row about the
resource-heap-tier-1 comparison that the third commit removes again; the row is left out. #37 can be closed when
this lands.

What and why

On NVIDIA Pascal, a texture in a CPU-visible heap (CUSTOM write-back or write-combine, L0) is a texture the CPU reads
and writes with WriteToSubresource / ReadFromSubresource. The layer creates it with
VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT when the format reports VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT;
vkCreateImage succeeds, but vkGetImageMemoryRequirements then returns memoryTypeBits = 0, so no memory type
can back it and CreateCommittedResource answers E_OUTOFMEMORY where D3D12 creates the texture. The same image
without host-transfer usage takes device-local memory (memoryTypeBits = 0x82 on the card below).

Resource::create_texture now remakes such an unbound image without host-transfer usage and continues on the
staging-copy path, the one a device without VK_EXT_host_image_copy already uses. A failed vkCreateImage leaves
image_ null. VulkanDeviceInfo::force_host_transfer_retry lets d3d12_vulkan_device_test and
d3d12_subresource_copy_test take this branch on any GPU (their third CPU-copy path), so it is covered where the
driver does not reproduce it.

Tested

GeForce GTX 1050 Ti 4 GB (Pascal, no Resizable BAR), NVIDIA 582.66, Windows 10 Pro 19045, MSVC (VS 2022 Build
Tools), RelWithDebInfo. main at 4a50cafc7 against this branch, each test run 3 times
(ctest --repeat until-fail:3):

test main this branch
d3d12_subresource_copy fails (line 391, CPU copies (host image copy): the steps differ from the host's) passes, 3 of 3
d3d12_heap_properties, committed texture, CUSTOM write-back L0 and write-combine L0 ours 0x8007000e host 0x0 match the host
d3d12_vulkan_device, the CPU-heap texture (line 174) and the CPU copies (line 7046) fail pass; WriteToSubresource/ReadFromSubresource (staging copy): ... matched

The layer logs host-transfer image has no memory type; using staging copies, format 37 (and format 133) on this
card. root_sig and d3d12_state_sweep fail identically on both sides (this Windows 10 runtime refuses the
per-face stencil pipelines the layer accepts). Still failing on both, and not part of this PR: the
resource-heap-tier-1 comparisons, ALLOW_ALL heaps in d3d12_heap_properties and heap_mismatches (line 7330) in
d3d12_vulkan_device; on main the latter is not reached because the test stops at the CPU-heap texture first.

#37 also lists independent runs on a GTX 1060 6 GB (582.78), a GTX 1070 (581.80), a GTX 1050 Ti (560.94), an
RTX 3080 Ti and an RTX 3080, on its original base.

GPUs tested: NVIDIA GeForce GTX 1050 Ti, driver 582.66, Windows 10 19045. No game files.

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption (CONTRIBUTING.md).
  • A new translator rule is in the contract table of docs/design.md. (No translator change; the behaviour is
    documented in docs/d3d12_vulkan.md.)

🤖 Generated with Claude Code

**@⁠qhukz13** on GitHub · 2026-11-24 22:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1364) `qhukz13:cont/old-4682` → `main` · +81 −17 · 5 files · 3 commits · merged 2026-11-24 23:15 UTC Claimed in the coordination issue as: OLD-4682 ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)) Carries #37 (`old-pr/4682`, TEST-995) onto current `main`. The three commits are cherry-picked unchanged with their authors: ray3242 (the fallback), Gustavo Rafael Schmidt (the forced retry the tests use) and Rayhan Robin (log wording, stale doc row). The only conflict was in `docs/testing.md`, where the first commit added a row about the resource-heap-tier-1 comparison that the third commit removes again; the row is left out. #37 can be closed when this lands. ### What and why On NVIDIA Pascal, a texture in a CPU-visible heap (CUSTOM write-back or write-combine, L0) is a texture the CPU reads and writes with `WriteToSubresource` / `ReadFromSubresource`. The layer creates it with `VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT` when the format reports `VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT`; `vkCreateImage` succeeds, but `vkGetImageMemoryRequirements` then returns `memoryTypeBits = 0`, so no memory type can back it and `CreateCommittedResource` answers `E_OUTOFMEMORY` where D3D12 creates the texture. The same image without host-transfer usage takes device-local memory (`memoryTypeBits = 0x82` on the card below). `Resource::create_texture` now remakes such an unbound image without host-transfer usage and continues on the staging-copy path, the one a device without `VK_EXT_host_image_copy` already uses. A failed `vkCreateImage` leaves `image_` null. `VulkanDeviceInfo::force_host_transfer_retry` lets `d3d12_vulkan_device_test` and `d3d12_subresource_copy_test` take this branch on any GPU (their third CPU-copy path), so it is covered where the driver does not reproduce it. ### Tested GeForce GTX 1050 Ti 4 GB (Pascal, no Resizable BAR), NVIDIA 582.66, Windows 10 Pro 19045, MSVC (VS 2022 Build Tools), RelWithDebInfo. `main` at `4a50cafc7` against this branch, each test run 3 times (`ctest --repeat until-fail:3`): | test | `main` | this branch | |---|---|---| | `d3d12_subresource_copy` | fails (line 391, `CPU copies (host image copy): the steps differ from the host's`) | passes, 3 of 3 | | `d3d12_heap_properties`, `committed texture, CUSTOM write-back L0` and `write-combine L0` | `ours 0x8007000e host 0x0` | match the host | | `d3d12_vulkan_device`, the CPU-heap texture (line 174) and the CPU copies (line 7046) | fail | pass; `WriteToSubresource/ReadFromSubresource (staging copy): ... matched` | The layer logs `host-transfer image has no memory type; using staging copies, format 37` (and format 133) on this card. `root_sig` and `d3d12_state_sweep` fail identically on both sides (this Windows 10 runtime refuses the per-face stencil pipelines the layer accepts). Still failing on both, and not part of this PR: the resource-heap-tier-1 comparisons, `ALLOW_ALL` heaps in `d3d12_heap_properties` and `heap_mismatches` (line 7330) in `d3d12_vulkan_device`; on `main` the latter is not reached because the test stops at the CPU-heap texture first. #37 also lists independent runs on a GTX 1060 6 GB (582.78), a GTX 1070 (581.80), a GTX 1050 Ti (560.94), an RTX 3080 Ti and an RTX 3080, on its original base. GPUs tested: NVIDIA GeForce GTX 1050 Ti, driver 582.66, Windows 10 19045. No game files. AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption (CONTRIBUTING.md). - [ ] A new translator rule is in the contract table of `docs/design.md`. (No translator change; the behaviour is documented in `docs/d3d12_vulkan.md`.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Ported from @gustavorafaelschmidt's #3077 commit 2612b150 (author credited
below). With their go-ahead on #4682, keep one fix for both the empty-mask
driver case and the allocation-failure case this PR already handled:

- VulkanDeviceInfo::force_host_transfer_retry (tests only) forces the
  no-memory-type branch on any GPU, so d3d12_vulkan_device_test and
  d3d12_subresource_copy_test run their CPU copies through a third path.
- create_image() is a lambda that leaves image_ null after a failed create
  (the handle is undefined on failure and ~Resource destroys any non-null
  one), and log_once reports when the fallback fires.
- After dropping host-transfer usage, check_image_support is re-run before
  the image is made again; this PR's allocation/bind-failure retry is kept
  alongside it.
- docs/d3d12_vulkan.md and docs/testing.md record the Pascal measurement and
  the tier-1 host note.

The tier-1 heap/WARP comparison changes in #3077 are not part of this port:
they belong to D3D-504 (#5000). Tests on GTX 1060 / 582.78: both executables
built with MSVC 19.44; d3d12_subresource_copy_test OK with all three paths
(109 compared steps, 0 mismatches each); d3d12_vulkan_device_test's three
CPU-copy paths matched, with only the known pre-existing tier-1
heap_mismatches assert (D3D-504) still failing. No game data.

AI-assisted (OpenCode).

Original commit by Gustavo Rafael Schmidt <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:48:52 +00:00
github manually merged commit c3c5c82759 into gh-pr/1364/base 2026-11-26 09:48:55 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 23:15 UTC · original

Merged. Thanks for carrying this forward with the original authors kept on their commits.

  • Claim: valid. OLD-4682 was posted at 22:34 UTC, a minute before this PR, and is unedited. Nobody else had claimed it.
  • Same change as old-pr/4682: the added and removed lines are identical. The only difference is the docs/testing.md row that one commit added and a later one removed.
  • The change holds up: an image whose host-transfer usage leaves it with no memory type is destroyed and created once more without that usage, and both directions (writes and read-backs) follow host_transfer_ in the one function that does them. A real allocation failure still returns E_OUTOFMEMORY after the single retry. Nothing changes where host copies work.
  • Windows suite under Wine (clang-cl; llvmpipe and an RDNA2 iGPU, RADV), main 28a32e190 + this PR against that main: no test changed state on either device. d3d12_subresource_copy and d3d12_vulkan_device pass on both; on the iGPU all three copy paths ran (host image copy, staging, and the forced fallback) with 0 mismatches in 109 steps each.
  • On today's main d9f0a98e1 + c3c5c8275: it merges cleanly; the 13 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files. The merges into main since that suite run do not touch the files this PR changes.
  • Not measured here: the real case, an NVIDIA Pascal driver that gives the empty mask by itself, and native Windows. Those rest on the author's GTX 1050 Ti run and the NVIDIA runs listed on #37.
  • CI had not finished on this head.

A small follow-up if you like: the new docs/d3d12_vulkan.md row says driver 582.78 for the GTX 1050 Ti, while the run in the description was on 582.66.

#37, the carried-over draft of the same patch, is closed in favour of this one.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 23:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1364#issuecomment-7147186887) Merged. Thanks for carrying this forward with the original authors kept on their commits. - **Claim:** valid. `OLD-4682` was posted at 22:34 UTC, a minute before this PR, and is unedited. Nobody else had claimed it. - **Same change as `old-pr/4682`:** the added and removed lines are identical. The only difference is the `docs/testing.md` row that one commit added and a later one removed. - **The change holds up:** an image whose host-transfer usage leaves it with no memory type is destroyed and created once more without that usage, and both directions (writes and read-backs) follow `host_transfer_` in the one function that does them. A real allocation failure still returns `E_OUTOFMEMORY` after the single retry. Nothing changes where host copies work. - **Windows suite under Wine** (clang-cl; llvmpipe and an RDNA2 iGPU, RADV), `main` `28a32e190` + this PR against that `main`: no test changed state on either device. `d3d12_subresource_copy` and `d3d12_vulkan_device` pass on both; on the iGPU all three copy paths ran (host image copy, staging, and the forced fallback) with 0 mismatches in 109 steps each. - **On today's `main` `d9f0a98e1` + `c3c5c8275`:** it merges cleanly; the 13 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. The merges into `main` since that suite run do not touch the files this PR changes. - **Not measured here:** the real case, an NVIDIA Pascal driver that gives the empty mask by itself, and native Windows. Those rest on the author's GTX 1050 Ti run and the NVIDIA runs listed on #37. - **CI had not finished on this head.** A small follow-up if you like: the new `docs/d3d12_vulkan.md` row says driver 582.78 for the GTX 1050 Ti, while the run in the description was on 582.66. #37, the carried-over draft of the same patch, is closed in favour of this one. AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.