Vulkan win32_surface创建失败

时间:2018-02-03 22:32:29

标签: visual-c++ vulkan

寻求学习和使用vulkan,我已经遵循了几个例子,并且取得了成功,但是一旦我在所需的上下文(引擎)中应用我所知道的东西,事情就不会发生,或者根本不可行。

我遇到了几个问题,但明确阻止我的是win32类型的表面创建。

context:windows应用程序,x64,使用HWND窗口,使用Vulkan API版本:1.0.65,使用VC工具120(c ++ 11)在win 7 x64 OS上使用VisStudio2015构建

操作顺序:程序开始 - >创建HWND窗口 - >创建vulkan实例 - >创造vulkan表面 - >失败

包含设置:

#if defined(_WIN32)
#define VK_USE_PLATFORM_WIN32_KHR
#endif
#include <vulkan/vulkan.h>

创建窗口(hInstance var由WinMain条目设置):

GAppWindow = CreateWindowEx( WS_EX_APPWINDOW, *WindowClassName, *Name, WindowStyle, WindowPosX, WindowPosY, WindowWidth, WindowHeight, NULL, NULL, hInstance, NULL );

创建实例:

VkInstance instance;
VkSurfaceKHR surface;

if (enableValidationLayers && !checkValidationLayerSupport())
{ appError("Validation layers requested but not available!"); }

VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.applicationVersion = 1;
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = 1;
appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0);

uint32_t ReqExtensionCount = 0;
std::vector<const char*> ReqExtensions = GetRequiredInstanceExtensions(ReqExtensionCount);

VkInstanceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
createInfo.enabledExtensionCount = ReqExtensionCount;
createInfo.ppEnabledExtensionNames = ReqExtensionCount ? ReqExtensions.data() : NULL;
createInfo.enabledLayerCount = 0; 
createInfo.ppEnabledLayerNames = NULL;

if (enableValidationLayers)
{
    createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
    createInfo.ppEnabledLayerNames = validationLayers.data();
} 

if (vkCreateInstance(&createInfo, NULL, &instance) != VK_SUCCESS)
{ appError("Failed to create instance!"); }

请注意,ReqExtensions是“VK_KHR_surface”和“VK_KHR_win32_surface”。

表面创建:

#if defined(VK_USE_PLATFORM_WIN32_KHR)
VkWin32SurfaceCreateInfoKHR surfaceInfo = {};
surfaceInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surfaceInfo.pNext = NULL;
surfaceInfo.flags = 0;
surfaceInfo.hinstance = hInstance;
surfaceInfo.hwnd = GAppWindow;

VkResult result = vkCreateWin32SurfaceKHR(instance, &surfaceInfo, NULL, &surface);
if(result != VK_SUCCESS)
{
    appError("Failed to create Win32 surface");
    return 1;
}
#endif

结果是:VK_ERROR_EXTENSION_NOT_PRESENT

然而根据vulkaninfo我的系统有以下内容:

实例扩展数= 11 VK_EXT_debug_report:扩展修订版9
VK_EXT_display_surface_counter:扩展修订版1
VK_KHR_get_physical_device_properties2:扩展修订版1
VK_KHR_get_surface_capabilities2:扩展修订版1
VK_KHR_surface:扩展修订版25
VK_KHR_win32_surface:扩展修订版6
VK_KHX_device_group_creation:扩展修订版1
VK_KHR_external_fence_capabilities:扩展修订版1
VK_KHR_external_memory_capabilities:扩展修订版1
VK_KHR_external_semaphore_capabilities:扩展修订版1
VK_NV_external_memory_capabilities:扩展修订版1

可呈现的表面:
GPU id:0(GeForce GTX 980)
表面类型:VK_KHR_win32_surface
格式:count = 2
B8G8R8A8_UNORM
B8G8R8A8_SRGB
现在模式:count = 3
FIFO_KHR
FIFO_RELAXED_KHR
MAILBOX_KHR

所以我很难过为什么它说不存在......

0 个答案:

没有答案