Foundations

GPU synchronization: barriers, stages, layouts

A GPU runs the commands of a command buffer in order, but not one after the other: they overlap, and their results sit in caches for a while. When one command reads what another wrote, the program has to say so, with a barrier. This page explains what a barrier does, how to write one well, and how images add layouts on top. The last part shows RASM's barriers.

In short

  • Two uses of the same memory, where at least one writes, form a hazard: read after write, write after read, or write after write.
  • A barrier is an execution dependency (later work waits for earlier work) plus, for writes, a memory dependency (the write is flushed from caches and made visible to the reader).
  • Both halves are scoped by pipeline stages and access types: "wait for these stages, and make these writes visible to those reads".
  • Narrow scopes keep the GPU busy. Too wide is slow but correct; too narrow is a bug that may only show on another GPU.
  • Images also have a layout, the way their memory is arranged for one kind of use. A barrier changes it, and the old contents can be discarded at the same time.
  • Across submissions and queues, semaphores order GPU work and fences tell the CPU. A render graph can write all of this from declared reads and writes.

1Why the GPU needs to be told

Commands in one command buffer start in the order they were recorded. But a GPU is a pipeline with many cores: the next command starts as soon as there is room, long before the last one is done. Without a barrier, a command that reads a buffer can run at the same time as the command that writes it.

No barrier dispatch A: writes buffer X dispatch B: reads buffer X both run here: a race reads half-old data With a barrier dispatch A: writes buffer X barrier dispatch B: reads buffer X B waits for A, and A's writes are flushed time on the GPU
The barrier costs the overlap between A and B. That is the price of correct data, and the reason to make barriers no wider than needed.

Older APIs found these cases themselves. Vulkan and Direct3D 12 do not: the program says where they are.

A missing barrier is silent

A missing barrier is not an error the driver reports. It is a race, and it may only show up on another GPU, another driver, or under more load.

2Hazards

Take two commands, A then B, that use the same memory. What matters is which of them writes.

a write a read
A writes B reads draw list

RAW: read after write

Culling writes a draw list, the draw reads it.

Barrier: wait for A, and make A's writes visible to B

A reads B writes texture

WAR: write after read

A pass samples a texture, the next frame draws into it.

Barrier: only wait for A. A read leaves nothing in a cache to flush.

A writes B writes render target

WAW: write after write

Two passes draw into the same target.

Barrier: wait for A, and order the writes, so the last one wins

A reads B reads texture

RAR: read after read

Two passes sample the same texture.

Barrier: nothing. Reads never conflict (but an image may still need a layout change).

3Two halves: execution and memory

"Wait for A" is only half of the job. The other half is caches. A GPU has a small cache next to each group of cores, a larger shared one, and then memory. A write first lands in a cache near the core that made it. Another core may hold an old copy of the same bytes in its own cache.

core 1: writes 7 core 2: reads cache 1: 7 cache 2: 3 (old) shared cache memory: 3 1. make available: flush to shared cache 2. make visible: drop the old copy, read again
The real cache layout differs per GPU. The API hides it behind these two words: a write is made available, then made visible to a set of readers.
A barrier B waits B time

Execution dependency

"Work after the barrier, in these stages, does not start before work before the barrier, in those stages, has finished." Enough for write after read.

A's write travels to B cache of A7 shared7 cache of B3 → 7 available visible

Memory dependency

"Writes of these kinds, before the barrier, are made available, and then visible to accesses of those kinds after it." Needed for read after write and write after write.

4Pipeline stages: what to wait for

A command passes through stages. A draw goes through the graphics pipeline; a dispatch through the compute stage; a copy through the transfer stage. A barrier names stages on both sides:

A draw, stage by stage drawindirect index andvertex input vertexshader earlydepth tests fragmentshader latedepth tests coloroutput Other work compute shader copy (transfer) host (the CPU) pseudo-stages: NONE (nothing),ALL_COMMANDS (everything)
The source stages are the ones to wait for, in commands before the barrier. The destination stages are the ones that wait, in commands after it. Stages of later commands that are not named still run.

