user6678646
user6678646

Reputation:

vkCreateSwapchainKHR Error

Even though validation layers and debug callback extensions are enabled and working (they respond to wrong structs etc.), I'm still getting a "VK_ERROR_VALIDATION_FAILED_EXT" result from vkCreateSwapchainKHR(), and there's no validation layer error to pinpoint the mistake... Swap chain creation (using GTX 970 ) :

VkBool32 isSupported = false;
vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevices[0], 0, surface, &isSupported);

if (!isSupported) {
    std::cout << "*ERROR* This device doesn't support surfaces" << std::endl;
}

VkSurfaceCapabilitiesKHR surfCaps;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevices[0], surface, &surfCaps);

std::vector<VkSurfaceFormatKHR> deviceFormats;
uint32_t formatCount;
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices[0], surface, &formatCount, nullptr);
deviceFormats.resize(formatCount);
vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevices[0], surface, &formatCount, deviceFormats.data());


swapChainInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
swapChainInfo.pNext = nullptr;
swapChainInfo.flags = 0;
swapChainInfo.surface = surface;

swapChainInfo.minImageCount = surfCaps.minImageCount; 
swapChainInfo.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;
swapChainInfo.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
swapChainInfo.imageExtent = surfCaps.currentExtent;
swapChainInfo.imageArrayLayers = 1;
swapChainInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
swapChainInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;

swapChainInfo.queueFamilyIndexCount = 0;
swapChainInfo.pQueueFamilyIndices = VK_NULL_HANDLE;
swapChainInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; 
swapChainInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
swapChainInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR;
swapChainInfo.clipped = VK_TRUE; // TODO : TEST clipping against another window
swapChainInfo.oldSwapchain = VK_NULL_HANDLE;

result = vkCreateSwapchainKHR( device, &swapChainInfo, nullptr, &swapChain );
if (result) {
    std::cout << "*ERROR* Swapchain Creation Failed :" << result << std::endl;
}

Surface Creation using GLFW (Which doesn't return any error):

if (result = glfwCreateWindowSurface(instance, window, nullptr, &surface)) 
    {
        std::cout << "*ERROR* Surface Creation Failed : " << result << std::endl;
    }

Upvotes: 3

Views: 3149

Answers (2)

krOoze
krOoze

Reputation: 13246

Just a few points about your code (potentially cause of problems):

  • You are not checking VkResult of all the vkGet* commands
  • You are not checking swapChainInfo.imageFormat against supported formats in your deviceFormats
  • You are not accounting for the situation that surfCaps.currentExtent can be 0xFFFFFFFF
  • swapChainInfo.pQueueFamilyIndices is a pointer not a handle; use nullptr
  • You are not checking swapChainInfo.preTransform against surfCaps.supportedTransforms
  • You are not checking swapChainInfo.compositeAlpha against surfCaps.supportedCompositeAlpha

Upvotes: 1

MuertoExcobito
MuertoExcobito

Reputation: 10039

There are a huge number of reasons validation of vkCreateSwapchainKHR will fail (check out PreCallValidateCreateSwapchainKHR in core_validation.cpp).

There may not be enough code here to tell why it is failing, for example, the failure might be because of an invalid surface. But, to pinpoint the problem, it should give a failure message in the debug log, which will tell you exactly why. You should enable it by calling CreateDebugReportCallbackEXT, before trying to create the swapchain. This will also require you to enable the VK_EXT_debug_report extension. See here for details.

Upvotes: 1

Related Questions