vulkan: coalesce equal image layout ranges (VK-IMAGE-LAYOUT-RANGE-COALESCING) #1713

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

@⁠akimfomin on GitHub · 2026-11-25 09:16 UTC · original
akimfomin:codex/vulkan-image-layout-range-coalescing → main · +90 −15 · 2 files · 1 commits · open

Claimed in the coordination issue as: VK-IMAGE-LAYOUT-RANGE-COALESCING

What and why

Merge adjacent initialized rectangles with the same prior Vulkan image layout and aspect. The replay still issues the same ordered calls and synchronization scopes. Mixed first-use cells keep individual pieces. Uniform, small mixed, and singleton-only ranges retain fast paths. There is a regression case for a two-mip, two-layer stripe beside first-use cells.

DadaCap suggested a separate follow-up in #1284. This change applies to main itself, and a local combination with #1284 also passed.

Tested

On Windows, Clang 23.1.6 built and ran d3d12_state_map_test, replay_texture_barrier_test, and 96 seeded per-cell geometry cases on current main 626d1281 and on this patch. The same tests and a rollback/commit fixture passed on both arms of the combined tree with #1284 head 2c178819. The combined partial-release case uses 3 instead of 12 image barriers. The ordered fixture uses 5 instead of 14 with the same per-cell layouts and scopes. Same-layout recording allocates zero in both arms.

The earlier two-core CPU benchmark measured 640 to 2 records and 41.7–47.1% less partition time on stripes. Mostly-undefined and checkerboard partitions did not improve in that benchmark. Pinned benchmark and fixture sources

GPUs tested: none on this exact head. The linked earlier Vulkan readback used RTX 4070 Ti SUPER and tested a different revision.

AI-assisted: yes (Codex). PortBridge

Checklist

  • Based on current main and merges cleanly.
  • One topic and a separate follow-up.
  • No game inputs, keys or decryption.