That last sentence is where the speed comes from. Name the latest source stage that really writes, and the earliest destination stage that really reads. Everything else can overlap:

src = color output, dst = fragment shader earlier pass vertex fragment color out later pass vertex waits fragment color out done sooner src = color output, dst = ALL_COMMANDS earlier pass vertex fragment color out later pass waits vertex fragment out Both are correct. The second one throws away the time the later vertex shader could have run.
Real stages overlap much more than these blocks suggest, across many draws. The rule stays the same: a late destination stage means more overlap.

5Access types: what to flush and make visible

Stages say when. Access types say which memory traffic the memory dependency covers. Each access type belongs to certain stages:

StageReadsWrites
draw indirectindirect command read—
index input, vertex inputindex read, vertex attribute read—
vertex, fragment, compute shaderuniform read, shader sampled read, shader storage readshader storage write
early and late depth testsdepth attachment readdepth attachment write
color outputcolor attachment read (blending, load)color attachment write
copytransfer readtransfer write
hosthost readhost write

One barrier, read from left to right. This one is the example of section 6:

Source scope: commands before Destination scope: commands after barrier src stage: wait until these finish COMPUTE_SHADER dst stage: these wait DRAW_INDIRECT execution dependency: the stages src access: flush these writes (writes only) SHADER_STORAGE_WRITE dst access: these reads and writes see them INDIRECT_COMMAND_READ memory dependency: the accesses
Stages say when. Accesses say which memory traffic. A barrier has both, on both sides.
The access rule
  • Source access: only the writes before the barrier. A read leaves nothing to flush, so naming it does nothing.
  • Destination access: every read and write after the barrier that must see the earlier writes (or come after them).
  • Write after read: source access is empty. The stages alone are enough.

6Writing a barrier: Vulkan synchronization2

Vulkan 1.3 made synchronization2 core. It packs stage and access together for each side of each barrier, which is easier to read than the original call. One call, vkCmdPipelineBarrier2, takes a list of barriers of three kinds:

buffer buffer buffer

Memory barrier

Covers all memory. Use it for buffers. Drivers rarely do better with a per-buffer barrier, and a global one also covers memory read through GPU pointers.

offset size not covered

Buffer barrier

Covers one range of one buffer. Use it to pass a buffer between queue families (section 9).

mip 0 mip 1 old layout → new layout

Image barrier

Covers some mips and layers of one image. Use it for images: it is the only kind that can change a layout.

A memory barrier for the example on this page's first picture, where a compute shader writes the draw commands of a later indirect draw:

// A compute pass wrote draw commands; the next draw reads them as indirect arguments.
VkMemoryBarrier2 barrier = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER_2,
                            .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
                            .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
                            .dstStageMask = VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT,
                            .dstAccessMask = VK_ACCESS_2_INDIRECT_COMMAND_READ_BIT};
VkDependencyInfo dependency = {.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .memoryBarrierCount = 1, .pMemoryBarriers = &barrier};
vkCmdPipelineBarrier2(commandBuffer, &dependency);

Put several barriers into one call when they sit at the same point: the driver can then do one wait instead of several. And never put a barrier between two draws "just in case": every barrier drains part of the pipeline.

7Image layouts

GPUs store images in different arrangements for different uses: tiled and compressed for drawing into, a different tiling for sampling, plain lines for the display. Vulkan calls the arrangement a layout, and it is part of the image's state. An image barrier changes it, between the source and the destination scopes.

