vulkan_replay: use cleared aspectMask for depth/stencil rect-clear attachment views (OLD-7634) #619

Open
github-bot wants to merge 1 commit from github-bot/gh-619 into main AGit
Owner

@⁠KarolKurzyna on GitHub · 2026-11-24 10:00 UTC · original
KarolKurzyna:fix/stencil-rect-clear-view-aspect → main · +39 −6 · 2 files · 1 commits · open

Claimed in the coordination issue as: OLD-7634 (#14)

Carried over from upstream ItsNotRexed/Leonida PR #7634 (69d7d53539), where it received 10/10 independent PASS hardware reviews (@MartinIndra02 RTX 3080, @jeangoes Intel UHD 730 confirming the fix on a second Gen12 Intel iGPU, @Ueslii RX 5600 XT, @eizispark RX 9070 XT, @CowBoYdu76, @Ekabusto RX 9070 XT, @trick-ye RX 7800 XT, @egexon RTX 5070, @sgonzalez-glitch RTX 2080, @BeetjeMatig RTX 5070 Ti).

What was wrong

In runtime/src/vulkan_replay.h, prepare() passed p.binding.aspects (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) to rect_view() for ClearDepthStencilView with rectangles even when clear->flags cleared only a single plane (D3D12_CLEAR_FLAG_DEPTH or D3D12_CLEAR_FLAG_STENCIL).
On Intel's Windows Vulkan driver (101.6129 on UHD Graphics 770 and UHD Graphics 730), back-to-back depth-only then stencil-only rectangle clears sharing that combined DEPTH | STENCIL attachment VkImageView silently drop the stencil vkCmdClearAttachments (8/8 combined depth-stencil cases in d3d12_clear_formats read back stale stencil values).

What changed

  • Pass the actually cleared aspects to rect_view() in prepare() so single-plane rectangle clears bind a matching single-aspect attachment VkImageView, and skip rect_view() when !aspects (D3D-437).
  • Add split-plane (D3D12_CLEAR_FLAG_DEPTH rectangle clear followed by D3D12_CLEAR_FLAG_STENCIL rectangle clear) regression cases for DXGI_FORMAT_D24_UNORM_S8_UINT and DXGI_FORMAT_D32_FLOAT_S8X24_UINT in runtime/test/d3d12_clear_test.cpp.

Tested

  • Intel(R) UHD Graphics 770 (101.6129, Vulkan 1.3.295, Windows 11):
    • Before fix: d3d12_clear_formats FAILED (8/8 combined depth-stencil stencil-plane checks failed on split rectangle clears).
    • After fix: d3d12_clear_formats PASS, vulkan_replay_test PASS, zero validation errors under LEONIDA_VK_VALIDATION=1.
  • NVIDIA GeForce RTX 3070 Ti (621.24, Vulkan 1.4.357, Windows 11):
    • d3d12_clear_formats PASS, vulkan_replay_test PASS, zero validation errors under LEONIDA_VK_VALIDATION=1.
  • Independently confirmed on Intel UHD Graphics 730 (@jeangoes) and 9 other NVIDIA/AMD GPUs on upstream #7634.

AI-assisted.

**@⁠KarolKurzyna** on GitHub · 2026-11-24 10:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/619) `KarolKurzyna:fix/stencil-rect-clear-view-aspect` → `main` · +39 −6 · 2 files · 1 commits · open Claimed in the coordination issue as: OLD-7634 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Carried over from upstream `ItsNotRexed/Leonida` PR `#7634` (`69d7d53539`), where it received **10/10 independent `PASS` hardware reviews** (`@MartinIndra02` RTX 3080, `@jeangoes` Intel UHD 730 confirming the fix on a second Gen12 Intel iGPU, `@Ueslii` RX 5600 XT, `@eizispark` RX 9070 XT, `@CowBoYdu76`, `@Ekabusto` RX 9070 XT, `@trick-ye` RX 7800 XT, `@egexon` RTX 5070, `@sgonzalez-glitch` RTX 2080, `@BeetjeMatig` RTX 5070 Ti). ### What was wrong In `runtime/src/vulkan_replay.h`, `prepare()` passed `p.binding.aspects` (`VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT`) to `rect_view()` for `ClearDepthStencilView` with rectangles even when `clear->flags` cleared only a single plane (`D3D12_CLEAR_FLAG_DEPTH` or `D3D12_CLEAR_FLAG_STENCIL`). On Intel's Windows Vulkan driver (`101.6129` on UHD Graphics 770 and UHD Graphics 730), back-to-back depth-only then stencil-only rectangle clears sharing that combined `DEPTH | STENCIL` attachment `VkImageView` silently drop the stencil `vkCmdClearAttachments` (`8/8` combined depth-stencil cases in `d3d12_clear_formats` read back stale stencil values). ### What changed - Pass the actually cleared `aspects` to `rect_view()` in `prepare()` so single-plane rectangle clears bind a matching single-aspect attachment `VkImageView`, and skip `rect_view()` when `!aspects` (`D3D-437`). - Add split-plane (`D3D12_CLEAR_FLAG_DEPTH` rectangle clear followed by `D3D12_CLEAR_FLAG_STENCIL` rectangle clear) regression cases for `DXGI_FORMAT_D24_UNORM_S8_UINT` and `DXGI_FORMAT_D32_FLOAT_S8X24_UINT` in `runtime/test/d3d12_clear_test.cpp`. ### Tested - **Intel(R) UHD Graphics 770** (`101.6129`, Vulkan `1.3.295`, Windows 11): - Before fix: `d3d12_clear_formats` **FAILED** (8/8 combined depth-stencil stencil-plane checks failed on split rectangle clears). - After fix: `d3d12_clear_formats` **PASS**, `vulkan_replay_test` **PASS**, zero validation errors under `LEONIDA_VK_VALIDATION=1`. - **NVIDIA GeForce RTX 3070 Ti** (`621.24`, Vulkan `1.4.357`, Windows 11): - `d3d12_clear_formats` **PASS**, `vulkan_replay_test` **PASS**, zero validation errors under `LEONIDA_VK_VALIDATION=1`. - Independently confirmed on **Intel UHD Graphics 730** (`@jeangoes`) and 9 other NVIDIA/AMD GPUs on upstream `#7634`. AI-assisted.
prepare() passed p.binding.aspects (DEPTH | STENCIL) to rect_view() for
ClearDepthStencilView with rectangles even when clearing a single plane.
On Intel's proprietary Windows Vulkan driver (101.6129, UHD Graphics 770),
back-to-back depth-only then stencil-only rectangle clears sharing that
combined DEPTH | STENCIL attachment image view silently drop the stencil
vkCmdClearAttachments (8 of 8 combined depth-stencil cases in
d3d12_clear_formats).

