Skip to content

d3d12: ResolveSubresourceRegion past the destination fails Close instead of dropping the list - #9439

Closed
haayden wants to merge 1 commit into
ProjectLeonida:mainfrom
haayden:fix/resolve-region-bounds
Closed

haayden wants to merge 1 commit into
ProjectLeonida:mainfrom
haayden:fix/resolve-region-bounds

Conversation

@haayden

@haayden haayden commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #9065 (comment)

What and why

ResolveSubresourceRegion (runtime/shims/d3d12_com.cpp) recorded a region that runs past the destination's width or height without checking it. Replay then refused it (prepare_resolve in runtime/src/vulkan_replay.h returns invalid_copy), so Close returned S_OK, and at ExecuteCommandLists every command in the list was lost without any error reaching the app. That includes clears recorded before the resolve.

The host runtime and WARP both fail Close with E_INVALIDARG when DstX/DstY plus the region size (pSrcRect, or the whole source when it is null) is larger than the destination's top-level Width/Height. The region is now checked when it is recorded, the same way.

4x MSAA 4x4 RGBA8 source, 4x4 RGBA8 destination:

Case RTX 5070 Ti host WARP Layer on main
whole source at (1,2) Close 0x80070057 Close 0x80070057 Close S_OK, every byte 00 (its clears lost too)
rect (0,0)-(3,3) at (2,2) 0x80070057 0x80070057 S_OK, every byte 00
rect (1,1)-(4,2) at (3,0) 0x80070057 0x80070057 S_OK, every byte 00
two regions that fit match match match

#8542 adds the same recording-time check for ResolveSubresource; it leaves ResolveSubresourceRegion alone.

Tested

Windows 11, RTX 5070 Ti (NVIDIA 621.14), MSVC 14.44, RelWithDebInfo, main 6312c05. No game files.

  • The new d3d12_resolve_region_clip_test records the same clears and resolves on the Vulkan device and on the host device, then compares the Close result and the destination bytes. d3d12_resolve_region_clip_warp runs it against WARP. It skips (77) if a device is missing.
    • main: resolve region clip: 3 of 5 cases differ, exit 1, against both the host and WARP.
    • this PR: 0 of 5 cases differ, exit 0, against both.
  • ctest -R "resolve_region_clip|close_parity|d3d12_clear$": 4/4 pass. d3d12_vulkan_device and d3d12_depth_resolve fail the same way with or without this change; both are already known on main.
  • No Vulkan validation layer is installed here, so there was no LEONIDA_VK_VALIDATION=1 run.

AI-assisted: yes

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. (n/a, no translator change)

…ead of dropping the list

ResolveSubresourceRegion recorded a region that ran past the destination's width or height, and replay refused it
at Execute, so Close said S_OK and the whole list (clears recorded before the resolve included) was lost without a
word. The host runtime and WARP fail Close with E_INVALIDARG when DstX/DstY plus the region (pSrcRect, or the whole
source) exceeds the destination's top level. The region is now checked when it is recorded.

d3d12_resolve_region_clip_test resolves a 4x MSAA 4x4 source into a 4x4 destination on the Vulkan device and on
the host (and WARP), comparing Close and the bytes: 3 of 5 cases differ on main, 0 with the fix.

AI-assisted: yes

@al3xar al3xar 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.

Independent Windows + GPU + Vulkan validation verification of c335fbf4e (AI-assisted).

  • Environment: Windows 11 x64, MSVC 19.44.35230.0 (Ninja Release), Windows SDK 10.0.26100.0, NVIDIA GeForce RTX 3060 (driver 621.24), Vulkan SDK 1.4.363.0 (LEONIDA_VK_VALIDATION=1), no game files.
  • Test runs (LEONIDA_VK_VALIDATION=1):
    • Against NVIDIA RTX 3060 host: d3d12_resolve_region_clip_test → PASS (resolve region clip: 0 of 5 cases differ, exit 0, 0 Vulkan validation errors).
    • Against WARP (PROBE_WARP=1): d3d12_resolve_region_clip_test → PASS (resolve region clip: 0 of 5 cases differ, exit 0, 0 Vulkan validation errors).
  • Negative control: Reverted runtime/shims/d3d12_com.cpp to upstream/main (6312c057f) and re-ran d3d12_resolve_region_clip_test → FAIL (resolve region clip: 3 of 5 cases differ, exit 1).
  • Code review:
    • Recording-time bounds check in ResolveSubresourceRegion uses 64-bit addition (x + w > dst_desc.Width || y + h > dst_desc.Height) and cleanly matches both host and WARP Close() -> E_INVALIDARG.
    • Minor non-blocking notes: widening INT64(rect->right) - INT64(rect->left) would avoid signed 32-bit overflow on extreme negative/positive LONG bounds; std::getenv("PROBE_WARP") at d3d12_resolve_region_clip_test.cpp:151 emits MSVC C4996.