Layout (Vulkan)For
UNDEFINED"I do not care about the contents". Only valid as the old layout: changing from it may throw the contents away.
COLOR_ATTACHMENT_OPTIMALdrawing into the image
DEPTH_STENCIL_ATTACHMENT_OPTIMALdepth testing and writing
SHADER_READ_ONLY_OPTIMALsampling in shaders
TRANSFER_SRC / TRANSFER_DST_OPTIMALcopies and blits
GENERALanything, including storage writes; possibly slower
PRESENT_SRChanding a swapchain image to the display
An offscreen color target, each frame UNDEFINEDold frame, not needed COLOR_ATTACHMENTa pass draws into it SHADER_READ_ONLYa later pass samples it discard RAW next frame: WAR, the new draw must wait for the old samples A swapchain image UNDEFINED COLOR_ATTACHMENT PRESENT_SRC
Each orange arrow is one image barrier. "Discard" means the old layout is UNDEFINED: a free way to tell the GPU the old contents can go, which also saves the work of decompressing them.

Place the barriers of such a target yourself. Here two passes sample it after the draw.

a barrier (click a tall bar to add or remove it) layout for drawing into the image layout for sampling a pass that is safe a pass with a wrong layout or a hazard
Remove the barrier before the blur pass and read what goes wrong. Put it back, then add the third one: is it needed? Last, remove all three.

Two details catch people out:

old samples discard barrier waits new draw time

A discard still waits

An image barrier is a full barrier. Even a "discard" must still wait for the last use of the image (a write after read), so its source stages are not empty.

mip 0 mip 1 mip 0: color attachment mips 1 to 3: shader read only

One layout per mip and layer

The layout belongs to each mip level and array layer. A barrier can change only some of them, and the program must then track each one.

8Worked example: the barriers of a small frame

A frame with four steps: a compute pass builds a draw list, a pass draws the scene into an offscreen target using that list, a post pass samples the target and draws into the swapchain image, and the image is presented. Click through the barriers (or use the arrow keys).

1. Draw list: compute writes, the draw reads

cull (compute)writes the draw list draw list buffer scene drawreads it as indirect args Memory barrier (RAW) src stage COMPUTE_SHADER src access SHADER_STORAGE_WRITE dst stage DRAW_INDIRECT dst access INDIRECT_COMMAND_READ If the vertex shader also reads the list, add VERTEX_SHADER + SHADER_STORAGE_READ to the destination.

A global memory barrier is enough: no layout is involved. The destination is the earliest stage that reads the list.

2. Offscreen target: discard, then draw

last frame's post passsampled the target scene drawdraws into the target offscreen targetUNDEFINED → COLOR Image barrier (WAR + discard) src stage FRAGMENT_SHADER src access NONE dst stage COLOR_ATTACHMENT_OUTPUT dst access COLOR_ATTACHMENT_WRITE layout UNDEFINED → COLOR_ATT. The source is a read: no access to flush, only a stage to wait for.

The pass clears the target, so the old contents can go: the old layout is UNDEFINED. The source stage still makes the draw wait for last frame's samples.

3. Post pass: the target becomes a texture

scene drawwrote the target post passsamples the target offscreen targetCOLOR_ATTACHMENT → SHADER_READ_ONLY Image barrier (RAW) src stage COLOR_ATTACHMENT_OUTPUT src access COLOR_ATTACHMENT_WRITE dst stage FRAGMENT_SHADER dst access SHADER_SAMPLED_READ layout COLOR → SHADER_READ The post pass's vertex shader may already run during the scene draw.

This is the code snippet's twin, for an image. In the same call goes the barrier for the swapchain image: UNDEFINED to color attachment, waiting at color output, where the acquire semaphore waits too (see the swapchain).

4. Present

post passwrote the swapchain image presentafter the semaphore swapchain imageCOLOR_ATTACHMENT → PRESENT_SRC Image barrier src stage COLOR_ATTACHMENT_OUTPUT src access COLOR_ATTACHMENT_WRITE dst stage NONE dst access NONE layout COLOR → PRESENT_SRC Nothing on this queue waits: the semaphore signal at submit end covers it.

Four barriers for four uses. In a bigger frame, the same reasoning repeats per resource: who wrote it last, who reads it next, which layout.

9Beyond one command buffer

A barrier works inside one queue. Other borders need other tools:

one queue barrier submit 1A submit 2B submission order

