From d98acda22ef2f837973645582901403c0ccc20c8 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 15 Dec 2021 19:54:07 +0800 Subject: [PATCH] splited DeviceAttribute::Refresh function. --- inc/hgl/graph/VKDeviceAttribute.h | 7 +- src/SceneGraph/Vulkan/VKDeviceAttribute.cpp | 90 ++++++++++++--------- 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/inc/hgl/graph/VKDeviceAttribute.h b/inc/hgl/graph/VKDeviceAttribute.h index 1fc52328..c5eea50d 100644 --- a/inc/hgl/graph/VKDeviceAttribute.h +++ b/inc/hgl/graph/VKDeviceAttribute.h @@ -55,7 +55,12 @@ public: bool CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags properties,uint32_t *typeIndex) const; - void Refresh(); + void RefreshSurfaceCaps(); + +private: + + void RefreshSurface(); + void RefreshQueueFamily(); public: diff --git a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp index d3b852e0..d9c85dc1 100644 --- a/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceAttribute.cpp @@ -13,7 +13,9 @@ GPUDeviceAttribute::GPUDeviceAttribute(VulkanInstance *inst,const GPUPhysicalDev physical_device=pd; surface=s; - Refresh(); + RefreshSurfaceCaps(); + RefreshSurface(); + RefreshQueueFamily(); } GPUDeviceAttribute::~GPUDeviceAttribute() @@ -42,11 +44,16 @@ bool GPUDeviceAttribute::CheckMemoryType(uint32_t typeBits,VkMemoryPropertyFlags return physical_device->CheckMemoryType(typeBits,properties,typeIndex); } -void GPUDeviceAttribute::Refresh() +void GPUDeviceAttribute::RefreshSurfaceCaps() { VkPhysicalDevice pdevice = *physical_device; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(pdevice, surface, &surface_caps); +} + +void GPUDeviceAttribute::RefreshSurface() +{ + VkPhysicalDevice pdevice = *physical_device; { if (surface_caps.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) @@ -116,58 +123,61 @@ void GPUDeviceAttribute::Refresh() present_modes.Clear(); } } +} + +void GPUDeviceAttribute::RefreshQueueFamily() +{ + VkPhysicalDevice pdevice = *physical_device; + + uint32_t family_count; + vkGetPhysicalDeviceQueueFamilyProperties(pdevice, &family_count, nullptr); + family_properties.SetCount(family_count); + vkGetPhysicalDeviceQueueFamilyProperties(pdevice, &family_count, family_properties.GetData()); { - uint32_t family_count; - vkGetPhysicalDeviceQueueFamilyProperties(pdevice, &family_count, nullptr); - family_properties.SetCount(family_count); - vkGetPhysicalDeviceQueueFamilyProperties(pdevice, &family_count, family_properties.GetData()); - + supports_present.SetCount(family_count); + VkBool32 *sp = supports_present.GetData(); + for (uint32_t i = 0; i < family_count; i++) { - supports_present.SetCount(family_count); - VkBool32 *sp = supports_present.GetData(); - for (uint32_t i = 0; i < family_count; i++) - { - vkGetPhysicalDeviceSurfaceSupportKHR(pdevice, i, surface, sp); - ++sp; - } + vkGetPhysicalDeviceSurfaceSupportKHR(pdevice, i, surface, sp); + ++sp; } + } + { + VkQueueFamilyProperties *fp = family_properties.GetData(); + VkBool32 *sp = supports_present.GetData(); + for (uint32_t i = 0; i < family_count; i++) { - VkQueueFamilyProperties *fp = family_properties.GetData(); - VkBool32 *sp = supports_present.GetData(); - for (uint32_t i = 0; i < family_count; i++) + if (fp->queueFlags & VK_QUEUE_GRAPHICS_BIT) { - if (fp->queueFlags & VK_QUEUE_GRAPHICS_BIT) - { - if (graphics_family == ERROR_FAMILY_INDEX) - graphics_family = i; + if (graphics_family == ERROR_FAMILY_INDEX) + graphics_family = i; - if (*sp) - { - graphics_family = i; - present_family = i; - break; - } - } - - ++fp; - ++sp; - } - } - - if (present_family == ERROR_FAMILY_INDEX) - { - VkBool32 *sp = supports_present.GetData(); - for (uint32_t i = 0; i < family_count; i++) - { if (*sp) { + graphics_family = i; present_family = i; break; } - ++sp; } + + ++fp; + ++sp; + } + } + + if (present_family == ERROR_FAMILY_INDEX) + { + VkBool32 *sp = supports_present.GetData(); + for (uint32_t i = 0; i < family_count; i++) + { + if (*sp) + { + present_family = i; + break; + } + ++sp; } } }