Skip to content

Fix synchronization validation errors, edit comments, add SDL_SyncWindow#6

Open
th3or14 wants to merge 4 commits into
stevelittlefish:mainfrom
th3or14:main
Open

Fix synchronization validation errors, edit comments, add SDL_SyncWindow#6
th3or14 wants to merge 4 commits into
stevelittlefish:mainfrom
th3or14:main

Conversation

@th3or14

@th3or14 th3or14 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  1. Fixed synchronization validation errors.

I set the environment variable VK_VALIDATION_VALIDATE_SYNC=1 and got synchronization validation error messages.

After realizing that they come from vkx_transition_image_layout calls, I located which calls trigger errors. I did it by temporarily changing access and stage masks the following way

barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
barrier.srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
barrier.dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;

inside vkx_transition_image_layout for every pair of old_layout and new_layout until all the synchronization validation error messages were gone. This way I located 2 cases giving synchronization validation error messages:

	else if (old_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
			&& new_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
		barrier.srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
		barrier.srcAccessMask = 0;
		barrier.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
		barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;

and

	else if (old_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
			&& new_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
		barrier.srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
		barrier.srcAccessMask = 0;
		barrier.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
		barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;

Then I looked around for what values of access and stage masks should be used in those cases. When fixing the first case, I used the symmetric (where old layout and new layout are swapped) case

	else if (old_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
			&& new_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
		barrier.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
		barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
		barrier.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
		barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
	}

as a reference. When fixing the second case, I used the symmetric case

	else if (old_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
			&& new_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
		barrier.srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
		barrier.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
		barrier.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
		barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
	}

as a reference. Then synchronization validation error messages do not appear on my side anymore with the environment variable VK_VALIDATION_VALIDATE_SYNC=1 set.

  1. Corrected a few comments to vkx_transition_image_layout.

  2. Removed confusing comments // Create the base descriptor sets. They are identical and probably wrong. Right few lines above them there are already comments // ----- Create the descriptor sets ----- and // ----- Create the screen descriptor sets -----.

  3. Added SDL_SyncWindow after SDL_SetWindowFullscreen.

When you toggle the fullscreen mode, you may notice that after the message

Framebuffer resized - recreating swap chain

there are messages

Swapchain was suboptimal
Swapchain is still suboptimal - recreating

because the window may be not yet resized by the time the swapchain is recreated after toggling the fullscreen mode. So then the swapchain is recreated again by the time the window is really resized. It happens because SDL_SetWindowFullscreen is asynchronous. After adding SDL_SyncWindow, the swapchain becomes recreated just once after toggling the fullscreen mode.

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.

1 participant