Commands on one queue, even in different submissions

Use a pipeline barrier. Its first scope covers everything submitted earlier to the same queue, and its second scope everything later.

Submission order is enough; no semaphore needed.

queue 1 queue 2 submit: signal submit: wait semaphore

Two queues (graphics and async compute, or transfer)

Use a semaphore. The signaling submit finishes and makes its writes available; the waiting submit waits at the stages it names.

GPU writes fence: done buffer CPU reads barrier to host

GPU → CPU

Use a fence (or timeline value), plus a barrier to the host stage. The barrier makes the GPU's writes available to the host; the fence says they are done.

Memory that is not host-coherent: also invalidate the CPU's range before reading.

CPU writes submit reads buffer

CPU → GPU

Use the submit itself. Host writes made before a submit are visible to it.

Memory that is not host-coherent: flush the range first.

Passing a resource between queue families

compute queue graphics queue write the buffer release barriercompute → graphics signal sem. semaphore wait sem. acquire barriercompute → graphics read
With exclusive sharing, each resource belongs to one queue family at a time. The ownership change is a pair of barriers with the same family indices. Concurrent sharing skips the pair, and may be slower. One queue needs none of this.

When to use a second queue, and what it costs: Async compute and multiple queues.

10Other APIs

APIWho places barriersHow
Vulkanthe programpipeline barriers with stages, accesses and layouts; events for split barriers
Direct3D 12the programresource barriers between resource states (a state is roughly layout + access); "enhanced barriers" add Vulkan-like stages and accesses; split barriers with begin and end
Metalthe driver, by defaulttracks hazards per resource; resources can opt out ("untracked") and use fences or events instead
WebGPUthe implementation, alwaystracks every use inside and between passes; the program never writes a barrier

11Automating it, and pitfalls

Writing every barrier by hand does not scale. Two common helpers:

call: "make this texture readable" texture, state:COLOR_ATT. texture, state:SHADER_READ the barrier comes from the remembered state

Track the state of each resource

Each image remembers its current layout and last use. A call like "make this texture readable" records the right barrier, or none. Simple, but each call only knows the past.

pass A pass B pass C target depth declared writes and reads → barriers

A render graph

Passes declare what they read and write before anything is recorded. The graph knows the whole frame, so it can place, merge and move barriers. See render graphs.

The usual mistakes:

Read access in the source mask
Does nothing. The intended write is not flushed if it was left out.
Forgetting write after read
A pass overwrites a texture while the previous pass still samples it.
ALL_COMMANDS on both sides, everywhere
Correct but slow: the GPU drains at every barrier.
Wrong old layout
Undefined contents, or a validation error. UNDEFINED as old layout when the contents are needed loses them.
A barrier inside a render pass
Not allowed in Vulkan's dynamic rendering, except for special self-dependencies. End the pass first.
Testing on one GPU
Some GPUs flush caches anyway, and hide the missing barrier. Use the validation layer's synchronization validation.

12In RASM

RASM uses synchronization2, a graphics queue and, with async compute on, a compute queue. The RHI offers two barrier calls, deliberately coarse: a global memoryBarrier between sets of PipelineStage, and an image transition between two TextureUsage values. RenderContext remembers each texture's usage, and the RenderGraph derives barriers from what passes declare.

caller (engine, render graph) RenderContext, rhi Vulkan memoryBarrier(cmd, before, after) stages and accesses from PipelineStage VkMemoryBarrier2 global, one per call transitionImageLayout(cmd, texture, usage, discard) TextureStates old usage = texture's state VkImageMemoryBarrier2 all mips and layers UploadManager::flush staging copies copyBuffers: barrier, copies, barrier ALL_COMMANDS → COPY, COPY → ALL_COMMANDS submit(SubmitInfo) waits, swapchain image fence waits; VulkanSwapchain adds its semaphores fence waits at ALL_COMMANDS acquire wait at color output RenderContext refuses memoryBarrier and transitionImageLayout between beginRendering and endRendering.
Every vkCmdPipelineBarrier2 in RASM comes from src/rhi/vulkan/vulkanCommandBuffer.cpp. Three more calls there record barriers of their own: aliasingBarrier (a global barrier before the first pass of a transient target, memory aliasing), copyToTextures (staged texture uploads: every texture of the batch to the copy layout in one call, then back to SAMPLED) and copyFromTexture (a readback: the one mip and layer to the copy layout and back, then the buffer to the host). Textures filled from the CPU in a format with host image copy skip the GPU entirely: fillTexture changes their layout on the host (vkTransitionImageLayout) and leaves them SAMPLED.

