Skip to content

Commit

Permalink
[dxvk] Adjust swapchain format preferences in various cases
Browse files Browse the repository at this point in the history
For sRGB, using a native sRGB format allows the swapchain blitter
to use a more efficient code path for drawing the HUD.

Also allow RGB9E5 for sRGB and HDR10.
  • Loading branch information
doitsujin committed Jan 13, 2025
1 parent 1582ead commit cb57e40
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/dxvk/dxvk_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,13 @@ namespace dxvk {
const VkSurfaceFormatKHR* pSupported,
VkColorSpaceKHR colorSpace,
VkFormat format) {
static const std::array<VkFormat, 15> srgbFormatList = {
static const std::array<std::pair<VkFormat, VkFormat>, 3> srgbFormatMap = {{
{ VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_SRGB },
{ VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_SRGB },
{ VK_FORMAT_A8B8G8R8_UNORM_PACK32, VK_FORMAT_A8B8G8R8_SRGB_PACK32 },
}};

static const std::array<VkFormat, 13> srgbFormatList = {
VK_FORMAT_B5G5R5A1_UNORM_PACK16,
VK_FORMAT_R5G5B5A1_UNORM_PACK16,
VK_FORMAT_A1B5G5R5_UNORM_PACK16_KHR,
Expand All @@ -714,21 +720,19 @@ namespace dxvk {
VK_FORMAT_R8G8B8A8_SRGB,
VK_FORMAT_B8G8R8A8_SRGB,
VK_FORMAT_A8B8G8R8_SRGB_PACK32,
VK_FORMAT_R8G8B8A8_UNORM,
VK_FORMAT_B8G8R8A8_UNORM,
VK_FORMAT_A8B8G8R8_UNORM_PACK32,
VK_FORMAT_A2R10G10B10_UNORM_PACK32,
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
VK_FORMAT_R16G16B16A16_UNORM,
VK_FORMAT_R16G16B16A16_SFLOAT,
};

static const std::array<VkFormat, 5> hdr10FormatList = {
VK_FORMAT_A2R10G10B10_UNORM_PACK32,
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
VK_FORMAT_R16G16B16A16_UNORM,
VK_FORMAT_R16G16B16A16_SFLOAT,
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
};

static const std::array<VkFormat, 1> scRGBFormatList = {
Expand All @@ -744,6 +748,15 @@ namespace dxvk {
scRGBFormatList.size(), scRGBFormatList.data() },
}};

// For the sRGB color space, always prefer an actual sRGB
// format so that the blitter can use alpha blending.
if (colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
for (const auto& e : srgbFormatMap) {
if (format == e.first)
format = e.second;
}
}

// If the desired format is supported natively, use it
VkFormat fallback = VK_FORMAT_UNDEFINED;

Expand Down

0 comments on commit cb57e40

Please sign in to comment.