1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 01:24:14 +01:00

[dxvk] Introduce DxvkFormatQuery

This commit is contained in:
Philip Rebohle 2022-09-11 15:09:23 +02:00
parent ce47bf4264
commit 3a636f6094
6 changed files with 63 additions and 38 deletions

View File

@ -1554,9 +1554,15 @@ namespace dxvk {
// Check if the device supports the given combination of format
// and sample count. D3D exposes the opaque concept of quality
// levels to the application, we'll just define one such level.
auto properties = m_dxvkDevice->getFormatLimits(format,
VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, flags);
DxvkFormatQuery formatQuery = { };
formatQuery.format = format;
formatQuery.type = VK_IMAGE_TYPE_2D;
formatQuery.tiling = VK_IMAGE_TILING_OPTIMAL;
formatQuery.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
formatQuery.flags = flags;
auto properties = m_dxvkDevice->getFormatLimits(formatQuery);
if (properties && (properties->sampleCounts & sampleCountFlag))
*pNumQualityLevels = 1;
return S_OK;
@ -2128,8 +2134,13 @@ namespace dxvk {
? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
: VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
auto limits = m_dxvkDevice->getFormatLimits(fmtMapping.Format,
VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, usage, 0);
DxvkFormatQuery formatQuery = { };
formatQuery.format = fmtMapping.Format;
formatQuery.type = VK_IMAGE_TYPE_2D;
formatQuery.tiling = VK_IMAGE_TILING_OPTIMAL;
formatQuery.usage = usage;
auto limits = m_dxvkDevice->getFormatLimits(formatQuery);
if (limits && limits->sampleCounts > VK_SAMPLE_COUNT_1_BIT) {
flags1 |= D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET
@ -2185,14 +2196,20 @@ namespace dxvk {
BOOL D3D11Device::GetImageTypeSupport(VkFormat Format, VkImageType Type, VkImageCreateFlags Flags) const {
auto properties = m_dxvkDevice->getFormatLimits(Format,
Type, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, Flags);
DxvkFormatQuery formatQuery = { };
formatQuery.format = Format;
formatQuery.type = Type;
formatQuery.tiling = VK_IMAGE_TILING_OPTIMAL;
formatQuery.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
formatQuery.flags = Flags;
auto properties = m_dxvkDevice->getFormatLimits(formatQuery);
if (!properties) {
properties = m_dxvkDevice->getFormatLimits(Format,
Type, VK_IMAGE_TILING_LINEAR, VK_IMAGE_USAGE_SAMPLED_BIT, Flags);
formatQuery.tiling = VK_IMAGE_TILING_LINEAR;
properties = m_dxvkDevice->getFormatLimits(formatQuery);
}
return properties.has_value();
}

View File

@ -472,13 +472,17 @@ namespace dxvk {
BOOL D3D11CommonTexture::CheckImageSupport(
const DxvkImageCreateInfo* pImageInfo,
VkImageTiling Tiling) const {
VkImageUsageFlags usage = pImageInfo->usage;
DxvkFormatQuery formatQuery = { };
formatQuery.format = pImageInfo->format;
formatQuery.type = pImageInfo->type;
formatQuery.tiling = Tiling;
formatQuery.usage = pImageInfo->usage;
formatQuery.flags = pImageInfo->flags;
if (pImageInfo->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)
usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
formatQuery.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
auto properties = m_device->GetDXVKDevice()->getFormatLimits(
pImageInfo->format, pImageInfo->type, Tiling, usage, pImageInfo->flags);
auto properties = m_device->GetDXVKDevice()->getFormatLimits(formatQuery);
if (!properties)
return FALSE;

View File

@ -397,9 +397,14 @@ namespace dxvk {
BOOL D3D9CommonTexture::CheckImageSupport(
const DxvkImageCreateInfo* pImageInfo,
VkImageTiling Tiling) const {
auto properties = m_device->GetDXVKDevice()->getFormatLimits(
pImageInfo->format, pImageInfo->type, Tiling,
pImageInfo->usage, pImageInfo->flags);
DxvkFormatQuery formatQuery = { };
formatQuery.format = pImageInfo->format;
formatQuery.type = pImageInfo->type;
formatQuery.tiling = Tiling;
formatQuery.usage = pImageInfo->usage;
formatQuery.flags = pImageInfo->flags;
auto properties = m_device->GetDXVKDevice()->getFormatLimits(formatQuery);
if (!properties)
return FALSE;

View File

@ -43,19 +43,15 @@ namespace dxvk {
std::optional<DxvkFormatLimits> DxvkDevice::getFormatLimits(
VkFormat format,
VkImageType type,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkImageCreateFlags flags) const {
const DxvkFormatQuery& query) 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;
info.format = query.format;
info.type = query.type;
info.tiling = query.tiling;
info.usage = query.usage;
info.flags = query.flags;
VkImageFormatProperties2 properties = { VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2 };

View File

@ -186,19 +186,11 @@ namespace dxvk {
/**
* \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
* \param [in] query Format query info
* \returns Format limits if the given image is supported
*/
std::optional<DxvkFormatLimits> getFormatLimits(
VkFormat format,
VkImageType type,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkImageCreateFlags flags) const;
const DxvkFormatQuery& query) const;
/**
* \brief Get device status

View File

@ -34,6 +34,17 @@ namespace dxvk {
VkDeviceSize maxResourceSize;
};
/**
* \brief Format query info
*/
struct DxvkFormatQuery {
VkFormat format;
VkImageType type;
VkImageTiling tiling;
VkImageUsageFlags usage;
VkImageCreateFlags flags;
};
/**
* \brief Planar format info
*/