Skip to content

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

Open
akimfomin wants to merge 1 commit into
ProjectLeonida:mainfrom
akimfomin:codex/vulkan-image-layout-range-coalescing
Open

akimfomin wants to merge 1 commit into
ProjectLeonida:mainfrom
akimfomin:codex/vulkan-image-layout-range-coalescing

Conversation

@akimfomin

Copy link
Copy Markdown
Contributor

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.

@kawaii-shakal kawaii-shakal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

@akimfomin

Copy link
Copy Markdown
Contributor Author

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).

@potatoe0100

Copy link
Copy Markdown
Contributor

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).

@akimfomin

Copy link
Copy Markdown
Contributor Author

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.

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.

3 participants