From a6accd663e4764df48abc92f1dda555753afd80f Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Thu, 17 Feb 2022 18:11:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0=20=D0=BE=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=B9=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/PhysicalDevice.h | 2 -- include/Queue.h | 13 +++++++++++++ include/vk.h | 4 +++- src/PhysicalDevice.cpp | 16 ---------------- src/vk.cpp | 31 ++++++++++++++++++++++++++++--- 5 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 include/Queue.h delete mode 100644 src/PhysicalDevice.cpp diff --git a/include/PhysicalDevice.h b/include/PhysicalDevice.h index 23b5e41..48f51bd 100644 --- a/include/PhysicalDevice.h +++ b/include/PhysicalDevice.h @@ -12,8 +12,6 @@ typedef struct _PhysicalDevice VkPhysicalDeviceFeatures features; // функции VkPhysicalDeviceMemoryProperties memory; // память std::vector queueFamilyProperties; // семейства очередей - - uint32_t pickQueueFamily(VkQueueFlags); } PhysicalDevice; #endif // PHYSICALDEVICE_H diff --git a/include/Queue.h b/include/Queue.h new file mode 100644 index 0000000..59b6e6f --- /dev/null +++ b/include/Queue.h @@ -0,0 +1,13 @@ +#ifndef QUEUE_H +#define QUEUE_H + +#include + +typedef struct _Queue +{ + uint32_t index; + VkQueue descriptor; + VkQueueFamilyProperties properties; +} Queue; + +#endif // QUEUE_H diff --git a/include/vk.h b/include/vk.h index 68e7d97..7c7feb6 100644 --- a/include/vk.h +++ b/include/vk.h @@ -6,6 +6,7 @@ #include "PhysicalDevice.h" #include "Surface.h" +#include "Queue.h" class Vulkan { @@ -16,7 +17,7 @@ class Vulkan VkInstance instance; // Экземпляр Vulkan PhysicalDevice physicalDevice; // Физическое устройство VkDevice logicalDevice; // логическое устройство - VkQueue graphicalQueue; // очередь для работы с графикой + Queue queue; // очередь Surface surface; // Поверхность окна VkSwapchainKHR swapChain; // Список показа @@ -29,6 +30,7 @@ class Vulkan void createInstance(); // Создание экземпяра Vulkan void selectPhysicalDevice(std::vector &deviceExtensions); // Выбор физического устройства + void pickQueues(); // Выбор очередей void createLogicalDevice(std::vector &deviceExtensions); // Создание логического устройства void createWindowSurface(GLFWwindow* window); // Создание поверхности окна void createSwapchain(GLFWwindow* window); // Создание цепочки показа diff --git a/src/PhysicalDevice.cpp b/src/PhysicalDevice.cpp deleted file mode 100644 index 92fbf4a..0000000 --- a/src/PhysicalDevice.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "PhysicalDevice.h" - -// Возвращает индекс первой попавшейся очереди, соответствующей требуемым флагам -uint32_t PhysicalDevice::pickQueueFamily(VkQueueFlags flags) -{ - // Цикл по параметрам семейств очередей - for (uint32_t index = 0; index < queueFamilyProperties.size(); index++) - { - // Если очередь соответствует требованиям по возможностям очереди - if (queueFamilyProperties[index].queueFlags & flags) - { - // возвращаем её индекс - return index; - } - } -} \ No newline at end of file diff --git a/src/vk.cpp b/src/vk.cpp index 05ec62f..0d65032 100644 --- a/src/vk.cpp +++ b/src/vk.cpp @@ -268,17 +268,42 @@ void Vulkan::selectPhysicalDevice(std::vector &deviceExtensions) } } +// Выбор очередей +void Vulkan::pickQueues() +{ + queue.index = -1; + + for (int i = 0; i < physicalDevice.queueFamilyProperties.size(); i++) + { + // Проверка возможности вывода + VkBool32 presentSupport = false; + vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice.device, i, surface.surface, &presentSupport); + // Проверка поддержки очередью графических операций + if (physicalDevice.queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT + && presentSupport) + { + queue.index = i; + queue.properties = physicalDevice.queueFamilyProperties[i]; + break; + } + } +} + +// Создание логического устройства void Vulkan::createLogicalDevice(std::vector &deviceExtensions) { + // Выберем очереди + pickQueues(); + // Приоритеты очередей float priority[1] = {1}; // Данные о необходимых очередях VkDeviceQueueCreateInfo queueCreateInfo{}; queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queueCreateInfo.queueFamilyIndex = physicalDevice.pickQueueFamily(VK_QUEUE_GRAPHICS_BIT); + queueCreateInfo.queueFamilyIndex = queue.index; queueCreateInfo.queueCount = 1; queueCreateInfo.pQueuePriorities = priority; - + // слои для логического устройства std::vector layers; // Подключение других слоев @@ -315,7 +340,7 @@ void Vulkan::createLogicalDevice(std::vector &deviceExtensions) } // Получим дескриптор очереди логического устройства - vkGetDeviceQueue(logicalDevice, queueCreateInfo.queueFamilyIndex, 0, &graphicalQueue); + vkGetDeviceQueue(logicalDevice, queueCreateInfo.queueFamilyIndex, 0, &queue.descriptor); } // Создание поверхности окна