d3d12: fall back to staging copies when host-transfer image has no memory type #849

Closed
github-bot wants to merge 1 commit from gh-pr/849/head into gh-pr/849/base
Owner

@⁠kotekompotek on GitHub · 2026-11-24 14:32 UTC · original
kotekompotek:work/d3d12-host-image-copy-fix → main · +23 −3 · 2 files · 1 commits · closed without merging

Claimed in the coordination issue as: coordination issue #14

What and why

  • Rebased onto current main.
  • When creating a HOST_TRANSFER image returns memoryTypeBits == 0 in vkGetImageMemoryRequirements on drivers with identicalMemoryTypeRequirements = false, destroy the probe image, log once via log_once, clear VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, and fall back to staging copies; synced docs/d3d12_vulkan.md.

Tested

  • CTest d3d12_com (Passed, 0.61s), d3d12_d24_support (Passed, 0.39s), d3d12_shader_cache (Passed, 1.06s), and d3d12_subresource_copy (Passed, 0.79s) -> 4/4 Passed.
  • In d3d12_vulkan_device_test: both WriteToSubresource/ReadFromSubresource (host image copy) and (staging copy) matched ([rt] d3d12: host-transfer image had no usable memory type; falling back to staging copies, usage 4194311); pre-existing unrelated invalid arguments heap mismatch at line 7317 fails on this Windows host.

GPUs tested: NVIDIA GeForce GTX 1050 (driver 582.28, Windows)

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.
**@⁠kotekompotek** on GitHub · 2026-11-24 14:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/849) `kotekompotek:work/d3d12-host-image-copy-fix` → `main` · +23 −3 · 2 files · 1 commits · closed without merging Claimed in the coordination issue as: coordination issue #14 ### What and why - Rebased onto current `main`. - When creating a `HOST_TRANSFER` image returns `memoryTypeBits == 0` in `vkGetImageMemoryRequirements` on drivers with `identicalMemoryTypeRequirements = false`, destroy the probe image, log once via `log_once`, clear `VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT`, and fall back to staging copies; synced `docs/d3d12_vulkan.md`. ### Tested - CTest `d3d12_com` (`Passed`, 0.61s), `d3d12_d24_support` (`Passed`, 0.39s), `d3d12_shader_cache` (`Passed`, 1.06s), and `d3d12_subresource_copy` (`Passed`, 0.79s) -> `4/4 Passed`. - In `d3d12_vulkan_device_test`: both `WriteToSubresource/ReadFromSubresource (host image copy)` and `(staging copy)` matched (`[rt] d3d12: host-transfer image had no usable memory type; falling back to staging copies, usage 4194311`); pre-existing unrelated `invalid arguments heap` mismatch at line 7317 fails on this Windows host. GPUs tested: NVIDIA GeForce GTX 1050 (driver 582.28, Windows) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:24:27 +00:00
github-bot closed this pull request 2026-11-26 09:24:27 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 14:38 UTC · original · approved these changes

Audited and verified. On older Vulkan implementations (e.g. Pascal on NVIDIA 582.28) where VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT is accepted during create image queries but yields memoryTypeBits == 0 in memory requirements, destroying the provisional image and falling back to staging copies prevents spurious E_OUTOFMEMORY allocation failures. Clean error recovery and doc update in docs/d3d12_vulkan.md. Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 14:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/849#pullrequestreview-6041260641) · **approved these changes** Audited and verified. On older Vulkan implementations (e.g. Pascal on NVIDIA 582.28) where VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT is accepted during create image queries but yields memoryTypeBits == 0 in memory requirements, destroying the provisional image and falling back to staging copies prevents spurious E_OUTOFMEMORY allocation failures. Clean error recovery and doc update in docs/d3d12_vulkan.md. Approved.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 14:39 UTC · original · approved these changes

Clean-Room Audit & Architectural Review — PR #849 (d3d12-host-image-copy-fix)

Excellent fix for driver-specific Vulkan memory property reporting!

Architectural Verification

  1. Driver Anomaly Handling:
    • On drivers such as NVIDIA 582.28 (GTX 1050 family where identicalMemoryTypeRequirements == false), vkGetPhysicalDeviceImageFormatProperties2 accepts VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, but subsequent vkGetImageMemoryRequirements yields memoryTypeBits == 0.
    • The conditional check if (host_transfer_ && (created != VK_SUCCESS || !requirements.memoryTypeBits)) gracefully cleans up the provisional image handle (image_ = VK_NULL_HANDLE), clears the bit, and falls back to standard staging copies.
  2. Spec & Docs Conformance:
    • Correctly updates docs/d3d12_vulkan.md with the observed driver behavior.
    • Does not affect devices where host transfer works correctly.
  3. Clean-Room Compliance:
    • 0 game binaries, 0 proprietary headers, strictly conforming to the Vulkan specification and D3D12 layer runtime contract.

Verdict: APPROVED

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 14:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/849#pullrequestreview-6041274579) · **approved these changes** ### Clean-Room Audit & Architectural Review — PR #849 (`d3d12-host-image-copy-fix`) Excellent fix for driver-specific Vulkan memory property reporting! #### Architectural Verification 1. **Driver Anomaly Handling**: - On drivers such as NVIDIA 582.28 (GTX 1050 family where `identicalMemoryTypeRequirements == false`), `vkGetPhysicalDeviceImageFormatProperties2` accepts `VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT`, but subsequent `vkGetImageMemoryRequirements` yields `memoryTypeBits == 0`. - The conditional check `if (host_transfer_ && (created != VK_SUCCESS || !requirements.memoryTypeBits))` gracefully cleans up the provisional image handle (`image_ = VK_NULL_HANDLE`), clears the bit, and falls back to standard staging copies. 2. **Spec & Docs Conformance**: - Correctly updates `docs/d3d12_vulkan.md` with the observed driver behavior. - Does not affect devices where host transfer works correctly. 3. **Clean-Room Compliance**: - 0 game binaries, 0 proprietary headers, strictly conforming to the Vulkan specification and D3D12 layer runtime contract. **Verdict: APPROVED**
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:50 UTC · original

Thanks for this fix and for testing it on a GTX 1050. We're closing this in favour of #37, which makes the same
fix:

  • #37 detects the same case (memoryTypeBits == 0 on a host-transfer image) and also falls back when allocation
    or bind fails.
  • #37 sets image_ to VK_NULL_HANDLE after a failed vkCreateImage. Vulkan leaves output handles undefined
    after an error, so we never call vkDestroyImage on that value.
  • #37 adds a test-only force_host_transfer_retry switch, so d3d12_vulkan_device_test and
    d3d12_subresource_copy_test run the fallback path on any GPU and compare it with the host runtime. This PR's
    branch can only run on a Pascal driver.
  • Two things from here are worth keeping in #37:
    • your GTX 1050 / 582.28 result, as another data point;
    • a mention of the fallback in the "Every other case" sentence of docs/d3d12_vulkan.md.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/849#issuecomment-7142670217) Thanks for this fix and for testing it on a GTX 1050. We're closing this in favour of #37, which makes the same fix: - #37 detects the same case (`memoryTypeBits == 0` on a host-transfer image) and also falls back when allocation or bind fails. - #37 sets `image_` to `VK_NULL_HANDLE` after a failed `vkCreateImage`. Vulkan leaves output handles undefined after an error, so we never call `vkDestroyImage` on that value. - #37 adds a test-only `force_host_transfer_retry` switch, so `d3d12_vulkan_device_test` and `d3d12_subresource_copy_test` run the fallback path on any GPU and compare it with the host runtime. This PR's branch can only run on a Pascal driver. - Two things from here are worth keeping in #37: - your GTX 1050 / 582.28 result, as another data point; - a mention of the fallback in the "Every other case" sentence of `docs/d3d12_vulkan.md`. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.