diff options
author | asuonpaa <34128694+asuonpaa@users.noreply.github.com> | 2020-08-14 16:20:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-14 14:20:28 +0100 |
commit | 70f6725a0ab6b9d5f9f5df1f00db01414e60025f (patch) | |
tree | 7c6f4f9b9d9cb71d6219de21dc6ca2d593479d93 | |
parent | 88f78401e9af26f1249944b942ddf5dd706572e8 (diff) | |
download | amber-70f6725a0ab6b9d5f9f5df1f00db01414e60025f.tar.gz |
Use native vkGetPhysicalDeviceProperties2 for Vulkan 1.1 and up (#901)
We cannot assume vkGetPhysicalDeviceProperties2KHR is exposed when the native version is available. This change uses the native function if available and searches for the extension function only when running Vulkan 1.0.
-rw-r--r-- | src/vulkan/device.cc | 54 | ||||
-rw-r--r-- | src/vulkan/device.h | 1 | ||||
-rw-r--r-- | src/vulkan/vk-funcs.inc | 1 |
3 files changed, 38 insertions, 18 deletions
diff --git a/src/vulkan/device.cc b/src/vulkan/device.cc index a1c05ea..839acd2 100644 --- a/src/vulkan/device.cc +++ b/src/vulkan/device.cc @@ -390,6 +390,16 @@ Result Device::LoadVulkanPointers(PFN_vkGetInstanceProcAddr getInstanceProcAddr, return {}; } +bool Device::SupportsApiVersion(uint32_t major, + uint32_t minor, + uint32_t patch) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" + return physical_device_properties_.apiVersion >= + VK_MAKE_VERSION(major, minor, patch); +#pragma clang diagnostic pop +} + Result Device::Initialize( PFN_vkGetInstanceProcAddr getInstanceProcAddr, Delegate* delegate, @@ -629,35 +639,43 @@ Result Device::Initialize( ptrs_.vkGetPhysicalDeviceMemoryProperties(physical_device_, &physical_memory_properties_); - bool use_physical_device_features_2 = false; - for (auto& ext : required_instance_extensions) { - if (ext == "VK_KHR_get_physical_device_properties2") - use_physical_device_features_2 = true; - } - subgroup_size_control_properties_ = {}; const bool needs_subgroup_size_control = std::find(required_features.begin(), required_features.end(), kSubgroupSizeControl) != required_features.end(); if (needs_subgroup_size_control) { - if (!use_physical_device_features_2) { - return Result( - "Vulkan: Device::Initialize subgroup size control feature also " - "requires VK_KHR_get_physical_device_properties2"); - } - - PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR = - reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>( - getInstanceProcAddr(instance_, - "vkGetPhysicalDeviceProperties2KHR")); - VkPhysicalDeviceProperties2KHR properties2 = {}; properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; properties2.pNext = &subgroup_size_control_properties_; subgroup_size_control_properties_.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT; - vkGetPhysicalDeviceProperties2KHR(physical_device_, &properties2); + + if (SupportsApiVersion(1, 1, 0)) { + // Use vkGetPhysicalDeviceProperties2 available starting Vulkan + // version 1.1. + ptrs_.vkGetPhysicalDeviceProperties2(physical_device_, &properties2); + } else { + // Vulkan 1.0: search for the VK_KHR_get_physical_device_properties2 + // extension and use that for filling the properties2 structure. + bool extension_found = false; + for (auto& ext : required_instance_extensions) { + if (ext == "VK_KHR_get_physical_device_properties2") + extension_found = true; + } + if (!extension_found) { + return Result( + "Vulkan: Device::Initialize subgroup size control feature also " + "requires VK_KHR_get_physical_device_properties2 or an API version " + "of 1.1 or higher"); + } + PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR = + reinterpret_cast<PFN_vkGetPhysicalDeviceProperties2KHR>( + getInstanceProcAddr(instance_, + "vkGetPhysicalDeviceProperties2KHR")); + + vkGetPhysicalDeviceProperties2KHR(physical_device_, &properties2); + } } return {}; diff --git a/src/vulkan/device.h b/src/vulkan/device.h index eccab8b..3fe3159 100644 --- a/src/vulkan/device.h +++ b/src/vulkan/device.h @@ -92,6 +92,7 @@ class Device { private: Result LoadVulkanPointers(PFN_vkGetInstanceProcAddr, Delegate* delegate); + bool SupportsApiVersion(uint32_t major, uint32_t minor, uint32_t patch); VkInstance instance_ = VK_NULL_HANDLE; VkPhysicalDevice physical_device_ = VK_NULL_HANDLE; diff --git a/src/vulkan/vk-funcs.inc b/src/vulkan/vk-funcs.inc index 22c37e8..fb7d3f6 100644 --- a/src/vulkan/vk-funcs.inc +++ b/src/vulkan/vk-funcs.inc @@ -56,6 +56,7 @@ AMBER_VK_FUNC(vkGetImageMemoryRequirements) AMBER_VK_FUNC(vkGetPhysicalDeviceFormatProperties) AMBER_VK_FUNC(vkGetPhysicalDeviceMemoryProperties) AMBER_VK_FUNC(vkGetPhysicalDeviceProperties) +AMBER_VK_FUNC(vkGetPhysicalDeviceProperties2) AMBER_VK_FUNC(vkMapMemory) AMBER_VK_FUNC(vkQueueSubmit) AMBER_VK_FUNC(vkResetCommandBuffer) |