The three stage sets

PipelineStageVulkan stagesAccesses as before (writes only)Accesses as after
COMPUTEcompute shadershader storage writeshader storage read and write, uniform read
GRAPHICSdraw indirect, index input, vertex shader, fragment shadershader storage writeindirect command, index, shader storage and uniform read; shader storage write
HOSThosthost writehost read and write

PipelineStage is a set of flags, so one barrier can name several with |. Before the late culling the graph records GRAPHICS | COMPUTE → COMPUTE: the early draws read the lists that it rewrites, and the Hi-Z build wrote what it reads. endFrame ends with COMPUTE → HOST, so the CPU reads the cull stats after the fence.

Texture usages and their scopes

TextureUsageVulkan layoutAs old usage, waits forAs new usage, blocks
UNKNOWNundefinedcolor output, depth tests, fragment and compute shaders; flushes color, depth and storage writes— (not a target)
COLOR_ATTACHMENTcolor attachmentcolor output writescolor output reads and writes
DEPTH_STENCIL_ATTACHMENTdepth attachmentdepth test writesdepth test reads and writes
STORAGEgeneralcompute shader storage writescompute shader storage reads and writes
SAMPLEDshader read onlyfragment and compute shaders (no access: reads)fragment and compute shader reads
PRESENT_SRCpresent— (not a source)nothing

Any other usage has no scope: the transition logs an error, records nothing and returns false. The source scope comes only from the old usage and the destination only from the new one, so each table row is written once. UNKNOWN as the old usage is the "discard" of section 7: it waits for every stage that could have used the image, because the last use is not known. Its color output stage also chains the barrier to the swapchain's acquire semaphore.

Remembering texture states

TextureStates::transition texture state = new usage each time unsubmitted texture, command buffer, before submitted forget its command buffers' ones discardUnsubmitted put the rest back, last first
SAMPLED → SAMPLED records nothing (read after read). Any other same-usage transition is still recorded, because attachments are written: COLOR_ATTACHMENT → COLOR_ATTACHMENT orders earlier draws before a pass that loads the image. submitBatches calls discardRecording when a submit fails or the frame is dropped, so the next frame starts from the layouts the GPU really has. With async compute a frame is several submits, so each submit forgets only its own command buffers' changes: the batches that went out keep theirs.

The barriers of one frame

frame command buffer · left column, then right Animate, Skin · compute GRAPHICS | COMPUTE → COMPUTElast frame's uses Animate, a barrier, Skinposes, vertices Cull 1 · compute GRAPHICS | COMPUTE → COMPUTElast frame's passes countMain, early COMPUTE → COMPUTEinside the pass writeMain, early Scene 1 · graphics aliasingBarrierfirst pass of a transient target COMPUTE → GRAPHICSlists, vertices for the draws scene_hdr: UNKNOWN → attachment beginRendering (clear), early draws, endRendering Hi-Z · compute COMPUTE → COMPUTElast frame's Cull 2 depth → SAMPLEDreadDepth Hi-Z: one dispatch per level+ C → C each Uploads go out before it, in their own submit, with the copyBuffers barriers. Legend: memory barrier (global) image transition compute work rendering Cull 2 · compute GRAPHICS | COMPUTE → COMPUTEafter Scene 1 countMain, late COMPUTE → COMPUTEinside the pass writeMain, late Scene 2 · graphics COMPUTE → GRAPHICSlists for the draws color, depth → attachment, kept beginRendering (load), late draws, endRendering Transparent · graphics COMPUTE → GRAPHICSvisibility, for ghosts color, depth → attachment, kept beginRendering (load), see-through draws Tone Map · graphics image: UNKNOWN → attachmentno depth beginRendering (clear), one triangle endFrame image → PRESENT_SRCwith a window COMPUTE → HOSTcull stats for the CPU
One frame of Renderer::render with the default EngineConfig: occlusionCulling on; async compute, anti-aliasing, bloom and the UI off. Every pass is a graph pass in the one frame command buffer, so no barrier sits inside a rendering scope. With async compute on, the barriers between the two queues become waits (next section). The graph records the barrier before each pass from what the pass declares; the COMPUTE → COMPUTE barriers between dispatches inside a pass come from the pass itself (recordSceneCulling, recordHiz). With EngineConfig::ui, a UI pass after the tone map loads the image. A readback asked for this frame is copied in endFrame, before the move to PRESENT_SRC. See occlusion culling.

Across queues

With EngineConfig::asyncCompute, the Animate, Skin, culling and Hi-Z passes run on a compute queue from a family without graphics. Work on the other queue is outside a barrier's scopes, so a barrier between the queues becomes a wait: the waiting submit waits for the other queue's timeline fence (FenceValue in SubmitInfo::waits).

one queue (default) Cull 1 C → G Scene 1 A barrier: its first scope covers earlier work on the same queue. two queues (async compute) compute Cull 1 signal c+1 graphics wait c+1 Scene 1 computeFence The wait blocks all commands (ALL_COMMANDS) and makes the other queue's writes visible, so no barrier follows it.
The graph adds the wait before a pass that uses what the other queue wrote, or writes what it used (render graphs). The frame's batches and their values: the frame loop.
BetweenRASM uses
passes on one queuea barrier, as without async compute
a compute batch and a graphics batcha timeline fence wait at all commands (VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT), since a batch often starts with a layout transition that must come after it
uploads and the compute queuethe upload submit waits for the last compute submit, and a compute submit waits for the last upload (UploadManager::lastSubmit)
barriers in a compute-queue command bufferfitToComputeQueue: graphics source stages become all commands, which chains to the submit's wait; graphics destination stages and graphics-only accesses are dropped
resource ownershipwith a compute queue, every buffer and image is created VK_SHARING_MODE_CONCURRENT for both families; a texture a load fills on the transfer queue moves to the graphics family by a release and an acquire (transfer queues)

The render graph's part

Before each pass, RenderGraph::execute records at most one memoryBarrier, moves the textures the pass reads to SAMPLED and, for a compute pass, the storage target it writes to STORAGE (bloom). Before the first pass of a transient target it records the aliasingBarrier. bufferBarrier keeps, per buffer and per queue, the stages of the last write and of the reads since. Its rules are the hazards of section 2: a read after a write waits for the write (once per reading stage), and a write waits for every use since the last write. A use on the other queue gets a wait instead (RenderGraph::waitForOtherQueue). The state carries over to the next frame. See render graphs.

Where RASM follows the textbook, and where it differs

