Skip to content

Commit

Permalink
layer: Fix oldSwapchain when going in/out of XWayland bypassing
Browse files Browse the repository at this point in the history
We need to NULL this out if we are swapping here, as oldSwapchain in the driver can't handle the difference in underlying surface types here.
  • Loading branch information
misyltoad committed Dec 16, 2024
1 parent ff45361 commit 4da5e4a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions layer/VkLayer_FROG_gamescope_wsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,9 @@ namespace GamescopeWSILayer {
gamescope_swapchain_destroy(state->object);
}
GamescopeSwapchain::remove(swapchain);
fprintf(stderr, "[Gamescope WSI] Destroying swapchain: %p\n", swapchain);
pDispatch->DestroySwapchainKHR(device, swapchain, pAllocator);
fprintf(stderr, "[Gamescope WSI] Destroyed swapchain: %p\n", swapchain);
}

static VkResult CreateSwapchainKHR(
Expand All @@ -1103,14 +1105,20 @@ namespace GamescopeWSILayer {
return pDispatch->CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
}

const bool canBypass = gamescopeSurface->canBypassXWayland();

VkSwapchainCreateInfoKHR swapchainInfo = *pCreateInfo;

if (pCreateInfo->oldSwapchain) {
if (auto gamescopeSwapchain = GamescopeSwapchain::get(pCreateInfo->oldSwapchain)) {
gamescopeSwapchain->retired = true;
// If we are going to/from being able to bypass XWayland, make sure
// we NULL out oldSwapchain, as they'll be for different surfaces and swapchain types.
if (gamescopeSwapchain->isBypassingXWayland != canBypass)
swapchainInfo.oldSwapchain = VK_NULL_HANDLE;
}
}

VkSwapchainCreateInfoKHR swapchainInfo = *pCreateInfo;

if (gamescopeSurface->flags & GamescopeLayerClient::Flag::ForceSwapchainExtent) {
if (!gamescopeSurface->isWayland()) {
auto rect = xcb::getWindowRect(gamescopeSurface->connection, gamescopeSurface->window);
Expand All @@ -1121,7 +1129,6 @@ namespace GamescopeWSILayer {
}
}

const bool canBypass = gamescopeSurface->canBypassXWayland();
// If we can't flip, fallback to the regular XCB surface on the XCB window.
if (!canBypass)
swapchainInfo.surface = gamescopeSurface->fallbackSurface;
Expand Down Expand Up @@ -1151,8 +1158,9 @@ namespace GamescopeWSILayer {
minImageCount = std::max(getMinImageCount(), minImageCount);
swapchainInfo.minImageCount = minImageCount;

fprintf(stderr, "[Gamescope WSI] Creating swapchain for xid: 0x%0x - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
fprintf(stderr, "[Gamescope WSI] Creating swapchain for xid: 0x%0x - oldSwapchain: %p - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
gamescopeSurface->window,
pCreateInfo->oldSwapchain,
pCreateInfo->minImageCount,
minImageCount,
vkroots::helpers::enumString(pCreateInfo->imageFormat),
Expand Down Expand Up @@ -1231,8 +1239,9 @@ namespace GamescopeWSILayer {
uint32_t imageCount = 0;
pDispatch->GetSwapchainImagesKHR(device, *pSwapchain, &imageCount, nullptr);

fprintf(stderr, "[Gamescope WSI] Created swapchain for xid: 0x%0x - imageCount: %u\n",
fprintf(stderr, "[Gamescope WSI] Created swapchain for xid: 0x%0x swapchain: %p - imageCount: %u\n",
gamescopeSurface->window,
*pSwapchain,
imageCount);

gamescope_swapchain_swapchain_feedback(
Expand Down

0 comments on commit 4da5e4a

Please sign in to comment.