Pass the actually cleared `aspects` to rect_view() so single-plane
rectangle clears use a matching single-aspect attachment view, and skip
rect_view() when !aspects (D3D-437). Add split-plane (depth-only then
stencil-only) rectangle clear regression cases for D24_UNORM_S8_UINT and
D32_FLOAT_S8X24_UINT to d3d12_clear_test.cpp.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:12:09 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-24 20:10 UTC · original

Tested 701dac39 applied onto main 23c459644 on an AMD Radeon RX 7900 XT: no change on this GPU. d3d12_clear still fails here, for the same pre-existing reason as on main (NaN depth clear, see below), and it stops before reaching the new split-plane case. With that one early exit bypassed locally, the new depth-only + stencil-only rect clear case matches WARP on both main and this PR, so the Intel driver issue does not reproduce on AMD and the fix does not regress it.

Hardware/software: AMD Radeon RX 7900 XT (RDNA3), AMD Windows driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300, VS 2022 (MSBuild, x64 RelWithDebInfo), Vulkan SDK 1.4.363.0.

Build (both trees configured the same way):

cmake -S runtime -B runtime/build/d3d12 -G "Visual Studio 17 2022" -A x64 -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON
cmake --build runtime/build/d3d12 --config RelWithDebInfo --parallel 16

Targeted tests, each run 3 times on main and 3 times on the PR build (third run with LEONIDA_VK_VALIDATION=1):

ctest --test-dir runtime/build/d3d12 -C RelWithDebInfo -R "^<name>$" --output-on-failure
test main (3 runs) PR (3 runs)
d3d12_clear fail 3/3 fail 3/3 (same output)
d3d12_clear_formats pass 3/3, "251 matched WARP, 0 differ" pass 3/3, "251 matched WARP, 0 differ"
vk_command_replay pass 3/3 pass 3/3
replay_clear_gate pass 3/3 pass 3/3

Why d3d12_clear fails on this GPU (main and PR alike): check_depth_clear_edge_values fails at "a NaN depth stays NaN" — all 15 texels read back layer cleared 1, WARP nan — and main() returns 1 there, before the color/depth format loop where the new split-plane case lives. With validation on, the same run also reports 4 errors, all VUID-VkClearDepthStencilValue-depth-00022 (depth 1.5, -0.5 and NaN without VK_EXT_depth_range_unrestricted) from that same edge-value section. So on AMD the stock test never executes the case this PR adds.

