我正在通过这教程学习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->实例、contextOut->窗口、nullptr、&contextOut->面);
返回VK_ERROR_EXTENSION_NOT_PRESENT
为什么表面创造失败?
我的系统:Ubuntu18.04 64位,NVIDIA RTX3000,GPU驱动程序NVIDIA 430
发布于 2019-10-17 15:34:47
您正在将实例创建为局部变量:
bool CreateVulkanInstance(VkInstance instanceOut) {
vkCreateInstance(&createInfo, nullptr, &instanceOut)
}可能应该是VkInstance&。
https://stackoverflow.com/questions/58435411
复制相似问题