From 28cf4ed6e3dfefa6be736df72e66601c8ca043a3 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 8 Mar 2020 18:10:12 +0100 Subject: [PATCH] Make Vk::Device store a reference to Vk::PhysicalDevice info --- include/Nazara/VulkanRenderer/Wrapper/Device.hpp | 4 +++- include/Nazara/VulkanRenderer/Wrapper/Device.inl | 13 +++++++++---- src/Nazara/VulkanRenderer/Vulkan.cpp | 2 +- src/Nazara/VulkanRenderer/Wrapper/Device.cpp | 15 ++++----------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp index 71c9b28fc..1e381d16d 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ namespace Nz Device(Device&&) = delete; inline ~Device(); - bool Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); + bool Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr); inline void Destroy(); inline const std::vector& GetEnabledQueues() const; @@ -47,6 +48,7 @@ namespace Nz inline const Instance& GetInstance() const; inline VkResult GetLastErrorCode() const; inline VkPhysicalDevice GetPhysicalDevice() const; + inline const Vk::PhysicalDevice& GetPhysicalDeviceInfo() const; inline bool IsExtensionLoaded(const std::string& extensionName); inline bool IsLayerLoaded(const std::string& layerName); diff --git a/include/Nazara/VulkanRenderer/Wrapper/Device.inl b/include/Nazara/VulkanRenderer/Wrapper/Device.inl index a5035a75d..5affb6bc2 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Device.inl +++ b/include/Nazara/VulkanRenderer/Wrapper/Device.inl @@ -14,8 +14,8 @@ namespace Nz { inline Device::Device(Instance& instance) : m_instance(instance), - m_device(VK_NULL_HANDLE), - m_physicalDevice(VK_NULL_HANDLE) + m_physicalDevice(nullptr), + m_device(VK_NULL_HANDLE) { } @@ -32,7 +32,7 @@ namespace Nz vkDestroyDevice(m_device, (m_allocator.pfnAllocation) ? &m_allocator : nullptr); m_device = VK_NULL_HANDLE; - m_physicalDevice = VK_NULL_HANDLE; + m_physicalDevice = nullptr; } } @@ -65,7 +65,12 @@ namespace Nz inline VkPhysicalDevice Device::GetPhysicalDevice() const { - return m_physicalDevice; + return m_physicalDevice->device; + } + + inline const Vk::PhysicalDevice& Device::GetPhysicalDeviceInfo() const + { + return *m_physicalDevice; } inline bool Device::IsExtensionLoaded(const std::string& extensionName) diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index 3ffbd9fc4..344f50103 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -429,7 +429,7 @@ namespace Nz }; std::shared_ptr device = std::make_shared(s_instance); - if (!device->Create(gpu, createInfo)) + if (!device->Create(GetPhysicalDeviceInfo(gpu), createInfo)) { NazaraError("Failed to create Vulkan Device: " + TranslateVulkanError(device->GetLastErrorCode())); return {}; diff --git a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp index fe462adb6..8f15e73ba 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp @@ -12,23 +12,16 @@ namespace Nz { namespace Vk { - bool Device::Create(VkPhysicalDevice device, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) + bool Device::Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator) { - std::vector queuesProperties; - if (!m_instance.GetPhysicalDeviceQueueFamilyProperties(device, &queuesProperties)) - { - NazaraError("Failed to query queue family properties"); - return false; - } - - m_lastErrorCode = m_instance.vkCreateDevice(device, &createInfo, allocator, &m_device); + m_lastErrorCode = m_instance.vkCreateDevice(deviceInfo.device, &createInfo, allocator, &m_device); if (m_lastErrorCode != VkResult::VK_SUCCESS) { NazaraError("Failed to create Vulkan device"); return false; } - m_physicalDevice = device; + m_physicalDevice = &deviceInfo; // Store the allocator to access them when needed if (allocator) @@ -76,7 +69,7 @@ namespace Nz if (info.familyIndex > maxFamilyIndex) maxFamilyIndex = info.familyIndex; - const VkQueueFamilyProperties& queueProperties = queuesProperties[info.familyIndex]; + const VkQueueFamilyProperties& queueProperties = deviceInfo.queues[info.familyIndex]; info.flags = queueProperties.queueFlags; info.minImageTransferGranularity = queueProperties.minImageTransferGranularity; info.timestampValidBits = queueProperties.timestampValidBits;