d3d12: honor predication when clearing buffer UAVs #2277

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

@⁠PyZikYG on GitHub · 2026-11-26 12:14 UTC · original
PyZikYG:d3d12-predicated-buffer-uav-clear → main · +209 −60 · 8 files · 1 commits · open

Claimed as D3D-PREDICATED-BUFFER-UAV-CLEAR.

Summary

Buffer ClearUnorderedAccessViewUint and ClearUnorderedAccessViewFloat now honor SetPredication. The Vulkan replay uses the existing conditional compute path to repeat the encoded UAV element across each validated range. It carries the element position across descriptor windows and excludes the helper dispatches from application pipeline statistics.

Verification

Checked skipped and executed buffer clears by reading back their bytes, including narrow float-converted elements, overlapping integer ranges and a wide pattern split across descriptor windows. Ran the existing predicated-copy and short-clear coverage.

AI-assisted: yes.

**@⁠PyZikYG** on GitHub · 2026-11-26 12:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2277) `PyZikYG:d3d12-predicated-buffer-uav-clear` → `main` · +209 −60 · 8 files · 1 commits · open Claimed as [D3D-PREDICATED-BUFFER-UAV-CLEAR](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). ### Summary Buffer `ClearUnorderedAccessViewUint` and `ClearUnorderedAccessViewFloat` now honor `SetPredication`. The Vulkan replay uses the existing conditional compute path to repeat the encoded UAV element across each validated range. It carries the element position across descriptor windows and excludes the helper dispatches from application pipeline statistics. ### Verification Checked skipped and executed buffer clears by reading back their bytes, including narrow float-converted elements, overlapping integer ranges and a wide pattern split across descriptor windows. Ran the existing predicated-copy and short-clear coverage. AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:15:33 +00:00
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:24 UTC · original

Partly verified on main a73a57e1 with Mesa llvmpipe (Mesa 25.2.8, LLVM 20.1.2, 256 bits, Ubuntu 24.04 x86-64, no GPU), GCC 13.3, Ninja. Merges cleanly.

  • vk_predicated_copy (ctest) passes with this PR: "32 gated + 32 reused submissions; byte offsets, forced windows, copy dependency, rebinding/reset and untouched bytes passed". The PR's runtime/test/vk_predicated_copy_test.cpp built against main fails, so its new case fails on main and passes with the change.
  • Not run: d3d12_uav_clear_test, which links d3d12/dxgi and is built on Windows only.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2277#issuecomment-7191952694) Partly verified on main a73a57e1 with Mesa llvmpipe (Mesa 25.2.8, LLVM 20.1.2, 256 bits, Ubuntu 24.04 x86-64, no GPU), GCC 13.3, Ninja. Merges cleanly. - vk_predicated_copy (ctest) passes with this PR: "32 gated + 32 reused submissions; byte offsets, forced windows, copy dependency, rebinding/reset and untouched bytes passed". The PR's runtime/test/vk_predicated_copy_test.cpp built against main fails, so its new case fails on main and passes with the change. - Not run: d3d12_uav_clear_test, which links d3d12/dxgi and is built on Windows only. AI-assisted: yes (Claude Code)
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 13:50 UTC · original

I ran the Windows D3D12 buffer-clear test that the llvmpipe verification left open. On an RTX 4090, the parent executed clears that the predicate should have skipped. The PR preserved the expected bytes.

Test using the PR’s fixtures Parent a73a57e13 PR c53811511
d3d12_uav_clear_test 25 incorrect bytes. Bytes 3–7 were ff instead of 80 after the R8_UNORM clear, and the skipped integer clear overwrote earlier values. All 256 bytes in the predicated buffer matched. The full executable passed.
vk_predicated_copy_test Failed the first combined source/destination readback check. Passed all 32 gated and 32 reused submissions, including the forced descriptor-window case.

