perf(sync): scope frame-loop barriers to swapchain image + real per-pass stages (#115)

The inter-pass and acquire/present barriers in the frame loop set both
stage masks to ALL_COMMANDS, and the inter-pass dependency used a
queue-wide VkMemoryBarrier — fully serialising against every pipeline
stage and flushing all caches every frame, when all the next pass needs
is the swapchain image the previous one wrote.

Replace the inter-pass global VkMemoryBarrier with an image memory
barrier scoped to the swapchain image's single colour subresource (as
the intra-pass UI barrier already does), and derive the barrier stage
masks per pass: RenderPass::SwapchainStage() is overridden by UIRenderer
(COMPUTE_SHADER) and RTPass (RAY_TRACING_SHADER), so a compute->compute
edge only serialises COMPUTE while an RT pass pulls in RAY_TRACING — the
acquire/present frame-edge masks use the real union of the frame's
passes (SwapchainStageUnion). The base default and the empty-passes
fallback are the conservative COMPUTE | RAY_TRACING | TRANSFER union, so
a polymorphic or un-overridden pass can only be over- not
under-synchronised.

Adds SwapchainBarrierScope (pure CPU) pinning the per-pass derivation,
the union narrowing, and the inter-pass barrier scope; FrameLoopSync
already drives the real GPU frame loop with validation enabled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
catbot 2026-06-17 19:44:33 +00:00
commit 9414863cff
6 changed files with 316 additions and 8 deletions

View file

@ -201,6 +201,15 @@ export namespace Crafter {
void Record(GraphicsCommandBuffer cmd, std::uint32_t frameIdx, Window& window) override;
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
// A UI pass draws into the swapchain image entirely from compute
// shaders (see Dispatch), so the frame loop's inter-pass / frame-edge
// barriers only need to synchronise the COMPUTE_SHADER stage for it.
VkPipelineStageFlags SwapchainStage() const override {
return VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
}
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
UIDispatchHeader FillHeader(std::uint32_t itemBufferSlot,
std::uint32_t itemCount,
std::array<float,4> clipRectPx = {0.0f, 0.0f, 1e9f, 1e9f},