From c0fdf1449c0d28563ed4a8fc252b684adb5e7dc0 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 11 Sep 2022 15:28:14 +0200 Subject: [PATCH] [dxvk] Allow querying external memory features for image formats --- src/dxvk/dxvk_device.cpp | 13 ++++++++++++- src/dxvk/dxvk_format.h | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 6657d6881..25b2e45cb 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -46,6 +46,9 @@ namespace dxvk { const DxvkFormatQuery& query) const { auto vk = m_adapter->vki(); + VkPhysicalDeviceExternalImageFormatInfo externalInfo = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO }; + externalInfo.handleType = query.handleType; + VkPhysicalDeviceImageFormatInfo2 info = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2 }; info.format = query.format; info.type = query.type; @@ -53,20 +56,28 @@ namespace dxvk { info.usage = query.usage; info.flags = query.flags; + if (externalInfo.handleType) + externalInfo.pNext = std::exchange(info.pNext, &externalInfo); + + VkExternalImageFormatProperties externalProperties = { VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES }; VkImageFormatProperties2 properties = { VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2 }; + if (externalInfo.handleType) + externalProperties.pNext = std::exchange(properties.pNext, &externalProperties); + VkResult vr = vk->vkGetPhysicalDeviceImageFormatProperties2( m_adapter->handle(), &info, &properties); if (vr != VK_SUCCESS) return std::nullopt; - DxvkFormatLimits result; + DxvkFormatLimits result = { }; result.maxExtent = properties.imageFormatProperties.maxExtent; result.maxMipLevels = properties.imageFormatProperties.maxMipLevels; result.maxArrayLayers = properties.imageFormatProperties.maxArrayLayers; result.sampleCounts = properties.imageFormatProperties.sampleCounts; result.maxResourceSize = properties.imageFormatProperties.maxResourceSize; + result.externalFeatures = externalProperties.externalMemoryProperties.externalMemoryFeatures; return result; } diff --git a/src/dxvk/dxvk_format.h b/src/dxvk/dxvk_format.h index c6d0c9fba..34084642a 100644 --- a/src/dxvk/dxvk_format.h +++ b/src/dxvk/dxvk_format.h @@ -27,22 +27,24 @@ namespace dxvk { * \brief Format support limits for a given set of image usage flags */ struct DxvkFormatLimits { - VkExtent3D maxExtent; - uint32_t maxMipLevels; - uint32_t maxArrayLayers; - VkSampleCountFlags sampleCounts; - VkDeviceSize maxResourceSize; + VkExtent3D maxExtent; + uint32_t maxMipLevels; + uint32_t maxArrayLayers; + VkSampleCountFlags sampleCounts; + VkDeviceSize maxResourceSize; + VkExternalMemoryFeatureFlags externalFeatures; }; /** * \brief Format query info */ struct DxvkFormatQuery { - VkFormat format; - VkImageType type; - VkImageTiling tiling; - VkImageUsageFlags usage; - VkImageCreateFlags flags; + VkFormat format; + VkImageType type; + VkImageTiling tiling; + VkImageUsageFlags usage; + VkImageCreateFlags flags; + VkExternalMemoryHandleTypeFlagBits handleType; }; /**