I also varied the predicate in a test-only copy of the buffer fixture. For each of EQUAL_ZERO and NOT_EQUAL_ZERO, I used a zero word and a word with exactly one bit set, at bit 0, 31, 32 or 63. The fixture exercised both executing and skipping integer and float clears in every run. All eight 256-byte readbacks matched, including bytes outside the clear ranges.

Windows 11, NVIDIA 616.64, MSVC Release, synthetic inputs. Both stock executables and all eight additional configurations passed on the PR with Vulkan synchronization validation enabled and zero validation errors. The stock suite reported its format-specific skip for A4B4G4R4_UNORM on this card.

AI-assisted verification by OpenAI Codex (GPT-6).

**@⁠ecox982745** on GitHub · 2026-11-26 13:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2277#issuecomment-7193904862) I ran the Windows D3D12 buffer-clear test that the [llvmpipe verification](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/2277) left open. On an RTX 4090, the parent executed clears that the predicate should have skipped. The PR preserved the expected bytes. | Test using the PR’s fixtures | Parent `a73a57e13` | PR `c53811511` | | --- | --- | --- | | `d3d12_uav_clear_test` | 25 incorrect bytes. Bytes 3–7 were `ff` instead of `80` after the R8_UNORM clear, and the skipped integer clear overwrote earlier values. | All 256 bytes in the predicated buffer matched. The full executable passed. | | `vk_predicated_copy_test` | Failed the first combined source/destination readback check. | Passed all 32 gated and 32 reused submissions, including the forced descriptor-window case. | I also varied the predicate in a test-only copy of the buffer fixture. For each of `EQUAL_ZERO` and `NOT_EQUAL_ZERO`, I used a zero word and a word with exactly one bit set, at bit 0, 31, 32 or 63. The fixture exercised both executing and skipping integer and float clears in every run. All eight 256-byte readbacks matched, including bytes outside the clear ranges. Windows 11, NVIDIA 616.64, MSVC Release, synthetic inputs. Both stock executables and all eight additional configurations passed on the PR with Vulkan synchronization validation enabled and zero validation errors. The stock suite reported its format-specific skip for A4B4G4R4_UNORM on this card. AI-assisted verification by OpenAI Codex (GPT-6).
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 19:03 UTC · original · reviewed

macOS arm64 / GPU check of #2277 (D3D12-PREDICATED-UAV-CLEAR). A Vulkan compute pass, its host plumbing and a GPU test, so it runs here on KosmicKrisp (MoltenVK has no VK_EXT_conditional_rendering).

Tested head c53811511 merged onto main bdbc7e923 as merge 3eb6e4442 (clean, no conflicts).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0, KosmicKrisp = Mesa 26.3.0 (subgroup 32), glslang 16.6.0.

The pass runs, and both controls bite

  • vk_predicated_copy_test on the merge, KosmicKrisp: exit 0, 32 gated + 32 reused submissions; byte offsets, forced windows, copy dependency, rebinding/reset and untouched bytes passed. The new clear case is inside that run (the test forces 67-byte descriptor windows, so the pattern is carried across window splits).
  • MoltenVK: the test skips (requires conditional rendering and storageBuffer8BitAccess), exit 0 - see the finding.
  • main bdbc7e923 with its own (copy-only) test on KosmicKrisp: exit 0. The old test never issues a clear, which is why this PR's bug could exist at all.
  • Negative control 1 (shader semantics): kept everything, removed the copy.phase term from predicated_copy.comp (byte_index = i % copy.element_size), regenerated the header and rebuilt. Exit 1 at line 120: std::memcmp(dst_data,expected.data(),bytes)==0 ... - the pattern restarted at each 67-byte window. Restored.
  • Negative control 2 (predication): kept everything, changed the new if (predicated) fill branch in vulkan_replay.h:3653 to if (false), so the clear fell through to the transfer path like main. Exit 1 at the same line 120 - the suppressed clear wrote its bytes. Restored.
  • The checked-in SPIR-V is exactly what glslang 16.6.0 -V --target-env vulkan1.2 -Os --spirv-val produces from predicated_copy.comp: 564 words, byte-identical. That is the first time I could compare rather than just run (the header names the same glslang version this machine has).
  • Related portable tests on the merge: predicated_copy_test, vk_command_replay_test, replay_query_edges_test and vk_predicate_capture_test (KosmicKrisp) all pass, as does replay_query_predication_test on both drivers. The out.unpredicated_copies change removes one counter increment and nothing depended on it.
  • Predication polarity cross-check, since this PR makes a new command class depend on it: EQUAL_ZERO → no inverted bit, NOT_EQUAL_ZERO → VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT here is the same mapping vkd3d uses (libs/vkd3d/command.c, d3d12_command_list_SetPredication), and the fills are emitted inside the same conditional scope (the branch is under the SetPredication capture), so a clear inside a predicate follows the same rule as a copy. I read the mapping as suspicious at first and checked it against vkd3d before writing this; it is right.

