Skip to content

Draft: resolve in a requested format, prototype for D3D-411 design - #5880

Draft
agulerman wants to merge 3 commits into
ItsNotRexed:mainfrom
agulerman:d3d411-format-resolve
Draft

agulerman wants to merge 3 commits into
ItsNotRexed:mainfrom
agulerman:d3d411-format-resolve

Conversation

@agulerman

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-411 design proposal (on #313). Draft prototype for the design question, not for merging yet: D3D-411 waits for the layer's owners to choose between a view-format resolve and a shader resolve, and this is the evidence for the first one.

Depends on: #4745, #4884 (same resolve code in vulkan_replay.h)

What and why

ResolveSubresource drops Format (d3d12_com.cpp), so:

  • typeless 4x → typeless 1x resolved as R8G8B8A8_UNORM_SRGB is averaged as UNORM, with no error (wrong colour space, darker AA edges);
  • typeless 4x → typed UNORM_SRGB 1x (D3D12's "one typed" case) is refused in prepare_resolve (Vulkan formats differ), and the whole list fails.

This prototype passes the format both resources are viewed in when it isn't their own (color_resolve_view_format, which checks MUTABLE_FORMAT, the castable list and texel size), and replay resolves in a rendering scope with both images viewed in it: a colour attachment with an AVERAGE resolve, reusing the depth/stencil resolve path. About 80 lines in the layer.

Known gap: a destination without ALLOW_RENDER_TARGET has no COLOR_ATTACHMENT usage, so that case is refused (never resolved wrongly). The full version would resolve into a temporary attachment and copy, as #4745 does for shifted depth resolves.

Spec notes: Vulkan only says an sRGB resolve should average in linear space. With VK_KHR_maintenance10, VK_RENDERING_ATTACHMENT_RESOLVE_ENABLE_TRANSFER_FUNCTION_BIT_KHR forces it; the full version would set it when available. A shader resolve would be exact everywhere but several times the code.

Tested

New d3d12_resolve_format_test: a 4x target cleared blue, green in one sample of four (SampleMask 0x1), so every pixel resolves to 64/191 as UNORM and 137/225 as sRGB averaged linearly. Wine 9.0 + llvmpipe (Mesa 25.2.8), clang-cl 19 cross-build:

case main this
typed sRGB → typed sRGB, as sRGB 137/225 137/225
typeless → typeless, as sRGB 64/191 (silent) 137/225
typeless → typeless, as UNORM 64/191 64/191
typeless → typed sRGB, as sRGB refused 137/225
typeless → typeless as sRGB, dest without ALLOW_RENDER_TARGET 64/191 (silent) refused (known gap)

Related tests pass: command_list, vk_command_replay, d3d12_com, d3d12_close_parity, d3d12_msaa_draw, d3d12_draw, d3d12_vulkan_device, typeless_rtv, conservative_raster. d3d12_view_slices and d3d12_depth_resolve fail the same way on main in this setup (Wine/vkd3d). test_ctest_registration.py and test_ci_registration.py pass.

Not tested: a real GPU, Windows/MSVC, and Vulkan validation (the layer isn't installed under Wine). The expected 137/225 assumes D3D12 averages sRGB in linear space; please check against WARP or native D3D12. Testers on NVIDIA/AMD/Intel: ctest -R d3d12_resolve_format.

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

AI-assisted (Claude Code). Synthetic test data only.

🤖 Generated with Claude Code

@Stalkerino

Copy link
Copy Markdown

D3D-411 hardware check on unmodified head 0b3b7325, with a separate vkd3d-proton comparison. The four implemented cases pass on the integrated RDNA2 Radeon in a Ryzen 7 9800X3D (RADV RAPHAEL_MENDOCINO, Mesa 26.3.1). The unchanged PR test exited 0 under both Wine 11.22 and Proton-CachyOS 11.0-20261015 SLR.

With one green sample and three blue, all 256 pixels read back green/blue 137/225 for typed sRGB, typeless resolved as sRGB, and typeless source → typed sRGB destination. Typeless resolved as UNORM gave 64/191. I also ran a PC D3D12 program against vkd3d-proton 3.1.0, on the same adapter (1002:13c0), using HLSL compiled to DXBC, the same geometry, clear, sample mask, formats, barriers and readback. It agrees on those four. For the fifth case (typeless → typeless as sRGB, destination without ALLOW_RENDER_TARGET), the PR explicitly refuses the command. vkd3d-proton executes it and returns 64/191 on every pixel.

To distinguish a reused readback from a real change, I inverted the mixture (SampleMask=0x7, three green samples and one blue) and ran additional destination controls. The two columns below give the observed green/blue bytes on all 256 pixels; red was 0 and alpha 255 on successful resolves. All rows request the sRGB resolve format unless marked UNORM.

Source → destination Destination ALLOW_RENDER_TARGET PR prototype vkd3d-proton
typed sRGB → typed sRGB off 225/137 225/137
typeless → typeless, UNORM off 191/64 191/64
typeless → typed sRGB off refused 225/137
typed sRGB → typeless on 225/137 225/137
typed sRGB → typeless off refused 191/64
typeless → typeless off refused 191/64

This gives a specific native Windows/WARP comparison to settle: change only the destination format between TYPELESS and UNORM_SRGB with the flag off. On this vkd3d-proton backend that changes the color space of the readback. It is a Linux comparison, not a measurement of Microsoft's driver.

For a separate Wine run, the host Vulkan loader inserted the Khronos layer. The only VUID logged was the existing device-creation dependency VUID-vkCreateDevice-ppEnabledExtensionNames-01387 (external-memory FD); there were no resolve or image-view VUIDs in that run. Synthetic data only. AI-assisted.

@lines9686-rgb

Copy link
Copy Markdown
Contributor

NVIDIA data point for the D3D-411 choice, the one @Gabzinnn12's write-up on #313 left open (vkd3d-proton routes view-format colour resolves to a shader on NVIDIA_PROPRIETARY because "some drivers ignore the view format for resolve attachments").

Tested 0b3b7325 on Windows 11 (26200), RTX 3060 Ti (Ampere), NVIDIA 610.88, MSVC Ninja RelWithDebInfo, LEONIDA_VK_VALIDATION=1: d3d12_resolve_format_test exits 0, 0 validation messages.

case pixel (R,G,B,A) expected
typed sRGB → typed sRGB, as sRGB 0,137,225,255 137/225 (linear average): ok
typeless → typeless, as sRGB 0,137,225,255 ok
typeless → typeless, as UNORM 0,64,191,255 ok
typeless → typed sRGB, as sRGB 0,137,225,255 ok
typeless → typeless as sRGB, dest without ALLOW_RENDER_TARGET refused (replay 9) known gap

So this NVIDIA driver honours the sRGB view format on the resolve attachment: the attachment resolve averages in linear space (137, not the byte average 64), the same as AMD 26.11.2 in Gabzinnn12's probe and RADV in @Stalkerino's run. With 137/225 matching the PC runtime's own answer on AMD and WARP, option 1 now holds on AMD Windows, RADV and NVIDIA Windows. What this doesn't cover: older NVIDIA drivers, Intel, and whatever vkd3d-proton's comment was written for; a shader fallback for drivers that ignore the view format would still need a way to detect them. No game files. AI-assisted (Claude Code).

@agulerman

Copy link
Copy Markdown
Contributor Author

@Stalkerino thanks, that's the first real-GPU data for this, and it matches: 137/225 and 64/191 on RADV under Wine 11.22 and Proton, the inverted SampleMask 0x7 case reversed as expected, and no resolve or image-view VUIDs.

Your vkd3d-proton comparison points at the open question. vkd3d-proton gives 137/225 when the destination is a render target, but 64/191 for typeless→typeless as sRGB when it isn't, so its own path falls back to the typeless format's colour space exactly where this prototype refuses. Which of those native D3D12 does is what the WARP/native check should settle: same sources, only the destination's ALLOW_RENDER_TARGET flag (and TYPELESS vs UNORM_SRGB) changed, as you suggest.

The refused cases (destination without ALLOW_RENDER_TARGET, both directions) are the gap I listed. I'm leaving them until #4745 lands, so they can share its temporary single-sample image instead of adding a second copy of that machinery.

@lines9686-rgb thanks, that's the Windows/NVIDIA data point with validation on, and it matches exactly. So far: RADV (Stalkerino), AMD Windows (Gabzinnn12's probe on #313) and NVIDIA 610.88 all average an sRGB view format linearly in a rendering-scope resolve.

On detecting drivers that ignore the view format (the case behind vkd3d-proton's NVIDIA_PROPRIETARY route to a shader): the layer could check once at device creation. Resolve a tiny 2x2, 4x typeless target with a known one-in-four sample pattern as UNORM_SRGB, read it back, and compare with the expected 137/225 (or set VK_RENDERING_ATTACHMENT_RESOLVE_ENABLE_TRANSFER_FUNCTION_BIT_KHR where maintenance10 exists and skip the check). A driver that fails would take the refusal path, or a shader resolve if the owners want one, instead of resolving wrongly.

@kotorvr and the layer's owners: with three driver families passing, is the view-format route OK to finish here (the temporary attachment for non-render-target destinations once #4745 lands, the maintenance10 flag, ResolveSubresourceRegion, and the startup check)?

@agulerman

Copy link
Copy Markdown
Contributor Author

Pushed dac2897: ResolveSubresourceRegion (AVERAGE) with a cast format now goes through the same view-format path instead of being refused. d3d12_resolve_format_test has three region cases into a destination cleared red first; under Wine 9.0 on llvmpipe the rectangle holds 137/225 and every other pixel stays red, for typeless→typeless and typeless→typed sRGB. A rectangle moved to other coordinates is refused like the non-render-target destination: a rendering scope resolves in place, so both wait for #4745's temporary image and a copy. If anyone can rerun d3d12_resolve_format on Windows (NVIDIA/AMD/Intel), the new region cases are the ones to check.

@nullmarsh

Copy link
Copy Markdown

Tested dac2897c (base 561b65a8) natively on Windows 11 26200, AMD Radeon RX 9060 XT (RDNA4, AMD 26.11.2 / 32.0.32029.2010), MSVC 14.44 RelWithDebInfo: pass. These are the new region cases you asked about.

d3d12_resolve_format_test exits 0 in 3/3 plain runs and 3/3 with LEONIDA_VK_VALIDATION=1. The test returns 1 on any validation error, so that is 0 errors. All runs print the same values:

Case Replay Pixel Wrong of 256 Verdict
typed_srgb 0 0,137,225,255 0 ok
typeless_srgb 0 0,137,225,255 0 ok
typeless_unorm 0 0,64,191,255 0 ok
mixed_srgb 0 0,137,225,255 0 ok
typeless_srgb_no_rt 9 — 0 refused (known gap)
region_typeless_srgb 0 0,137,225,255 0 ok, red outside
region_mixed_srgb 0 0,137,225,255 0 ok, red outside
region_shifted_srgb 9 — 0 refused (known gap)

So the 137/225 sRGB linear average and the 64/191 UNORM one come out the same on the AMD proprietary driver as on your llvmpipe and Stalkerino's RADV runs. Both region rectangles hold the average, and the cleared red is intact outside them.

Synthetic tests only, no game files. AI-assisted (Claude Code).

@lines9686-rgb

Copy link
Copy Markdown
Contributor

The native check for the open question (@agulerman's reply above, @Stalkerino's vkd3d-proton comparison): does D3D12 change the colour space when only the destination's own format and ALLOW_RENDER_TARGET change?

A standalone D3D12 probe (no Leonida code): a 4x R8G8B8A8_TYPELESS target written through a UNORM RTV, cleared blue, then green into sample 0 only (PSO SampleMask 0x1), resolved with ResolveSubresource into a fresh 1x destination per case, read back through a copy. Windows 11 (26200), RTX 3060 Ti with NVIDIA 610.88's native D3D12 driver, and WARP; debug layer on.

destination Format NVIDIA native WARP
TYPELESS, no ALLOW_RENDER_TARGET UNORM_SRGB 0,137,225,255 0,137,225,255
TYPELESS, ALLOW_RENDER_TARGET UNORM_SRGB 0,137,225,255 0,137,225,255
UNORM_SRGB, no ALLOW_RENDER_TARGET UNORM_SRGB 0,137,225,255 0,137,225,255
UNORM_SRGB, ALLOW_RENDER_TARGET UNORM_SRGB 0,137,225,255 0,137,225,255
TYPELESS, no ALLOW_RENDER_TARGET UNORM 0,64,191,255 0,64,191,255

Every case: Close S_OK, all 256 pixels equal, device alive. The debug layer's only messages are the five "no clear value at resource creation" performance warnings; no error for any resolve.

So on Windows the Format argument alone picks the averaging space; neither the destination's own format nor its ALLOW_RENDER_TARGET flag changes it. For the case the prototype refuses (typeless → typeless as sRGB, destination without ALLOW_RENDER_TARGET), D3D12's answer is 137/225, where vkd3d-proton gives 64/191 in Stalkerino's run. That makes the refusal a known gap rather than the PC behaviour, and points the full version at the temporary-attachment-then-copy route you mention (or a shader) for destinations without colour-attachment usage, with 137/225 as the expected value. Matches @Gabzinnn12's AMD and WARP numbers for the cases they share. No game files. AI-assisted (Claude Code).

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of standalone head dac2897c with 561b65a8. Windows 11 x64, RTX 3080 Ti / 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0.

Six supported d3d12_resolve_format cases passed. All 1,536 pixels matched the fixture's expected colors, including 401 unchanged red border pixels across the 8×6 and 7×9 region resolves. The sRGB cases returned (0, 137, 225, 255), and the full UNORM control returned (0, 64, 191, 255). Vulkan core and synchronization validation reported zero errors.

The scratch fixture selected the four full-image and two unshifted region cases. It omitted the documented cases without render-target usage and with shifted destinations. This run used the fixture's expected colors as the reference. AI-assisted.

…-411)

ResolveSubresource dropped its Format: a typeless pair resolved as
UNORM_SRGB was averaged as UNORM (no error, darker edges), and a typeless
source with a typed UNORM_SRGB destination was refused because the
Vulkan formats differ. ResolveSubresourceRegion refused both.

The front end now passes the format both resources are viewed in when it
isn't their own (color_resolve_view_format: a typed, non-integer member
of a MUTABLE_FORMAT resource's family, in its view-format list, of the
same texel size). Replay resolves such a colour resolve in a rendering
scope with both images viewed in that format: a colour attachment with
an AVERAGE resolve, on the depth/stencil resolve path.

A destination without ALLOW_RENDER_TARGET has no attachment usage, and a
rendering scope resolves each pixel in place, so a destination without
it, or a rectangle moved to other coordinates, resolves into a
one-sample scratch image and is copied over (vkCmdCopyImage between
size-compatible formats). This reuses ItsNotRexed#4745's depth resolve scratch
images, which now get colour attachment usage for a colour aspect.

d3d12_resolve_format_test clears a 4x target to blue and writes green to
one sample of four (SampleMask 0x1), so every pixel resolves to 64/191
as UNORM and 137/225 as sRGB averaged linearly (native D3D12 and WARP
give 137/225, with or without ALLOW_RENDER_TARGET on the destination).
Eight cases: typed and typeless sources, typeless and typed sRGB
destinations, a destination without ALLOW_RENDER_TARGET, and three
regions into a destination cleared red (in place, typed sRGB, moved).
Under Wine 9.0 on llvmpipe all eight give the expected value on every
pixel; main gives 64/191 for the typeless sRGB cases and refuses the
others.

Depends on: ItsNotRexed#4745

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GN11jcpJWD4phrXJyDgED6
@agulerman
agulerman force-pushed the d3d411-format-resolve branch from dac2897 to ded2455 Compare November 23, 2026 14:36
@agulerman

Copy link
Copy Markdown
Contributor Author

Pushed ded2455, now stacked on #4745 (Depends on: #4745; until it lands the diff shows its commits too). The gap is closed: a destination without ALLOW_RENDER_TARGET, and a rectangle moved to other coordinates, now resolve into #4745's one-sample scratch image and are copied over (vkCmdCopyImage between size-compatible formats). The scratch images get colour attachment usage for a colour aspect.

Per @lines9686-rgb's native D3D12/WARP probe, both now expect and get 137/225. d3d12_resolve_format has 8 cases, all exact under Wine 9.0 on llvmpipe, every pixel: typed/typeless/mixed, the non-render-target destination, and three regions into a destination cleared red (in place, typed sRGB, moved). #4745's replay_depth_resolve_offset still passes.

Testers on Windows (NVIDIA/AMD/Intel): ctest -R "d3d12_resolve_format|d3d12_depth_resolve|replay_depth_resolve_offset" at ded2455 would cover both this and the shared scratch path.

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