Repository navigation
Conversation
…e stack emit made a std::vector<VkImageMemoryBarrier2> for each TextureBarrier: one heap allocation for each enhanced texture barrier. The barriers of the usual one or two layout pieces are now in a stack array; a vector holds them only when a range has more than two pieces. replay_cpu_bench gets an enhanced texture barrier row, and its self-test fails when emit allocates for that row. replay_texture_barrier_test checks the barriers of a one-piece range (no allocation) and of a three-piece range. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Built and ran replay_texture_barrier_test at 7b1e5b40 on Windows 11: replay_texture_barrier_test: OK, exit 0.
An enhanced texture barrier's image barriers now stay on the stack during emit (no heap allocation), and the new test plus the existing replay behaviour pass. No blocking issue.
Flyander
left a comment
There was a problem hiding this comment.
Reviewed 7b1e5b4: emit uses two stack slots for the common one- or two-piece layout case and allocates a vector only for larger piece counts. The synthetic test checks both single-piece allocation behavior and per-mip barriers for mixed layouts; Windows test report passes.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Removes per-command heap allocation when emitting enhanced texture barriers in Vulkan replay, and adds tests/bench coverage to prevent regressions.
Changes:
- Update
emitto use a small stack buffer for the common 1–2 image barrier case, heap-allocating only when needed. - Add a dedicated replay test that validates barrier emission shape (count/layouts) and asserts no heap allocations for the 1-piece case.
- Extend CPU replay bench with a new enhanced texture barrier row plus a self-test allocation check.
| File | Description |
|---|---|
| runtime/src/vulkan_replay.h | Switch texture barrier barrier storage from always-heap std::vector to stack-first storage. |
| runtime/test/replay_texture_barrier_test.cpp | New test validating barrier recording and ensuring emit does not allocate in the 1-piece case. |
| runtime/test/replay_cpu_bench.cpp | Add benchmark kind for enhanced texture barrier pairs and enforce zero emit allocations in self-test. |
| runtime/CMakeLists.txt | Wire the new replay texture barrier test into the build and CTest. |
Review effort: Lite
| // One image barrier for each piece: emit keeps the usual one or two on the stack. | ||
| if (kind.name == texture_barrier_kind && r.emit.allocations != 0) { | ||
| std::fprintf(stderr, "FAIL %s: emit makes %.2f heap allocations per command\n", kind.name, | ||
| r.emit.allocations); |
There was a problem hiding this comment.
Fixed in c448630. The self-test now compares the row name by content: std::strcmp(kind.name, texture_barrier_kind) == 0. replay_cpu_bench --self-test passes on Windows 11 with MSVC 14.51. AI-assisted.
|
|
||
| void* operator new(std::size_t size) { | ||
| ++g_allocations; | ||
| if (void* p = std::malloc(size ? size : 1)) return p; | ||
| throw std::bad_alloc(); | ||
| } | ||
| void* operator new[](std::size_t size) { return operator new(size); } | ||
| void operator delete(void* p) noexcept { std::free(p); } | ||
| void operator delete[](void* p) noexcept { std::free(p); } | ||
| void operator delete(void* p, std::size_t) noexcept { std::free(p); } | ||
| void operator delete[](void* p, std::size_t) noexcept { std::free(p); } | ||
|
|
There was a problem hiding this comment.
Fixed in c448630. replay_texture_barrier_test now also replaces the aligned forms: operator new and operator new[] with std::align_val_t, and the four aligned operator delete forms. Each aligned allocation adds 1 to the counter. The nothrow forms of the standard library call the replaced forms, thus the counter includes them. There was no link error before this change, because the standard library supplies the aligned forms when a program does not replace them. replay_texture_barrier_test passes, and ctest -R "replay_|command_list" passes 10 of 10 on Windows 11 with MSVC 14.51. The Linux build runs in CI. AI-assisted.
|
Tested
No game data. AI-assisted. |
…locations Review of ItsNotRexed#4468: replay_cpu_bench compares the row name with std::strcmp instead of by pointer, and replay_texture_barrier_test also replaces the aligned forms of operator new and delete, so that an allocation of an over-aligned type is counted. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested c448630 merged with main d0835dd (merged tree fd523a0ebd) on Windows 11 with two GPUs (MSVC 14.51): built
Negative control: |
|
Tested c448630 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran AI-assisted. |

Claimed in the coordination issue as: RT-290 (claim). Finding: item 4 of the runtime audit.
What and why
emitinruntime/src/vulkan_replay.hmade astd::vector<VkImageMemoryBarrier2>for eachTextureBarrier. Thus each enhanced texture barrier made one heap allocation. #901 removed the allocations of the other barriers, clears and copies, but not this one.replay_cpu_benchhad no enhanced texture barrier row, thus the allocation column did not show it.This change:
emitkeeps the image barriers in a stack array of 2. A range has one barrier for each layout piece. The usual range has one or two pieces (LayoutPieces). A vector holds the barriers only when a range has more than two pieces.emitcontinues to make onevkCmdPipelineBarrier2call with all the barriers of the range.replay_cpu_benchhas a new row,texture barrier pair (enh.). Its self-test fails whenemitallocates for this row.replay_texture_barrier_testis new. It records the barriers of thevkCmdPipelineBarrier2call. Case 1: a range in one layout gives one barrier and no heap allocation inemit. Case 2: three mips in three layouts give three barriers in one call, each with the old layout of its mip.The diff in
vulkan_replay.his 10 added lines and 5 removed lines. I examined the open pull requests #1872, #2471, #2928, #2969, #3693 and #3784. They do not change these lines.Tested
Windows 11, MSVC 14.51, CMake + Ninja,
RelWithDebInfo. NVIDIA GeForce RTX 4090, driver 32.0.16.2101. No game files.The tests that fail before the change and pass after it:
main(03b09a08)replay_texture_barrier_testFAIL: emit allocates nothing for a barrier with one piece(1 allocation)replay_cpu_bench --self-testFAIL texture barrier pair (enh.): emit makes 1.00 heap allocations per commandreplay_cpu_bench --reps 101, rowtexture barrier pair (enh.), 4096 commands, 5 runs for each build, in turns:mainOther tests:
cteston this branch: 134 of 135 tests pass.xbox_presentfails. Fullctestonmain: 132 of 134 tests pass.d3d12_presentandxbox_presentfail. These two tests fail onmainon this computer because of the window manager.d3d12_presentpasses in some runs and fails in others, onmainalso. 10 tests do not run on the two builds (no game files, no SDL3, no validation layer).vk_command_replay_teston the RTX 4090: OK (validation off, because the Vulkan SDK is not installed).vk_queue_teston the RTX 4090: OK.command_list_testand the otherreplay_*tests: OK.AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator rule.)🤖 Generated with Claude Code