To exercise the new case anyway, I compiled a local copy of the PR's d3d12_clear_test.cpp in which the only change is that the if (!check_depth_clear_edge_values(...)) return 1; line prints a message and continues. I linked it once against main's libraries and once against the PR's (the runtime sources were not touched), and ran it 3 times against each, the third time with LEONIDA_VK_VALIDATION=1:

  • main: RTV and DSV clears: 234 full/rectangle readbacks matched WARP (exit 0, 2/2 runs); with validation it reaches the end and exits 1 only because of the same 4 edge-value validation errors.
  • PR: identical, 234 full/rectangle readbacks matched WARP (exit 0, 2/2 runs); with validation the same 4 errors and nothing new. The depth-only and stencil-only single-aspect attachment views produce no validation messages.

The 234 includes the two new split-plane cases (D24_UNORM_S8_UINT and D32_FLOAT_S8X24_UINT), which pass on main as well, so this AMD driver does not drop the stencil-only clear when the combined DEPTH | STENCIL view is shared. Note that on this driver the layer logs D24_UNORM_S8_UINT unavailable, using D32_SFLOAT_S8_UINT, so both new cases end up on the same Vulkan format here.

Full ctest on the PR build:

ctest --test-dir runtime/build/d3d12 -C RelWithDebInfo -j 4 --timeout 600 --output-on-failure

PR: 300/305 passed (98%), failures vk_queue_query_sync, d3d12_texture_tiles, d3d12_execute_indirect_validation, d3d12_clear, d3d12_pipeline_library_host. Main at 23c459644: the same 300/305 with the same five failures and the same skipped/disabled list. No new failures.

Something you could consider, separate from this PR: since the NaN edge-value check returns early from main(), d3d12_clear on AMD hides every case after it, including this one. Recording that failure and continuing, the way the format loop counts format_failures, would let the later cases run on this hardware.

**@⁠adrianmjim** on GitHub · 2026-11-24 20:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/619#issuecomment-7143154713) Tested 701dac39 applied onto main 23c459644 on an AMD Radeon RX 7900 XT: no change on this GPU. d3d12_clear still fails here, for the same pre-existing reason as on main (NaN depth clear, see below), and it stops before reaching the new split-plane case. With that one early exit bypassed locally, the new depth-only + stencil-only rect clear case matches WARP on both main and this PR, so the Intel driver issue does not reproduce on AMD and the fix does not regress it. Hardware/software: AMD Radeon RX 7900 XT (RDNA3), AMD Windows driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300, VS 2022 (MSBuild, x64 RelWithDebInfo), Vulkan SDK 1.4.363.0. Build (both trees configured the same way): ``` cmake -S runtime -B runtime/build/d3d12 -G "Visual Studio 17 2022" -A x64 -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON cmake --build runtime/build/d3d12 --config RelWithDebInfo --parallel 16 ``` Targeted tests, each run 3 times on main and 3 times on the PR build (third run with `LEONIDA_VK_VALIDATION=1`): ``` ctest --test-dir runtime/build/d3d12 -C RelWithDebInfo -R "^<name>$" --output-on-failure ``` | test | main (3 runs) | PR (3 runs) | |---|---|---| | d3d12_clear | fail 3/3 | fail 3/3 (same output) | | d3d12_clear_formats | pass 3/3, "251 matched WARP, 0 differ" | pass 3/3, "251 matched WARP, 0 differ" | | vk_command_replay | pass 3/3 | pass 3/3 | | replay_clear_gate | pass 3/3 | pass 3/3 | Why d3d12_clear fails on this GPU (main and PR alike): `check_depth_clear_edge_values` fails at "a NaN depth stays NaN" — all 15 texels read back `layer cleared 1, WARP nan` — and `main()` returns 1 there, before the color/depth format loop where the new split-plane case lives. With validation on, the same run also reports 4 errors, all VUID-VkClearDepthStencilValue-depth-00022 (depth 1.5, -0.5 and NaN without VK_EXT_depth_range_unrestricted) from that same edge-value section. So on AMD the stock test never executes the case this PR adds. To exercise the new case anyway, I compiled a local copy of the PR's d3d12_clear_test.cpp in which the only change is that the `if (!check_depth_clear_edge_values(...)) return 1;` line prints a message and continues. I linked it once against main's libraries and once against the PR's (the runtime sources were not touched), and ran it 3 times against each, the third time with `LEONIDA_VK_VALIDATION=1`: - main: `RTV and DSV clears: 234 full/rectangle readbacks matched WARP` (exit 0, 2/2 runs); with validation it reaches the end and exits 1 only because of the same 4 edge-value validation errors. - PR: identical, `234 full/rectangle readbacks matched WARP` (exit 0, 2/2 runs); with validation the same 4 errors and nothing new. The depth-only and stencil-only single-aspect attachment views produce no validation messages. The 234 includes the two new split-plane cases (D24_UNORM_S8_UINT and D32_FLOAT_S8X24_UINT), which pass on main as well, so this AMD driver does not drop the stencil-only clear when the combined DEPTH | STENCIL view is shared. Note that on this driver the layer logs `D24_UNORM_S8_UINT unavailable, using D32_SFLOAT_S8_UINT`, so both new cases end up on the same Vulkan format here. Full ctest on the PR build: ``` ctest --test-dir runtime/build/d3d12 -C RelWithDebInfo -j 4 --timeout 600 --output-on-failure ``` PR: 300/305 passed (98%), failures vk_queue_query_sync, d3d12_texture_tiles, d3d12_execute_indirect_validation, d3d12_clear, d3d12_pipeline_library_host. Main at 23c459644: the same 300/305 with the same five failures and the same skipped/disabled list. No new failures. Something you could consider, separate from this PR: since the NaN edge-value check returns early from `main()`, d3d12_clear on AMD hides every case after it, including this one. Recording that failure and continuing, the way the format loop counts `format_failures`, would let the later cases run on this hardware.
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 01:23 UTC · original

