check for presentation queue
This commit is contained in:
parent
25ea883b25
commit
1051a13dea
1 changed files with 33 additions and 5 deletions
38
main.cpp
38
main.cpp
|
|
@ -156,28 +156,51 @@ private:
|
|||
if (familyProperty.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
|
||||
mGraphicsQueueFamilyIndex = index;
|
||||
}
|
||||
|
||||
VkBool32 presentationQueueSupport = false;
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(mPhysicalDevice, index, mSurface, &presentationQueueSupport);
|
||||
|
||||
if (presentationQueueSupport) {
|
||||
mPresentationQueueFamilyIndex = index;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index == -1) throw std::runtime_error("nu require queue families found");
|
||||
if (mPresentationQueueFamilyIndex == -1 || mGraphicsQueueFamilyIndex == -1) {
|
||||
throw std::runtime_error("nu require queue families found");
|
||||
}
|
||||
}
|
||||
|
||||
void createLogicalDevice() {
|
||||
float queuePriority = 1.f;
|
||||
|
||||
VkDeviceQueueCreateInfo queueCreateInfos {
|
||||
VkDeviceQueueCreateInfo graphicsQueueCreateInfos {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||
.queueFamilyIndex = mGraphicsQueueFamilyIndex,
|
||||
.queueCount = 1,
|
||||
.pQueuePriorities = &queuePriority,
|
||||
};
|
||||
|
||||
VkDeviceQueueCreateInfo presentationQueueCreateInfos {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||
.queueFamilyIndex = mPresentationQueueFamilyIndex,
|
||||
.queueCount = 1,
|
||||
.pQueuePriorities = &queuePriority,
|
||||
};
|
||||
|
||||
std::vector<VkDeviceQueueCreateInfo> queues = { graphicsQueueCreateInfos };
|
||||
|
||||
if (mPresentationQueueFamilyIndex != mGraphicsQueueFamilyIndex) {
|
||||
queues.push_back(graphicsQueueCreateInfos);
|
||||
}
|
||||
|
||||
VkPhysicalDeviceFeatures features {};
|
||||
|
||||
VkDeviceCreateInfo deviceCreateInfo {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||
.queueCreateInfoCount = 1,
|
||||
.pQueueCreateInfos = &queueCreateInfos,
|
||||
.queueCreateInfoCount = (uint32_t) queues.size(),
|
||||
.pQueueCreateInfos = queues.data(),
|
||||
.pEnabledFeatures = &features,
|
||||
};
|
||||
|
||||
|
|
@ -188,6 +211,7 @@ private:
|
|||
|
||||
void getQueues() {
|
||||
vkGetDeviceQueue(mDevice, mGraphicsQueueFamilyIndex, 0, &mGraphicsQueue);
|
||||
vkGetDeviceQueue(mDevice, mPresentationQueueFamilyIndex, 0, &mPresentQueue);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -200,11 +224,15 @@ private:
|
|||
private:
|
||||
GLFWwindow* mWindow = nullptr;
|
||||
|
||||
uint32_t mGraphicsQueueFamilyIndex = -1;
|
||||
uint32_t mPresentationQueueFamilyIndex = -1;
|
||||
|
||||
VkInstance mInstance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
|
||||
uint32_t mGraphicsQueueFamilyIndex = -1;
|
||||
VkDevice mDevice = VK_NULL_HANDLE;
|
||||
|
||||
VkQueue mGraphicsQueue = VK_NULL_HANDLE;
|
||||
VkQueue mPresentQueue = VK_NULL_HANDLE;
|
||||
|
||||
VkSurfaceKHR mSurface = VK_NULL_HANDLE;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue