diff --git a/src/d3d11/d3d11_texture.cpp b/src/d3d11/d3d11_texture.cpp index 8b8e1c3c..7e7719cc 100644 --- a/src/d3d11/d3d11_texture.cpp +++ b/src/d3d11/d3d11_texture.cpp @@ -145,6 +145,7 @@ namespace dxvk { // render target capabilities if available, but these // should in no way affect the default image layout imageInfo.usage |= EnableMetaCopyUsage(imageInfo.format, imageInfo.tiling); + imageInfo.usage |= EnableMetaPackUsage(imageInfo.format, m_desc.CPUAccessFlags); // Check if we can actually create the image if (!CheckImageSupport(&imageInfo, imageInfo.tiling)) { @@ -353,6 +354,23 @@ namespace dxvk { return requestedUsage; } + + VkImageUsageFlags D3D11CommonTexture::EnableMetaPackUsage( + VkFormat Format, + UINT CpuAccess) const { + if ((CpuAccess & D3D11_CPU_ACCESS_READ) == 0) + return 0; + + const auto dsMask = VK_IMAGE_ASPECT_DEPTH_BIT + | VK_IMAGE_ASPECT_STENCIL_BIT; + + auto formatInfo = imageFormatInfo(Format); + + return formatInfo->aspectMask == dsMask + ? VK_IMAGE_USAGE_SAMPLED_BIT + : 0; + } + D3D11_COMMON_TEXTURE_MAP_MODE D3D11CommonTexture::DetermineMapMode( const DxvkImageCreateInfo* pImageInfo) const { @@ -369,6 +387,11 @@ namespace dxvk { if (m_desc.Usage == D3D11_USAGE_DYNAMIC) return D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER; + // Depth-stencil formats in D3D11 can be mapped and follow special + // packing rules, so we need to copy that data into a buffer first + if (GetPackedDepthStencilFormat(m_desc.Format)) + return D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER; + // Images that can be read by the host should be mapped directly in // order to avoid expensive synchronization with the GPU. This does // however require linear tiling, which may not be supported for all diff --git a/src/d3d11/d3d11_texture.h b/src/d3d11/d3d11_texture.h index 7f8848ee..b400dbee 100644 --- a/src/d3d11/d3d11_texture.h +++ b/src/d3d11/d3d11_texture.h @@ -203,6 +203,10 @@ namespace dxvk { VkFormat Format, VkImageTiling Tiling) const; + VkImageUsageFlags EnableMetaPackUsage( + VkFormat Format, + UINT CpuAccess) const; + D3D11_COMMON_TEXTURE_MAP_MODE DetermineMapMode( const DxvkImageCreateInfo* pImageInfo) const;