Skip to content

Depth/stencil region resolves keep the texels around the rectangle (MoltenVK resolves the whole subresource) - #1971

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jolymmiles:mac/depth-resolve-subrect
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Jolymmiles:mac/depth-resolve-subrect

Conversation

@Jolymmiles

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: item 1 of #1745 (comment) (d3d12_depth_resolve on a Mac under Wine)

What and why

On a Mac, d3d12_depth_resolve failed every "rect 1" MIN/MAX case (8 of them, depth and plane formats) with destination differs from the clears.

The layer replays a depth or stencil ResolveSubresourceRegion as an empty dynamic-rendering block, with the destination as the resolve attachment and renderArea set to the source rectangle (runtime/src/vulkan_replay.h). Vulkan limits a render pass's resolve to the render area. MoltenVK resolves through Metal's store action (MTLStoreActionMultisampleResolve / StoreAndMultisampleResolve, MVKAttachmentDescription::getMTLStoreAction), which has no render area, so it overwrites the whole destination subresource.

Native reproduction, plain Vulkan on arm64: a 4x D32 source, an 8×6 destination, render area (2,1) of size 5×4.

  • MoltenVK 1.4.2 and 1.4.3: all 48 texels written, 28 of them outside the area. The result is the same for MIN, MAX and SAMPLE_ZERO, for store op NONE and STORE, and for 2D and 2D_ARRAY views.
  • KosmicKrisp: only the 20 texels inside the area.
  • llvmpipe: has only SAMPLE_ZERO depth resolves, so the test refuses MIN/MAX there. That is why the Linux Wine job passes.

I re-ran the repro: MoltenVK 28 texels outside the render area written: FAIL, KosmicKrisp 0 … ok.

The fix is keep_around_resolve in vulkan_replay.h. When the rectangle is smaller than the subresource, the texels around it (up to four bands) are copied to copy_scratch before the resolve and back after it, with the transitions and barriers of the existing round_trip. No Vulkan property reports this behaviour and MoltenVK doesn't document it, so the path runs on every device rather than on a vendor check. On conformant drivers it costs two extra transfer copies, only for region resolves of depth/stencil. If reviewers prefer a gate, the only option is driverID == VK_DRIVER_ID_MOLTENVK. docs/d3d12_vulkan.md describes it, with the measurements.

Native test: part I of vk_command_replay_test is a 4x D32 MIN resolve of a 5×4 rectangle through the replay. The 28 texels around it must be kept, and a list without copy_scratch must be refused.

Tested

Apple M3 Max, macOS 27.3.

