Skip to content

Commit

Permalink
color_space_helper: Allow 8- and 10-bit fmts for the sRGB color space (
Browse files Browse the repository at this point in the history
…#175)

* color_space_helper: Allow 8- and 10-bit fmts for the sRGB color space

Most texture formats should be presentable on the default sRGB color
space, in particular 10-bit formats for higher bit depth and detail than
the typical 8-bit.

A couple notes:
- This currently only affects `VK_KHR_display` as there is a
  `needsWorkaround` case in `PhysicalDevice::GetSurfaceFormats()` that
  returns exclusively RGBA8 and BGRA8 in the windowed/compositor case;
- Before this patch, `A2B10G10R10` wasn't in the list returned by
  `vkGetPhysicalDeviceSurfaceFormatsKHR()` but worked anyway on
  `VK_KHR_display` _without_ validation errors;
- Using the `A2B10G10R10` format inside a 10-bit compositor works
  anyway, albeit with validation layer errors;
- RADV also allows 10-bit sRGB swapchains, but only in a compositor, not
  in `VK_KHR_display`;
- Windows also does not report support for this 10-bit sRGB format
  combination, but it works anyway (also with validation layer errors);
- This was previously `Fmt_All` already before commit 02e867e ("Update
  xgl from commit 2aeb0b25") but it is assumed that sub-commit "Fix
  ColorspaceHelper's lookup table so it only reports formats that are
  legal" changed this behaviour. At least 10-bit sRGB should be retained?

(When saying "it works", I mean that it works as intended, i.e.
any 8-bit banding previously observable is gone when using a 10-bit
swapchain)

* color_space_helper: Split out 10bpc format in unorm and srgb
  • Loading branch information
MarijnS95 committed Feb 19, 2024
1 parent 53c29db commit 44902e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
18 changes: 12 additions & 6 deletions icd/api/color_space_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ struct LookupDefines

const LookupDefines colorspaceLookup[] =
{
{ Pal::ScreenColorSpace::CsSrgb, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, FmtSupport::Fmt_8bpc },
{ Pal::ScreenColorSpace::CsSrgb, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, FmtSupport::Fmt_KnownSRGB },
{ Pal::ScreenColorSpace::CsBt709, VK_COLOR_SPACE_BT709_NONLINEAR_EXT, FmtSupport::Fmt_All },
{ Pal::ScreenColorSpace::TfHlg, VK_COLOR_SPACE_HDR10_HLG_EXT, FmtSupport::Fmt_KnownHDR },
{ Pal::ScreenColorSpace::TfPq2084, VK_COLOR_SPACE_HDR10_ST2084_EXT, FmtSupport::Fmt_10bpc },
{ Pal::ScreenColorSpace::TfPq2084, VK_COLOR_SPACE_HDR10_ST2084_EXT, FmtSupport::Fmt_10bpc_unorm },
{ Pal::ScreenColorSpace::TfDolbyVision, VK_COLOR_SPACE_DOLBYVISION_EXT, FmtSupport::Fmt_8bpc_unorm },
{ Pal::ScreenColorSpace::CsBt2020, VK_COLOR_SPACE_BT2020_LINEAR_EXT, FmtSupport::Fmt_10bpc },
{ Pal::ScreenColorSpace::CsBt2020, VK_COLOR_SPACE_BT2020_LINEAR_EXT, FmtSupport::Fmt_10bpc_unorm },
{ Pal::ScreenColorSpace::CsAdobe, VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT, FmtSupport::Fmt_All },
{ Pal::ScreenColorSpace::CsDciP3, VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT, FmtSupport::Fmt_All },
{ Pal::ScreenColorSpace::CsScrgb, VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT, FmtSupport::Fmt_16bpc_sfloat },
Expand Down Expand Up @@ -140,10 +140,16 @@ ColorSpaceHelper::FmtSupport ColorSpaceHelper::GetBitFormat(Pal::ChNumFormat pal
fmt = Fmt_9bpc;
break;
case 10:
fmt = Fmt_10bpc;
break;
case 11:
fmt = Fmt_10bpc;
if (Pal::Formats::IsSrgb(palFormat))
{
fmt = Fmt_10bpc_srgb;
}
else
{
VK_ASSERT(Pal::Formats::IsUnorm(palFormat));
fmt = Fmt_10bpc_unorm;
}
break;
case 12:
fmt = Fmt_12bpc;
Expand Down
25 changes: 14 additions & 11 deletions icd/api/include/color_space_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@ class ColorSpaceHelper
Fmt_8bpc_srgb = 0x0008,
Fmt_8bpc_unorm = 0x0010,
Fmt_9bpc = 0x0020,
Fmt_10bpc = 0x0040,
Fmt_11bpc = 0x0080,
Fmt_12bpc = 0x0100,
Fmt_16bpc_unorm = 0x0200,
Fmt_16bpc_sfloat = 0x0400,
Fmt_32bpc = 0x0800,

Fmt_8bpc = Fmt_8bpc_srgb | Fmt_8bpc_unorm,
Fmt_16bpc = Fmt_16bpc_unorm | Fmt_16bpc_sfloat,
Fmt_KnownHDR = Fmt_10bpc | Fmt_11bpc | Fmt_12bpc | Fmt_16bpc,
Fmt_All = Fmt_4bpc | Fmt_5bpc | Fmt_6bpc | Fmt_8bpc | Fmt_KnownHDR | Fmt_32bpc,
Fmt_10bpc_srgb = 0x0040,
Fmt_10bpc_unorm = 0x0080,
Fmt_11bpc = 0x0100,
Fmt_12bpc = 0x0200,
Fmt_16bpc_unorm = 0x0400,
Fmt_16bpc_sfloat = 0x0800,
Fmt_32bpc = 0x1000,

Fmt_8bpc = Fmt_8bpc_srgb | Fmt_8bpc_unorm,
Fmt_10bpc = Fmt_10bpc_srgb | Fmt_10bpc_unorm,
Fmt_16bpc = Fmt_16bpc_unorm | Fmt_16bpc_sfloat,
Fmt_KnownHDR = Fmt_10bpc_unorm | Fmt_11bpc | Fmt_12bpc | Fmt_16bpc,
Fmt_KnownSRGB = Fmt_8bpc | Fmt_10bpc,
Fmt_All = Fmt_4bpc | Fmt_5bpc | Fmt_6bpc | Fmt_8bpc | Fmt_10bpc_srgb | Fmt_KnownHDR | Fmt_32bpc,

Fmt_FreeSync2 = Fmt_10bpc | Fmt_16bpc,
};
Expand Down

0 comments on commit 44902e7

Please sign in to comment.