From 3405b89494aac3f38ad6607bda07bb03ea5a46df Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 12 Apr 2018 15:36:01 +0200 Subject: [PATCH] [dxgi] Rename and move DXGI format lookup related structures This is part of a major refactoring process regarding DXGI->Vulkan format conversions. Since we don't patch format lookup tables any longer, we can create a global lookup table. --- src/dxgi/dxgi_adapter.cpp | 20 ++++++++-------- src/dxgi/dxgi_adapter.h | 6 ++--- src/dxgi/dxgi_format.cpp | 9 ++++++++ src/dxgi/dxgi_format.h | 47 ++++++++++++++++++++++++++++++++++++++ src/dxgi/dxgi_interfaces.h | 41 ++------------------------------- src/dxgi/dxgi_output.cpp | 2 +- src/dxgi/meson.build | 1 + 7 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 src/dxgi/dxgi_format.cpp create mode 100644 src/dxgi/dxgi_format.h diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 70924348e..bc37b0227 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -173,7 +173,7 @@ namespace dxvk { } - DxgiFormatInfo STDMETHODCALLTYPE DxgiAdapter::LookupFormat( + DXGI_VK_FORMAT_INFO STDMETHODCALLTYPE DxgiAdapter::LookupFormat( DXGI_FORMAT format, DxgiFormatMode mode) { // If the mode is 'Any', probe color formats first @@ -191,7 +191,7 @@ namespace dxvk { } Logger::err(str::format("DxgiAdapter: No format mapping for ", format)); - return DxgiFormatInfo(); + return DXGI_VK_FORMAT_INFO(); } @@ -247,7 +247,7 @@ namespace dxvk { void DxgiAdapter::AddColorFormatTypeless( DXGI_FORMAT srcFormat, VkFormat dstFormat) { - DxgiFormatInfo formatPair; + DXGI_VK_FORMAT_INFO formatPair; formatPair.format = dstFormat; formatPair.aspect = VK_IMAGE_ASPECT_COLOR_BIT; formatPair.swizzle = { @@ -255,7 +255,7 @@ namespace dxvk { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; - formatPair.flags = DxgiFormatFlag::Typeless; + formatPair.flags = DXGI_VK_FORMAT_TYPELESS; m_colorFormats.insert(std::make_pair(srcFormat, formatPair)); } @@ -264,11 +264,11 @@ namespace dxvk { DXGI_FORMAT srcFormat, VkFormat dstFormat, VkComponentMapping swizzle) { - DxgiFormatInfo formatPair; + DXGI_VK_FORMAT_INFO formatPair; formatPair.format = dstFormat; formatPair.aspect = VK_IMAGE_ASPECT_COLOR_BIT; formatPair.swizzle = swizzle; - formatPair.flags = DxgiFormatFlags(); + formatPair.flags = 0; m_colorFormats.insert(std::make_pair(srcFormat, formatPair)); } @@ -276,7 +276,7 @@ namespace dxvk { void DxgiAdapter::AddDepthFormatTypeless( DXGI_FORMAT srcFormat, VkFormat dstFormat) { - DxgiFormatInfo formatPair; + DXGI_VK_FORMAT_INFO formatPair; formatPair.format = dstFormat; formatPair.aspect = 0; formatPair.swizzle = { @@ -284,7 +284,7 @@ namespace dxvk { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; - formatPair.flags = DxgiFormatFlag::Typeless; + formatPair.flags = DXGI_VK_FORMAT_TYPELESS; m_depthFormats.insert(std::make_pair(srcFormat, formatPair)); } @@ -293,7 +293,7 @@ namespace dxvk { DXGI_FORMAT srcFormat, VkFormat dstFormat, VkImageAspectFlags srvAspect) { - DxgiFormatInfo formatPair; + DXGI_VK_FORMAT_INFO formatPair; formatPair.format = dstFormat; formatPair.aspect = srvAspect; formatPair.swizzle = { @@ -301,7 +301,7 @@ namespace dxvk { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; - formatPair.flags = DxgiFormatFlags(); + formatPair.flags = 0; m_depthFormats.insert(std::make_pair(srcFormat, formatPair)); } diff --git a/src/dxgi/dxgi_adapter.h b/src/dxgi/dxgi_adapter.h index 1c7d9f1bd..0a399736b 100644 --- a/src/dxgi/dxgi_adapter.h +++ b/src/dxgi/dxgi_adapter.h @@ -54,7 +54,7 @@ namespace dxvk { const VkPhysicalDeviceFeatures* pFeatures, IDXGIVkDevice** ppDevice) final; - DxgiFormatInfo STDMETHODCALLTYPE LookupFormat( + DXGI_VK_FORMAT_INFO STDMETHODCALLTYPE LookupFormat( DXGI_FORMAT format, DxgiFormatMode mode) final; @@ -72,8 +72,8 @@ namespace dxvk { private: - using FormatMap = std::unordered_map; - using OutputMap = std::unordered_map; + using FormatMap = std::unordered_map; + using OutputMap = std::unordered_map; Com m_factory; Rc m_adapter; diff --git a/src/dxgi/dxgi_format.cpp b/src/dxgi/dxgi_format.cpp new file mode 100644 index 000000000..417a909a2 --- /dev/null +++ b/src/dxgi/dxgi_format.cpp @@ -0,0 +1,9 @@ +#include "dxgi_format.h" + +#include + +namespace dxvk { + + + +}; \ No newline at end of file diff --git a/src/dxgi/dxgi_format.h b/src/dxgi/dxgi_format.h new file mode 100644 index 000000000..e410ed3ea --- /dev/null +++ b/src/dxgi/dxgi_format.h @@ -0,0 +1,47 @@ +#pragma once + +#include "dxgi_include.h" + +#include "../dxvk/dxvk_include.h" + +namespace dxvk { + + /** + * \brief Format information + */ + enum DXGI_VK_FORMAT_FLAGS : uint32_t { + DXGI_VK_FORMAT_TYPELESS = 0, + }; + + /** + * \brief Format info + * + * Stores a Vulkan image format for a given + * DXGI format and some additional information + * on how resources with the particular format + * are supposed to be used. + */ + struct DXGI_VK_FORMAT_INFO { + VkFormat format = VK_FORMAT_UNDEFINED; + VkImageAspectFlags aspect = 0; + VkComponentMapping swizzle = { + VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, + VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; + UINT flags = 0; + }; + + /** + * \brief Format lookup mode + * + * When looking up an image format, additional information + * might be needed on how the image is going to be used. + * This is used to properly map typeless formats and color + * formats to depth formats if they are used on depth images. + */ + enum class DxgiFormatMode : uint32_t { + Any = 0, + Color = 1, + Depth = 2, + }; + +}; \ No newline at end of file diff --git a/src/dxgi/dxgi_interfaces.h b/src/dxgi/dxgi_interfaces.h index 3dff8c2aa..4a09ef5f2 100644 --- a/src/dxgi/dxgi_interfaces.h +++ b/src/dxgi/dxgi_interfaces.h @@ -2,6 +2,7 @@ #include "../dxvk/dxvk_include.h" +#include "dxgi_format.h" #include "dxgi_include.h" namespace dxvk { @@ -10,44 +11,6 @@ namespace dxvk { class DxvkBuffer; class DxvkDevice; class DxvkImage; - - /** - * \brief Format information - */ - enum class DxgiFormatFlag { - Typeless = 0, - }; - - using DxgiFormatFlags = Flags; - - /** - * \brief Format info - * - * Stores a Vulkan image format for a given - * DXGI format and some additional information - * on how resources with the particular format - * are supposed to be used. - */ - struct DxgiFormatInfo { - VkFormat format; - VkImageAspectFlags aspect; - VkComponentMapping swizzle; - DxgiFormatFlags flags; - }; - - /** - * \brief Format lookup mode - * - * When looking up an image format, additional information - * might be needed on how the image is going to be used. - * This is used to properly map typeless formats and color - * formats to depth formats if they are used on depth images. - */ - enum class DxgiFormatMode : uint32_t { - Any = 0, - Color = 1, - Depth = 2, - }; } @@ -105,7 +68,7 @@ IDXGIVkAdapter : public IDXGIAdapter1 { * \param [in] mode Format lookup mode * \returns Vulkan format pair */ - virtual dxvk::DxgiFormatInfo STDMETHODCALLTYPE LookupFormat( + virtual dxvk::DXGI_VK_FORMAT_INFO STDMETHODCALLTYPE LookupFormat( DXGI_FORMAT format, dxvk::DxgiFormatMode mode) = 0; }; diff --git a/src/dxgi/dxgi_output.cpp b/src/dxgi/dxgi_output.cpp index 7ac38b891..d3ab6d23c 100644 --- a/src/dxgi/dxgi_output.cpp +++ b/src/dxgi/dxgi_output.cpp @@ -325,7 +325,7 @@ namespace dxvk { uint32_t DxgiOutput::GetFormatBpp(DXGI_FORMAT Format) const { - DxgiFormatInfo formatInfo = m_adapter->LookupFormat(Format, DxgiFormatMode::Any); + DXGI_VK_FORMAT_INFO formatInfo = m_adapter->LookupFormat(Format, DxgiFormatMode::Any); return imageFormatInfo(formatInfo.format)->elementSize * 8; } diff --git a/src/dxgi/meson.build b/src/dxgi/meson.build index 2d6a22624..cc76baebd 100644 --- a/src/dxgi/meson.build +++ b/src/dxgi/meson.build @@ -8,6 +8,7 @@ dxgi_src = [ 'dxgi_device.cpp', 'dxgi_enums.cpp', 'dxgi_factory.cpp', + 'dxgi_format.cpp', 'dxgi_main.cpp', 'dxgi_output.cpp', 'dxgi_presenter.cpp',