Skip to content
4 changes: 3 additions & 1 deletion gfx/common/vulkan_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,9 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,

if (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
vulkan_emulated_mailbox_init(&vk->mailbox, vk->context.device, vk->swapchain);


/* This flag needs to be cleared otherwise elsewhere it can be perceived as if there's a new swapchain created everytime its being called */
Copy link
Contributor

Choose a reason for hiding this comment

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

If this helps, it might point to bugs elsewhere, but alone, this looks very wrong. I'm no longer familiar with this code, but further up there's stuff like:

   vk->flags        |= VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;

   if (       (vk->swapchain != VK_NULL_HANDLE)
         && (!(vk->context.flags & VK_CTX_FLAG_INVALID_SWAPCHAIN))
         &&   (vk->context.swapchain_width  == width)
         &&   (vk->context.swapchain_height == height)
         &&   (vk->context.swap_interval    == swap_interval))
   {
      /* Do not bother creating a swapchain redundantly. */
#ifdef VULKAN_DEBUG
      RARCH_DBG("[Vulkan] Do not need to re-create swapchain.\n");
#endif
      vulkan_create_wait_fences(vk);

      if (     (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
            && (vk->mailbox.swapchain == VK_NULL_HANDLE))
      {
         vulkan_emulated_mailbox_init(
               &vk->mailbox, vk->context.device, vk->swapchain);
         vk->flags                &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
         return true;
      }

If that code path is reached without a new swapchain having been created that seems like it should not be possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

When the code figures out there is no need to recreate it's already clearing that flag.

Copy link
Author

@ro8inmorgan ro8inmorgan Oct 9, 2025

Choose a reason for hiding this comment

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

If this helps, it might point to bugs elsewhere, but alone, this looks very wrong. I'm no longer familiar with this code, but further up there's stuff like:

   vk->flags        |= VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;

   if (       (vk->swapchain != VK_NULL_HANDLE)
         && (!(vk->context.flags & VK_CTX_FLAG_INVALID_SWAPCHAIN))
         &&   (vk->context.swapchain_width  == width)
         &&   (vk->context.swapchain_height == height)
         &&   (vk->context.swap_interval    == swap_interval))
   {
      /* Do not bother creating a swapchain redundantly. */
#ifdef VULKAN_DEBUG
      RARCH_DBG("[Vulkan] Do not need to re-create swapchain.\n");
#endif
      vulkan_create_wait_fences(vk);

      if (     (vk->flags & VK_DATA_FLAG_EMULATING_MAILBOX)
            && (vk->mailbox.swapchain == VK_NULL_HANDLE))
      {
         vulkan_emulated_mailbox_init(
               &vk->mailbox, vk->context.device, vk->swapchain);
         vk->flags                &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
         return true;
      }

If that code path is reached without a new swapchain having been created that seems like it should not be possible.

Thats actually not true, there are paths in this function that will return true without ever clearing the flag. This function is a one off so it should always be cleared after creation is success. Could you ellaborate on why it looks "very wrong"? Because IMO it should always be cleared before the function ends.

The flag is set at line 1960 with
vk->flags |= VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;

and it def could reach the last return true without ever clearing the flag even tho its succesfull. In fact I actually see another path now in this function at line 2220 that doesn't clear the flag either, which could cause the same issue.

Leaving this flag set it will life beyond this function and can cause false positive on new swapchains being created. I personally feel nog clearing this flag here is the bug.

I searched issues here on github and I am definitly not the only one having the same problem specific with Vulkan.

Copy link
Author

@ro8inmorgan ro8inmorgan Oct 9, 2025

Choose a reason for hiding this comment

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

When the code figures out there is no need to recreate it's already clearing that flag.

That is the problem, it isn't. There are atleast 2 paths where its creating it but not clearing the flag.

vk->flags &= ~VK_DATA_FLAG_CREATED_NEW_SWAPCHAIN;
return true;
}

Expand Down
Loading