Skip to content

Runtime: depth and stencil resolves in ResolveSubresourceRegion - #1155

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:depth-resolve
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:depth-resolve

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

docs/d3d12_vulkan.md listed depth-stencil resolves as open, and ResolveSubresourceRegion refused everything but AVERAGE on colour. It now resolves one depth or stencil plane:

  • MIN and MAX of either plane;
  • AVERAGE of the depth plane when Format is the plane's own format (R32_FLOAT, R24_UNORM_X8_TYPELESS).

The AVERAGE rule is measured. On the PC runtime (RTX 5070 driver 621.24, and WARP, a fresh device per case), Close fails with E_INVALIDARG for AVERAGE when Format is the depth format (D32_FLOAT, D24_UNORM_S8_UINT) and for any stencil plane. MIN and MAX are accepted with either kind of format. The layer accepts and refuses the same set.

How it works. Each resolve is a vkCmdBeginRendering scope with no draws:

  • Attachments: the multisampled plane is the depth or stencil attachment (LOAD, store NONE), and the destination plane is its resolve target (VK_KHR_depth_stencil_resolve, core in 1.2). The render area is the source rect.
  • Layouts: both images move from their resolve layouts to DEPTH_STENCIL_ATTACHMENT_OPTIMAL and back through the existing round_trip helpers. The other plane is never attached, so it keeps its contents.
  • Record-time checks: each call is checked against D3D12's rules (format family, plane from the subresource index, same plane on both sides, MSAA source and 1x destination) and against supportedDepthResolveModes/supportedStencilResolveModes, queried at device creation. One plane per scope, so independentResolve never applies.
  • Refusals: a refused call fails Close and records nothing.
  • Scope: the rendering scope holds only the resolve, so the section 4.6 assumption about query resets still holds.
  • Colour: colour resolves are unchanged.
Case Layer RTX 5070 host WARP
MIN/MAX, depth format, D32 / D24S8 depth / D24S8 stencil, whole + rect ok match D24S8 match
MIN/MAX via R32_FLOAT, R24_UNORM_X8, X24_G8 ok match match (not D32)
AVERAGE via R32_FLOAT / R24_UNORM_X8 ok match match (not D32)
R32_TYPELESS / R24G8_TYPELESS resources ok match match (not D32)
AVERAGE by depth format or of stencil; whole subresource to another offset refused, destination kept Close E_INVALIDARG Close E_INVALIDARG
rect to another offset, wrong-plane format, DECOMPRESS refused, destination kept not run not run

Test: the new d3d12_depth_resolve_test is registered in ctest and skips with 77 without a Vulkan GPU.

  • How it checks: it clears a 4x 8x6 target with three overlapping values, resolves one plane, and reads both planes back against computed values.
  • Results: 31/31 cases match the RTX 5070 host and 26/26 match WARP. WARP is skipped for Format = D32_FLOAT, which removes its device, and is compared on the resolved plane only, since it writes both D24S8 planes.
  • Validation: 0 Vulkan validation errors, including synchronization validation (checked as active with a deliberately broken barrier).
  • Full ctest: 55/55.

Gaps:

AI-assisted.

MIN and MAX of either plane, and AVERAGE of the depth plane when Format is
the plane's own format, as the PC runtime accepts them (RTX 5070 and WARP).
Each resolve is a vkCmdBeginRendering scope with no draws: the MSAA plane
is the depth or stencil attachment and the destination plane its resolve
target, checked at record time against D3D12's rules and the device's
supported resolve modes. Colour resolves are unchanged.
@kapitche

Copy link
Copy Markdown
Contributor

Tested 73dd6d7 on Windows 11 with two GPUs on one machine (MSVC 14.51): the layer matches WARP everywhere, but d3d12_depth_resolve fails in ctest on both GPUs, because of the comparison against the hardware D3D12 driver:

RTX 4080 SUPER (32.0.16.1714) Intel UHD 770 (32.0.101.6129)
Vulkan resolve modes depth 0x2f, stencil 0x2d depth 0xf, stencil 0xd
vs WARP 26 of 26 match, 5 refusals alike 26 of 26 match, 5 refusals alike
vs the default adapter 19 of 31 match 19 of 31 match