Reviewed 701dac39: ran check_no_game_data.py (OK), the Linux replay/clear CTests (vk_command_replay, replay_clear_gate, depth24_convert, clear_color, etc., 15/15 pass) and a small vulkan_replay.h + llvmpipe harness against origin/main on Linux arm64.

  • Confirmed: single-plane rect clears now build distinct DEPTH (0x2) / STENCIL (0x4) attachment views instead of sharing one cached DEPTH|STENCIL (0x6) view; D24S8 and D32S8 readbacks are exact in both cases. emit already used the masked aspects on main, so the view was the only mismatch.
  • Confirmed: with !aspects (no-op plane, e.g. clear_stencil on D32_FLOAT) the rect clear is now skipped without calling rect_view(), where main returned unsupported when dynamic rendering was unavailable. That is a second behaviour change in the same hunk, consistent with D3D-437; maybe worth one line in the PR text.
  • The two new D24S8/D32S8 split-plane cases match the clear_depth_and_read signature, and distinct stencil values (0x5A full vs 0xA5 rect) make a dropped stencil clear visible.

Not run here: the Windows/WARP d3d12_clear_test and the Intel 101.6129 driver behaviour itself. git merge-tree with current main is clean. No findings.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/619#issuecomment-7149501636) Reviewed 701dac39: ran `check_no_game_data.py` (OK), the Linux replay/clear CTests (`vk_command_replay`, `replay_clear_gate`, `depth24_convert`, `clear_color`, etc., 15/15 pass) and a small `vulkan_replay.h` + llvmpipe harness against `origin/main` on Linux arm64. - Confirmed: single-plane rect clears now build distinct `DEPTH` (0x2) / `STENCIL` (0x4) attachment views instead of sharing one cached `DEPTH|STENCIL` (0x6) view; D24S8 and D32S8 readbacks are exact in both cases. `emit` already used the masked aspects on main, so the view was the only mismatch. - Confirmed: with `!aspects` (no-op plane, e.g. `clear_stencil` on `D32_FLOAT`) the rect clear is now skipped without calling `rect_view()`, where main returned `unsupported` when dynamic rendering was unavailable. That is a second behaviour change in the same hunk, consistent with D3D-437; maybe worth one line in the PR text. - The two new D24S8/D32S8 split-plane cases match the `clear_depth_and_read` signature, and distinct stencil values (0x5A full vs 0xA5 rect) make a dropped stencil clear visible. Not run here: the Windows/WARP `d3d12_clear_test` and the Intel 101.6129 driver behaviour itself. `git merge-tree` with current main is clean. No findings. AI-assisted review. **Recommendation:** Merge
This pull request has changes conflicting with the target branch.
  • runtime/src/vulkan_replay.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/619/head:github-bot/gh-619'
git switch 'github-bot/gh-619'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-619'
git switch 'github-bot/gh-619'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-619'
git switch 'github-bot/gh-619'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-619'
git switch 'main'
git merge --squash 'github-bot/gh-619'
git switch 'main'
git merge --ff-only 'github-bot/gh-619'
git switch 'main'
git merge 'github-bot/gh-619'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.