Skip to content

Add Synchronization 2 tutorial series #339

Open
gpx1000 wants to merge 2 commits intoKhronosGroup:mainfrom
gpx1000:sync2-tutorial
Open

Add Synchronization 2 tutorial series #339
gpx1000 wants to merge 2 commits intoKhronosGroup:mainfrom
gpx1000:sync2-tutorial

Conversation

@gpx1000
Copy link
Copy Markdown
Contributor

@gpx1000 gpx1000 commented Mar 21, 2026

with validation and advanced topics.

Introduce comprehensive Synchronization 2 tutorial covering modern Vulkan synchronization patterns. Add chapters on dependency anatomy, pipeline barriers, timeline semaphores, frame-in-flight architecture, async compute, transfer queues, dynamic rendering sync, host image copies, and synchronization validation. Include practical examples from Simple Engine and guidance on debugging with validation layers and interpreting VUIDs.

gpx1000 added 2 commits March 20, 2026 23:16
…pics

Introduce comprehensive Synchronization 2 tutorial covering modern Vulkan synchronization patterns. Add chapters on dependency anatomy, pipeline barriers, timeline semaphores, frame-in-flight architecture, async compute, transfer queues, dynamic rendering sync, host image copies, and synchronization validation. Include practical examples from Simple Engine and guidance on debugging with validation layers and interpreting VUIDs.
Update all xref links to use absolute paths prefixed with 'Synchronization/' instead of relative paths. Correct image references to use absolute paths starting with '/images/'. This ensures proper navigation between chapters and correct image rendering across the Synchronization tutorial series.
Copy link
Copy Markdown
Collaborator

@SaschaWillems SaschaWillems left a comment

Choose a reason for hiding this comment

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

Did a first review run and added comments to the documentation where possible.

The information presented here is great, I'm just not sure if it's the best idea to have this as a separate part of the tutorial.

Here are some random additional thoughts that we could discuss:

  • This duplicates some information we already have in the tutorial and/or the guide
  • It's heavily based on the simple game engine part of the tutorial
    • So it at least should come after that part of the tutorial (in the navigation)
  • It should have a few more links to existing resources, esp. the spec
  • It could use some more images, some chapters are text only and feel like walls of text

So my thought after reading this was "Why a separate chapter, why not integrate this into the tutorial right away?"

* Synchronization 2
** xref:Synchronization/introduction.adoc[Introduction]
** Anatomy of a Dependency
*** xref:Synchronization/Anatomy_of_a_Dependency/01_introduction.adoc[Introduction]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Navigation is missing a lot of the new chapters. There's only links to the introduction chapters.


* **The Hardware Perspective**: Understanding why execution barriers alone are not enough to prevent data corruption on modern, multi-cache GPUs.
* **Execution vs. Memory Dependencies**: Learning how to distinguish between stopping a stage and ensuring its data is actually readable by the next one.
* **The Synchronization 2 Advantage**: Why the new `vk::DependencyInfo` and `vkCmdPipelineBarrier2` are more than just a syntax cleanup—they are a fundamental shift in how we express intent to the driver.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be vk::CmdPipelineBarrier2 instead of vkCmdPipelineBarrier2.

** xref:courses/18_Ray_tracing/05_Shadow_transparency.adoc[Shadow transparency]
** xref:courses/18_Ray_tracing/06_Reflections.adoc[Reflections]
** xref:courses/18_Ray_tracing/07_Conclusion.adoc[Conclusion]
* Synchronization 2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As this is heavily referencing the simple game engine, we should put this after the SGE chapter.


== Implementation: Modernizing Simple Engine

While `Simple Engine`'s renderer has been largely modernized to use the `pipelineBarrier2` calls we've discussed, the codebase still contains "legacy islands" that we are in the process of refactoring. A prime example is the `PhysicsSystem` (`physics_system.cpp`), which still uses the old-style `pipelineBarrier` for synchronizing its compute dispatches.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One of the apostrophes caused the first line to be rendered as code instead of text.


When we talk about "physical reorganization," we're referring to how different hardware units see the same bits. For instance, a Rasterizer might use a specialized tiled compression format (like Delta Color Compression) to save bandwidth. However, a Compute shader sampling that same image might not understand that compression. The layout transition ensures the data is "decompressed" or moved into a format that the next stage can consume.

== Anatomizing the Image Barrier
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very minor and mostly a language barrier issue: But I had to look up what "Anatomizing" actually means ^^


In a simple Vulkan application, we might use the same queue for graphics, compute, and transfer work. This is easy to implement, but it's not efficient. Every time we submit a large transfer, the graphics queue has to stop what it's doing and wait for the transfer engine to finish. This creates a "stutter" in our frame rate.

By using a **Dedicated Transfer Queue**, we can perform these uploads in the background. The transfer engine is a specialized piece of hardware that can move data between memory locations without using the GPU's compute or graphics cores. By offloading these tasks, we can keep our main rendering pipeline running at full speed.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should show how to actually get/identify a dedicated transfer queue.


For most of Vulkan's history, if you wanted to move data into an image, you had to follow a very specific ritual: create a staging buffer, map it, write your data, record a `copyBufferToImage` command, and then submit that command buffer to a queue. While this is efficient for large, asynchronous uploads, it's a lot of overhead for simple, direct updates—like updating a small UI texture or a single mip level.

With the arrival of **Vulkan 1.4**, we have a powerful new tool: **Host Image Copies** (`VK_EXT_host_image_copy`). This feature allows the CPU to copy data directly into a GPU-optimal image without recording or submitting a single command buffer. It's the most direct way to move data between CPU and GPU memory.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should have a note that support for host image copies is still optional in 1.4.


== Enabling Sync Validation

The **LunarG Synchronization Validation** layer is not part of the standard `VK_LAYER_KHRONOS_validation` by default on all platforms. In many environments, you must explicitly enable it through the `vk_layer_settings.txt` file or through your engine's `vk::InstanceCreateInfo`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could also have a note on using vkconfig instead, which lets you easily toggle sync validation.


----
VALIDATION [SYNC-HAZARD-READ-AFTER-WRITE] (0x01234567)
VUID: VUID-vkCmdDraw-None-07888
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is the wrong VUID for this message. That VUID refers to texel buffers and atomic usage? https://docs.vulkan.org/refpages/latest/refpages/source/vkCmdDraw.html#VUID-vkCmdDraw-None-07888


== Hardware Profilers

The most effective way to optimize your synchronization code is to see what the GPU is actually doing. We use hardware profilers like **NVIDIA Nsight Graphics**, **AMD Radeon GPU Profiler**, or **Intel Graphics Performance Analyzers** to visualize the pipeline.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Intel Graphics Performance Analyzers has been discontinued in 2025.

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.

2 participants