Cannot run here: d3d12_uav_clear_test, the Windows end of the PR (MSVC + a D3D12 device). So the API path - ClearUnorderedAccessViewUint inside SetPredication with the new Clear::Predicate cases, the info.storage_buffer_8bit gate and the no-helper-device rejection - is unexecuted on my side. It also only runs its new cases where conditional_rendering && storage_buffer_8bit both hold, so on an older AMD/Intel driver or a WARP without 8-bit storage the D3D12 coverage is skipped as well.

Finding: the capability skip is a pass, so the new clear coverage can be silently absent
runtime/test/vk_predicated_copy_test.cpp:27-30 returns 0 with predicated copy: skipped (...) when the device lacks VK_EXT_conditional_rendering or storageBuffer8BitAccess. vk_predicated_copy is registered with SKIP_RETURN_CODE 77 (runtime/CMakeLists.txt:2083), and the device-unavailable path already return 77, so returning 77 here would make CTest report a skip; returning 0 reports PASS. My MoltenVK run is exactly that case: a green test that ran none of the new code. On any CI GPU without the extension, the predicated-fill path this PR adds would be unverified while the suite looks clean. One line: return 77; for the capability skip, as the file already does for DeviceStatus::unavailable.

Nit: the replay now sets p.skip = true when the fills list is empty (vulkan_replay.h:3650-3653) even though detail::prepare_buffer_uav_clear already sets it for that case (:2100); one of the two is redundant. Harmless, and the explicit one reads better in the predicated branch, so I would only remove the older one if you touch it.

Not re-run: the shader corpus and the 268 GPU fixtures (no translator or harness change); the same-main baseline stands (195 PASS / 3 FAIL / 70 SKIP MoltenVK, 190 / 5 / 73 KosmicKrisp at bdbc7e923).