**@⁠akimfomin** on GitHub · 2026-11-25 09:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1713) `akimfomin:codex/vulkan-image-layout-range-coalescing` → `main` · +90 −15 · 2 files · 1 commits · open Claimed in the coordination issue as: [VK-IMAGE-LAYOUT-RANGE-COALESCING](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Merge adjacent initialized rectangles with the same prior Vulkan image layout and aspect. The replay still issues the same ordered calls and synchronization scopes. Mixed first-use cells keep individual pieces. Uniform, small mixed, and singleton-only ranges retain fast paths. There is a regression case for a two-mip, two-layer stripe beside first-use cells. DadaCap suggested a separate follow-up in #1284. This change applies to main itself, and a local combination with #1284 also passed. ### Tested On Windows, Clang 23.1.6 built and ran `d3d12_state_map_test`, `replay_texture_barrier_test`, and 96 seeded per-cell geometry cases on current main `626d1281` and on this patch. The same tests and a rollback/commit fixture passed on both arms of the combined tree with #1284 head `2c178819`. The combined partial-release case uses 3 instead of 12 image barriers. The ordered fixture uses 5 instead of 14 with the same per-cell layouts and scopes. Same-layout recording allocates zero in both arms. The earlier two-core CPU benchmark measured 640 to 2 records and 41.7–47.1% less partition time on stripes. Mostly-undefined and checkerboard partitions did not improve in that benchmark. [Pinned benchmark and fixture sources](https://github.com/akimfomin/PortBridge/tree/049b46286518c20d98dc74ae700e66599110d964/research/continued-layout-range-coalescing) GPUs tested: none on this exact head. The linked earlier Vulkan readback used RTX 4070 Ti SUPER and tested a different revision. AI-assisted: yes (Codex). [PortBridge](https://github.com/akimfomin/PortBridge) ### Checklist - [x] Based on current main and merges cleanly. - [x] One topic and a separate follow-up. - [x] No game inputs, keys or decryption.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:59 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 09:45 UTC · original · reviewed

Review (read-only, not run). I traced the merge and the early-out:

  • index - 1 is the previous mip of the same layer, and index - e.mips is the previous layer of the same plane, only read when mip/layer is past the range base, so both are in bounds;
  • last_run is keyed by mip with the aspect compared, so a depth run and a stencil run never merge;
  • UNDEFINED cells keep one piece each, so initialize() still gets its per-piece transfer regions.

Looks correct to me. Two small things:

  • area with VK_REMAINING_MIP_LEVELS / VK_REMAINING_ARRAY_LAYERS is about 2^64. It only feeds the <= 2 test, so it is harmless, but visit clamps the range and this doesn't, which reads oddly. Clamping it the same way would make the intent obvious.
  • "GPUs tested: none on this exact head". The replay emits fewer, larger barriers now, so one replay_texture_barrier + d3d12_msaa_draw run on a GPU with the sync validation layer would be worth it. I ran both on an RTX 5070 Ti for #778's merge with main; I can run this head the same way if useful.

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

**@⁠kawaii-shakal** on GitHub · 2026-11-25 09:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1713#pullrequestreview-6055209960) · **reviewed** Review (read-only, not run). I traced the merge and the early-out: - `index - 1` is the previous mip of the same layer, and `index - e.mips` is the previous layer of the same plane, only read when `mip`/`layer` is past the range base, so both are in bounds; - `last_run` is keyed by mip with the aspect compared, so a depth run and a stencil run never merge; - `UNDEFINED` cells keep one piece each, so `initialize()` still gets its per-piece transfer regions. Looks correct to me. Two small things: - `area` with `VK_REMAINING_MIP_LEVELS` / `VK_REMAINING_ARRAY_LAYERS` is about 2^64. It only feeds the `<= 2` test, so it is harmless, but `visit` clamps the range and this doesn't, which reads oddly. Clamping it the same way would make the intent obvious. - "GPUs tested: none on this exact head". The replay emits fewer, larger barriers now, so one `replay_texture_barrier` + `d3d12_msaa_draw` run on a GPU with the sync validation layer would be worth it. I ran both on an RTX 5070 Ti for #778's merge with main; I can run this head the same way if useful. AI-assisted review (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-25 09:59 UTC · original

Thanks for tracing the merge, @⁠kawaii-shakal. Your RTX 5070 Ti run would be useful. Please use the unchanged ef9ae1fd54d5c452eb31236c1ca86debe0a5fda9 head and run replay_texture_barrier and d3d12_msaa_draw with Vulkan synchronization validation enabled. Please record the exact SHA, driver and OS, pass/fail/skip for each test, and any synchronization-validation diagnostics or confirm there were none.

Agreed that clamping the VK_REMAINING_* range in the area check the same way as visit would make the early-out clearer. I’ll leave this head pinned for your run and revisit that readability point afterward.

AI-assisted (Codex drafted this reply).

**@⁠akimfomin** on GitHub · 2026-11-25 09:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1713#issuecomment-7159070010) Thanks for tracing the merge, @⁠kawaii-shakal. Your RTX 5070 Ti run would be useful. Please use the unchanged `ef9ae1fd54d5c452eb31236c1ca86debe0a5fda9` head and run `replay_texture_barrier` and `d3d12_msaa_draw` with Vulkan synchronization validation enabled. Please record the exact SHA, driver and OS, pass/fail/skip for each test, and any synchronization-validation diagnostics or confirm there were none. Agreed that clamping the `VK_REMAINING_*` range in the `area` check the same way as `visit` would make the early-out clearer. I’ll leave this head pinned for your run and revisit that readability point afterward. AI-assisted (Codex drafted this reply).
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 11:46 UTC · original

Tested the unchanged head ef9ae1fd5 merged onto main bcaa13dad (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, Vulkan SDK 1.4.363.0.

  • With LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1: replay_texture_barrier, d3d12_msaa_draw and d3d12_state_map pass, with no VUIDs and no sync hazards. vk_sync_validation passes in the same run (it reports its deliberate WRITE_AFTER_WRITE), so synchronization validation was really on.
  • Full ctest -j 6: 409 of 409 passed, same as main. run_gpu_tests.py: 209/263, identical to main.

AI-assisted testing (non-developer tester).

**@⁠potatoe0100** on GitHub · 2026-11-25 11:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1713#issuecomment-7161475134) Tested the unchanged head `ef9ae1fd5` merged onto `main` `bcaa13dad` (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, Vulkan SDK 1.4.363.0. - With `LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_VALIDATE_SYNC=1`: `replay_texture_barrier`, `d3d12_msaa_draw` and `d3d12_state_map` pass, with no VUIDs and no sync hazards. `vk_sync_validation` passes in the same run (it reports its deliberate WRITE_AFTER_WRITE), so synchronization validation was really on. - Full `ctest -j 6`: 409 of 409 passed, same as `main`. `run_gpu_tests.py`: 209/263, identical to `main`. AI-assisted testing (non-developer tester).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 02:27 UTC · original

DadaCap, thank you for suggesting that the equal-layout change stand on its own. kawaii-shakal, your review caught the difference between the range used by the early-out and the clamped range used for the visit. potatoe0100, the deliberate validation hazard in your RTX 4060 control makes your clean replay and MSAA results particularly valuable.

I’m moving PortBridge to passive support and leaving this head at ef9ae1fd54d5c452eb31236c1ca86debe0a5fda9 for comparison. The small fixtures and benchmark and independent GPU run are preserved. A future reviewer can check whether to align the early-out with the clamped range and whether the change is useful on today's replay path. The measured barrier counts and CPU partition timings cover the fixtures; whole-frame timing is still open. Please feel free to carry this through your usual review process. Incoming questions are welcome here. Codex helped prepare the handover.

**@⁠akimfomin** on GitHub · 2026-11-26 02:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1713#issuecomment-7180829192) DadaCap, thank you for suggesting that the equal-layout change stand on its own. kawaii-shakal, your review caught the difference between the range used by the early-out and the clamped range used for the visit. potatoe0100, the deliberate validation hazard in your RTX 4060 control makes your clean replay and MSAA results particularly valuable. I’m moving [PortBridge](https://github.com/akimfomin/PortBridge) to passive support and leaving this head at `ef9ae1fd54d5c452eb31236c1ca86debe0a5fda9` for comparison. The [small fixtures and benchmark](https://github.com/akimfomin/PortBridge/tree/049b46286518c20d98dc74ae700e66599110d964/research/continued-layout-range-coalescing) and [independent GPU run](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1713) are preserved. A future reviewer can check whether to align the early-out with the clamped range and whether the change is useful on today's replay path. The measured barrier counts and CPU partition timings cover the fixtures; whole-frame timing is still open. Please feel free to carry this through your usual review process. Incoming questions are welcome here. Codex helped prepare the handover.
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/1713/head:github-bot/gh-1713'
git switch 'github-bot/gh-1713'

Merge

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