Skip to content

D3D12/Vulkan: fix copies within one texture subresource - #3348

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
s0las16:devin/1795377751-d3d12-graphics-fix
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
s0las16:devin/1795377751-d3d12-graphics-fix

Conversation

@s0las16

@s0las16 s0las16 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: claiming: new D3D item for #3232 — replay disjoint same-subresource copies in GENERAL and reject overlapping regions. Claim included here because this account cannot comment upstream.

What and why

D3D12 Enhanced Barriers allow a COMMON-layout subresource to copy between disjoint regions of itself. On first use, replay put the same mip into two different Vulkan layouts (VUID-vkCmdCopyImage-srcImage-09460). Use GENERAL for both sides with one read/write dependency, and reject intersecting regions before emitting GPU commands.

Tested

  • vk_command_replay_test: reproduced the layout error before the fix; after it, synchronization validation is clean, synthetic RGBA8 readback matches, and partial overlap is rejected.
  • CTest: command_list, vk_sync_validation, vk_bc_zero_init, replay_copy_offset, and replay_readback_stages passed.
  • Ubuntu 22.04, Mesa llvmpipe 23.2.1 (software Vulkan), LunarG validation 1.4.363.1. The Windows/MSVC runtime was not compiled locally, and the game was not run.
  • AI-assisted (Devin).

Checklist

  • No game data, keys or decryption.
  • Translator rule in the contract table (not applicable).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@hidrogenone

Copy link
Copy Markdown
Contributor

Tested 9e6544a3 on NVIDIA GeForce RTX 5080 (Blackwell), driver 32.0.16.2124, Windows 11, Vulkan SDK 1.4.357.0. Build: VS 2026 (MSVC 19.51), Windows SDK 10.0.26100, Ninja RelWithDebInfo.

vk_command_replay_test runs its sections A–J and exits 0 on this adapter — including the ones this PR touches:

G: one subresource copied twice in one list
J: disjoint same-subresource copies, overlapping copy rejected

First NVIDIA coverage for the within-one-subresource copy fix. AI-assisted.

@Desamodeth Desamodeth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 9e6544a3 on Windows 11, MSVC 19.44, physical RTX 5070 (NVIDIA 621.24), with Khronos validation 1.4.363 and synchronization validation enabled. The unmodified Release vk_command_replay_test passed all ten parts (A–J) with zero validation errors.

I also tried a vertical copy to complement J's horizontal case: two distinct pixels copied from the bottom row to the top row at the same X offset. All eight RGBA8 pixels matched, including the untouched columns. The PR rejected a partially overlapping copy during preparation. With only vulkan_replay.h restored to main f847748c, the same rejection assertion failed before command submission.

Synthetic textures only. AI-assisted with Codex.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 9e6544a36b2a24a5fe11f0c0a022ce630f325781.

The static review found the same-subresource path uses one GENERAL layout with a read/write dependency, and overlap is rejected before command submission. The existing independent test comment reports Release vk_command_replay_test A–J passing with synchronization validation on an RTX 5070, including vertical disjoint copy and overlap rejection. The PR also reports a llvmpipe run.

I did not compile the C++ target or rerun Vulkan locally; no game files were used. I found no correctness issue in the diff.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 9e6544a on Windows 11, RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1): ctest -R "replay_|command_list|vk_sync_validation|vk_bc_zero_init|d3d12_copy|d3d12_stencil_copy" (13 tests) plus vk_command_replay_test run directly (MSVC, RelWithDebInfo, LEONIDA_VK_DEVICE set per run) — no failures on either GPU.

  • RTX 5080: 12 passed, 1 skipped (vk_sync_validation: "LEONIDA_VK_VALIDATION is not set", and no validation layer is installed here); vk_command_replay_test exit 0.
  • AMD Radeon (gfx1036): 12 passed, same 1 skip; vk_command_replay_test exit 0.
    Not run: the full ctest suite, and no sync-validation run (no validation layer on this machine), so the PR's synchronization claims are only checked as far as the tests above run them.

AI-assisted.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 9e6544a merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • Whole run_gpu_tests.py: 185/199 native, 185/199 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.

No game files. AI-assisted (Claude Code).

@traeb0n

traeb0n commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code review of 9e6544a (read only, no runs): looks right to me.

  • The overlap test: |a - b| < size on each axis, using the block-padded width and height and the depth, is the condition for the source box and the destination box sharing a texel. D3D12 requires them not to overlap within one subresource, so invalid_copy matches it. The BC ↔ uncompressed branch returns earlier, but one image has one format, so it never sees the same subresource on both sides.
  • The layout: Vulkan allows the same subresource as both source and destination of vkCmdCopyImage only in GENERAL (or shared-present). Taking copy_layout(..., GENERAL, READ | WRITE) once and reusing it as dst_layout does that, and the tracker records GENERAL for the range, so the next barrier moves it from there.
  • Scope of the flag: it's set only on the texture-to-texture path, before any early return, and it's false otherwise.

One note for merge order: #2928 moves a copy's prepared data (source, the region vectors, staged*) from detail::Prepared into detail::PreparedCopy. same_copy_subresource is copy-only, so it belongs there, with a line in PreparedCopy::reset(), since entries are reused across executions. Whichever lands second, I'm glad to do the move.

AI-assisted (Claude Code).

@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9e6544a (merged onto main aa2988c) on RTX 3060 (Ampere), driver 617.14, Windows 11, MSVC 14.44, RelWithDebInfo: pass

  • ctest: 153/153 pass, also with LEONIDA_VK_VALIDATION=1 (153/153).
  • scripts/run_gpu_tests.py: native 164/210 (46 skipped), with LEONIDA_W64_EMULATE=1 195/210 (15 skipped). Same as main at aa2988c.
  • Eight *_test.exe programs that ctest does not register (d3d12_clear, tiny_game_exit_code, vk_bindless, vk_compute, vk_sampler, vk_store, vk_texture, vk_xdxr_build) were run by hand, with and without validation: same results as on main.
  • No game files used.

AI-assisted: this check was run and written with Claude Code (Anthropic) on my machine; the numbers above are its unedited output.

@ItsNotRexed
ItsNotRexed merged commit 29f6a3e into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
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.

9 participants