From 6c2f16fce8d84118a1f21bf7525e490a8a4ee72e Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 26 Mar 2019 17:17:32 +0100 Subject: [PATCH] [dxgi] Add methods to retrieve original format mappings --- src/dxgi/dxgi_format.cpp | 64 +++++++++++++++++++++++++++------------- src/dxgi/dxgi_format.h | 21 +++++++++++++ 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/dxgi/dxgi_format.cpp b/src/dxgi/dxgi_format.cpp index 6c956e44..41ff3875 100644 --- a/src/dxgi/dxgi_format.cpp +++ b/src/dxgi/dxgi_format.cpp @@ -853,26 +853,16 @@ namespace dxvk { DXGI_VK_FORMAT_INFO DXGIVkFormatTable::GetFormatInfo( DXGI_FORMAT Format, DXGI_VK_FORMAT_MODE Mode) const { - const DXGI_VK_FORMAT_MAPPING* mapping = GetFormatMapping(Format); - - switch (Mode) { - case DXGI_VK_FORMAT_MODE_ANY: - return mapping->FormatColor != VK_FORMAT_UNDEFINED - ? DXGI_VK_FORMAT_INFO { mapping->FormatColor, mapping->AspectColor, mapping->Swizzle } - : DXGI_VK_FORMAT_INFO { mapping->FormatDepth, mapping->AspectDepth }; - - case DXGI_VK_FORMAT_MODE_COLOR: - return { mapping->FormatColor, mapping->AspectColor, mapping->Swizzle }; - - case DXGI_VK_FORMAT_MODE_DEPTH: - return { mapping->FormatDepth, mapping->AspectDepth }; - - case DXGI_VK_FORMAT_MODE_RAW: - return { mapping->FormatRaw, mapping->AspectColor }; - } - - Logger::err("DXGI: GetFormatInfo: Internal error"); - return DXGI_VK_FORMAT_INFO(); + return GetFormatInfoFromMapping( + GetFormatMapping(Format), Mode); + } + + + DXGI_VK_FORMAT_INFO DXGIVkFormatTable::GetPackedFormatInfo( + DXGI_FORMAT Format, + DXGI_VK_FORMAT_MODE Mode) const { + return GetFormatInfoFromMapping( + GetPackedFormatMapping(Format), Mode); } @@ -890,6 +880,30 @@ namespace dxvk { } + DXGI_VK_FORMAT_INFO DXGIVkFormatTable::GetFormatInfoFromMapping( + const DXGI_VK_FORMAT_MAPPING* pMapping, + DXGI_VK_FORMAT_MODE Mode) const { + switch (Mode) { + case DXGI_VK_FORMAT_MODE_ANY: + return pMapping->FormatColor != VK_FORMAT_UNDEFINED + ? DXGI_VK_FORMAT_INFO { pMapping->FormatColor, pMapping->AspectColor, pMapping->Swizzle } + : DXGI_VK_FORMAT_INFO { pMapping->FormatDepth, pMapping->AspectDepth }; + + case DXGI_VK_FORMAT_MODE_COLOR: + return { pMapping->FormatColor, pMapping->AspectColor, pMapping->Swizzle }; + + case DXGI_VK_FORMAT_MODE_DEPTH: + return { pMapping->FormatDepth, pMapping->AspectDepth }; + + case DXGI_VK_FORMAT_MODE_RAW: + return { pMapping->FormatRaw, pMapping->AspectColor }; + } + + Logger::err("DXGI: GetFormatInfoFromMapping: Internal error"); + return DXGI_VK_FORMAT_INFO(); + } + + const DXGI_VK_FORMAT_MAPPING* DXGIVkFormatTable::GetFormatMapping( DXGI_FORMAT Format) const { const size_t formatId = size_t(Format); @@ -900,6 +914,16 @@ namespace dxvk { } + const DXGI_VK_FORMAT_MAPPING* DXGIVkFormatTable::GetPackedFormatMapping( + DXGI_FORMAT Format) const { + const size_t formatId = size_t(Format); + + return formatId < g_dxgiFormats.size() + ? &g_dxgiFormats[formatId] + : &g_dxgiFormats[0]; + } + + bool DXGIVkFormatTable::CheckImageFormatSupport( const Rc& Adapter, VkFormat Format, diff --git a/src/dxgi/dxgi_format.h b/src/dxgi/dxgi_format.h index 1d48944b..c05a4de6 100644 --- a/src/dxgi/dxgi_format.h +++ b/src/dxgi/dxgi_format.h @@ -114,6 +114,20 @@ namespace dxvk { DXGI_FORMAT Format, DXGI_VK_FORMAT_MODE Mode) const; + /** + * \brief Retrieves original info for a given DXGI format + * + * Doesn't perform any format adjustment, so this + * can be used to determine the packed data format + * of a DXGI format for things like data uploads. + * \param [in] Format The DXGI format to look up + * \param [in] Mode the format lookup mode + * \returns Format info + */ + DXGI_VK_FORMAT_INFO GetPackedFormatInfo( + DXGI_FORMAT Format, + DXGI_VK_FORMAT_MODE Mode) const; + /** * \brief Retrieves a format family * @@ -129,10 +143,17 @@ namespace dxvk { std::array m_dxgiFormats; std::array m_dxgiFamilies; + + DXGI_VK_FORMAT_INFO GetFormatInfoFromMapping( + const DXGI_VK_FORMAT_MAPPING* pMapping, + DXGI_VK_FORMAT_MODE Mode) const; const DXGI_VK_FORMAT_MAPPING* GetFormatMapping( DXGI_FORMAT Format) const; + const DXGI_VK_FORMAT_MAPPING* GetPackedFormatMapping( + DXGI_FORMAT Format) const; + bool CheckImageFormatSupport( const Rc& Adapter, VkFormat Format,