我正在通过this教程学习Vulkan。我已经使用GLFW创建了窗口并初始化了Vulkan实例,而没有错误。但是Vulkan无法创建VKSurfaceKHR。
bool CreateRenderContext(RenderContext* contextOut)
{
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
contextOut->window = glfwCreateWindow(contextOut->width, contextOut->height, "Vulkan", NULL, NULL);
if(!CreateVulkanInstance(contextOut->instance))
{
printf("failed creating vulkan instance\n");
}
if(!glfwVulkanSupported())
{
return false;
}
VkResult err = glfwCreateWindowSurface(contextOut->instance, contextOut->window,nullptr, &contextOut->surface);
if (err != VK_SUCCESS)
{
// Window surface creation failed
printf("failed to create surface");
return false;
}
return true;
}
[CreateVulkanInstance
()看起来像这样:
bool CreateVulkanInstance(VkInstance instanceOut)
{
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello Triangle";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions = nullptr;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
createInfo.enabledExtensionCount = glfwExtensionCount;
createInfo.ppEnabledExtensionNames = glfwExtensions;
createInfo.enabledLayerCount = 0;
if (vkCreateInstance(&createInfo, nullptr, &instanceOut) != VK_SUCCESS)
{
return false;
}
return true;
}
GLFW返回以下必需的扩展名:
VK_KHR_surface
VK_KHR_xcb_surface
但是VkResult err = glfwCreateWindowSurface(contextOut-> instance,contextOut-> window,nullptr,&contextOut-> surface);
返回VK_ERROR_EXTENSION_NOT_PRESENT
为什么曲面创建失败?
我的系统:[Ubuntu 18.04 64位,NVIDIA RTX3000,GPU驱动程序NVIDIA 430
您正在将实例创建为临时实例:
bool CreateVulkanInstance(VkInstance instanceOut) {
vkCreateInstance(&createInfo, nullptr, &instanceOut)
}
可能是VkInstance&
。