diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 13e508c1c..5974f08e1 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -147,6 +147,16 @@ namespace dxvk { } + void DxgiAdapter::AddFormat( + DXGI_FORMAT srcFormat, + VkFormat dstFormat) { + DxgiFormatPair formatPair; + formatPair.wanted = dstFormat; + formatPair.actual = dstFormat; + m_formats.insert(std::make_pair(srcFormat, formatPair)); + } + + void DxgiAdapter::AddFormat( DXGI_FORMAT srcFormat, VkFormat dstFormat, @@ -177,93 +187,147 @@ namespace dxvk { void DxgiAdapter::SetupFormatTable() { - AddFormat( - DXGI_FORMAT_R8G8B8A8_TYPELESS, - VK_FORMAT_R8G8B8A8_UINT, {}, 0); + AddFormat(DXGI_FORMAT_UNKNOWN, VK_FORMAT_UNDEFINED); + + AddFormat(DXGI_FORMAT_R32G32B32A32_TYPELESS, VK_FORMAT_R32G32B32A32_UINT); + AddFormat(DXGI_FORMAT_R32G32B32A32_FLOAT, VK_FORMAT_R32G32B32A32_SFLOAT); + AddFormat(DXGI_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT); + AddFormat(DXGI_FORMAT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT); + + AddFormat(DXGI_FORMAT_R32G32B32_TYPELESS, VK_FORMAT_R32G32B32_UINT); + AddFormat(DXGI_FORMAT_R32G32B32_FLOAT, VK_FORMAT_R32G32B32_SFLOAT); + AddFormat(DXGI_FORMAT_R32G32B32_UINT, VK_FORMAT_R32G32B32_UINT); + AddFormat(DXGI_FORMAT_R32G32B32_SINT, VK_FORMAT_R32G32B32_SINT); + + AddFormat(DXGI_FORMAT_R16G16B16A16_TYPELESS, VK_FORMAT_R16G16B16A16_UINT); + AddFormat(DXGI_FORMAT_R16G16B16A16_FLOAT, VK_FORMAT_R16G16B16A16_SFLOAT); + AddFormat(DXGI_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_R16G16B16A16_UNORM); + AddFormat(DXGI_FORMAT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT); + AddFormat(DXGI_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_SNORM); + AddFormat(DXGI_FORMAT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT); + + AddFormat(DXGI_FORMAT_R32G32_TYPELESS, VK_FORMAT_R32G32_UINT); + AddFormat(DXGI_FORMAT_R32G32_FLOAT, VK_FORMAT_R32G32_SFLOAT); + AddFormat(DXGI_FORMAT_R32G32_UINT, VK_FORMAT_R32G32_UINT); + AddFormat(DXGI_FORMAT_R32G32_SINT, VK_FORMAT_R32G32_SINT); + + AddFormat(DXGI_FORMAT_D32_FLOAT_S8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT); +// AddFormat(DXGI_FORMAT_R32G8X24_TYPELESS, VK_FORMAT_UNDEFINED); +// AddFormat(DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, VK_FORMAT_UNDEFINED); +// AddFormat(DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, VK_FORMAT_UNDEFINED); + + AddFormat(DXGI_FORMAT_R10G10B10A2_TYPELESS, VK_FORMAT_A2R10G10B10_UINT_PACK32); + AddFormat(DXGI_FORMAT_R10G10B10A2_UINT, VK_FORMAT_A2R10G10B10_UINT_PACK32); + AddFormat(DXGI_FORMAT_R10G10B10A2_UNORM, VK_FORMAT_A2R10G10B10_UNORM_PACK32); + + AddFormat(DXGI_FORMAT_R11G11B10_FLOAT, VK_FORMAT_B10G11R11_UFLOAT_PACK32); + + AddFormat(DXGI_FORMAT_R8G8B8A8_TYPELESS, VK_FORMAT_R8G8B8A8_UINT); + AddFormat(DXGI_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM); + AddFormat(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, VK_FORMAT_R8G8B8A8_SRGB); + AddFormat(DXGI_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT); + AddFormat(DXGI_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_SNORM); + AddFormat(DXGI_FORMAT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT); + + AddFormat(DXGI_FORMAT_R16G16_TYPELESS, VK_FORMAT_R16G16_UINT); + AddFormat(DXGI_FORMAT_R16G16_FLOAT, VK_FORMAT_R16G16_SFLOAT); + AddFormat(DXGI_FORMAT_R16G16_UNORM, VK_FORMAT_R16G16_UNORM); + AddFormat(DXGI_FORMAT_R16G16_UINT, VK_FORMAT_R16G16_UINT); + AddFormat(DXGI_FORMAT_R16G16_SNORM, VK_FORMAT_R16G16_SNORM); + AddFormat(DXGI_FORMAT_R16G16_SINT, VK_FORMAT_R16G16_SINT); + + AddFormat(DXGI_FORMAT_R32_TYPELESS, VK_FORMAT_R32_UINT); + AddFormat(DXGI_FORMAT_R32_FLOAT, VK_FORMAT_R32_SFLOAT); + AddFormat(DXGI_FORMAT_R32_UINT, VK_FORMAT_R32_UINT); + AddFormat(DXGI_FORMAT_R32_SINT, VK_FORMAT_R32_SINT); + + AddFormat(DXGI_FORMAT_R8G8_TYPELESS, VK_FORMAT_R8G8_UINT); + AddFormat(DXGI_FORMAT_R8G8_UNORM, VK_FORMAT_R8G8_UNORM); + AddFormat(DXGI_FORMAT_R8G8_UINT, VK_FORMAT_R8G8_UINT); + AddFormat(DXGI_FORMAT_R8G8_SNORM, VK_FORMAT_R8G8_SNORM); + AddFormat(DXGI_FORMAT_R8G8_SINT, VK_FORMAT_R8G8_SINT); + + AddFormat(DXGI_FORMAT_R16_TYPELESS, VK_FORMAT_R16_UINT); + AddFormat(DXGI_FORMAT_R16_FLOAT, VK_FORMAT_R16_SFLOAT); + AddFormat(DXGI_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM); + AddFormat(DXGI_FORMAT_R16_UINT, VK_FORMAT_R16_UINT); + AddFormat(DXGI_FORMAT_R16_SNORM, VK_FORMAT_R16_SNORM); + AddFormat(DXGI_FORMAT_R16_SINT, VK_FORMAT_R16_SINT); + + AddFormat(DXGI_FORMAT_R8_TYPELESS, VK_FORMAT_R8_UINT); + AddFormat(DXGI_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM); + AddFormat(DXGI_FORMAT_R8_UINT, VK_FORMAT_R8_UINT); + AddFormat(DXGI_FORMAT_R8_SNORM, VK_FORMAT_R8_SNORM); + AddFormat(DXGI_FORMAT_R8_SINT, VK_FORMAT_R8_SINT); +// AddFormat(DXGI_FORMAT_A8_UNORM, VK_FORMAT_UNDEFINED); + +// AddFormat(DXGI_FORMAT_R1_UNORM, VK_FORMAT_UNDEFINED); + + AddFormat(DXGI_FORMAT_R9G9B9E5_SHAREDEXP, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32); +// AddFormat(DXGI_FORMAT_R8G8_B8G8_UNORM, VK_FORMAT_UNDEFINED); + AddFormat(DXGI_FORMAT_G8R8_G8B8_UNORM, VK_FORMAT_UNDEFINED); + + AddFormat(DXGI_FORMAT_BC1_TYPELESS, VK_FORMAT_BC1_RGBA_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC1_UNORM, VK_FORMAT_BC1_RGBA_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC1_UNORM_SRGB, VK_FORMAT_BC1_RGBA_SRGB_BLOCK); + + AddFormat(DXGI_FORMAT_BC2_TYPELESS, VK_FORMAT_BC2_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC2_UNORM, VK_FORMAT_BC2_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC2_UNORM_SRGB, VK_FORMAT_BC2_SRGB_BLOCK); + + AddFormat(DXGI_FORMAT_BC3_TYPELESS, VK_FORMAT_BC3_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC3_UNORM, VK_FORMAT_BC3_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC3_UNORM_SRGB, VK_FORMAT_BC3_SRGB_BLOCK); + + AddFormat(DXGI_FORMAT_BC4_TYPELESS, VK_FORMAT_BC4_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC4_UNORM, VK_FORMAT_BC4_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC4_SNORM, VK_FORMAT_BC4_SNORM_BLOCK); + + AddFormat(DXGI_FORMAT_BC5_TYPELESS, VK_FORMAT_BC5_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC5_UNORM, VK_FORMAT_BC5_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC5_SNORM, VK_FORMAT_BC5_SNORM_BLOCK); + + AddFormat(DXGI_FORMAT_B5G6R5_UNORM, VK_FORMAT_B5G6R5_UNORM_PACK16); + AddFormat(DXGI_FORMAT_B5G5R5A1_UNORM, VK_FORMAT_B5G5R5A1_UNORM_PACK16); + + AddFormat(DXGI_FORMAT_B8G8R8A8_TYPELESS, VK_FORMAT_B8G8R8A8_UNORM); + AddFormat(DXGI_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM); +// AddFormat(DXGI_FORMAT_B8G8R8X8_UNORM, VK_FORMAT_B8G8R8A8_UNORM); + AddFormat(DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, VK_FORMAT_B8G8R8A8_SRGB); +// AddFormat(DXGI_FORMAT_B8G8R8X8_TYPELESS, VK_FORMAT_B8G8R8A8_UNORM); +// AddFormat(DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, VK_FORMAT_B8G8R8A8_SRGB); + +// AddFormat(DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, VK_FORMAT_UNDEFINED); + + AddFormat(DXGI_FORMAT_BC6H_TYPELESS, VK_FORMAT_BC6H_UFLOAT_BLOCK); + AddFormat(DXGI_FORMAT_BC6H_UF16, VK_FORMAT_BC6H_UFLOAT_BLOCK); + AddFormat(DXGI_FORMAT_BC6H_SF16, VK_FORMAT_BC6H_SFLOAT_BLOCK); + + AddFormat(DXGI_FORMAT_BC7_TYPELESS, VK_FORMAT_BC7_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC7_UNORM, VK_FORMAT_BC7_UNORM_BLOCK); + AddFormat(DXGI_FORMAT_BC7_UNORM_SRGB, VK_FORMAT_BC7_SRGB_BLOCK); AddFormat( - DXGI_FORMAT_R8G8B8A8_UINT, - VK_FORMAT_R8G8B8A8_UINT, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); - - AddFormat( - DXGI_FORMAT_R8G8B8A8_UNORM, - VK_FORMAT_R8G8B8A8_UNORM, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT); - - AddFormat( - DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, - VK_FORMAT_R8G8B8A8_SRGB, {}, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT); - - AddFormat( - DXGI_FORMAT_R8G8B8A8_SINT, - VK_FORMAT_R8G8B8A8_SINT, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); - - AddFormat( - DXGI_FORMAT_R8G8B8A8_SNORM, - VK_FORMAT_R8G8B8A8_SNORM, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT); - - AddFormat( - DXGI_FORMAT_R32G32B32_FLOAT, - VK_FORMAT_R32G32B32_SFLOAT, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT); - - AddFormat( - DXGI_FORMAT_R32G32B32A32_FLOAT, - VK_FORMAT_R32G32B32A32_SFLOAT, {}, - VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT | - VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT | - VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | - VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT); + DXGI_FORMAT_D32_FLOAT, + VK_FORMAT_D32_SFLOAT, { + VK_FORMAT_D32_SFLOAT_S8_UINT, + }, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); AddFormat( DXGI_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, { VK_FORMAT_D32_SFLOAT_S8_UINT, }, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); - AddFormat( - DXGI_FORMAT_D16_UNORM, - VK_FORMAT_D16_UNORM, {}, - VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | - VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); + AddFormat(DXGI_FORMAT_D16_UNORM, VK_FORMAT_D16_UNORM); + +// AddFormat(DXGI_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_UNDEFINED); +// AddFormat(DXGI_FORMAT_R24_UNORM_X8_TYPELESS, VK_FORMAT_UNDEFINED); +// AddFormat(DXGI_FORMAT_X24_TYPELESS_G8_UINT, VK_FORMAT_UNDEFINED); // TODO finish me } diff --git a/src/dxgi/dxgi_adapter.h b/src/dxgi/dxgi_adapter.h index ea69cf968..be61708c4 100644 --- a/src/dxgi/dxgi_adapter.h +++ b/src/dxgi/dxgi_adapter.h @@ -58,6 +58,10 @@ namespace dxvk { std::unordered_map m_formats; + void AddFormat( + DXGI_FORMAT srcFormat, + VkFormat dstFormat); + void AddFormat( DXGI_FORMAT srcFormat, VkFormat dstFormat, diff --git a/src/dxgi/dxgi_presenter.cpp b/src/dxgi/dxgi_presenter.cpp index ba7295b43..17f438cb0 100644 --- a/src/dxgi/dxgi_presenter.cpp +++ b/src/dxgi/dxgi_presenter.cpp @@ -22,7 +22,7 @@ namespace dxvk { // Create swap chain for the surface DxvkSwapchainProperties swapchainProperties; swapchainProperties.preferredSurfaceFormat = this->pickFormat(bufferFormat); - swapchainProperties.preferredPresentMode = VK_PRESENT_MODE_FIFO_KHR; + swapchainProperties.preferredPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; swapchainProperties.preferredBufferSize.width = bufferWidth; swapchainProperties.preferredBufferSize.height = bufferHeight; @@ -206,7 +206,7 @@ namespace dxvk { DXGI_FORMAT bufferFormat) { DxvkSwapchainProperties swapchainProperties; swapchainProperties.preferredSurfaceFormat = this->pickFormat(bufferFormat); - swapchainProperties.preferredPresentMode = VK_PRESENT_MODE_FIFO_KHR; + swapchainProperties.preferredPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; swapchainProperties.preferredBufferSize.width = bufferWidth; swapchainProperties.preferredBufferSize.height = bufferHeight; diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index d9bf4a82d..f8745c8df 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -56,24 +56,15 @@ namespace dxvk { } - std::optional DxvkAdapter::imageFormatProperties( - VkFormat format, - VkImageType type, - VkImageTiling tiling, - VkImageUsageFlags usage, - VkImageCreateFlags flags) const { - VkImageFormatProperties formatProperties; - - VkResult status = m_vki->vkGetPhysicalDeviceImageFormatProperties( - m_handle, format, type, tiling, usage, flags, &formatProperties); - - switch (status) { - case VK_SUCCESS: return formatProperties; - case VK_ERROR_FORMAT_NOT_SUPPORTED: return { }; - - default: - throw DxvkError("DxvkAdapter::imageFormatProperties: Failed to query format properties"); - } + VkResult DxvkAdapter::imageFormatProperties( + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkImageFormatProperties& properties) const { + return m_vki->vkGetPhysicalDeviceImageFormatProperties( + m_handle, format, type, tiling, usage, flags, &properties); } diff --git a/src/dxvk/dxvk_adapter.h b/src/dxvk/dxvk_adapter.h index acd2fc8e7..c30c945be 100644 --- a/src/dxvk/dxvk_adapter.h +++ b/src/dxvk/dxvk_adapter.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "./vulkan/dxvk_vulkan_extensions.h" #include "dxvk_include.h" @@ -86,14 +84,16 @@ namespace dxvk { * \param [in] tiling Image tiling * \param [in] usage Image usage flags * \param [in] flags Image create flags - * \returns Image format support info + * \param [out] properties Format properties + * \returns \c VK_SUCCESS or \c VK_ERROR_FORMAT_NOT_SUPPORTED */ - std::optional imageFormatProperties( - VkFormat format, - VkImageType type, - VkImageTiling tiling, - VkImageUsageFlags usage, - VkImageCreateFlags flags) const; + VkResult imageFormatProperties( + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkImageFormatProperties& properties) const; /** * \brief Graphics queue family index diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 69d5f21a8..6f2697a91 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -27,6 +27,7 @@ namespace dxvk { m_flags.set( DxvkContextFlag::GpDirtyPipeline, + DxvkContextFlag::GpDirtyPipelineState, DxvkContextFlag::GpDirtyDynamicState, DxvkContextFlag::GpDirtyResources, DxvkContextFlag::GpDirtyIndexBuffer,