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

Closed
KarolKurzyna wants to merge 1 commit from upstream-pr/619 into main
KarolKurzyna commented 2026-11-24 10:00:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KarolKurzyna on 2026-11-24T10:00:12Z.


Claimed in the coordination issue as: OLD-7634 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128154815)

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469984640 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/619). Originally posted by [KarolKurzyna](https://github.com/KarolKurzyna) on 2026-11-24T10:00:12Z. --- Claimed in the coordination issue as: OLD-7634 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128154815) 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.
adrianmjim commented 2026-11-24 20:10:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-24T20:10:54Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143154713 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/619#issuecomment-7143154713). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-24T20:10:54Z. --- 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.
PierreEbele commented 2026-11-25 01:23:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T01:23:49Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7149501636 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/619#issuecomment-7149501636). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T01:23:49Z. --- 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
MoonEyes commented 2026-11-27 23:20:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:12Z.


Hi @KarolKurzyna, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/src/vulkan_replay.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230061299 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/619#issuecomment-7230061299). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:12Z. --- Hi @KarolKurzyna, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/src/vulkan_replay.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:31:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:31:04Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317737630 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/619#issuecomment-7317737630). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:31:04Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!619
No description provided.