All 12 mismatches report host differs from the clears, layer and host differ. They're the D24S8 / R24G8_TYPELESS stencil MIN/MAX (also as X24_G8) and the depth-as-R24_X8 AVERAGE cases, on both rects. So the native NVIDIA and Intel D3D12 drivers give something other than the cleared values in the same cases, while the layer agrees with WARP. If the hardware result for these modes isn't defined by the spec, it may be better to compare only against WARP for them, or log hardware differences without failing the test. Otherwise this fails on every real GPU. Other ctest results: NVIDIA 54/55 (only this test); Intel adds the two known main failures.

@marquezinii

Copy link
Copy Markdown
Contributor

Tested 73dd6d7 on NVIDIA GeForce RTX 5070, driver 621.24 (32.0.16.2124), Windows 11 26H2 (26300), MSVC 14.52 (VS Build Tools 18), Ninja, RelWithDebInfo: pass.

@troythedecoyx

troythedecoyx commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 73dd6d7 merged onto main d3841c0 (no conflicts) on Windows 11 Home, NVIDIA GeForce RTX 4060 Ti (Ada), driver 621.24 (32.0.16.2124), Vulkan SDK 1.4.363, MSVC (VS 2022), RelWithDebInfo + Ninja: d3d12_depth_resolve fails, exactly as @kapitche saw it.

Vulkan resolve modes: depth 0x2f, stencil 0x2d
depth/stencil resolves against the default adapter: 19 of 31 match, 5 refusals alike
depth/stencil resolves against WARP: 26 of 26 match, 5 refusals alike

The 12 mismatches are the same cases (host differs from the clears, layer and host differ): D24S8 stencil MIN/MAX (also as X24_G8) and D24S8 depth as R24_X8 AVERAGE on rects 0 and 1, plus R24G8_TYPELESS stencil as D24S8 MAX and depth as R24_X8 AVERAGE on rect 1.

This lines up by GPU generation, not by driver: @marquezinii's RTX 5070 (Blackwell) passes on the same 621.24 driver, while this RTX 4060 Ti and the RTX 4080 SUPER (both Ada) and the UHD 770 fail with the same 12. The source comment says the cases were measured on the RTX 5070, so the host behaviour for these D24S8 modes looks hardware-specific. That supports @kapitche's suggestion to compare these cases with WARP only (or report hardware differences without failing).

Everything else: on this PR the other 56 ctest tests pass and only d3d12_depth_resolve fails (gameinput is "Not Run" here, the same as on main); main d3841c0 itself passes here.

AI-assisted (Claude Code).

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested 73dd6d7 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: d3d12_depth_resolve fails against the NVIDIA host runtime, passes against WARP.

  • Build: 0 warnings. ctest: 55/56, the only failure is the new d3d12_depth_resolve.
  • Output (the same with and without LEONIDA_VK_VALIDATION=1, 0 validation errors from this test):
    Vulkan resolve modes: depth 0x2f, stencil 0x2d
    depth/stencil resolves against the default adapter: 19 of 31 match, 5 refusals alike
    depth/stencil resolves against WARP: 26 of 26 match, 5 refusals alike
    
  • The 12 mismatches are all D24S8 / R24G8_TYPELESS: stencil MIN and MAX (as D24S8 and as X24_G8) and depth as R24_X8 AVERAGE, rects 0 and 1. Each one reads host Close 0x00000000, host differs from the clears, layer and host differ. So NVIDIA's own D3D12 driver accepts these resolves but returns something other than the cleared values, while the layer matches WARP.
  • Possible next steps: treat the hardware host as advisory for D24S8 MIN/MAX/AVERAGE (WARP as the reference), or check what NVIDIA's runtime actually writes there. I have not dug into which side is right.
  • With validation, d3d12_vulkan_device_test also reports VUID-vkCreateDevice-ppEnabledExtensionNames-01387 twice. That is not from this PR: the branch predates ff69741, which fixes it on main. d3d12_vulkan_device_test itself passes.

AI-assisted. No game files.

@ItsNotRexed
ItsNotRexed merged commit 2a333b5 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…st quirk

#1155's comparison failed on an RTX 4060 Ti: NVIDIA's D3D12 driver returns, for 12 of 31 D24S8 / R24G8 rectangle
resolves, planes that match neither the clears nor WARP, while the layer matches both (WARP: 26 of 26). The layer
is already checked against the clears above, so such a case is now reported as a host quirk and counted, not failed;
a host that matches the clears still has to agree with the layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants