From c5f7f9f3b08d7d0fed1ee0fce3bd766e8002cfee Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 27 Sep 2018 11:32:23 +0200 Subject: [PATCH] [d3d11] Enable usage flags for meta copy formats This is required in order to make meta copies work between images that do not have the necessary D3D11 bind flags set, and it may speed things up because it allows rendering to the destination image directly rather than requiring a temporary image. --- src/d3d11/d3d11_texture.cpp | 47 ++++++++++++++++++++++++++++++++++++- src/d3d11/d3d11_texture.h | 4 ++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/d3d11/d3d11_texture.cpp b/src/d3d11/d3d11_texture.cpp index 2c70e904..36a8b273 100644 --- a/src/d3d11/d3d11_texture.cpp +++ b/src/d3d11/d3d11_texture.cpp @@ -55,7 +55,7 @@ namespace dxvk { bool isMutable = formatFamily.FormatCount > 1; if (isMutable && (formatProperties->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)) { - imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + imageInfo.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; // Typeless UAV images have relaxed reinterpretation rules if (!isTypeless || !(m_desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS)) { @@ -139,6 +139,11 @@ namespace dxvk { // it is going to be used by the game. if (imageInfo.tiling == VK_IMAGE_TILING_OPTIMAL) imageInfo.layout = OptimizeLayout(imageInfo.usage); + + // For some formats, we need to enable sampled and/or + // render target capabilities if available, but these + // should in no way affect the default image layout + imageInfo.usage |= EnableMetaCopyUsage(imageInfo.format, imageInfo.tiling); // Check if we can actually create the image if (!CheckImageSupport(&imageInfo, imageInfo.tiling)) { @@ -308,6 +313,46 @@ namespace dxvk { } + VkImageUsageFlags D3D11CommonTexture::EnableMetaCopyUsage( + VkFormat Format, + VkImageTiling Tiling) const { + VkFormatFeatureFlags requestedFeatures = 0; + + if (Format == VK_FORMAT_D16_UNORM || Format == VK_FORMAT_D32_SFLOAT) { + requestedFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT + | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; + } + + if (Format == VK_FORMAT_R16_UNORM || Format == VK_FORMAT_R32_SFLOAT) { + requestedFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT + | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; + } + + if (requestedFeatures == 0) + return 0; + + // Enable usage flags for all supported and requested features + VkFormatProperties properties = m_device->GetDXVKDevice()->adapter()->formatProperties(Format); + + requestedFeatures &= Tiling == VK_IMAGE_TILING_OPTIMAL + ? properties.optimalTilingFeatures + : properties.linearTilingFeatures; + + VkImageUsageFlags requestedUsage = 0; + + if (requestedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) + requestedUsage |= VK_IMAGE_USAGE_SAMPLED_BIT; + + if (requestedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + requestedUsage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + if (requestedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) + requestedUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + + return requestedUsage; + } + + D3D11_COMMON_TEXTURE_MAP_MODE D3D11CommonTexture::DetermineMapMode( const DxvkImageCreateInfo* pImageInfo) const { // Don't map an image unless the application requests it diff --git a/src/d3d11/d3d11_texture.h b/src/d3d11/d3d11_texture.h index 2c886cb7..7f8848ee 100644 --- a/src/d3d11/d3d11_texture.h +++ b/src/d3d11/d3d11_texture.h @@ -199,6 +199,10 @@ namespace dxvk { VkFormat Format, VkFormatFeatureFlags Features) const; + VkImageUsageFlags EnableMetaCopyUsage( + VkFormat Format, + VkImageTiling Tiling) const; + D3D11_COMMON_TEXTURE_MAP_MODE DetermineMapMode( const DxvkImageCreateInfo* pImageInfo) const;