[Mesa-dev] [PATCH 10/11] mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB

2014-09-16 Thread Dave Airlie
From: Richard Sandiford rsand...@linux.vnet.ibm.com

This means that each  SRGB format has a reversed counterpart,
which is necessary for handling big-endian mesa-gallium mappings.

Signed-off-by: Richard Sandiford rsand...@linux.vnet.ibm.com
Signed-off-by: Dave Airlie airl...@redhat.com
---
 src/mesa/drivers/dri/i965/brw_surface_formats.c |  1 +
 src/mesa/main/format_pack.c | 60 +
 src/mesa/main/format_unpack.c   | 42 +
 src/mesa/main/formats.c | 16 +++
 src/mesa/main/formats.csv   |  3 ++
 src/mesa/main/formats.h |  3 ++
 src/mesa/main/texformat.c   | 10 +
 src/mesa/swrast/s_texfetch.c|  3 ++
 src/mesa/swrast/s_texfetch_tmp.h| 24 ++
 9 files changed, 162 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c 
b/src/mesa/drivers/dri/i965/brw_surface_formats.c
index b726c27..21b8adb 100644
--- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
+++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
@@ -517,6 +517,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
   [MESA_FORMAT_B5G5R5X1_UNORM] = BRW_SURFACEFORMAT_B5G5R5X1_UNORM,
   [MESA_FORMAT_R8G8B8X8_SNORM] = 0,
   [MESA_FORMAT_R8G8B8X8_SRGB] = 0,
+  [MESA_FORMAT_X8B8G8R8_SRGB] = 0,
   [MESA_FORMAT_RGBX_UINT8] = 0,
   [MESA_FORMAT_RGBX_SINT8] = 0,
   [MESA_FORMAT_B10G10R10X2_UNORM] = BRW_SURFACEFORMAT_B10G10R10X2_UNORM,
diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 231fd6c..15bf0e5 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -1076,6 +1076,31 @@ pack_float_B8G8R8A8_SRGB(const GLfloat src[4], void *dst)
 }
 
 
+/* MESA_FORMAT_A8R8G8B8_SRGB */
+
+static void
+pack_ubyte_A8R8G8B8_SRGB(const GLubyte src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+   GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]);
+   GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]);
+   *d = PACK_COLOR_(b, g, r, src[ACOMP]);
+}
+
+static void
+pack_float_A8R8G8B8_SRGB(const GLfloat src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLubyte r, g, b, a;
+   r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+   g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+   b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
+   UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+   *d = PACK_COLOR_(b, g, r, a);
+}
+
+
 /* MESA_FORMAT_R8G8B8A8_SRGB */
 
 static void
@@ -1750,6 +1775,21 @@ pack_float_R8G8B8X8_SRGB(const GLfloat src[4], void *dst)
 }
 
 
+/*
+ * MESA_FORMAT_X8B8G8R8_SRGB
+ */
+
+static void
+pack_float_X8B8G8R8_SRGB(const GLfloat src[4], void *dst)
+{
+   GLuint *d = (GLuint *) dst;
+   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
+   *d = PACK_COLOR_(r, g, b, 127);
+}
+
+
 /* MESA_FORMAT_B10G10R10X2_UNORM */
 
 static void
@@ -1899,6 +1939,20 @@ pack_float_B8G8R8X8_SRGB(const GLfloat src[4], void *dst)
*d = PACK_COLOR_(127, r, g, b);
 }
 
+/*
+ * MESA_FORMAT_X8R8G8B8_SRGB
+ */
+
+static void
+pack_float_X8R8G8B8_SRGB(const GLfloat src[4], void *dst)
+{
+   GLuint *d = (GLuint *) dst;
+   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
+   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
+   *d = PACK_COLOR_(b, g, r, 127);
+}
+
 /**
  * Return a function that can pack a GLubyte rgba[4] color.
  */
@@ -1966,6 +2020,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format format)
   table[MESA_FORMAT_BGR_SRGB8] = pack_ubyte_BGR_SRGB8;
   table[MESA_FORMAT_A8B8G8R8_SRGB] = pack_ubyte_A8B8G8R8_SRGB;
   table[MESA_FORMAT_B8G8R8A8_SRGB] = pack_ubyte_B8G8R8A8_SRGB;
+  table[MESA_FORMAT_A8R8G8B8_SRGB] = pack_ubyte_A8R8G8B8_SRGB;
   table[MESA_FORMAT_R8G8B8A8_SRGB] = pack_ubyte_R8G8B8A8_SRGB;
   table[MESA_FORMAT_L_SRGB8] = pack_ubyte_L_SRGB8;
   table[MESA_FORMAT_L8A8_SRGB] = pack_ubyte_L8A8_SRGB;
