From cbf4772973da6191f3313ec8bf2b6fed720896d3 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 3 Jul 2018 12:44:56 +0200 Subject: [PATCH] [d3d11] Pass image format family to the backend --- src/d3d11/d3d11_device.cpp | 7 +++++ src/d3d11/d3d11_device.h | 4 +++ src/d3d11/d3d11_texture.cpp | 58 ++++++++++++++++++++++--------------- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 434a9834..dbf39517 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1719,6 +1719,13 @@ namespace dxvk { } + DXGI_VK_FORMAT_FAMILY D3D11Device::LookupFamily( + DXGI_FORMAT Format, + DXGI_VK_FORMAT_MODE Mode) const { + return m_dxgiAdapter->LookupFormatFamily(Format, Mode); + } + + DxvkBufferSlice D3D11Device::AllocateCounterSlice() { std::lock_guard lock(m_counterMutex); diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index 9128a876..12e302ce 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -327,6 +327,10 @@ namespace dxvk { DXGI_FORMAT Format, DXGI_VK_FORMAT_MODE Mode) const; + DXGI_VK_FORMAT_FAMILY LookupFamily( + DXGI_FORMAT Format, + DXGI_VK_FORMAT_MODE Mode) const; + bool TestOption(D3D11Option Option) const { return m_d3d11Options.test(Option); } diff --git a/src/d3d11/d3d11_texture.cpp b/src/d3d11/d3d11_texture.cpp index 0c5cc50d..1e649b53 100644 --- a/src/d3d11/d3d11_texture.cpp +++ b/src/d3d11/d3d11_texture.cpp @@ -8,34 +8,44 @@ namespace dxvk { const D3D11_COMMON_TEXTURE_DESC* pDesc, D3D11_RESOURCE_DIMENSION Dimension) : m_device(pDevice), m_desc(*pDesc) { - DXGI_VK_FORMAT_MODE formatMode = GetFormatMode(); - DXGI_VK_FORMAT_INFO formatInfo = m_device->LookupFormat(m_desc.Format, formatMode); - + 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); + DxvkImageCreateInfo imageInfo; - imageInfo.type = GetImageTypeFromResourceDim(Dimension); - imageInfo.format = formatInfo.Format; - imageInfo.flags = 0; - imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT; - imageInfo.extent.width = m_desc.Width; - imageInfo.extent.height = m_desc.Height; - imageInfo.extent.depth = m_desc.Depth; - imageInfo.numLayers = m_desc.ArraySize; - imageInfo.mipLevels = m_desc.MipLevels; - imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT - | VK_IMAGE_USAGE_TRANSFER_DST_BIT; - imageInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT; - imageInfo.access = VK_ACCESS_TRANSFER_READ_BIT - | VK_ACCESS_TRANSFER_WRITE_BIT; - imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; - imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL; + imageInfo.type = GetImageTypeFromResourceDim(Dimension); + imageInfo.format = formatInfo.Format; + imageInfo.flags = 0; + imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT; + imageInfo.extent.width = m_desc.Width; + imageInfo.extent.height = m_desc.Height; + imageInfo.extent.depth = m_desc.Depth; + imageInfo.numLayers = m_desc.ArraySize; + imageInfo.mipLevels = m_desc.MipLevels; + imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT + | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + imageInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT; + imageInfo.access = VK_ACCESS_TRANSFER_READ_BIT + | VK_ACCESS_TRANSFER_WRITE_BIT; + imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; + imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL; + imageInfo.viewFormatCount = formatFamily.FormatCount; + imageInfo.viewFormats = formatFamily.Formats; DecodeSampleCount(m_desc.SampleDesc.Count, &imageInfo.sampleCount); - // Typeless formats need the MUTABLE_FORMAT_BIT to be set - // since they can be reinterpreted. We'll always set this - // for UAV images for integer clear operations to work. - bool mutableFormat = (formatInfo.Aspect == 0) - || (m_desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS); + // The image must be marked as mutable if it can be + // reinterpreted by a view with a different format + bool mutableFormat = formatFamily.FormatCount > 1; + + // For UAVs, the format restrictions are more relaxed. + // FIXME for typed formats, we should just add the + // corresponding integer format to the format family + if (m_desc.BindFlags & D3D11_BIND_UNORDERED_ACCESS) { + imageInfo.viewFormatCount = 0; + imageInfo.viewFormats = nullptr; + mutableFormat = true; + } // Depth-stencil formats are not compatible to each other. VkImageAspectFlags formatAspect = imageFormatInfo(formatInfo.Format)->aspectMask;