PartThis pageRASM
Stagesname the latest source and earliest destinationThree coarse sets. GRAPHICS always means four stages, so a barrier into GRAPHICS waits from draw indirect on: correct, sometimes wider than needed.
Access rulesource: writes; destination: reads and writesThe same, in memoryBarrier.
Buffer barriersglobal memory barriers are fineGlobal ones. Shaders reach buffers through device addresses, which a per-buffer barrier could not name anyway. The one buffer barrier is a readback's: copy → host, on the buffer the image was copied into.
Image barriersper mip and layerAlways the whole mip chain and every layer. No per-mip tracking. Only a readback's copy moves the one mip and layer it copies, and puts it back.
Batchingseveral barriers per callOne barrier per vkCmdPipelineBarrier2 call, except two: copyToTextures moves all the textures of an upload batch in one call, and copyFromTexture ends with the image and the buffer barrier in one call.
State trackingper resource, or a render graphBoth: TextureStates for textures, RenderGraph::bufferAccess for buffers used by graph passes, the scene passes included, per queue. RenderGraph::textureAccess tracks textures across queues only. Only the barriers between dispatches inside one pass are placed by the pass itself.
DiscardUNDEFINED as old layoutThe discard flag, or UNKNOWN as the state. beginPass discards the attachments a pass clears, and keeps the ones it loads.
Split barriers, eventspossibleNone.
Queuessemaphores, ownership transfersA graphics queue, and a compute queue when EngineConfig::asyncCompute is on and the GPU has one. Timeline fence waits between them, and concurrent sharing instead of ownership transfers (P11). The frames' uploads go on the graphics queue and need no semaphore there: copyBuffers brackets them with all-commands barriers. The loads' copies go on a transfer queue (EngineConfig::transferQueue); a frame waits only for load values the CPU saw reached, and a texture filled there is released by the transfer queue and acquired by the graphics queue (transfer queues).
Host readsbarrier to host, fence, invalidateAll three: COMPUTE → HOST at the end of the frame, or of its last compute batch with async compute, the slot's fences, and readBuffer invalidates the range. A readback has its own copy → host barrier, and takeReadback waits for the fence of the frame that copied it (readbacks).
Host-side layout change—Loaded textures use host image copy where it costs the GPU nothing for their format (on lavapipe, not on the RTX 3060): fillTexture transitions and fills them on the CPU, with no GPU barrier. The others go through the staging ring, with the barriers of copyToTextures.

Where it lives in code

WhatWhere
PipelineStage, TextureUsageinclude/rasm/render/resource.h
Stage and access masks, image scopes, upload barriers, compute-queue barrierstoVkStageMask, getSrcScope, getDstScope, copyBuffers, copyToTextures, copyFromTexture, aliasingBarrier, fitToComputeQueue in src/rhi/vulkan/vulkanCommandBuffer.cpp
Fence waits of a submitVulkanQueue::submit in src/rhi/vulkan/vulkanQueue.cpp; RenderContext::submit in src/rhi/renderContext.cpp
Texture state trackingTextureStates in src/rhi/textureStates.cpp
Checks: no barrier inside a passRenderContext::memoryBarrier, transitionImageLayout in src/rhi/renderContext.cpp
Graph barriers and queue waitsRenderGraph::bufferBarrier, RenderGraph::waitForOtherQueue, RenderGraph::textureWaits in src/renderer/renderGraph.cpp; Renderer::waitForQueue in src/renderer/renderer.cpp
Barriers inside the culling and Hi-Z passesrecordSceneCulling, recordHiz in src/renderer/gpuScene.cpp
Pass and frame transitionsRenderer::beginPass, endPass, endFrame in src/renderer/renderer.cpp
Keep these true
  • Use synchronization2 (vkCmdPipelineBarrier2) and dynamic rendering; no render pass objects.
  • No barrier, dispatch or layout change between beginRendering and endRendering; RenderContext checks it.
  • A texture's layout changes only through transitionImageLayout, so Texture::state stays true. A frame that is not submitted calls discardRecording.
  • A new TextureUsage that textures move into needs a source and a destination scope in getSrcScope and getDstScope.
  • A graph pass declares every buffer and texture it uses, or the graph cannot place its barriers or its waits across queues.
  • Waits between queues stay at all commands, because the first commands of a batch are often layout transitions.
  • Test with enableValidation and enableSyncValidation on (or verify.py --sync); a change that adds validation messages is not done.
Not done yet

With async compute every resource is shared by both queue families instead of moving ownership (P11); only a texture a load fills on the transfer queue moves ownership, once (transfer queues). The render graph places barriers and aliases transient render targets, but does not cull passes (D9). Aliasing needs its own global barrier: see Transient memory and aliasing.

Further reading