vkCreateSwapchainKHR错误

时间:2017-09-13 11:57:19

标签: c++ windows vulkan

即使验证层和调试回调扩展已启用并正常工作(它们会响应错误的结构等),我仍然会得到一个" VK_ERROR_VALIDATION_FAILED_EXT"来自find ./GMDS_SRC/* -name '*.h' -o -name '*.c' -type f -exec chmod 444 {} \; 的结果,并且没有验证层错误来查明错误... 交换链创建(使用GTX 970):

vkCreateSwapchainKHR()

使用GLFW创建曲面(不会返回任何错误):

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;
}

2 个答案:

答案 0 :(得分:1)

关于代码的几点(可能导致问题):

  • 您未检查所有VkResult命令的vkGet*
  • 您没有在swapChainInfo.imageFormat
  • 中针对支持的格式检查deviceFormats
  • 您没有考虑surfCaps.currentExtent可以0xFFFFFFFF
  • 的情况
  • swapChainInfo.pQueueFamilyIndices是指针而不是句柄;使用nullptr
  • 您没有针对swapChainInfo.preTransform
  • 核对surfCaps.supportedTransforms
  • 您没有针对swapChainInfo.compositeAlpha
  • 核对surfCaps.supportedCompositeAlpha

答案 1 :(得分:0)

vkCreateSwapchainKHR验证失败的原因有很多(请查看core_validation.cpp中的PreCallValidateCreateSwapchainKHR)。

这里可能没有足够的代码来说明它失败的原因,例如,失败可能是因为表面无效。但是,为了查明问题,它应该在调试日志中给出一条失败消息,这将告诉你确切的原因。在尝试创建交换链之前,您应该通过调用CreateDebugReportCallbackEXT来启用它。这还需要您启用VK_EXT_debug_report扩展程序。有关详细信息,请参阅here