Skip to content

d3d12: depth and stencil copies with a buffer on a COPY or COMPUTE family without graphics need maintenance10 (RT-784) - #8871

Closed
Luqueze wants to merge 2 commits into
ProjectLeonida:mainfrom
Luqueze:rt-784-depth-stencil-copy-queue
Closed

Luqueze wants to merge 2 commits into
ProjectLeonida:mainfrom
Luqueze:rt-784-depth-stencil-copy-queue

Conversation

@Luqueze

@Luqueze Luqueze commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-784 (#8186 (comment))

What and why

When the GPU has a transfer-only (DMA) family, the layer puts COPY queues there, and COMPUTE queues go on an async-compute family. Neither family has graphics. On such a family Vulkan allows a copy between a buffer and a depth or stencil aspect only with VK_KHR_maintenance10 and the format's *_COPY_ON_{TRANSFER,COMPUTE}_QUEUE feature (VUID-vkCmdCopyBufferToImage-commandBuffer-07739 and -11781, VUID-vkCmdCopyImageToBuffer-commandBuffer-10216). The layer checked neither, so every footprint upload or readback of a depth texture on a COPY queue was invalid usage. On an RTX 4070 SUPER it also gave a wrong result: a D32S8 stencil-plane upload on the transfer family is left unwritten, both with and without validation (texel (1,0) reads 0, wrote 1). Native D3D12 accepts and runs the same copy.

  • runtime/shims/d3d12_vulkan_device.cpp: enables VK_KHR_maintenance10 with its feature on a Vulkan 1.3 device (the format features are read with VkFormatProperties3, core in 1.3), the same way as maintenance8. register_off_graphics_families takes the COPY and COMPUTE families without graphics and records, once, which depth and stencil aspects each depth/stencil format may copy there. The queue families are now enumerated once in the constructor and shared with the transfer-only, predication, timestamp and sparse checks.
  • runtime/src/vulkan_replay.h: OffGraphicsCopies (a fixed table: format → aspects) and ReplayFunctions::off_graphics, null on a family with graphics. detail::buffer_aspect_copy_allowed checks the three places the layer copies between a buffer and a depth or stencil aspect: footprint copies, the copy that ends the D24-as-D32 conversion (its pass also runs on an async-compute family), and both halves of a staged depth ↔ colour copy. A copy the family cannot run returns ReplayResult::unsupported, the same way D24/RGB96 conversions are already kept off a transfer-only queue. Image-to-image depth copies (vkCmdCopyImage) have no such rule and are unchanged.
  • runtime/src/vulkan_backend.h: VulkanContext::set_off_graphics_family. Each queue points its replay at its family's table: no allocation or copy per ExecuteCommandLists.
  • docs/d3d12_vulkan.md: the ID3D12CommandQueue row describes the rule and what was measured.

Refusing drops the whole batch, as for the other refusals on these queues. Running such a copy on a graphics-family queue with a semaphore handoff instead would keep it working on GPUs without the feature (or for the D32S8 stencil on NVIDIA). That is a larger change and could be a follow-up.

Tested

Windows 11 Pro (10.0.26300), NVIDIA GeForce RTX 4070 SUPER, driver 32.0.16.1742, Vulkan SDK 1.4.363.0, MSVC 14.44 (VS Build Tools 2022), RelWithDebInfo, LEONIDA_VK_VALIDATION=1 (synchronization validation on). On this GPU the COPY queues land on family 1 (TRANSFER | SPARSE_BINDING), the driver exposes VK_KHR_maintenance10, and the transfer-queue copy feature is set for the depth aspect of every depth format but not for the D32S8 stencil aspect.

  • New d3d12_copy_queue_depth_test (synthetic, no game files). It runs five copies on a COPY queue, with explicit COMMON ↔ copy-state barriers, on the layer and on native D3D12, and compares each with the expected outcome for this GPU (from the queue family's flags and the format features the driver reports: run, or refused):

    case before this PR with it native D3D12
    depth upload (D32) matched, VUID 07739 matched matched
    stencil upload (D32S8 plane 1) wrong data, VUID 07739 + 11781 refused (expected) matched
    depth readback on COPY matched, VUID 10216 matched matched
    depth → depth (vkCmdCopyImage) matched matched matched
    depth → colour (D32 → R32_FLOAT, staged) — (case added later) matched matched

    Validation errors: 8 before the change, 0 with it.

  • d3d12_vulkan_device_test gains a check that maintenance10 is enabled exactly when the GPU offers it on a 1.3 device, like the one for maintenance8. On this machine the test already fails earlier, at line 6574 (tiles == 1), the same as on main, so the new check did not run here.

  • Full ctest --test-dir runtime/build -C RelWithDebInfo with validation, rebased on main 867d922: 261 of 266 pass. The 5 that fail (vk_queue, d3d12_vulkan_device, d3d12_depth_resolve, d3d12_indirect_rt, d3d12_mesh) also failed on unmodified main (dde82f2) on this machine, built separately, with the same errors: buffer-copy WRITE_AFTER_WRITE hazards, mesh-shader pipeline statistics, ray query, tiling.

  • Not covered: a GPU without maintenance10 (every such copy refused), an async-compute family (only the COPY family was exercised here), and a Vulkan 1.2 device.

  • python -I scripts/check_no_game_data.py on every changed file: clean.

AI-assisted: yes (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • Synthetic test only; nothing from the game package was read.

Item: RT-784. Touches runtime/shims/d3d12_vulkan_device.cpp next to #8440 (different functions; whichever lands second may need a rebase).

…TE family cannot run (RT-784)

Enable VK_KHR_maintenance10 on 1.3 devices and allow such copies only where
the format has the *_COPY_ON_{TRANSFER,COMPUTE}_QUEUE feature. Covers
footprint copies, the D24 conversion's copy and staged depth<->colour copies.
New d3d12_copy_queue_depth_test (layer vs native D3D12).

AI-assisted (Claude Code).
@thehollowedone

Copy link
Copy Markdown

Native Windows COPY and COMPUTE verification of cf6a571f on an RTX 3080 Ti (621.35), MSVC 19.44, and Vulkan SDK 1.4.363. maintenance10 was enabled.

  • The stock d3d12_copy_queue_depth test passed on transfer-only COPY family 1. D32 upload, readback, image-to-image copy, and staged depth-to-color copy each matched all 256 texels. The family lacked D32S8 stencil-copy support, and the layer logged unsupported; nothing was submitted for that case. Native D3D12 matched all five cases.
  • In a temporary variant I switched the middle queue and command list to COMPUTE. Family 2 had compute and transfer support without graphics, and advertised both required aspect features. All five cases matched on the layer and native D3D12, including D32S8 stencil upload.

Both runs had zero skips or Vulkan core or synchronization validation messages. The runtime was unchanged. This covers maintenance10 enabled on the two queue families. Synthetic inputs only. AI-assisted.

@nnonno91

Copy link
Copy Markdown

Independent Windows verification of #8871 at cf6a571 on main 867d922. Windows 11 build 26200, MSVC 19.51, native x64 Release, Vulkan Headers 1.4.363, Khronos validation layer 1.4.357 and LEONIDA_VK_VALIDATION=1. Synthetic test inputs. AI-assisted.

I ran the original COPY fixture and added a local COMPUTE mode that executes the same five cases on the layer's non-graphics compute queue. For expected refusals the local test requires the shim to return ReplayResult::unsupported.

Vulkan adapter D3D12 queue and Vulkan family maintenance10 enabled With #8871 (3 runs each) main control (one run each)
Radeon gfx1036, 32.0.21042.62 COPY and COMPUTE both use family 1, COMPUTE + TRANSFER + SPARSE_BINDING No Four buffer-dependent cases refused, depth image-to-image copy matched 8 validation errors per queue type
RTX 5090, 617.42 COPY family 1, TRANSFER + SPARSE_BINDING Yes All five matched, including the D32S8 stencil upload 4 validation errors
RTX 5090, 617.42 COMPUTE family 2, COMPUTE + TRANSFER + SPARSE_BINDING Yes All five matched, including the D32S8 stencil upload 4 validation errors

Zero Vulkan validation errors in all 12 patched probe runs. The Windows D3D12 oracle selected the RTX 5090 in every run and matched all five cases on both queue types.

The control used separately built main replay/device code and identical probe source. The test target and default-false feature field were carried over to compile the probe. All four control runs attempted the buffer-dependent copies and reported the buffer/image queue VUIDs, including 07739 and 10216. The readbacks happened to match on these two GPUs.

Five focused CTests passed per GPU: d3d12_copy_queue_depth, d3d12_stencil_copy, d3d12_typeless_depth, vk_command_replay and d3d12_vulkan_device. I applied #7125 (703fc03) for the last test so it completed the new feature check after the existing slot-78 assertion.

@lohant27-netizen

Copy link
Copy Markdown

Tested cf6a571fe on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8871, #8869, #8825, #8863 and #8885 (no conflicts): pass.

…E (RT-784)

The expected outcome of each queue comes from the Vulkan family the layer
runs it on (transfer-only, compute without graphics, or one with graphics).
Both reviewers of ItsNotRexed#8871 had to add a COMPUTE mode locally.

AI-assisted (Claude Code).
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown

Independent CPU check of the replay guard at cf6a571f: pass, no bug found. The current head 4f191f388 changes only d3d12_copy_queue_depth_test.cpp, so the vulkan_replay.h logic checked here is unchanged.

It covers two cases the description lists as not tested: a GPU without maintenance10, and an async-compute family. Replay runs with mocked Vulkan functions, so it needs no GPU and no Vulkan loader. The check is a scratch file only, not proposed for the PR.

Setup: Windows 11, MSVC 2022, RelWithDebInfo, vendored Vulkan-Headers.

The check replays a list that holds an allowed RGBA8 footprint upload followed by one depth or stencil copy. The copy is one of 11 cases:

  • footprint copies of D32 depth, the D32S8 depth plane and the D32S8 stencil plane, in both directions;
  • D24 footprints held as D32S8, which go through the conversion pass, in both directions;
  • staged D32 ↔ R32_FLOAT copies, in both directions;
  • an RGBA8 control and a D32 → D32 vkCmdCopyImage control.

Each case is replayed under 7 ReplayFunctions::off_graphics settings:

  • nullptr (a graphics family);
  • on a transfer family (queue_stages_copy) and on a compute family (queue_stages_compute), each with:
    • an empty table (no maintenance10);
    • depth only for D32 and D32S8 (the RTX 4070 SUPER case in the description);
    • depth and stencil.

A copy must run exactly when the table allows its format and aspect. A refused copy must return ReplayResult::unsupported and must:

  • emit nothing, including the allowed upload before it and any barrier;
  • not ask for a D24 conversion job (depth24_prepare);
  • not ask for transfer scratch (copy_scratch).
vulkan_replay.h Checks Failures
PR head 253 (55 cases run, 22 refused) 0
mutation: buffer_aspect_copy_allowed always true 253 52
mutation: footprint call site (prepare, CopyTexture) removed 253 40
mutation: staged depth ↔ colour call site removed 253 12

What this shows:

  • The guard decides correctly on every buffer ↔ depth/stencil path in replay.
  • It looks up the Vulkan image format. For a D24 texture held as D32S8, that is D32_SFLOAT_S8_UINT, which matches the final copy of the conversion.
  • The refusal happens in prepare, before any command is recorded and before scratch or conversion jobs are allocated. A refused batch therefore leaves no partial command buffer.
  • On a compute family the rule is the same as on a transfer family. The colour and vkCmdCopyImage controls run under every table.

I also read the emit sites in vulkan_replay.h:

  • The remaining buffer ↔ image copies are colour-only (the zero fill in initialize, block-compressed staging) or graphics-only (resolve).
  • CopyTiles goes through the footprint path.

So no buffer ↔ depth/stencil copy reaches a non-graphics family unchecked.

Not covered:

  • register_off_graphics_families: building the table from real VkFormatProperties3 is not exercised here.
  • A real GPU, and a Vulkan 1.2 device.
  • That a transfer-only queue keeps D24 conversions off (outside this PR). The mock supplies the conversion functions on every family.

The head merges cleanly with #8187 and #8746 (git merge-tree). Synthetic inputs only, no game files. AI-assisted (Claude Code).

@nathans4ntos

nathans4ntos commented Nov 23, 2026 •

Copy link
Copy Markdown

Under Wine, d3d12_copy_queue_depth (from #8871, also on #9039 at 5a1da3035) fails because of its host column, not the layer. Linux, RTX 5070, NVIDIA 620.73.04, clang-cl + xwin build, Wine 11.22, #9039 merged onto main 6312c057f (the runtime of current main 5d74c2723, whose only newer commit changes README.md):

  • Layer: all 10 cases matched (expected matched) (COPY on family 1, transfer only; COMPUTE on family 2).
  • "native D3D12" (Wine's own d3d12, i.e. vkd3d): FAILED on stencil upload for both COPY and COMPUTE; the other 8 match.
  • runtime/test/d3d12_copy_queue_depth_test.cpp:305 counts host != Outcome::matched as a failure, so the test exits 1.

Other host-comparing tests skip the vkd3d comparison under Wine (#6500, #8703). This one probably should too, or report the host column without failing on it. main has a helper for exactly this: hostwine::host_is_wine() in runtime/test/host_wine.h (806ee52). d3d12_transfer_only_family passes here.

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

Luqueze added a commit to Luqueze/Leonida that referenced this pull request Nov 23, 2026
…(RT-784)

Under Wine the "native D3D12" device is vkd3d, which fails the D32S8 stencil
upload on COPY and COMPUTE where Microsoft's runtime runs it, so the test
exited 1 although the layer matched every case (nathans4ntos, ProjectLeonida#8871). As the
other host-comparing tests do, it now checks the layer's column alone there,
through hostwine::host_is_wine(), and says so. Windows still compares both.
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.

7 participants