python -I scripts/check_no_game_data.py on the .comp, the regenerated header, the three host headers and the two tests: clean.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 19:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2277#pullrequestreview-6079292109) · **reviewed** **macOS arm64 / GPU check of #2277** (D3D12-PREDICATED-UAV-CLEAR). A Vulkan compute pass, its host plumbing and a GPU test, so it runs here on KosmicKrisp (MoltenVK has no `VK_EXT_conditional_rendering`). Tested head `c53811511` merged onto `main` `bdbc7e923` as merge `3eb6e4442` (clean, no conflicts). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0, KosmicKrisp = Mesa 26.3.0 (subgroup 32), glslang 16.6.0. **The pass runs, and both controls bite** - `vk_predicated_copy_test` on the merge, KosmicKrisp: exit 0, `32 gated + 32 reused submissions; byte offsets, forced windows, copy dependency, rebinding/reset and untouched bytes passed`. The new clear case is inside that run (the test forces 67-byte descriptor windows, so the pattern is carried across window splits). - MoltenVK: the test skips (`requires conditional rendering and storageBuffer8BitAccess`), exit 0 - see the finding. - `main` `bdbc7e923` with its own (copy-only) test on KosmicKrisp: exit 0. The old test never issues a clear, which is why this PR's bug could exist at all. - Negative control 1 (shader semantics): kept everything, removed the `copy.phase` term from `predicated_copy.comp` (`byte_index = i % copy.element_size`), regenerated the header and rebuilt. Exit 1 at `line 120: std::memcmp(dst_data,expected.data(),bytes)==0 ...` - the pattern restarted at each 67-byte window. Restored. - Negative control 2 (predication): kept everything, changed the new `if (predicated)` fill branch in `vulkan_replay.h:3653` to `if (false)`, so the clear fell through to the transfer path like `main`. Exit 1 at the same `line 120` - the suppressed clear wrote its bytes. Restored. - The checked-in SPIR-V is exactly what `glslang 16.6.0 -V --target-env vulkan1.2 -Os --spirv-val` produces from `predicated_copy.comp`: 564 words, byte-identical. That is the first time I could compare rather than just run (the header names the same glslang version this machine has). - Related portable tests on the merge: `predicated_copy_test`, `vk_command_replay_test`, `replay_query_edges_test` and `vk_predicate_capture_test` (KosmicKrisp) all pass, as does `replay_query_predication_test` on both drivers. The `out.unpredicated_copies` change removes one counter increment and nothing depended on it. - Predication polarity cross-check, since this PR makes a new command class depend on it: `EQUAL_ZERO` → no inverted bit, `NOT_EQUAL_ZERO` → `VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT` here is the same mapping vkd3d uses (`libs/vkd3d/command.c`, `d3d12_command_list_SetPredication`), and the fills are emitted inside the same conditional scope (the branch is under the `SetPredication` capture), so a clear inside a predicate follows the same rule as a copy. I read the mapping as suspicious at first and checked it against vkd3d before writing this; it is right. **Cannot run here**: `d3d12_uav_clear_test`, the Windows end of the PR (MSVC + a D3D12 device). So the API path - `ClearUnorderedAccessViewUint` inside `SetPredication` with the new `Clear::Predicate` cases, the `info.storage_buffer_8bit` gate and the no-helper-device rejection - is unexecuted on my side. It also only runs its new cases where `conditional_rendering && storage_buffer_8bit` both hold, so on an older AMD/Intel driver or a WARP without 8-bit storage the D3D12 coverage is skipped as well. **Finding: the capability skip is a pass, so the new clear coverage can be silently absent** `runtime/test/vk_predicated_copy_test.cpp:27-30` returns 0 with `predicated copy: skipped (...)` when the device lacks `VK_EXT_conditional_rendering` or `storageBuffer8BitAccess`. `vk_predicated_copy` is registered with `SKIP_RETURN_CODE 77` (`runtime/CMakeLists.txt:2083`), and the device-unavailable path already `return 77`, so returning 77 here would make CTest report a skip; returning 0 reports PASS. My MoltenVK run is exactly that case: a green test that ran none of the new code. On any CI GPU without the extension, the predicated-fill path this PR adds would be unverified while the suite looks clean. One line: `return 77;` for the capability skip, as the file already does for `DeviceStatus::unavailable`. **Nit**: the replay now sets `p.skip = true` when the fills list is empty (`vulkan_replay.h:3650-3653`) even though `detail::prepare_buffer_uav_clear` already sets it for that case (`:2100`); one of the two is redundant. Harmless, and the explicit one reads better in the predicated branch, so I would only remove the older one if you touch it. **Not re-run**: the shader corpus and the 268 GPU fixtures (no translator or harness change); the same-main baseline stands (195 PASS / 3 FAIL / 70 SKIP MoltenVK, 190 / 5 / 73 KosmicKrisp at `bdbc7e923`). `python -I scripts/check_no_game_data.py` on the `.comp`, the regenerated header, the three host headers and the two tests: clean. No game files. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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