[Mesa-dev] [PATCH 1/2] gallium: add b5g6r5 srgb format

sroland at vmware.com sroland at vmware.com
Thu Mar 20 08:56:15 PDT 2014


From: Roland Scheidegger <sroland at vmware.com>

GL generally doesn't seem to allow srgb formats with less (or more) than 8 bit
for the rgb channels, though some hw could easily do it (typically for formats
with up to 10 bits for the rgb channels, at least for formats with less than 8
bits support is likely widespread even). While it may be true there aren't
really any benefits for such formats, we need for it for d3d, though luckily
only for b5g6r5_srgb it seems.
So add this format along with the util code for conversion - since that util
code is heavily tuned for 8bit srgb this isn't really all that well optimized
and rounding doesn't seem right but at least it should give some halfway
meaningful results.
---
 src/gallium/auxiliary/util/u_format.csv     |    3 +++
 src/gallium/auxiliary/util/u_format.h       |    4 ++++
 src/gallium/auxiliary/util/u_format_pack.py |   16 ++++++++++++----
 src/gallium/include/pipe/p_format.h         |    2 ++
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv
index 8fb068b..8aa5c36 100644
--- a/src/gallium/auxiliary/util/u_format.csv
+++ b/src/gallium/auxiliary/util/u_format.csv
@@ -373,3 +373,6 @@ PIPE_FORMAT_R16A16_SINT             , plain, 1, 1, sp16 , sp16 ,     ,     , x00
 PIPE_FORMAT_R32A32_UINT             , plain, 1, 1, up32 , up32 ,     ,     , x00y, rgb
 PIPE_FORMAT_R32A32_SINT             , plain, 1, 1, sp32 , sp32 ,     ,     , x00y, rgb
 PIPE_FORMAT_R10G10B10A2_UINT        , plain, 1, 1, up10 , up10 , up10, up2 , xyzw, rgb
+
+PIPE_FORMAT_B5G6R5_SRGB             , plain, 1, 1, un5 , un6 , un5 ,     , zyx1, srgb
+
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 747e142..1dd5d52 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -906,6 +906,8 @@ util_format_srgb(enum pipe_format format)
       return PIPE_FORMAT_DXT3_SRGBA;
    case PIPE_FORMAT_DXT5_RGBA:
       return PIPE_FORMAT_DXT5_SRGBA;
+   case PIPE_FORMAT_B5G6R5_UNORM:
+      return PIPE_FORMAT_B5G6R5_SRGB;
    default:
       return PIPE_FORMAT_NONE;
    }
@@ -949,6 +951,8 @@ util_format_linear(enum pipe_format format)
       return PIPE_FORMAT_DXT3_RGBA;
    case PIPE_FORMAT_DXT5_SRGBA:
       return PIPE_FORMAT_DXT5_RGBA;
+   case PIPE_FORMAT_B5G6R5_SRGB:
+      return PIPE_FORMAT_B5G6R5_UNORM;
    default:
       return format;
    }
diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py
index d1f68c8..8072fdb 100644
--- a/src/gallium/auxiliary/util/u_format_pack.py
+++ b/src/gallium/auxiliary/util/u_format_pack.py
@@ -272,8 +272,11 @@ def conversion_expr(src_channel,
         if src_colorspace == SRGB:
             assert src_channel.type == UNSIGNED
             assert src_channel.norm
-            assert src_channel.size == 8
+            assert src_channel.size <= 8
+            assert src_channel.size >= 4
             assert dst_colorspace == RGB
+            if src_channel.size < 8:
+                value = '%s << %x | %s >> %x' % (value, 8 - src_channel.size, value, 2 * src_channel.size - 8)
             if dst_channel.type == FLOAT:
                 return 'util_format_srgb_8unorm_to_linear_float(%s)' % value
             else:
@@ -284,15 +287,20 @@ def conversion_expr(src_channel,
         elif dst_colorspace == SRGB:
             assert dst_channel.type == UNSIGNED
             assert dst_channel.norm
-            assert dst_channel.size == 8
+            assert dst_channel.size <= 8
             assert src_colorspace == RGB
             if src_channel.type == FLOAT:
-                return 'util_format_linear_float_to_srgb_8unorm(%s)' % value
+                value =  'util_format_linear_float_to_srgb_8unorm(%s)' % value
             else:
                 assert src_channel.type == UNSIGNED
                 assert src_channel.norm
                 assert src_channel.size == 8
-                return 'util_format_linear_to_srgb_8unorm(%s)' % value
+                value = 'util_format_linear_to_srgb_8unorm(%s)' % value
+            # XXX rounding is all wrong.
+            if dst_channel.size < 8:
+                return '%s >> %x' % (value, 8 - dst_channel.size)
+            else:
+                return value
         elif src_colorspace == ZS:
             pass
         elif dst_colorspace == ZS:
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index 34ab662..a7fdcd0 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -342,6 +342,8 @@ enum pipe_format {
    PIPE_FORMAT_R32A32_SINT             = 252,
    PIPE_FORMAT_R10G10B10A2_UINT        = 253,
 
+   PIPE_FORMAT_B5G6R5_SRGB             = 254,
+
    PIPE_FORMAT_COUNT
 };
 
-- 
1.7.9.5


More information about the mesa-dev mailing list