d3d12: LEONIDA_HOST_IMAGE_COPY switch; auto leaves host image copies off on NVIDIA #1851
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1851"
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 QemmHD on 2026-11-25T13:07:50Z.
Depends on #1827 (DadaCap): without host image copies, title images only get filled once #1827 lands; otherwise they stay zero (verified by ecox982745 on an RTX 4090). Merge #1827 first.
The layer uses
VK_EXT_host_image_copyforWriteToSubresource/ReadFromSubresourcewhenever the device has the extension and itshostImageCopyfeature. On an RTX 4070 SUPER (Windows 11), a real boot lost the device with WRITE_INVALID in 7 of 7 runs that used host image copies and in 0 of 2 that didn't (481 s and 901 s, both still running at their time limits, up to 31,841ExecuteCommandListsand 7,960 presents). The mechanism is still open. Details, and what's been ruled out, are in #1608:What this adds:
LEONIDA_HOST_IMAGE_COPY.0: never.1: whenever available (the old behaviour).auto(the default; also for unset or unrecognised text): the same as1, except on NVIDIA (vendorID0x10DE), where it's off.When it's off, the extension is neither enabled nor chained, no image gets host-transfer usage, and every CPU texture copy takes the existing staging submit. That's exactly the path a device without the extension already takes. Device creation logs one line in place of the old "no VK_EXT_host_image_copy" line:
[rt] d3d12: host image copy: on|off (<reason>).Files
runtime/src/host_image_copy_policy.h(new): the choice as a pure function.runtime/test/host_image_copy_policy_test.cpp(new, registered ashost_image_copy_policy): the decision table (unset, empty,auto,0,1, other text) on NVIDIA, AMD and Intel, available and not.runtime/shims/d3d12_vulkan_device.cpp: uses the choice.runtime/README.mdanddocs/d3d12_vulkan.md: the variable, and whyautois off on NVIDIA.Tested (Windows 11, RTX 4070 SUPER, MSVC RelWithDebInfo):
ctest -j 4: 415/416. The only failure isd3d12_depth_resolve, the known NVIDIA MFAA sample-position case (#1505).autoand other text logoff (auto: NVIDIA);=0and=1log their own reason.test_runtime_pathsfailure).check_no_game_data.pyis clean.Cost and caveats
=1and with the default), and reports from AMD/Intel on whetherautoshould stay NVIDIA-only, are very welcome. If the mechanism turns out to be a layer usage error, the right fix replaces this default.Claimed in #1608 as RT-HOST-IMAGE-COPY-SWITCH.
AI-assisted (Claude Code, Claude Opus 5.5).
🤖 Generated with Claude Code
https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T13:16:23Z.
Please land #1827 before enabling the NVIDIA default in this PR. I reproduced the dependency on an RTX 4090 (Windows 11, NVIDIA 616.64) using the production
create_vulkan_device_standaloneentry point. Each run started a fresh process, so the runtime itself selected the extension and created the Vulkan device.LEONIDA_HOST_IMAGE_COPYauto/01auto/01Exact sources were #1851
59c1586d4and the same revision with the #1827ea6d535ffdiff applied. I tested unset,auto,0and1separately in both builds. Every passing BC7 run also preserved all 21 subresources after rewriting only mip 3 of array slice 2 and again after a submission with no writes. The CPUhost_image_copy_policytest passed in both builds.The R8 fixture was
check_mapped_planefromd3d12_existing_heap_test.cpp. The BC7 fixture used fenced GPU texture-to-buffer copies over 43,632 payload bytes per submission. This verifies texture contents under the proposed default and the forced-on control. Retail boot stability remains unmeasured in this run. Synthetic fixture details on #1827AI-assisted verification with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T13:19:29Z.
Review: COMMENTED
One more NVIDIA configuration: desktop RTX 4060 (Ada), driver 610.88, Windows 11, MSVC 19.44 RelWithDebInfo, head
59c1586d4.host_image_copy_policy: passes.d3d12_texture_memoryandd3d12_texture1d(both build the device throughcreate_vulkan_device_standalone, so they read the switch), run three times:LEONIDA_HOST_IMAGE_COPYhost image copy: off (auto: NVIDIA); CPU texture copies use a staging submit0host image copy: off (LEONIDA_HOST_IMAGE_COPY=0); CPU texture copies use a staging submit1host image copy: on (LEONIDA_HOST_IMAGE_COPY=1)These two only check that the switch is read and the device comes up; they do no CPU texture copies.
d3d12_subresource_copybuilds its own devices withhost_image_copyset per path, so it ignores the switch: in all three runs its host-image-copy and forced-retry paths reported 0 mismatches against the host and Microsoft's recorded answers (109 steps each). That says host copies are correct in this synthetic test on this card, not that the switch's staging path was exercised. None of this covers the BC7/R8 cases from the 4090 comment here (#1827).A driver fact that may help with the open mechanism: on this card and driver,
vulkaninforeportsidenticalMemoryTypeRequirements = false(VkPhysicalDeviceVulkan14Properties, promoted fromVkPhysicalDeviceHostImageCopyPropertiesEXT), withhostImageCopy = trueand 28 copy src/dst layouts. So addingVK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXTmay change an image's memory requirements on NVIDIA. The layer adds that usage (d3d12_vulkan_device.cpp6196); it comparesmemoryTypeBitswith and without that usage for staged title images (6237-6258) and retries without it when no type is allowed (6332), but not for ordinary textures. That fits your note that the switch also changes the images' memory type; it is a lead, not a cause.The in-game replication on a 4070 Laptop / 621.40 is in #1608 (made with a local
info.host_image_copy = false, not this switch). #1810 also acceptsoff(hereofffalls toauto, so stays on outside NVIDIA) and makes the test harness (vk_test_device.h) honour=0; this PR covers=0in the layer only.AI-assisted: yes (Claude Code ran the build and the tests; a separate agent checked this text against the logs and the code; I read both).
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T13:23:04Z.
@ecox982745 thank you, that's an important catch, and the table makes it unambiguous. Without host copies, title images take neither path before #1827, so
autoon NVIDIA would leave them zero. Agreed: this depends on #1827 and shouldn't land before it. I've marked that in the description. Next on this side: a real-boot run of #1851 + #1827 with the default (auto → off on NVIDIA) on the RTX 4070 SUPER, checking for both the device loss and textured captures. I'll post the result here and on #1827.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by madvillain91 on 2026-11-25T13:52:03Z.
Review: COMMENTED
Independent NVIDIA Ampere data point on Windows 11 26H2 (26300.9711) at
59c1586d4against main384abe5b0(PR base98c2f7777), using VS 2022 Build Tools (MSVC 19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, and NVIDIA GeForce RTX 3070 Ti (driver 617.14, Vulkan 1.4.351).vulkaninforeportshostImageCopy = trueandidenticalMemoryTypeRequirements = falseon Ampere / 617.14 as well.host_image_copy_policy_test: passed (all cases passed).d3d12_texture_memory_test&d3d12_texture1d_test(both viacreate_vulkan_device_standalone):[rt] d3d12: host image copy: off (auto: NVIDIA); CPU texture copies use a staging submit(2/2 passed)LEONIDA_HOST_IMAGE_COPY=0:[rt] d3d12: host image copy: off (LEONIDA_HOST_IMAGE_COPY=0); CPU texture copies use a staging submit(2/2 passed)LEONIDA_HOST_IMAGE_COPY=1:[rt] d3d12: host image copy: on (LEONIDA_HOST_IMAGE_COPY=1)(2/2 passed)d3d12_subresource_copy_test: passed.Also independently verified prerequisite #1827 on this same RTX 3070 Ti (
d3d12_existing_heap_teststagedhost_image_copy=falsepaths +d3d12_subresource_copy_test+d3d12_m2_textured_test, all 0 VUIDs underLEONIDA_VK_VALIDATION=1). Not checked: retail boot. LGTM (pending #1827 landing first as noted).AI-assisted verification.
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T13:53:45Z.
Note: #1810 by abnalstlll-byte (opened earlier) adds
LEONIDA_HOST_IMAGE_COPY=0/offfor the same finding. This PR overlaps it and addsauto(off on NVIDIA) plus a tested decision table. I've offered on #1810 to rebase this on top of it with credit, or to fold the extra parts into it, whichever the maintainers prefer. Still blocked on #1827 either way.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T14:53:11Z.
#1827 has landed on main (
ea6d535ff, via #1192 at3d4f66123), so the dependency is met: withautooff on NVIDIA, title images now take the staged upload instead of staying zero. This branch merges cleanly onto3d4f66123. Since the last update, real-boot counts on the 4070 SUPER: 0 of 8 runs lose the device with host image copies off, against 7 of 7 with them, across both console profiles and two mains. OreoFR/MoonEyes reproduced it on a 4070 Laptop (621.40). A review from a maintainer would be welcome. On the overlap with #1810, whichever shape the maintainers prefer is fine by me.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T14:56:20Z.
Data point, not a decision: with #1893 (fixes the D32S8 → D32 depth copy that wrote past the end of the D32 image) and host image copy on (default), I no longer get crash A on my RTX 4070 Laptop 8 GB, driver 621.40.
lib_cs_01144) at ~266 s. Crash A used to hit between 236 and 323 s on this build, so this run only partly covers that window.So turning host image copy off may no longer be needed against crash A. That is 2 runs on one machine. Could someone with a 12 GB+ card (and ideally one who reproduced A with host copy on) run #1893 with host image copy on before we decide on this PR?
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T15:08:08Z.
@OreoFR that's a much better explanation than mine: a mismatched-format depth copy writing past the D32 image fits everything I saw (a driver routine, no translated store, the fault just past an image). It also explains why host image copies off only hid it, by moving memory around. I'm running #1893 with host image copies ON on the RTX 4070 SUPER now (12 GB; it reproduced A in 7 of 7 runs without the switch): 2 runs of #1893 alone, 1 with #1849, and a control without #1893 on the same main. If #1893 clears A here too, this PR's NVIDIA default shouldn't land. I'd then reduce it to the plain switch, or close it in favour of #1810, and #1893 is the real fix.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by Diegobecker07 on 2026-11-25T15:36:57Z.
Data point for this PR, on a desktop RTX 5070 Ti 16 GB with NVIDIA 621.24 (Windows 11 Pro 26300, Ryzen 9 5900X, 48 GB, own 1.0.2.1). Counts only.
71a769d7d+ #1827 + #1851, RelWithDebInfo with MSVC 2022 and SDL3. Shaders translated at0d80bc5df; no translator files changed between that commit and71a769d7d.scripts/windows-boot/boot.ps1defaults, plusLEONIDA_TITLE_WINDOWS_MB=1024andLEONIDA_TITLE_WATCHDOG=0.LEONIDA_HOST_IMAGE_COPYoff (auto: NVIDIA))0xc0000005inamd_fidelityfx_upscaler_xbox.dll+0x65ff(FSPX 27/29, #1862)11withLEONIDA_VK_VALIDATION=10xc0000005VUID-vkCmdCopyImage-srcImage-01548(the D32S8 → D32 copy that #1893 fixes) did not appear before the run ended. stdout went to a file and the run ended in an access violation, so a message still in the buffer at the end could be missing. The only VUIDs were four pairs ofVkImageViewCreateInfo-image-06724/-subresourceRange-06725(baseArrayLayer6784 on a one-layer image), which #1860 covers.MiB copied so far: 1023) in three of the four boots.This doesn't contradict the 4070 SUPER result. If #1893's explanation holds (a copy that writes past the end of a D32 image), whether that write hits something that faults probably depends on what is bound after the image, which can differ between cards. Because the control boots didn't fail here, I didn't run #1893 on this card.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T15:37:44Z.
Thanks @Diegobecker07, that's useful: no loss with host copies on in 3 of 3 boots on a 16 GB 5070 Ti fits #1893's explanation. Whether the write past the D32 image faults depends on what's bound after it, which differs with VRAM size and allocation order. Right now on the 4070 SUPER (same driver, 621.24): a control boot of main without #1893, then #1893 ×2 with host copies on, then #1893 + #1849. If #1893 clears it here, I'll drop this PR's NVIDIA default.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T16:10:26Z.
Merge order suggestion: #1893 first. If QemmHD's 4070 SUPER runs confirm that #1893 clears crash A with host image copy on, this PR could keep only the opt-in switch (
LEONIDA_HOST_IMAGE_COPY=0) and drop the NVIDIA default. Host copy off costs upload performance on every NVIDIA card. Happy to rerun if needed.Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-25T16:13:01Z.
Retail data for the default question, from a 16 GB card: host image copies on did not lose the device here once #1893 was in, and leaving them off costs about 3.9 GB of VRAM at the world start.
RTX 4080 16 GB, NVIDIA 621.24, Windows 11 26300, 32 GB RAM. Local merge of main
b0f3d3998+ #1849 #1893 #1889 #1860 #1886 #1882 #1887 and this PR;LEONIDA_TITLE_WINDOWS_MB=4096,LEONIDA_ARENA_MB=2048,LEONIDA_TITLE_WATCHDOG=0,LEONIDA_DEVICE_FAULT=1, scripted keyboard pad.LEONIDA_HOST_IMAGE_COPYAll six got to the world start (frames stop, large compute pipelines build); none got further, so this says nothing about later crashes.
Memory with
LEONIDA_MEM_PROBE=1, one run each:With the 2,048 MiB arena on top, the off run is at about 14.3 GB of 16 GB by 150 s, and in the other off run the log has "a 5594624-byte allocation did not fit in device-local memory and went to memory type 0". So on 16 GB the off default pushes allocations into shared memory around the world start; with copies on there is room left.
Not checked: main without #1893 with copies on (so I cannot say #1893 is what makes it safe here), anything past the world start, more than one probe run per setting. The probe times differ (150 s and 237 s); the later one is the smaller, so the gap is not from running longer.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by quartz-heron-58 on 2026-11-25T16:13:13Z.
One detail to my table above: the 174 s run with copies on also had Snooozs's merge of #1592 with main and a translated fspx_gfx (16,914 programs); the other five runs are the merge exactly as listed.
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T16:22:59Z.
Thanks @OreoFR, @quartz-heron-58 and @abnalstlll-byte. #1893 has landed now, and quartz-heron-58's numbers settle the default question by themselves: host copies OFF cost about 3.9 GB of device-local memory at world start (12.3 GB vs 8.2 GB on a 4080), which pushes 12 GB cards into shared memory. So the NVIDIA
auto: offdefault should go. I'll rework this PR into the plain opt-in switch:LEONIDA_HOST_IMAGE_COPY=0to force staging, default on as before, with the one log line and the decision test kept. I'll push that after my A/B of #1893 on the 4070 SUPER finishes (on the build that lost the device in 7 of 7 runs), and post the counts here.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T17:04:22Z.
Correction to my last comment, with data. I said I'd drop the NVIDIA default once #1893 was in; on the RTX 4070 SUPER it isn't that simple. On the build that lost the device in 7 of 7 runs with host copies on, adding #1893 changed nothing: 2 of 2 valid runs still lost the device with the same signature (WRITE_INVALID, same offset mod 2 MiB, same instruction-pointer entry; a third run was void). A log of every image-to-image copy at the patched spot shows no copy between two depth formats at all before the loss, so #1893 had nothing to act on here. On this card it's a different trigger from OreoFR's world-start one. That's also consistent with Diegobecker07's and quartz-heron-58's 16 GB cards not losing the device with copies on.
The running tally on the 4070 SUPER: losses in 9 of 9 runs with host image copies, 0 of 8 without, and 0 of 1 with only the
vkCopyMemoryToImagecalls skipped (usage and memory type unchanged). That points at a host copy write itself. Before the loss, the only unusual image copies in that window are block-compressed uploads with mips down to 1×1. I'm bisecting which class of host write is needed (BC formats, sub-block mips, …) to turn this into a narrow fix, so copies can stay on for everything else (quartz-heron-58's 3.9 GB matters). Until then I'd keep this PR as it is, and I'll update it with the bisect.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T17:54:46Z.
Correction to my last comment: two things I said there don't hold.
vkCopyMemoryToImageskipped" run was on a main where the load crawls, and it never reached the point where the loss happens. It's not evidence, so please disregard it.What stands: with host image copies enabled the loss happens every time on that build (11 of 11); with the extension unused it doesn't (0 of 2 there, 0 of 6 on newer mains). So, as OreoFR suggested for their case, what the switch changes is most likely placement:
HOST_TRANSFERusage changes the images' memory type and where they're bound, and that decides whether some other operation's overrun lands on unmapped memory. On this card that operation isn't the depth copy #1893 fixed. I'm addingVK_EXT_device_address_binding_reportto the loss diagnostics, with unbind history (or using @MoonEyes's version if it's up), to name the object at the fault on this card.AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-25T18:11:59Z.
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 QemmHD on 2026-11-25T18:22:50Z.
Thanks @Tyrannys, that's the second RTX 4070 SUPER: with host image copies off (
autofrom this PR) no WRITE_INVALID in either run, against your earlier loss with them on. That matches mine (on/off 11/11 vs 0/8 on the build that reproduces it). Two things in your table are worth their own threads: the three ScreenProbes compute programs at 30-32 minutes each (and the NVVM failure when built together), and the session cache that isn't written once a seeded cache is over the 4 GiB limit (#1886).AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T19:00:27Z.
Moving this back to draft. New evidence on the RTX 4070 SUPER suggests the host-image-copy switch doesn't address the root cause of the world-start loss here: with copies off, the runs simply never reached the stage where the loss happens. So the 0-of-8 is not evidence of a fix. Please don't merge on the strength of my earlier counts. I'll follow up once the root cause is confirmed and a proper fix is tested.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-27T03:59:43Z.
Retail data from profile M (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Merged onto
maind1dff7949together with #2412, #2260, #2020, #2166 and #2418, it merged cleanly. The log line readshost image copy: off (LEONIDA_HOST_IMAGE_COPY=0); CPU texture copies use a staging submitwith the switch, andoff (auto: NVIDIA)without it. Four runs with host copies off and #2020, up to 815 s each: no device loss at all. Two were stopped by my memory guard, one by an unrelated hang (#2418), and one reached the world phase (more than 63k indirect draws). Host commit went up (37 GB private at peak in the world phase), so a small page file is not enough with this on.MEASURED (n=4). (Edited a minute after posting: the first version said the runs had compute-timeout losses; those were in other runs with host copies on.) AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T17:42:00Z.
A/B of this PR against main on one machine: same recipe, same pipeline cache folder, only the runtime executable changes (my recipe-diff tool reports exactly one difference). n=1 per side, indicative only.
Note for reviewers, from reading main
ec91d695c:LEONIDA_HOST_IMAGE_COPYis not read anywhere inruntime/; it appears only in a recipe indocs/running.md. On main,LEONIDA_HOST_IMAGE_COPY=0therefore leaves it active when the driver offers VK_EXT_host_image_copy (it does here: no "no VK_EXT_host_image_copy" line in the main log). With this PR merged, the log sayshost image copy: off (LEONIDA_HOST_IMAGE_COPY=0), so the variable takes effect (that line is read from the log).Reading (marked):
AI-assisted (Claude Code, Claude Opus 5.5)