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

Closed
OreoFR wants to merge 0 commits from upstream-pr/1893 into main
OreoFR commented 2026-11-25 14:49:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T14:49:58Z.


Claimed in the coordination issue as: RT-DEPTH-FORMAT-COPY-STAGED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7165740106)

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"):

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

  • replay_copy_offset_test (no GPU, fake Vulkan callbacks), new case: D32S8 → D32 and D32 → D32S8 depth-plane copies are staged (no vkCmdCopyImage, depth aspect on both halves, 4 bytes a texel), and D32 → D32 keeps vkCmdCopyImage. It fails without the change (6 checks) and passes with it. Built with MSVC 19.44.
  • scripts/check_no_game_data.py on the changed files, and tests/test_text_write_line_endings.py: OK.
  • Retail 1.0.2.1 boots, native Windows 11, RTX 4070 Laptop 8 GB, NVIDIA 621.40, LEONIDA_ASYNC_PIPELINES=1, LEONIDA_DEVICE_FAULT=1, counts only:
    • before the change: 6 of 6 runs lost the device with crash A, between 236 and 323 s (~4,800 to 5,300 ExecuteCommandLists), with host image copies off plus #1827, #1849 and #1698;
    • with the change and that same set: 2 runs without crash A (stopped by me at 6,493 and 6,398 ExecuteCommandLists); one of them under validation, which no longer reported the copy;
    • with the change on main alone (host image copies on, the default): no crash A; that run stopped at ~266 s with the other known stop ("crash B", lib_cs_01144 in flight, a type-4-only fault report), which #1849 addresses;
    • with the change and #1849, host image copies on: no device loss up to the time of writing (6,200+ ExecuteCommandLists).

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5493645474 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-25T14:49:58Z. --- Claimed in the coordination issue as: RT-DEPTH-FORMAT-COPY-STAGED (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7165740106) ### 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: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164893397); - 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 - `replay_copy_offset_test` (no GPU, fake Vulkan callbacks), new case: D32S8 → D32 and D32 → D32S8 depth-plane copies are staged (no `vkCmdCopyImage`, depth aspect on both halves, 4 bytes a texel), and D32 → D32 keeps `vkCmdCopyImage`. It fails without the change (6 checks) and passes with it. Built with MSVC 19.44. - `scripts/check_no_game_data.py` on the changed files, and `tests/test_text_write_line_endings.py`: OK. - **Retail 1.0.2.1 boots**, native Windows 11, RTX 4070 Laptop 8 GB, NVIDIA 621.40, `LEONIDA_ASYNC_PIPELINES=1`, `LEONIDA_DEVICE_FAULT=1`, counts only: - before the change: 6 of 6 runs lost the device with crash A, between 236 and 323 s (~4,800 to 5,300 `ExecuteCommandLists`), with host image copies off plus #1827, #1849 and #1698; - with the change and that same set: 2 runs without crash A (stopped by me at 6,493 and 6,398 `ExecuteCommandLists`); one of them under validation, which no longer reported the copy; - with the change on `main` alone (host image copies on, the default): no crash A; that run stopped at ~266 s with the other known stop ("crash B", `lib_cs_01144` in flight, a type-4-only fault report), which #1849 addresses; - with the change and #1849, host image copies on: no device loss up to the time of writing (6,200+ `ExecuteCommandLists`). **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](https://claude.com/claude-code)
Snooozs commented 2026-11-25 14:56:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-25T14:56:57Z.


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 446574e76 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166065911 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893#issuecomment-7166065911). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-25T14:56:57Z. --- 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` 446574e76 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 commented 2026-11-25 15:00:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-25T15:00:57Z.


@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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166169122 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893#issuecomment-7166169122). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-25T15:00:57Z. --- @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 commented 2026-11-25 15:29:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-25T15:29:09Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7166916317 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893#issuecomment-7166916317). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-25T15:29:09Z. --- 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).
aslan2142 commented 2026-11-25 16:25:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T16:25:05Z.


Merged into main as 9e7720c9e. 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 #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 b0f3d3998 + daf31b820: 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7167949018 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893#issuecomment-7167949018). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T16:25:05Z. --- Merged into `main` as 9e7720c9e. 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 #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` b0f3d3998 + daf31b820:** 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 commented 2026-11-25 16:32:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T16:32:32Z.


Closing only to fix this page's state: the change is already on main as 9e7720c9e ("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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7168145585 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1893#issuecomment-7168145585). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T16:32:32Z. --- Closing only to fix this page's state: the change is already on `main` as 9e7720c9e ("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).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1893
No description provided.