LGTM.

@VibeClauding

Copy link
Copy Markdown

Tested c335fbf4e merged onto main 5d74c2723 on Windows 11 26200, MSVC 14.44 RelWithDebInfo, RTX 3070 (Ampere, NVIDIA 610.88): pass, with a negative control.

  • With the PR: d3d12_resolve_region_clip and d3d12_resolve_region_clip_warp pass, plain and with LEONIDA_VK_VALIDATION=1.
  • Control (the test with main's d3d12_com.cpp): both fail, so the test catches the out-of-bounds ResolveSubresourceRegion that main records silently.
  • d3d12_depth_resolve fails with and without the PR on this card. That failure is main's, and it has open fixes.

Nit: d3d12_resolve_region_clip_test.cpp:151 uses getenv, which gives MSVC C4996 under the runtime's /W4. GetEnvironmentVariableA, as other tests use, avoids it.

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

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at c335fbf. Full ctest -j 8, out of 241 tests:

No regression from this PR. The new d3d12_resolve_region_clip and d3d12_resolve_region_clip_warp pass. The known failures are the same 5 as on main dde82f2 on this card (vk_queue_query_sync, d3d12_vulkan_device tiles == 1, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; tracked in #8426). One extra failure in the parallel run, api_ref_state, was a Timeout (10.3 s) under -j 8 load. Rerun alone at this head it passes 10/10 in 0.14 s, and this PR doesn't touch it (see #8391 for that test under a busy machine). d3d12_depth_resolve still fails here, as on main.

AI-assisted (Claude Code).

@RAINighty

Copy link
Copy Markdown

Tested c335fbf4e merged with main 5d74c2723 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, hybrid-GPU laptop (RTX 5060 + Intel UHD, no adapter forced), MSVC 19.44.35228, RelWithDebInfo (Ninja): pass.

  • d3d12_resolve_region_clip and d3d12_resolve_region_clip_warp pass with this PR (2 of 2).
  • Negative control: this PR's test with main's runtime/shims/d3d12_com.cpp: both fail, so the new test does catch the change.
  • Code not reviewed beyond running it. No game files.

AI-assisted (Claude Code).

@singul-oss

Copy link
Copy Markdown

AI-assisted test. Pass, and the host on this GPU agrees.

Tested c335fbf4 merged onto main 5d74c272 (clean) on Windows 11 Home 10.0.26200, NVIDIA GeForce RTX 5080 (driver 610.88, subgroup 32..32), MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, RelWithDebInfo.

@nathans4ntos

nathans4ntos commented Nov 23, 2026 •

Copy link
Copy Markdown

Under Wine, both d3d12_resolve_region_clip and d3d12_resolve_region_clip_warp fail (5 of 5 cases, the same in 3 runs). The cause is the host column, not the layer. Linux, RTX 5070, NVIDIA 620.73.04, clang-cl + xwin build, Wine 11.22, c335fbf4e merged onto 6312c057f (the runtime of current main 5d74c2723, whose only newer commit changes README.md).

  • The layer does what the PR intends. It resolves the two cases that fit, and refuses the three that run past the destination with E_INVALIDARG at Close.
  • Wine's own d3d12 (vkd3d), which the test takes as the host, closes every case with S_OK and leaves the destination untouched (0x66 in every byte). PROBE_WARP=1 gives the same result, since Wine has no separate WARP.

main already has a helper for this: hostwine::host_is_wine() in runtime/test/host_wine.h (806ee52, "tests: D3D12 host comparisons skip under Wine"). d3d12_srgb_uav (#9531) and d3d12_a8_dimensions (#9336) use the same check and skip with exit 77 here. Calling it before the host comparison would keep this test green under Wine. The Windows checks above are unaffected.

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

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.

8 participants