without the fix with it
vk_command_replay_test part I, MoltenVK 1.4.2 / 1.4.3 (direct load) FAIL, 28 texels overwritten PASS (re-run by me)
same, KosmicKrisp PASS PASS, no validation errors (sync validation on)
same, llvmpipe — skipped with the reason shown: no MIN depth resolve
d3d12_depth_resolve under Wine 11.0 (CrossOver 26.3's loader) + MoltenVK 1.4.3 FAIL PASS (re-run by me)
full run_wine_tests.py list (114 tests), main 6a6704d vs branch 84 / 7 / 23 85 / 6 / 23

In the full list only d3d12_depth_resolve changed. The Windows build is cross-compiled with clang-cl 23.1.6, lld-link 22.1.8 and the xwin 10.0.26100 SDK.

  • Native ctest (runtime/build/mac): 35/36. xdxr_build_check fails on plain main too.
  • Not run: native Windows or Linux Wine; there the extra copies only preserve texels the driver already leaves alone.
  • The validation layer ran on KosmicKrisp only. vk_test_device doesn't create a MoltenVK device through the loader, on main either.
  • Colour resolves use vkCmdResolveImage, so they don't take this path.

A ready-to-file MoltenVK report (repro source, outputs, and the suggestion to resolve only the area through the resolveUnresolvableAttachments path) is prepared and will be linked here once filed.

No game files. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

A ResolveSubresourceRegion of a depth or stencil plane runs in a rendering scope whose render area is the source
rectangle, and Vulkan resolves only inside it. MoltenVK (1.4.2 and 1.4.3) resolves the whole destination
subresource: it resolves through Metal's store action, which has no render area. d3d12_depth_resolve failed its
eight MIN/MAX rectangle cases under Wine on an M3 Max for that reason.

The texels around the rectangle now go into copy_scratch before the scope and back after it, in up to four bands, on
every GPU: no device property reports the behaviour. vk_command_replay_test part I resolves a D32 rectangle natively
and checks the texels around it; it failed on MoltenVK before this change (all 28 overwritten) and passes on
MoltenVK and KosmicKrisp, with no validation errors on KosmicKrisp.

AI-assisted.
@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 111/113 pass. On current main three tests fail the same way on every PR I built, so they're not from this PR: d3d12_draw (bundle blend, bisected to #1660's merge, see #1902), d3d12_compute on both GPUs (line 515: device_proxy_ref_count(device.p) == 1), and d3d12_subgroup on the Intel UHD 770 (line 611: fragment_default). I'm bisecting the last two. Other Intel failures are the known d3d12_present and d3d12_m3_frame.

@JavierBlanco23

Copy link
Copy Markdown
Contributor

Tested ef4d3053 on NVIDIA GeForce RTX 5080, driver 616.56, Windows 11 (MSVC 19.44, Ninja): pass.

  • vk_command_replay_test.exe: tests A..I passed, including I: a 4x D32 MIN resolve of a 5x4 rectangle, 28 texels around it kept.
  • d3d12_depth_resolve_test.exe: 31/31 matched default adapter, 26/26 matched WARP (57 host comparisons matched, 9 refusals kept destination).

@XFlawless1

Copy link
Copy Markdown
Contributor

Tested ef4d305 natively on Windows with NVIDIA and AMD: pass, no regressions, no validation errors. This covers the "not run: native Windows" row in the description.

Setup: Windows 11 Pro 10.0.26300, MSVC 19.44.35230 (VS 2022 Build Tools), Vulkan SDK 1.4.363.0, scripts/build_runtime.ps1 (Ninja, RelWithDebInfo). Two GPUs, each selected with LEONIDA_VK_DEVICE:

  • NVIDIA GeForce RTX 5080, driver 621.14 (Vulkan 1.4.357)
  • AMD Radeon iGPU, Ryzen 7 9800X3D (RDNA2, 0x13C0), driver 32.0.21042.62 (Vulkan 1.4.315)

VK_LOADER_LAYERS_DISABLE=~implicit~. This PR is merged onto main 6a6704df and compared with 6a6704df alone on the same PC.

On these drivers the resolve already honours the render area, so the extra band copies only preserve texels that were never at risk, as the description says. The cost is two transfers per partial depth/stencil resolve.

AI-assisted (Claude Code).

@ezwinxdlmao

Copy link
Copy Markdown
Contributor

Tested ef4d305 on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101, Windows 11, native MSVC (VS 2022 Build Tools, Ninja, RelWithDebInfo): pass.

  • vk_command_replay_test passes. That includes the new case I: a 4x D32 MIN resolve of a 5x4 rectangle, with the 28 texels around it kept.
  • ctest -R d3d12_depth_resolve: pass.
  • Full ctest -j3: 111/113. The two failures are d3d12_compute (device_proxy_ref_count(device.p) == 1, line 515) and d3d12_draw (bundle blend pixel 127,0,127,255; TEST-266). Both fail identically at this PR's merge base 6a6704df on the same GPU.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 58cc88f into ItsNotRexed:main Nov 22, 2026
8 of 9 checks passed
@Jolymmiles

Copy link
Copy Markdown
Contributor Author

Filed upstream: KhronosGroup/MoltenVK#2919.

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