@@ -2040,6 +2095,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format format)
   table[MESA_FORMAT_B5G5R5X1_UNORM] = pack_ubyte_XRGB1555_UNORM;
   table[MESA_FORMAT_R8G8B8X8_SNORM] = NULL;
   table[MESA_FORMAT_R8G8B8X8_SRGB] = NULL;
+  table[MESA_FORMAT_X8B8G8R8_SRGB] = NULL;
   table[MESA_FORMAT_RGBX_UINT8] = NULL;
   table[MESA_FORMAT_RGBX_SINT8] = NULL;
   table[MESA_FORMAT_B10G10R10X2_UNORM] = pack_ubyte_B10G10R10X2_UNORM;
@@ -2055,6 +2111,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format format)
   table[MESA_FORMAT_R10G10B10A2_UNORM] = pack_ubyte_R10G10B10A2_UNORM;
 
   table[MESA_FORMAT_B8G8R8X8_SRGB] = NULL;
+  

Re: [Mesa-dev] [PATCH 10/11] mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB

2014-09-16 Thread Dave Airlie

  static void
 +FETCH(A8R8G8B8_SRGB)(const struct swrast_texture_image *texImage,
 + GLint i, GLint j, GLint k, GLfloat *texel)
 +{
 +   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
 +   texel[RCOMP] = nonlinear_to_linear( (s   8)  0xff );
 +   texel[GCOMP] = nonlinear_to_linear( (s  16)  0xff );
 +   texel[BCOMP] = nonlinear_to_linear( (s  24) );
 +   texel[ACOMP] = UBYTE_TO_FLOAT( s  0xff ); /* linear! */
 +}
 +
 +
 +static void
  FETCH(R8G8B8A8_SRGB)(const struct swrast_texture_image *texImage,
   GLint i, GLint j, GLint k, GLfloat *texel)
  {
 @@ -793,6 +805,18 @@ FETCH(R8G8B8X8_SRGB)(const struct swrast_texture_image 
 *texImage,


  static void
 +FETCH(X8B8G8R8_SRGB)(const struct swrast_texture_image *texImage,
 + GLint i, GLint j, GLint k, GLfloat *texel)
 +{
 +   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
 +   texel[RCOMP] = nonlinear_to_linear( (s  24) );
 +   texel[GCOMP] = nonlinear_to_linear( (s  16)  0xff );
 +   texel[BCOMP] = nonlinear_to_linear( (s   8)  0xff );
 +   texel[ACOMP] = 1.0f;
 +}
 +
 +

I've just noticed these locally don't build, I've fixed them to use
the new interfaces.

Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 10/11] mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB

2014-09-16 Thread Jason Ekstrand
Got a couple comments below.  Other than that,
Reviewed-by: Jason Ekstrand jason.ekstr...@intel.com

On Mon, Sep 15, 2014 at 11:28 PM, Dave Airlie airl...@gmail.com wrote:

 From: Richard Sandiford rsand...@linux.vnet.ibm.com

 This means that each  SRGB format has a reversed counterpart,
 which is necessary for handling big-endian mesa-gallium mappings.

 Signed-off-by: Richard Sandiford rsand...@linux.vnet.ibm.com
 Signed-off-by: Dave Airlie airl...@redhat.com
 ---
  src/mesa/drivers/dri/i965/brw_surface_formats.c |  1 +
  src/mesa/main/format_pack.c | 60
 +
  src/mesa/main/format_unpack.c   | 42 +
  src/mesa/main/formats.c | 16 +++
  src/mesa/main/formats.csv   |  3 ++
  src/mesa/main/formats.h |  3 ++
  src/mesa/main/texformat.c   | 10 +
  src/mesa/swrast/s_texfetch.c|  3 ++
  src/mesa/swrast/s_texfetch_tmp.h| 24 ++
  9 files changed, 162 insertions(+)

 diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c
 b/src/mesa/drivers/dri/i965/brw_surface_formats.c
 index b726c27..21b8adb 100644
 --- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
 +++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
 @@ -517,6 +517,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
[MESA_FORMAT_B5G5R5X1_UNORM] = BRW_SURFACEFORMAT_B5G5R5X1_UNORM,
[MESA_FORMAT_R8G8B8X8_SNORM] = 0,
[MESA_FORMAT_R8G8B8X8_SRGB] = 0,
 +  [MESA_FORMAT_X8B8G8R8_SRGB] = 0,


Any particular reason you go out of your way to add X8B8G8R8_SRGB and not
the other two?


[MESA_FORMAT_RGBX_UINT8] = 0,
[MESA_FORMAT_RGBX_SINT8] = 0,
[MESA_FORMAT_B10G10R10X2_UNORM] =
 BRW_SURFACEFORMAT_B10G10R10X2_UNORM,
 diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
 index 231fd6c..15bf0e5 100644
 --- a/src/mesa/main/format_pack.c
 +++ b/src/mesa/main/format_pack.c
 @@ -1076,6 +1076,31 @@ pack_float_B8G8R8A8_SRGB(const GLfloat src[4], void
 *dst)
  }


 +/* MESA_FORMAT_A8R8G8B8_SRGB */
 +
 +static void
 +pack_ubyte_A8R8G8B8_SRGB(const GLubyte src[4], void *dst)
 +{
 +   GLuint *d = ((GLuint *) dst);
 +   GLubyte r = util_format_linear_to_srgb_8unorm(src[RCOMP]);
 +   GLubyte g = util_format_linear_to_srgb_8unorm(src[GCOMP]);
 +   GLubyte b = util_format_linear_to_srgb_8unorm(src[BCOMP]);
 +   *d = PACK_COLOR_(b, g, r, src[ACOMP]);
 +}
 +
 +static void
 +pack_float_A8R8G8B8_SRGB(const GLfloat src[4], void *dst)
 +{
 +   GLuint *d = ((GLuint *) dst);
 +   GLubyte r, g, b, a;
 +   r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
 +   g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
 +   b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
 +   UNCLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
 +   *d = PACK_COLOR_(b, g, r, a);
 +}
 +
 +
  /* MESA_FORMAT_R8G8B8A8_SRGB */

  static void
 @@ -1750,6 +1775,21 @@ pack_float_R8G8B8X8_SRGB(const GLfloat src[4], void
 *dst)
  }


 +/*
 + * MESA_FORMAT_X8B8G8R8_SRGB
 + */
 +
 +static void
 +pack_float_X8B8G8R8_SRGB(const GLfloat src[4], void *dst)
 +{
 +   GLuint *d = (GLuint *) dst;
 +   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
 +   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
 +   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
 +   *d = PACK_COLOR_(r, g, b, 127);


That should be a max of 255, these aren't SNORM formats


 +}
 +
 +
  /* MESA_FORMAT_B10G10R10X2_UNORM */

  static void
 @@ -1899,6 +1939,20 @@ pack_float_B8G8R8X8_SRGB(const GLfloat src[4], void
 *dst)
 *d = PACK_COLOR_(127, r, g, b);
  }

 +/*
 + * MESA_FORMAT_X8R8G8B8_SRGB
 + */
 +
 +static void
 +pack_float_X8R8G8B8_SRGB(const GLfloat src[4], void *dst)
 +{
 +   GLuint *d = (GLuint *) dst;
 +   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
 +   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
 +   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
 +   *d = PACK_COLOR_(b, g, r, 127);


Max of 255 here too


 +}
 +
  /**
   * Return a function that can pack a GLubyte rgba[4] color.
   */
 @@ -1966,6 +2020,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format
 format)
