Vulkan-Samples icon indicating copy to clipboard operation
Vulkan-Samples copied to clipboard

Rework synchronization in port of my framework

Open SaschaWillems opened this issue 5 months ago • 0 comments

Back when I started doing Vulkan samples, I did use vkQueueWaitIdle to "sync" frame presentation. That made it easier to write samples, but kills any chance of CPU/GPU parallelism like frames-in-flight. This makes all samples based on the port of my framework sub-optimal from Vulkan's Point-of-View:

void ApiVulkanSample::submit_frame()
{
	if (get_render_context().has_swapchain())
	{
            ...
	}

	// DO NOT USE
	// vkDeviceWaitIdle and vkQueueWaitIdle are extremely expensive functions, and are used here purely for demonstrating the vulkan API
	// without having to concern ourselves with proper syncronization. These functions should NEVER be used inside the render loop like this (every frame).
	VK_CHECK(get_device().get_queue_by_present(0).wait_idle());
}

Removing this will require duplicating resources shared by CPU and GPU (e.g. uniform buffers) in all samples and redoing the semaphore/fence setup.

That's something I'm currently fixing in my own samples link, and after that I'd be willing to also do that for the Khronos samples.

Will probably be a larger effort (at least weeks, more prob. months) but in the end it'll be worth it to show how to properly use Vulkan.

SaschaWillems avatar Jul 28 '25 17:07 SaschaWillems