1

我正在尝试对 Vulkan 的工作进行简单测试。我一直在关注 LunarG 教程,但遇到了vkCreateWin32SurfaceKHR似乎无济于事的问题。即,surface没有被写入。该函数vkCreateWin32SurfaceKHR返回 0,因此它不报告失败。任何帮助表示赞赏。

    // create window
    sdlWindow = SDL_CreateWindow(APP_SHORT_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0);
    struct SDL_SysWMinfo wmInfo;
    SDL_VERSION(&wmInfo.version);
    SDL_GetWindowWMInfo(sdlWindow, &wmInfo);
    hWnd = wmInfo.info.win.window;
    hInstance = GetModuleHandle(NULL);

    // create a surface attached to the window
    VkWin32SurfaceCreateInfoKHR surface_info = {};
    surface_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
    surface_info.pNext = NULL;
    surface_info.hinstance = hInstance;
    surface_info.hwnd = hWnd;
    sanity(!vkCreateWin32SurfaceKHR(inst, &surface_info, NULL, &surface));
4

2 回答 2

2

Sascha Willems 正确地确定我没有请求创建表面所需的扩展。我将代码更改为请求扩展,如下所示,现在一切都按预期工作。

    // create an instance
    vector<char*> enabledInstanceExtensions;
    enabledInstanceExtensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
    enabledInstanceExtensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
#ifdef VALIDATE_VULKAN
    enabledInstanceExtensions.push_back("VK_EXT_debug_report");
#endif

    vector<char*> enabledInstanceLayers;
#ifdef VALIDATE_VULKAN
    enabledInstanceLayers.push_back("VK_LAYER_LUNARG_standard_validation");
#endif

    VkInstanceCreateInfo inst_info = {};
    inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    inst_info.pNext = NULL;
    inst_info.flags = 0;
    inst_info.pApplicationInfo = &app_info;
    inst_info.enabledExtensionCount = (uint32_t)enabledInstanceExtensions.size();
    inst_info.ppEnabledExtensionNames = enabledInstanceExtensions.data();
    inst_info.enabledLayerCount = (uint32_t)enabledInstanceLayers.size();
    inst_info.ppEnabledLayerNames = enabledInstanceLayers.data();
    sanity(!vkCreateInstance(&inst_info, NULL, &instance));
于 2016-05-18T20:10:55.580 回答
0

Beside what Joe added in his answer, I will also say that the call to vkCreateWin32SurfaceKHR() if provided invalid arguments does not fail and return VK_SUCCESS. I`m not sure about other platforms if this is still the case. When I say invalid arguments I am referring to the two most important hinstance and hwnd of the vulkan structure VkWin32SurfaceCreateInfoKHR. So pay close attention to those two arguments, it tricked me few times. Not sure tough why is returning VK_SUCCESS while providing invalid arguments, there may be some internal related things that god know why.

于 2018-02-16T09:54:47.470 回答