table[MESA_FORMAT_BGR_SRGB8] = pack_ubyte_BGR_SRGB8;
table[MESA_FORMAT_A8B8G8R8_SRGB] = pack_ubyte_A8B8G8R8_SRGB;
table[MESA_FORMAT_B8G8R8A8_SRGB] = pack_ubyte_B8G8R8A8_SRGB;
 +  table[MESA_FORMAT_A8R8G8B8_SRGB] = pack_ubyte_A8R8G8B8_SRGB;
table[MESA_FORMAT_R8G8B8A8_SRGB] = pack_ubyte_R8G8B8A8_SRGB;
table[MESA_FORMAT_L_SRGB8] = pack_ubyte_L_SRGB8;
table[MESA_FORMAT_L8A8_SRGB] = pack_ubyte_L8A8_SRGB;
 @@ -2040,6 +2095,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format
 format)
table[MESA_FORMAT_B5G5R5X1_UNORM] = pack_ubyte_XRGB1555_UNORM;
table[MESA_FORMAT_R8G8B8X8_SNORM] = NULL;

Re: [Mesa-dev] [PATCH 10/11] mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB

2014-09-16 Thread Dave Airlie
On 17 September 2014 09:56, Jason Ekstrand ja...@jlekstrand.net wrote:
 Got a couple comments below.  Other than that,
 Reviewed-by: Jason Ekstrand jason.ekstr...@intel.com

 On Mon, Sep 15, 2014 at 11:28 PM, Dave Airlie airl...@gmail.com wrote:

 From: Richard Sandiford rsand...@linux.vnet.ibm.com

 This means that each  SRGB format has a reversed counterpart,
 which is necessary for handling big-endian mesa-gallium mappings.

 Signed-off-by: Richard Sandiford rsand...@linux.vnet.ibm.com
 Signed-off-by: Dave Airlie airl...@redhat.com
 ---
  src/mesa/drivers/dri/i965/brw_surface_formats.c |  1 +
  src/mesa/main/format_pack.c | 60
 +
  src/mesa/main/format_unpack.c   | 42 +
  src/mesa/main/formats.c | 16 +++
  src/mesa/main/formats.csv   |  3 ++
  src/mesa/main/formats.h |  3 ++
  src/mesa/main/texformat.c   | 10 +
  src/mesa/swrast/s_texfetch.c|  3 ++
  src/mesa/swrast/s_texfetch_tmp.h| 24 ++
  9 files changed, 162 insertions(+)

 diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c
 b/src/mesa/drivers/dri/i965/brw_surface_formats.c
 index b726c27..21b8adb 100644
 --- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
 +++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
 @@ -517,6 +517,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
