Skip to content

replay: copies between depth formats that differ go through transfer scratch (RT-DEPTH-FORMAT-COPY-STAGED) - #1893

Closed
OreoFR wants to merge 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-depth-format-copy-staged
Closed

OreoFR wants to merge 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-depth-format-copy-staged

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-DEPTH-FORMAT-COPY-STAGED (#1608 (comment))

What and why

A CopyTextureRegion of the depth plane from a D32_SFLOAT_S8_UINT image into a D32_SFLOAT one (D3D12: D32_FLOAT_S8X24 and D32_FLOAT) was replayed as vkCmdCopyImage. Vulkan requires depth/stencil formats to match exactly (VUID-vkCmdCopyImage-srcImage-01548). The NVIDIA driver runs the copy anyway and writes past the end of the D32 image.

That is the world-start WRITE_INVALID device loss ("crash A"):

  • with VK_EXT_device_address_binding_report, the fault address is the first byte after a 2560x1440 D32_SFLOAT image (bound size 0xF00000); the next binding starts 64 KiB later (finding: Coordinating who works on what (continued from #14) #1608 (comment));
  • with LEONIDA_VK_VALIDATION=1, this VUID for exactly that pair is reported just before the loss.

depth_format_pair (new, runtime/src/vulkan_replay.h): two depth formats with the same depth encoding but not the same VkFormat (D32_SFLOAT / D32_SFLOAT_S8_UINT, D16_UNORM / D16_UNORM_S8_UINT, X8_D24_UNORM_PACK32 / D24_UNORM_S8_UINT) now take the image → transfer scratch → image path that depth ↔ colour and the two A8 backings already use. In a buffer the depth aspect has the same texel layout on both sides (4 bytes for D32). A whole-resource copy between such a pair was already refused before this point (the aspects differ), so only the depth-plane CopyTextureRegion changes.

Tested

Not shown yet: these are few runs on one machine. Whether host image copies can stay on by default on NVIDIA (#1810, #1851) needs more runs with them on; I'm doing those and will report in #1608. After crash A, the next stop here is a list-values gate stall (gates time out, frames drop to 0), which this change doesn't address.

Depends on: none.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…scratch (RT-DEPTH-FORMAT-COPY-STAGED)

A CopyTextureRegion of the depth plane from a D32_SFLOAT_S8_UINT image into a
D32_SFLOAT one was replayed as vkCmdCopyImage. Vulkan requires depth/stencil
formats to match exactly (VUID-vkCmdCopyImage-srcImage-01548), and the NVIDIA
driver (RTX 4070 Laptop, 621.40) wrote past the end of the D32 image: the
world-start WRITE_INVALID device loss, with the fault at the first byte after a
2560x1440 D32_SFLOAT image (VK_EXT_device_address_binding_report) and this VUID
reported by the validation layer just before the loss.

depth_format_pair: two depth formats with the same depth encoding but not the
same VkFormat (D32 / D32S8, D16 / D16S8, X8_D24 / D24S8) take the image ->
scratch -> image path depth <-> colour and A8 copies already use; the depth
aspect has the same texel layout in a buffer on both sides.

replay_copy_offset_test: the D32S8 -> D32 and D32 -> D32S8 depth-plane copies
are staged (no vkCmdCopyImage, depth aspect, 4 bytes a texel), and D32 -> D32
keeps vkCmdCopyImage. Fails without the change (6 checks).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Snooozs

Snooozs commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Great find. Reviewed and checked on a second machine (Windows 10 19045, RTX 5060 Ti, NVIDIA 621.01, MSVC 14.43), no boot:

  • replay_copy_offset_test: exit 0 with the change; with vulkan_replay.h of main 446574e under the same test, 6 checks fail (the two D32S8/D32 directions), as you describe.
  • The staged path fits: the scratch is sized from the source's depth texel and both sides have the same encoding, so the second half reads what the first wrote.

One gap next to it, not a blocker. The same invalid vkCmdCopyImage is still recorded when the two depth formats have different encodings. I added three pairs to the test locally (depth plane, whole 64x32 image, your branch): each replays as success with one vkCmdCopyImage and nothing staged:

source depth plane destination
D24_UNORM_S8_UINT D16_UNORM
D24_UNORM_S8_UINT D32_SFLOAT
D32_SFLOAT_S8_UINT D16_UNORM

prepare_texture_copy compares aspects, volume, samples and rgb96, and texel bytes only when the block sizes differ; I found no format check in CopyTextureRegion either. D3D12 does not allow such a copy, but the layer can make one out of a legal console copy: format 118 (D16S8) is made as D24S8 on NVIDIA (console D16S8 textures are made as D24S8 in my log, D16_UNORM_S8_UINT: no), so its depth plane copied into a D16 texture becomes the first row, two bytes a texel too many for the destination. I have no evidence the title does that copy; your binding report plus validation would show it as the same VUID with that pair.

Refusing it with invalid_copy would drop the whole submission, so for a follow-up I would log such a pair once and leave that one copy out (an empty image_copies is already skipped in emit), until someone measures whether it needs a converting copy. I can do that on top of this pull request if you don't want it in here; say so and I'll claim it.

I'm running the rest of ctest on this branch now and will add the result. AI-assisted (Claude Code).

@OreoFR

OreoFR commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@Snooozs thanks for the second-machine check and for testing the other pairs. Agreed: I'll keep #1893 to the same-encoding pairs I could measure, and the different-encoding ones are yours to take as a follow-up (log once, leave that copy out). I'll keep an eye out for that VUID with those pairs in my validation runs.

AI-assisted.

@Snooozs

Snooozs commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Thanks, done as #1905 on top of this. Two corrections from doing it: my sentence that an empty image_copies is already skipped in emit was wrong (it falls through to the buffer-to-image branch), so #1905 uses an explicit flag; and the pairs here are staged without a sample-count check, while a multisampled image has no buffer copy - #1905 leaves a multisampled pair out, in case you want that check here already. AI-assisted (Claude Code).

StofflHD pushed a commit to StofflHD/leonida that referenced this pull request Nov 25, 2026
…py-staged

replay: copies between depth formats that differ go through transfer scratch (RT-DEPTH-FORMAT-COPY-STAGED)
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged into main as 9e7720c. GitHub created the merge commit, but its merge call returned an error, so this page has not switched to "merged" yet. Thank you, @OreoFR, and thanks to @Snooozs for the second-machine check and for taking the different-encoding pairs as #1905.

  • Claim: RT-DEPTH-FORMAT-COPY-STAGED in Coordinating who works on what (continued from #14) #1608 came before the PR and is unedited.
  • The change: small, and it reuses the existing image → scratch → image path. depth_format_pair only takes pairs with the same depth encoding, which matches VUID-vkCmdCopyImage-srcImage-01548.
  • Tested here: Windows suite under Wine (llvmpipe and an RDNA2 iGPU) on main + this branch. Nothing goes from pass to fail, and replay_copy_offset passes on both devices. xmem_no_write_watch failed once under load and passed 3/3 alone; it is the known XMem flake.
  • Real boot on an RX 7900 XTX (RADV, Mesa 26.3.1) with this PR: it reaches the world start as before. The device loss we see there on RADV is a different one, a texture-cache read fault, and this PR doesn't change it. So no RADV confirmation of crash A from us, and no regression either.
  • Checked on main b0f3d39 + daf31b8: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 3 changed files.

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

@aslan2142

Copy link
Copy Markdown
Collaborator

Closing only to fix this page's state: the change is already on main as 9e7720c ("Merge pull request #1893"), whose parent is this branch's head daf31b820. GitHub created that merge commit, but its merge call returned an error and never marked this PR as merged. Nothing is lost, and there's nothing left to review.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants