From cc8010fb7ce16b2d0eece6b8863856717412d152 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 17 Aug 2022 14:01:45 +0200 Subject: [PATCH] [dxvk] Add format feature queries to DxvkDevice --- src/dxvk/dxvk_adapter.cpp | 13 +++++++++++++ src/dxvk/dxvk_adapter.h | 10 ++++++++++ src/dxvk/dxvk_device.cpp | 33 +++++++++++++++++++++++++++++++++ src/dxvk/dxvk_device.h | 29 +++++++++++++++++++++++++++++ src/dxvk/dxvk_format.h | 22 +++++++++++++++++++++- 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index cf694c0b..62c08e4d 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -60,6 +60,19 @@ namespace dxvk { } + DxvkFormatFeatures DxvkAdapter::getFormatFeatures(VkFormat format) const { + VkFormatProperties3 properties3 = { VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3 }; + VkFormatProperties2 properties2 = { VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, &properties3 }; + m_vki->vkGetPhysicalDeviceFormatProperties2(m_handle, format, &properties2); + + DxvkFormatFeatures result; + result.optimal = properties3.optimalTilingFeatures; + result.linear = properties3.linearTilingFeatures; + result.buffer = properties3.bufferFeatures; + return result; + } + + VkFormatProperties DxvkAdapter::formatProperties(VkFormat format) const { VkFormatProperties formatProperties; m_vki->vkGetPhysicalDeviceFormatProperties(m_handle, format, &formatProperties); diff --git a/src/dxvk/dxvk_adapter.h b/src/dxvk/dxvk_adapter.h index 42af9d15..18ff77f5 100644 --- a/src/dxvk/dxvk_adapter.h +++ b/src/dxvk/dxvk_adapter.h @@ -3,6 +3,7 @@ #include "dxvk_device_info.h" #include "dxvk_extensions.h" #include "dxvk_include.h" +#include "dxvk_format.h" namespace dxvk { @@ -135,6 +136,15 @@ namespace dxvk { */ VkPhysicalDeviceMemoryProperties memoryProperties() const; + /** + * \brief Queries format feature support + * + * \param [in] format Format to query + * \returns Format feature bits + */ + DxvkFormatFeatures getFormatFeatures( + VkFormat format) const; + /** * \brief Queries format support * diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 08289cee..5f3f0877 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -43,6 +43,39 @@ namespace dxvk { } + std::optional DxvkDevice::getFormatLimits( + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags) const { + auto vk = m_adapter->vki(); + + VkPhysicalDeviceImageFormatInfo2 info = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2 }; + info.format = format; + info.type = type; + info.tiling = tiling; + info.usage = usage; + info.flags = flags; + + VkImageFormatProperties2 properties = { VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2 }; + + VkResult vr = vk->vkGetPhysicalDeviceImageFormatProperties2( + m_adapter->handle(), &info, &properties); + + if (vr != VK_SUCCESS) + return std::nullopt; + + 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; + return result; + } + + bool DxvkDevice::isUnifiedMemoryArchitecture() const { return m_adapter->isUnifiedMemoryArchitecture(); } diff --git a/src/dxvk/dxvk_device.h b/src/dxvk/dxvk_device.h index e8f44ee6..7918c7b3 100644 --- a/src/dxvk/dxvk_device.h +++ b/src/dxvk/dxvk_device.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "dxvk_adapter.h" #include "dxvk_buffer.h" #include "dxvk_compute.h" @@ -178,6 +180,33 @@ namespace dxvk { return m_properties; } + /** + * \brief Queries format feature support + * + * \param [in] format Format to query + * \returns Format feature bits + */ + DxvkFormatFeatures getFormatFeatures(VkFormat format) const { + return m_adapter->getFormatFeatures(format); + } + + /** + * \brief Queries format limits + * + * \param [in] format Image format to quers + * \param [in] type Image type + * \param [in] tiling Image tiling + * \param [in] usage Image usage flags + * \param [in] flags Image create flags + * \returns Format limits if the given image is supported + */ + std::optional getFormatLimits( + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags) const; + /** * \brief Get device status * diff --git a/src/dxvk/dxvk_format.h b/src/dxvk/dxvk_format.h index 5697ee9a..6585deac 100644 --- a/src/dxvk/dxvk_format.h +++ b/src/dxvk/dxvk_format.h @@ -13,7 +13,27 @@ namespace dxvk { }; using DxvkFormatFlags = Flags; - + + /** + * \brief Format support info + */ + struct DxvkFormatFeatures { + VkFormatFeatureFlags2 optimal; + VkFormatFeatureFlags2 linear; + VkFormatFeatureFlags2 buffer; + }; + + /** + * \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; + }; + /** * \brief Planar format info */