[MESA_FORMAT_B5G5R5X1_UNORM] = BRW_SURFACEFORMAT_B5G5R5X1_UNORM,
[MESA_FORMAT_R8G8B8X8_SNORM] = 0,
[MESA_FORMAT_R8G8B8X8_SRGB] = 0,
 +  [MESA_FORMAT_X8B8G8R8_SRGB] = 0,


 Any particular reason you go out of your way to add X8B8G8R8_SRGB and not
 the other two?

no good one, I'll fix that up.

 +static void
 +pack_float_X8B8G8R8_SRGB(const GLfloat src[4], void *dst)
 +{
 +   GLuint *d = (GLuint *) dst;
 +   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
 +   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
 +   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
 +   *d = PACK_COLOR_(r, g, b, 127);


 That should be a max of 255, these aren't SNORM formats

These two are taken from equivalent code in
pack_float_B8G8R8X8_SRGB

that is currently in mesa, so I should send a patch to fix those up as well?

Thanks,
Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 10/11] mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB

2014-09-16 Thread Jason Ekstrand
On Sep 16, 2014 6:54 PM, Dave Airlie airl...@gmail.com wrote:

 On 17 September 2014 09:56, Jason Ekstrand ja...@jlekstrand.net wrote:
  Got a couple comments below.  Other than that,
  Reviewed-by: Jason Ekstrand jason.ekstr...@intel.com
 
  On Mon, Sep 15, 2014 at 11:28 PM, Dave Airlie airl...@gmail.com wrote:
 
  From: Richard Sandiford rsand...@linux.vnet.ibm.com
 
  This means that each  SRGB format has a reversed counterpart,
  which is necessary for handling big-endian mesa-gallium mappings.
 
  Signed-off-by: Richard Sandiford rsand...@linux.vnet.ibm.com
  Signed-off-by: Dave Airlie airl...@redhat.com
  ---
   src/mesa/drivers/dri/i965/brw_surface_formats.c |  1 +
   src/mesa/main/format_pack.c | 60
  +
   src/mesa/main/format_unpack.c   | 42 +
   src/mesa/main/formats.c | 16 +++
   src/mesa/main/formats.csv   |  3 ++
   src/mesa/main/formats.h |  3 ++
   src/mesa/main/texformat.c   | 10 +
   src/mesa/swrast/s_texfetch.c|  3 ++
   src/mesa/swrast/s_texfetch_tmp.h| 24 ++
   9 files changed, 162 insertions(+)
 
  diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c
  b/src/mesa/drivers/dri/i965/brw_surface_formats.c
  index b726c27..21b8adb 100644
  --- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
  +++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
  @@ -517,6 +517,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
 [MESA_FORMAT_B5G5R5X1_UNORM] = BRW_SURFACEFORMAT_B5G5R5X1_UNORM,
 [MESA_FORMAT_R8G8B8X8_SNORM] = 0,
 [MESA_FORMAT_R8G8B8X8_SRGB] = 0,
  +  [MESA_FORMAT_X8B8G8R8_SRGB] = 0,
 
 
  Any particular reason you go out of your way to add X8B8G8R8_SRGB and
not
  the other two?

 no good one, I'll fix that up.

  +static void
  +pack_float_X8B8G8R8_SRGB(const GLfloat src[4], void *dst)
  +{
  +   GLuint *d = (GLuint *) dst;
  +   GLubyte r = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
  +   GLubyte g = util_format_linear_float_to_srgb_8unorm(src[GCOMP]);
  +   GLubyte b = util_format_linear_float_to_srgb_8unorm(src[BCOMP]);
  +   *d = PACK_COLOR_(r, g, b, 127);
 
 
  That should be a max of 255, these aren't SNORM formats

 These two are taken from equivalent code in
 pack_float_B8G8R8X8_SRGB

 that is currently in mesa, so I should send a patch to fix those up as
well?

Yes, unless I'm going crazy. (Which is always a possibility.)
--Jason


 Thanks,
 Dave.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev