From f30ad1335fdef2743a67f78a018daa2a6c4df2a1 Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Mon, 7 Feb 2022 18:29:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83=20=D1=81?= =?UTF-8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=84=D0=B8?= =?UTF-8?q?=D0=B7.=20=D1=83=D1=81=D1=82=D1=80=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/PhysicalDevice.h | 17 +++++++++++++++++ include/vk.h | 4 +++- src/vk.cpp | 32 +++++++++++++++----------------- 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 include/PhysicalDevice.h diff --git a/include/PhysicalDevice.h b/include/PhysicalDevice.h new file mode 100644 index 0000000..48f51bd --- /dev/null +++ b/include/PhysicalDevice.h @@ -0,0 +1,17 @@ +#ifndef PHYSICALDEVICE_H +#define PHYSICALDEVICE_H + +#include + +#include + +typedef struct _PhysicalDevice +{ + VkPhysicalDevice device; // устройство + VkPhysicalDeviceProperties properties; // параметры + VkPhysicalDeviceFeatures features; // функции + VkPhysicalDeviceMemoryProperties memory; // память + std::vector queueFamilyProperties; // семейства очередей +} PhysicalDevice; + +#endif // PHYSICALDEVICE_H diff --git a/include/vk.h b/include/vk.h index 5f9ad47..6de6cb7 100644 --- a/include/vk.h +++ b/include/vk.h @@ -4,6 +4,8 @@ #include #include +#include "PhysicalDevice.h" + class Vulkan { public: @@ -11,7 +13,7 @@ class Vulkan void destroy(); // завершение работы private: VkInstance instance; // Экземпляр Vulkan - VkPhysicalDevice physicalDevice; // Физическое устройство + PhysicalDevice physicalDevice; // Физическое устройство // Структура для хранения флагов struct { diff --git a/src/vk.cpp b/src/vk.cpp index 8eb074f..90ec1b8 100644 --- a/src/vk.cpp +++ b/src/vk.cpp @@ -119,32 +119,32 @@ void Vulkan::createInstance() } // Выбор физического устройства на основании требований -VkPhysicalDevice selectPhysicalDeviceByProperties(std::vector & devices) +PhysicalDevice selectPhysicalDeviceByProperties(std::vector & devices) { int i; - VkPhysicalDeviceProperties properties; // Параметры конкретного устройства - VkPhysicalDeviceFeatures features; // Функции конкретного устройства - VkPhysicalDeviceMemoryProperties memory; // Память + PhysicalDevice result; // физическое устройство (PhysicalDevice.h) for (const auto& device : devices) { + // Запомним устройство + result.device = device; // Получаем данные - vkGetPhysicalDeviceProperties(device, &properties); - vkGetPhysicalDeviceFeatures(device, &features); - vkGetPhysicalDeviceMemoryProperties(device, &memory); + vkGetPhysicalDeviceProperties(device, &result.properties); + vkGetPhysicalDeviceFeatures(device, &result.features); + vkGetPhysicalDeviceMemoryProperties(device, &result.memory); // Данные по семействам очередей uint32_t queueFamilyPropertiesCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyPropertiesCount, nullptr); - std::vector queueFamilyProperties(queueFamilyPropertiesCount); - vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyPropertiesCount, queueFamilyProperties.data()); + result.queueFamilyProperties.resize(queueFamilyPropertiesCount); + vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyPropertiesCount, result.queueFamilyProperties.data()); // Производим оценку - if (features.geometryShader - && 4000 < memory.memoryHeaps[0].size / 1000 / 1000) - return device; + if (result.features.geometryShader + && 4000 < result.memory.memoryHeaps[0].size / 1000 / 1000) + return result; } - - return nullptr; + // Если устройство не найдено - вернем пустую структуру + return PhysicalDevice(); } // Выбор физического устройства @@ -168,10 +168,8 @@ void Vulkan::selectPhysicalDevice() physicalDevice = selectPhysicalDeviceByProperties(devices); // Если не удалось выбрать подходящее требованием устройство - выдадим исключение - if (!physicalDevice) + if (!physicalDevice.device) { throw std::runtime_error("failed to find a suitable GPU!"); } - - }