d3d12: stage title textures when their format or usage rules out host copies #1894
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1894"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T14:52:52Z.
Claimed as
RT-TITLE-STAGED-PER-FORMATin the coordination issue. This addresses the format-specific follow-up from the #1827 merge note.Depends on: #1827 (merged).
What and why
A Vulkan device can expose host image copy and still refuse it for a particular format or combination of image usages. In that case the runtime successfully created the image without host-transfer usage, but a subsequent title-texture refresh skipped its upload. Both a linear movie-plane fixture and a tiled compressed image returned incorrect bytes.
The runtime selects mandatory staging when the format, image usage or compatible memory types rule out host transfer. A GTX 1050 Ti reported no bindable memory type for a host-transfer R8 movie plane. Pascal hardware report A CPU-visible, single-sampled colour title image can use ordinary image memory and queue the upload when host transfer is unavailable. Images that can use either path retain the existing placement heuristic and host-backing retry. An allocation failure on an image that requires staging propagates normally.
Tested
Windows 11, NVIDIA GeForce RTX 4090 (616.64), MSVC 19.44. The test keeps host image copy enabled on the real device. A test shim masks the R8 format feature and separately rejects host-transfer usage in the BC1 image-support query.
446574e76with only the new test,d3d12_existing_heapfailed both readbacks: the persistently mapped R8 plane and the four-mip, two-slice BC1 array.14f04ce2d, both readbacks pass. All three existing heap CTests passed (default, write watch disabled, write watch enabled), including the unmasked controls.06ba2eb2d, a test shim reproduced the Pascal driver's empty memory type mask for a 256×8 R8 image. The previous head failed the pixel check. All three existing-heap CTests passed on the RTX 4090 with the fix, both with and without Vulkan validation. RTX 4090 test details2d258c8cd, the fallback logs the Vulkan format once per process for each affected format. The same three tests passed on the RTX 4090 with validation enabled and disabled (6/6). The shim produced exactly one format 9 (R8) fallback message in each test process.git diff --checkpassed.All texture inputs are synthetic. These tests exercise format-specific uploads and pixel readback on the reported GPUs.
AI-assisted: OpenAI Codex (
gpt-6.2-astra).Checklist
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-25T18:12:08Z.
Test report from a combined build on a second NVIDIA machine. Counts only.
Machine: Windows 11, RTX 4070 SUPER, NVIDIA 621.01, 64 GB, own 1.0.2.1 copy.
Build:
mainfe1553456(already contains #1827 and #1893), plus #674, #1662, #1851, #1849, #1905, #1957, #1950, #1886 and #1894. All of them merged without conflicts.Shaders: translated on
3de22a190+ #674 + #1662 with--wave64-emulate. 29,279 of 29,280 translated, and all 29,279 passspirv-val. That is 2,683 library programs and 29 of 29 FSPX.main's translator changes since then are correctness fixes only.Pipeline cache: warm and complete, 26,503 of 26,503 (9.6 GB).
ActivateRays,ActivateProbesandActivateProbesTargetprograms of indirect diffuse lighting.Recipe:
scripts/windows-boot/boot.ps1 -Seconds 480,LEONIDA_KEYBOARD_PAD=1 LEONIDA_SKIP_INT3=1 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_MAP_READBACK=1,LEONIDA_PIPELINE_CACHE_DIRpointing at the offline cache. Host image copy:off (auto: NVIDIA)from #1851. One run per row.LEONIDA_TITLE_WATCHDOG=0)game_scarlett_master.exe+0x23cf683)main42537e7b6+ #1631; my run table of 07:54 in #1608).AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T18:46:39Z.
Updated for
06ba2eb2d(Pascal memory-type fix). I rebuilt this head with #2020e500e9949. There is still one conflict inResource::create_texture. Keep #1894's side of the conflicting hunk and useconst bool can_stage = can_stage_title && (!shared_zero_ || no_host_copy);. All three existing-heap CTests passed on the RTX 4090 with Vulkan validation enabled, including the new zero-memory-type R8 fixture and #2020's shared BC placement checks.I tested this PR (
14f04ce2d) together with DadaCap's #2020 (e500e9949) on an RTX 4090, Windows 11, NVIDIA 616.64. The two heads have one merge conflict, inResource::create_texture. Git merged the documentation and test changes cleanly.For whoever rebases the second PR, the resolution I tested was to keep #1894's side of the conflicting hunk and replace
!shared_zero_incan_stagewith(!shared_zero_ || no_host_copy). The resulting declaration is:This keeps #2020's shared zero image eligible for a later staged upload when host image copies are disabled. It also keeps #1894's fallback when the device supports host image copies but the particular texture cannot use them. The rest of the source merged automatically.
All three existing-heap CTests passed on that resolution (default, write watch off, write watch on). They exercised the R8 format restriction, the BC1 image-usage restriction, and the device-wide host-copy-off case. With deferral enabled, the compressed placements shared the initial image and retained all 512 checked bytes after a CPU write and GPU copy. With
LEONIDA_PLACED_IMAGE_DEFER=0, the default CTest also passed and reported eager allocation with the same 512 bytes intact. These are synthetic GPU readbacks. AI-assisted verification with OpenAI Codex.Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-25T19:57:33Z.
Ran this on a GPU where the driver itself takes host image copy for the format but gives the HOST_TRANSFER image no memory type: Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB, no Resizable BAR), NVIDIA 582.66, MSVC RelWithDebInfo. Base main
9f9a7c5f3, with and without this PR (14f04ce2d, merged cleanly),d3d12_existing_heap*3x each, plain and withLEONIDA_VK_VALIDATION=1.Result is the same on both sides:
d3d12_existing_heap,_no_write_watchand_write_watchfail,d3d12_host_prefixpasses, no validation messages. The failure is the persistent slot-133 plane on the real (unmasked) device:The PR's own masked-R8 device and the
host_image_copy = falsedevice pass the same check here, so the new path works; it is just not taken for this case. ReadingResource::create_textureat14f04ce2d: for a placed LINEAR title image whose format does take host transfer,host_transfer_stays true, soneeds_stagingis false; the placement heuristic is skipped by!linear_placement; the image is created with HOST_TRANSFER;bind_texture_memorygetsmemoryTypeBits == 0; andcan_retry_hostis false, socreate_texturereturnsE_OUTOFMEMORY. The recreate-without-HOST_TRANSFER fallback from #1364 lives only in theorigin == ordinarybranch, so it never runs for title images.This predates the PR, but the PR is the natural place for it: treat "HOST_TRANSFER leaves no memory type" like "the format refuses host transfer". For example, when
can_stage && host_transfer_, checkdevice_.memory_requirements(info, with)up front and, ifwith.memoryTypeBits == 0, dropVK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT, sethost_transfer_ = falseand take theneeds_stagingbranch (any compatible type). This is the case Pascal hits for a movie plane, which is on the boot path. Happy to rerun a fix here.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T20:22:19Z.
@qhukz13, could you rerun
d3d12_existing_heap,d3d12_existing_heap_no_write_watchandd3d12_existing_heap_write_watchon the GTX 1050 Ti at06ba2eb2d? Your unmasked device is the check that matters here.The runtime now checks which memory types the host-transfer image can bind before choosing its backing. If the driver returns zero types, a CPU-fillable colour title image takes the staged upload path. This includes the mapped linear R8 plane from your report.
On the RTX 4090 (Windows 11, NVIDIA 616.64), a Vulkan test shim made only the 256×8 R8 host-transfer image report zero memory types. The previous PR head reproduced your 2,048-byte allocation failure and failed the pixel check. At the new head, all three CTests passed with validation off and all three passed with
VK_LAYER_KHRONOS_validationenabled. The original format and usage restrictions are also covered in those runs. All inputs were synthetic.AI-assisted with OpenAI Codex (
gpt-6.2-astra).Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-25T21:01:54Z.
Rerun at
06ba2eb2don the GTX 1050 Ti (Windows 10 Pro 19045, NVIDIA 582.66, MSVC RelWithDebInfo), merged onto main9f9a7c5f3, 3 runs each, plain and withLEONIDA_VK_VALIDATION=1:14f04ce2d06ba2eb2dd3d12_existing_heaptexture memory unavailable: 2048 bytes ... type bits 0x0 (vk format 9 256x8), plane check at line 1395)d3d12_existing_heap_no_write_watchd3d12_existing_heap_write_watchd3d12_host_prefix,d3d12_subresource_copyNo validation messages. So the real unmasked device is fixed, thanks.
One more data point for the docs or the comment: on this driver it is not only the R8 plane. A variant of the same check that logs (a local commit of mine on top of
14f04ce2d, same tests) took that branch for title images ofvk format 9(R8_UNORM),37(R8G8B8A8_UNORM) and133(BC1_RGBA_UNORM_BLOCK), so "Pascal gives a HOST_TRANSFER image no memory type" is the general case here, not an R8 quirk. Your head does not log that branch, so I could not count it there; alog_onceon it would make the next report easier.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-26T19:05:05Z.
One more data point for this PR, from a full
ctestbaseline on Pascal. On current main the title-placed texture tests fail, and with this PR they pass. GTX 1050 Ti, NVIDIA 582.66, Windows 10, both sides built from maine57bc63bc, the PR merged in cleanly:2d258c8cd)d3d12_existing_heapline 1530(pixels not61 * pass)d3d12_existing_heap_no_write_watchd3d12_existing_heap_write_watchd3d12_mapped_plane_asyncfirst use line 1584: filledd3d12_vulkan_deviceline 7362: heap_mismatches <= 0On main the log shows
slot 133 texture not created (hr 0x80070057, layout 6): dim 3 format 28 64x64x1 mips 12: an R8G8B8A8 texture the title places in its own memory is refused on this card, the HOST_TRANSFER case this PR handles. So the PR matters on Pascal for title-placed textures on that path in general, not only for the movie plane. Thed3d12_vulkan_devicefailure is unrelated: it fails identically on both sides.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by robot00f on 2026-11-27T05:57:29Z.
Independent check on real Pascal hardware of head
2d258c8c, for the case @qhukz13 reported on14f04ce2d(that commit predates the memory-type fix, so it could not have covered it).Machine: Windows 10 Pro 22H2 (19045), Intel Core i7-2600, 4 GB GeForce GTX 1050 Ti, NVIDIA 582.28, MSVC 19.44 RelWithDebInfo.
Setup:
maind1dff794, with only the two runtime files of this PR applied (clean 3-way apply; no commit, nothing pushed). The test binary was rebuilt from both trees with the same build directory.Before (
maind1dff794):d3d12_existing_heapfailed 3 of 3 runs, exit 1, at the persistent slot-133 plane check (std::all_of(pixels..., value == 61 * pass)), with this line twice per run:That is the real driver's
memoryTypeBits == 0for the 256x8 R8 plane, not the test shim, and it lands on the title-image branch (d3d12_vulkan_device.cpp, theorigin != TitleImageOrigin::ordinarypath) that had no recreate-without-host-transfer step.After (
2d258c8c): the same test passed 3 of 3 runs, exit 0, and the new line appeared 3 times per run:ctest -R "^d3d12_existing_heap"then reported 3 of 3 passed (the default,_no_write_watchand_write_watchentries). I stopped the repeated CTest iterations there, so the three CTest entries have one full pass each rather than three.Not covered by this check: validation layers were not enabled, other tests were not run, and only the memory-type branch above was exercised (the shim-forced paths were left alone).
AI-assisted (OpenCode, DeepSeek).
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-28T03:03:42Z.
I resolved the staging conflict locally using PR head
2d258c8cdand main02f71ccfe. Onlyruntime/shims/d3d12_vulkan_device.cppconflicted. In the single conflict block, keep the PR'sneeds_stagingbranch and change the first line of that block to:I also simplified the existing
no_host_copypredicate to!device_.copy_memory_to_image && cpu_copyable. This preserves main's shared-zero BC texture path when the device has no host image copy, alongside the PR's per-format fallback.RTX 4090, Windows 11, NVIDIA 616.64, Vulkan validation enabled. I ran the same synthetic texture checks on each tree, using a local driver restricted to the texture portion of the existing-heap fixture. The default, write-watch-on and write-watch-off runs all failed on main and all passed with the resolution. Shared BC1 placements preserved all 512 bytes after a CPU write and GPU copy with host image copies both enabled and disabled. The stock
d3d12_mapped_plane_asyncCTest also passed on the resolved tree. Both trees emitted the same device-destruction validation diagnostic (VUID-vkDestroyDevice-device-05137) during the focused runs.The public branch still needs the merge. GitHub declined the push because main brings CI workflow updates that the connected account lacks permission to publish. AI-assisted resolution and hardware verification using OpenAI Codex (GPT-6).
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-28T04:03:29Z.
The conflict resolution is on the public branch at
5c815be84b. I merged the upstream shared-BC change (e500e99494) into this PR. GitHub reports a clean merge. Its test merge438a5609ebhas parentsf77359c5b4(main) and5c815be84b(this PR), and treeb0d1bd5d66, identical to the tree I tested. The PR file list still uses an older base. The comparison against the tested main shows the three affected files. Three-file comparisonWindows 11, RTX 4090, NVIDIA 616.64, Vulkan validation enabled. I ran the synthetic texture portion of the existing-heap fixture in the default, write-watch-on and write-watch-off configurations. All three failed on plain
f77359c5b4with the PR's fixture (R8 plane and BC1 array readbacks). All three passed on the PR head and on the test merge. The stockd3d12_mapped_plane_asyncCTest also passed on the test merge. Main and the test merge both emittedVUID-vkDestroyDevice-device-05137at device teardown during the focused runs.AI-assisted integration and hardware verification using OpenAI Codex (GPT-6).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T02:36:05Z.
Independent Hardware Verification (RTX 3090, Windows 11,
VK_LAYER_KHRONOS_validation1.4.363.1)origin/main(04f484006e) + PR#1894(5c815be84b) — clean 3-way merge (0conflicts, confirming theshared_zero_integrationconst bool can_stage = can_stage_title && (!shared_zero_ || no_host_copy);inResource::create_texture).RelWithDebInfo), Vulkan SDK +VK_LAYER_KHRONOS_validation1.4.363.1(LEONIDA_VK_VALIDATION=1).Red -> Green Results
d3d12_existing_heapbuilt againstorigin/main'sruntime/shims/d3d12_vulkan_device.cpp):rc=8,9.40 s) when exercising the R8 format-feature mask, BC1 host-transfer usage rejection, and zero-memoryTypeBits256x8 R8 movie-plane shims.origin/main04f484006e+#18945c815be84b,LEONIDA_VK_VALIDATION=1):27.10 stotal):d3d12_existing_heap: Passed (shared BC1 placements, mapped R8 plane, mapped BC1 array, per-format R8/BC1 fallback, zero-memoryTypeBitsR8 plane fallback, andhost_image_copy = falsecontrols all matched)d3d12_mapped_plane_async: Passedd3d12_existing_heap_no_write_watch: Passedd3d12_existing_heap_write_watch: Passed (9.51 s)VUID-vkDestroyDevice-device-05137teardown message present identically onorigin/main).python -m unittest tests/test_docs_encoding.py tests/test_docs_repo_paths.py:6/6passed.python -I scripts/check_no_game_data.py docs/d3d12_vulkan.md runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_existing_heap_test.cpp: passed (0issues). No game files used.AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T05:47:48Z.
Verified by OreoFR — READY
c8bf0e7b6+ this PR (head5c815be84) merged with --no-ffd3d12_existing_heap,_no_write_watchand_write_watchall fail on main with the PR's new cases (slot 133 texture not created (hr 0x80070057)for a format-28 texture with no host copy).LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty), main + this PR alone; imports unchanged vs main (25 DLLs, 655 functions, no WS2_32)!needs_staging.AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T15:43:17Z.
Merged. Tested by @OreoFR on head
5c815be84(RTX 4070 Laptop 8 GB, Windows 11): red: d3d12_existing_heap(+_no_write_watch,_write_watch) fail on main (slot 133 texture not created); green pass. Correction: no CI check run or commit status exists for this head, so CI did not validate it. My earlier sentence about red jobs was wrong. Thanks @ecox982745!AI-assisted: yes