Skip to content

Commit

Permalink
fix VK_INCOMPLETE handling in vkGetSwapchainImagesKHR
Browse files Browse the repository at this point in the history
  • Loading branch information
DadSchoorse committed Dec 13, 2022
1 parent 10ba36e commit 08bb7e3
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/basalt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,29 +375,25 @@ namespace vkBasalt
// If the images got already requested once, return them again instead of creating new images
if (pLogicalSwapchain->fakeImages.size())
{
*pCount = std::min<uint32_t>(*pCount, pLogicalSwapchain->fakeImages.size());
VkResult res = *pCount < pLogicalSwapchain->fakeImages.size() ? VK_INCOMPLETE : VK_SUCCESS;
std::memcpy(pSwapchainImages, pLogicalSwapchain->fakeImages.data(), sizeof(VkImage) * (*pCount));
return VK_SUCCESS;
return res;
}

pLogicalSwapchain->imageCount = *pCount;
pLogicalSwapchain->images.reserve(*pCount);
pLogicalDevice->vkd.GetSwapchainImagesKHR(device, swapchain, &pLogicalSwapchain->imageCount, nullptr);
pLogicalSwapchain->images.resize(pLogicalSwapchain->imageCount);
pLogicalDevice->vkd.GetSwapchainImagesKHR(device, swapchain, &pLogicalSwapchain->imageCount, pLogicalSwapchain->images.data());

std::vector<std::string> effectStrings = pConfig->getOption<std::vector<std::string>>("effects", {"cas"});

// create 1 more set of images when we can't use the swapchain it self
uint32_t fakeImageCount = *pCount * (effectStrings.size() + !pLogicalDevice->supportsMutableFormat);
uint32_t fakeImageCount = pLogicalSwapchain->imageCount * (effectStrings.size() + !pLogicalDevice->supportsMutableFormat);

pLogicalSwapchain->fakeImages =
createFakeSwapchainImages(pLogicalDevice, pLogicalSwapchain->swapchainCreateInfo, fakeImageCount, pLogicalSwapchain->fakeImageMemory);
Logger::debug("created fake swapchain images");

VkResult result = pLogicalDevice->vkd.GetSwapchainImagesKHR(device, swapchain, pCount, pSwapchainImages);
for (unsigned int i = 0; i < *pCount; i++)
{
pLogicalSwapchain->images.push_back(pSwapchainImages[i]);
pSwapchainImages[i] = pLogicalSwapchain->fakeImages[i];
}

VkFormat unormFormat = convertToUNORM(pLogicalSwapchain->format);
VkFormat srgbFormat = convertToSRGB(pLogicalSwapchain->format);

Expand Down Expand Up @@ -528,7 +524,10 @@ namespace vkBasalt
Logger::debug(std::to_string(i) + " written commandbuffer " + convertToString(pLogicalSwapchain->commandBuffersNoEffect[i]));
}

return result;
*pCount = std::min<uint32_t>(*pCount, pLogicalSwapchain->fakeImages.size());
VkResult res = *pCount < pLogicalSwapchain->fakeImages.size() ? VK_INCOMPLETE : VK_SUCCESS;
std::memcpy(pSwapchainImages, pLogicalSwapchain->fakeImages.data(), sizeof(VkImage) * (*pCount));
return res;
}

VKAPI_ATTR VkResult VKAPI_CALL vkBasalt_QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
Expand Down

0 comments on commit 08bb7e3

Please sign in to comment.