From 9e15831a2df7fb1acded1355a4501e1b1089908c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 22 Jun 2021 04:09:07 +0200 Subject: [PATCH] [d3d11] Store packed format info in D3D11CommonTexture --- src/d3d11/d3d11_texture.cpp | 13 ++++++++----- src/d3d11/d3d11_texture.h | 13 +++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/d3d11/d3d11_texture.cpp b/src/d3d11/d3d11_texture.cpp index 563c10c9..bef3640c 100644 --- a/src/d3d11/d3d11_texture.cpp +++ b/src/d3d11/d3d11_texture.cpp @@ -14,6 +14,8 @@ namespace dxvk { DXGI_VK_FORMAT_MODE formatMode = GetFormatMode(); DXGI_VK_FORMAT_INFO formatInfo = m_device->LookupFormat(m_desc.Format, formatMode); DXGI_VK_FORMAT_FAMILY formatFamily = m_device->LookupFamily(m_desc.Format, formatMode); + DXGI_VK_FORMAT_INFO formatPacked = m_device->LookupPackedFormat(m_desc.Format, formatMode); + m_packedFormat = formatPacked.Format; DxvkImageCreateInfo imageInfo; imageInfo.type = GetImageTypeFromResourceDim(Dimension); @@ -246,7 +248,6 @@ namespace dxvk { case D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER: case D3D11_COMMON_TEXTURE_MAP_MODE_STAGING: { - auto formatInfo = imageFormatInfo(m_device->LookupPackedFormat(m_desc.Format, GetFormatMode()).Format); auto aspects = Aspect; // The exact aspect mask only matters for multi-plane formats, @@ -257,18 +258,20 @@ namespace dxvk { VkExtent3D mipExtent = MipLevelExtent(subresource.mipLevel); while (aspects) { + auto packedFormatInfo = imageFormatInfo(m_packedFormat); + auto aspect = vk::getNextAspect(aspects); auto extent = mipExtent; - auto elementSize = formatInfo->elementSize; + auto elementSize = packedFormatInfo->elementSize; - if (formatInfo->flags.test(DxvkFormatFlag::MultiPlane)) { - auto plane = &formatInfo->planes[vk::getPlaneIndex(aspect)]; + if (packedFormatInfo->flags.test(DxvkFormatFlag::MultiPlane)) { + auto plane = &packedFormatInfo->planes[vk::getPlaneIndex(aspect)]; extent.width /= plane->blockSize.width; extent.height /= plane->blockSize.height; elementSize = plane->elementSize; } - auto blockCount = util::computeBlockCount(extent, formatInfo->blockSize); + auto blockCount = util::computeBlockCount(extent, packedFormatInfo->blockSize); if (!layout.RowPitch) { layout.RowPitch = elementSize * blockCount.width; diff --git a/src/d3d11/d3d11_texture.h b/src/d3d11/d3d11_texture.h index fda60350..395c8c40 100644 --- a/src/d3d11/d3d11_texture.h +++ b/src/d3d11/d3d11_texture.h @@ -199,6 +199,18 @@ namespace dxvk { ? m_buffers[Subresource].slice : DxvkBufferSliceHandle(); } + + /** + * \brief Returns underlying packed Vulkan format + * + * This works even for staging resources that have no image. + * Note that for depth-stencil resources, the returned format + * may be different from the image format on some systems. + * \returns Packed Vulkan format + */ + VkFormat GetPackedFormat() const { + return m_packedFormat; + } /** * \brief Checks whether we can update the mapped buffer early @@ -296,6 +308,7 @@ namespace dxvk { D3D11_COMMON_TEXTURE_DESC m_desc; D3D11_COMMON_TEXTURE_MAP_MODE m_mapMode; DXGI_USAGE m_dxgiUsage; + VkFormat m_packedFormat; Rc m_image; std::vector m_buffers;