Skip to content

d3d12: ClearDepthStencilView ignores a flag for a plane the view lacks (D3D-437) - #4143

Open
Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/d3d-437-dsv-stencil
Open

Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/d3d-437-dsv-stencil

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: D3D-437 (from #313's Up for grabs), #4084 (comment)

What and why

ClearDepthStencilView with the STENCIL flag on a depth-only D32_FLOAT view made prepare (runtime/src/vulkan_replay.h ~2415) return invalid_clear. The whole command list was then dropped, including a later valid depth clear, while Close and the fence still succeeded. @inerthel-agi found it in #4084: native D3D12 (WARP and an RTX 5070 Ti) ignores the absent plane.

Change (runtime/src/vulkan_replay.h, the ClearDepthStencil case of prepare):

  • The requested aspects are masked to the planes the view has.
  • STENCIL alone on a depth-only view becomes an empty clear, and that command is skipped. Without the skip it would be issued with an aspect mask of 0, which Vulkan forbids.
  • DEPTH | STENCIL clears the depth plane.
  • A view with no depth or stencil plane is still invalid_clear, as before.

docs/d3d12_vulkan.md notes the rule.

Tested

Windows 11, MSVC, VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time.

New cases in runtime/test/d3d12_clear_test.cpp, each compared with WARP: three D32_FLOAT clear pairs.

  • A full DEPTH | STENCIL clear, then a DEPTH rectangle.
  • A full DEPTH clear, then a STENCIL-only rectangle.
  • A full DEPTH clear, then a DEPTH | STENCIL rectangle.

clear_depth_and_read takes optional flags for its two clears.

Results:

GPU Driver d3d12_clear_test
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D (device: AMD Radeon(TM) Graphics, selected with VK_LOADER_DRIVERS_SELECT=*amd*) 26.10.1 PASS, RTV and DSV clears: 200 full/rectangle readbacks matched WARP
NVIDIA GeForce RTX 5080 616.92 The 3 new cases match WARP. The run still exits 1 on failures that are also on main: R8G8B8A8_UNORM/SNORM, B8G8R8A8_UNORM, B8G8R8X8_UNORM (7f vs 80), and D16_UNORM (@ismailchaka1's finding in #3796).
  • Before the fix (same test, vulkan_replay.h reverted): all 3 new cases differ from WARP on the Radeon.
  • Negative control: I kept the absent stencil aspect instead of masking it (aspects &= depth_stencil_aspects). Case 1 fails on the Radeon. Then I reverted it.
  • Runtime ctest on the Radeon (full build): 100% of 122 tests passed. Skipped as usual: shader_library_corpus, fsr_dispatch, bvh_builder, vk_sync_validation, d3d12_first_light. gameinput is disabled.

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 rule: the layer rule is in docs/d3d12_vulkan.md.)

…s (D3D-437)

STENCIL on a D32_FLOAT view used to make prepare return invalid_clear, so
the whole command list was dropped. Like the PC runtime (WARP), the absent
plane is now ignored: STENCIL alone clears nothing, DEPTH | STENCIL clears
the depth plane. d3d12_clear_test compares three such cases with WARP.

AI-assisted.
@tupacfan04

Copy link
Copy Markdown
Contributor

Static verification only (no compiler/MSVC/cmake here): compileall, repo-path/links/table/CLI/design docs tests and check_no_game_data pass, merge clean.

The logic is right: both aspects are built, masked to available, and aspects &= available keeps valid clears (DEPTH, STENCIL, DEPTH|STENCIL on combined views) while STENCIL on a depth-only view becomes an empty skip (vulkan_replay.h:2411-2427); flags == 0 is rejected at record time (command_list.h:738), skip is honoured by emit and zero_clear_unavailable (vulkan_replay.h:3238,2277), and the D32-with-stencil-flag and depth-only alias cases behave as documented. The docs cite the host rule empirically, with the WARP-comparing test, which matches the repo's style.

One real gap: the new cases run only in the no-argument mode, which is not registered in CTest (runtime/CMakeLists.txt:1305-1310 registers only --rgb9e5); a device-free case belongs in replay_clear_gate_test (:1958-1964), otherwise CI never runs them.

Nit: skip is set after view_range/rect_view (:2421-2426), so a clear the host ignores can still fail as invalid_subresource (volume) or unsupported (no dynamic rendering); and :934 has a stale comment.

Approve with the CTest registration. AI-assisted review, no game files, no GPU.

@requiemsnkrp

Copy link
Copy Markdown

Tested fc2bd57a (merged onto main aa2988cc) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass for this change. The test as a whole still exits 1 because of differences main already has.

  • d3d12_clear_test (run directly, it isn't a ctest; LEONIDA_VK_VALIDATION=1) exits 1 with d3d12_clear_test: 5 color/depth format(s) differ from WARP: R8G8B8A8_UNORM case 0 byte 2: Vulkan 7f, WARP 80, R8G8B8A8_SNORM ... 3f vs 40, B8G8R8A8_UNORM and B8G8R8X8_UNORM ... 7f vs 80, depth format 55 case 1 byte 12: Vulkan ff, WARP 00.
  • Plain main aa2988cc gives the same 5 lines and exit 1 (rebuilt and rerun on this GPU). No new difference, and no D32_FLOAT (format 40) line, so the three new D32 clear pairs match WARP here. No validation errors were printed.
  • Full ctest (-E "present|swapchain|frame_pacer", llvm-mc build): 100% tests passed, 0 tests failed out of 148 (9 skipped/disabled, same set as main: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).

AI-assisted (Claude). No game files.

@2-CD

2-CD commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: NVIDIA GeForce RTX 5080 (driver 621.01) + AMD Radeon 610M iGPU (driver 32.0.13018.6), Windows 11, MSVC (VS BuildTools 18) + Ninja, RelWithDebInfo, Vulkan SDK headers fetched. Tested head fc2bd57a (base aa2988cc).

Build: clean, 363 targets, no warnings-as-errors failures.

Targeted (the PR's own change):

  • d3d12_clear_test run with no args exercises the new D3D-437 D32_FLOAT stencil-flag cases (STENCIL on a depth-only view, DEPTH|STENCIL, and the rectangle variants). All three plane cases pass - depth readback matches the WARP host oracle.
  • The same no-arg invocation also reports 5 color/depth rounding diffs vs WARP (R8G8B8A8_UNORM, R8G8B8A8_SNORM, B8G8R8A8_UNORM, B8G8R8X8_UNORM at 7f vs 80 round-half; depth format 55 case 1). These reproduce identically on the PR base aa2988cc, so they are pre-existing NVIDIA-vs-WARP host-comparison diffs, not introduced by this PR. (Note: this no-arg comparison path is not a registered ctest test - ctest registers only d3d12_rgb9e5_rtv, which uses the --rgb9e5 path and does not run these format comparisons.)
  • Registered clear/depth tests d3d12_rgb9e5_rtv, d3d12_stencil_copy, clear_color, replay_clear_gate, d3d12_uav_clear, d3d12_depth_resolve with --repeat until-fail:3: all pass (d3d12_rgb9e5_rtv skips on NVIDIA, passes on the iGPU).

Full suite (ctest -C RelWithDebInfo -j 6, excluding the 4 window-showing tests dxgi_swapchain|d3d12_present|vk_presenter_sync|xbox_present):

  • NVIDIA RTX 5080: 149/149 passed, 0 failed.
  • AMD Radeon 610M iGPU (LEONIDA_VK_DEVICE=Radeon): 149/149 passed, 0 failed.

The PR's unstable CI state did not reproduce locally.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@ricardotanaka

Copy link
Copy Markdown

Also tested fc2bd57a (merged onto main aa2988cc) on AMD Radeon RX 7600 (RDNA3, discrete), AMD driver 26.11.2, Windows 11 26200.9457, MSVC 19.44: pass, same as the Radeon rows above. d3d12_clear_test run directly (no args) exits 0 with RTV and DSV clears: 200 full/rectangle readbacks matched WARP, also with LEONIDA_VK_VALIDATION=1; unlike the NVIDIA runs, none of the main rounding differences show up on this card.

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

@slopradish slopradish left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and applied the same replay fix in my fork's diverged tree; both build and full ctest green (fork 16/16, upstream-based worktree 55/55).

The change is correct: aspects & ~available previously rejected any clear flag for a plane the view's format lacks, which is not what D3D12 does. Masking aspects with available and setting p.skip when nothing remains matches WARP and native drivers; I checked that emit() honours p.skip for clears (there are existing skip paths at the prepare/emit boundary), so no vkCmdClearDepthStencilImage is issued for an empty aspect set.

One thing worth confirming before merge: detail::view_range() is now called with aspects == 0 before the p.skip check in the test helper path — if any assertion inside it requires a nonzero aspect mask, moving if (!aspects) p.skip = true; ahead of the view_range call would be safer. The order in the diff is view_range then p.skip, which passed the local suite, so this is a defensive note rather than a blocker.

No GPU-specific hardware needed for this review.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested fc2bd57a on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass for this change.

  • d3d12_clear_test (no arguments; CTest only runs it as --rgb9e5): the three new D32_FLOAT stencil-flag cases match WARP (no stencil-flag case line). It still exits 1 on the same 5 formats as main aa2988cc on this card: R8G8B8A8_UNORM/SNORM, B8G8R8A8_UNORM, B8G8R8X8_UNORM (7f vs 80) and depth format 55 (D16_UNORM), matching your RTX 5080 note.
  • ctest: 144 passed, 10 skipped (as main), 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main.

AI-assisted (Claude Code).

@LucasDonin

Copy link
Copy Markdown

Tested fc2bd57a (head as is, base aa2988cc) on an NVIDIA GeForce GTX 1660 (Turing TU116), driver 610.88, Windows 11, MSVC 19.44 (Ninja, RelWithDebInfo), LEONIDA_VK_VALIDATION=1: pass.

AI-assisted run (Claude). No game files involved.

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