[Mesa-dev] [PATCH v4 2/3] nir: Add a lowering pass for UYVY textures

2017-06-21 Thread Johnson Lin
Similar with support for YUYV but with byte order difference in sampler
---
 src/compiler/nir/nir.h   |  1 +
 src/compiler/nir/nir_lower_tex.c | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ab7ba14303b7..1b4e47058d4d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2449,6 +2449,7 @@ typedef struct nir_lower_tex_options {
unsigned lower_y_uv_external;
unsigned lower_y_u_v_external;
unsigned lower_yx_xuxv_external;
+   unsigned lower_xy_uxvx_external;
 
/**
 * To emulate certain texture wrap modes, this can be used
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 4ef81955513e..65681decb1c0 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -301,6 +301,20 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
   nir_channel(b, xuxv, 3));
 }
 
+static void
+lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex)
+{
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *y = sample_plane(b, tex, 0);
+  nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+
+  convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, uxvx, 0),
+ nir_channel(b, uxvx, 2));
+}
+
 /*
  * Emits a textureLod operation used to replace an existing
  * textureGrad instruction.
@@ -760,6 +774,10 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
  progress = true;
   }
 
+  if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
+ lower_xy_uxvx_external(b, tex);
+ progress = true;
+  }
 
   if (sat_mask) {
  saturate_src(b, tex, sat_mask);
-- 
1.9.1

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


[Mesa-dev] [PATCH v4 1/3] dri: Add UYVY as available format

2017-06-21 Thread Johnson Lin
UYVY is diffrent with YUYV in byte order.
YUYV is already declared in dri_interface.h,
this CL add the difinitions for UYVY.
Drivers can add UYVY as supported format
---
 include/GL/internal/dri_interface.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bbe22ef..6992da16d5f8 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1211,6 +1211,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV120x3231564e
 #define __DRI_IMAGE_FOURCC_NV160x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV0x56595559
+#define __DRI_IMAGE_FOURCC_UYVY0x59565955
 
 #define __DRI_IMAGE_FOURCC_YVU410  0x39555659
 #define __DRI_IMAGE_FOURCC_YVU411  0x31315659
@@ -1224,7 +1225,7 @@ struct __DRIdri2ExtensionRec {
  * RGB and RGBA are may be usable directly as images but its still
  * recommended to call fromPlanar with plane == 0.
  *
- * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create
+ * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
  * usable sub-images, sampling from images return raw YUV data and
  * color conversion needs to be done in the shader.
  *
@@ -1236,6 +1237,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V   0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV  0x3005
+#define __DRI_IMAGE_COMPONENTS_Y_UXVX  0x3008
 #define __DRI_IMAGE_COMPONENTS_R   0x3006
 #define __DRI_IMAGE_COMPONENTS_RG  0x3007
 
-- 
1.9.1

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


[Mesa-dev] [PATCH v4 3/3] i965/i915: Add UYVY as the supported format

2017-06-21 Thread Johnson Lin
Trigger the correct sampler options for it. Similar with YUYV
---
 src/intel/compiler/brw_compiler.h|  1 +
 src/intel/compiler/brw_nir.c |  1 +
 src/mesa/drivers/dri/i915/intel_screen.c | 21 -
 src/mesa/drivers/dri/i965/brw_wm.c   |  7 +++
 src/mesa/drivers/dri/i965/intel_screen.c | 21 -
 5 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/src/intel/compiler/brw_compiler.h 
b/src/intel/compiler/brw_compiler.h
index 78873744ce5f..3f383403883c 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -168,6 +168,7 @@ struct brw_sampler_prog_key_data {
uint32_t y_u_v_image_mask;
uint32_t y_uv_image_mask;
uint32_t yx_xuxv_image_mask;
+   uint32_t xy_uxvx_image_mask;
 };
 
 /**
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index de8f519b4e10..49d3cf365647 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -770,6 +770,7 @@ brw_nir_apply_sampler_key(nir_shader *nir,
tex_options.lower_y_uv_external = key_tex->y_uv_image_mask;
tex_options.lower_y_u_v_external = key_tex->y_u_v_image_mask;
tex_options.lower_yx_xuxv_external = key_tex->yx_xuxv_image_mask;
+   tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask;
 
if (nir_lower_tex(nir, &tex_options)) {
   nir_validate_shader(nir);
diff --git a/src/mesa/drivers/dri/i915/intel_screen.c 
b/src/mesa/drivers/dri/i915/intel_screen.c
index cba5434b5e1b..7936d4915e65 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -227,17 +227,20 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
-* them as planar buffers in the compositors.  Plane 0 is GR88 and
-* samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
-* places U into the G component and V into A.  This lets the
-* texture sampler interpolate the Y components correctly when
-* sampling from plane 0, and interpolate U and V correctly when
-* sampling from plane 1. */
+   /* For YUYV and UYVY buffers, we set up two overlapping DRI images
+* and treat them as planar buffers in the compositors.
+* Plane 0 is GR88 and samples YU or YV pairs and places Y into
+* the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
+* clusters and places pairs and places U into the G component and
+* V into A.  This lets the texture sampler interpolate the Y
+* components correctly when sampling from plane 0, and interpolate
+* U and V correctly when sampling from plane 1. */
{ __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
-   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } }
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
+   { __DRI_IMAGE_FOURCC_UYVY, __DRI_IMAGE_COMPONENTS_Y_UXVX, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR, 4 } } }
 };
 
 static __DRIimage *
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index a93f4c503792..71118c1ca598 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -270,6 +270,10 @@ brw_debug_recompile_sampler_key(struct brw_context *brw,
found |= key_debug(brw, "yx_xuxv image bound",
   old_key->yx_xuxv_image_mask,
   key->yx_xuxv_image_mask);
+   found |= key_debug(brw, "xy_uxvx image bound",
+  old_key->xy_uxvx_image_mask,
+  key->xy_uxvx_image_mask);
+
 
for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
   found |= key_debug(brw, "textureGather workarounds",
@@ -412,6 +416,9 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 case __DRI_IMAGE_COMPONENTS_Y_XUXV:
key->yx_xuxv_image_mask |= 1 << s;
break;
+case __DRI_IMAGE_COMPONENTS_Y_UXVX:
+   key->xy_uxvx_image_mask |= 1 << s;
+   break;
 default:
break;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 83b8a24509a4..8c6f3d81b14a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -278,17 +278,20 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
-* them as planar buffers in the compositors.  Plane 0 is GR88 and
-* samples YU or YV pairs and places Y into the

[Mesa-dev] [PATCH v3 1/3] dri: Add UYVY as available format

2017-06-20 Thread Johnson Lin
UYVY is diffrent with YUYV in byte order.
YUYV is already declared in dri_interface.h,
this CL add the difinitions for UYVY.
Drivers can add UYVY as supported format
---
 include/GL/internal/dri_interface.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bbe22ef..6992da16d5f8 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1211,6 +1211,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV120x3231564e
 #define __DRI_IMAGE_FOURCC_NV160x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV0x56595559
+#define __DRI_IMAGE_FOURCC_UYVY0x59565955
 
 #define __DRI_IMAGE_FOURCC_YVU410  0x39555659
 #define __DRI_IMAGE_FOURCC_YVU411  0x31315659
@@ -1224,7 +1225,7 @@ struct __DRIdri2ExtensionRec {
  * RGB and RGBA are may be usable directly as images but its still
  * recommended to call fromPlanar with plane == 0.
  *
- * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create
+ * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
  * usable sub-images, sampling from images return raw YUV data and
  * color conversion needs to be done in the shader.
  *
@@ -1236,6 +1237,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V   0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV  0x3005
+#define __DRI_IMAGE_COMPONENTS_Y_UXVX  0x3008
 #define __DRI_IMAGE_COMPONENTS_R   0x3006
 #define __DRI_IMAGE_COMPONENTS_RG  0x3007
 
-- 
1.9.1

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


[Mesa-dev] [PATCH v3 3/3] i965/i915: Add UYVY as the supported format

2017-06-20 Thread Johnson Lin
Trigger the correct sampler options for it. Similar with YUYV
---
 src/intel/compiler/brw_compiler.h| 1 +
 src/intel/compiler/brw_nir.c | 1 +
 src/mesa/drivers/dri/i915/intel_screen.c | 9 ++---
 src/mesa/drivers/dri/i965/brw_wm.c   | 7 +++
 src/mesa/drivers/dri/i965/intel_screen.c | 9 ++---
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/intel/compiler/brw_compiler.h 
b/src/intel/compiler/brw_compiler.h
index 78873744ce5f..3f383403883c 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -168,6 +168,7 @@ struct brw_sampler_prog_key_data {
uint32_t y_u_v_image_mask;
uint32_t y_uv_image_mask;
uint32_t yx_xuxv_image_mask;
+   uint32_t xy_uxvx_image_mask;
 };
 
 /**
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index de8f519b4e10..49d3cf365647 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -770,6 +770,7 @@ brw_nir_apply_sampler_key(nir_shader *nir,
tex_options.lower_y_uv_external = key_tex->y_uv_image_mask;
tex_options.lower_y_u_v_external = key_tex->y_u_v_image_mask;
tex_options.lower_yx_xuxv_external = key_tex->yx_xuxv_image_mask;
+   tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask;
 
if (nir_lower_tex(nir, &tex_options)) {
   nir_validate_shader(nir);
diff --git a/src/mesa/drivers/dri/i915/intel_screen.c 
b/src/mesa/drivers/dri/i915/intel_screen.c
index cba5434b5e1b..a81c7eb07d6a 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -227,17 +227,20 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interpolate U and V correctly when
 * sampling from plane 1. */
{ __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
-   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } }
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
+   { __DRI_IMAGE_FOURCC_UYVY, __DRI_IMAGE_COMPONENTS_Y_UXVX, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR, 4 } } }
 };
 
 static __DRIimage *
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index 0f075a11f756..a8ec1f5c2368 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -270,6 +270,10 @@ brw_debug_recompile_sampler_key(struct brw_context *brw,
found |= key_debug(brw, "yx_xuxv image bound",
   old_key->yx_xuxv_image_mask,
   key->yx_xuxv_image_mask);
+   found |= key_debug(brw, "xy_uxvx image bound",
+  old_key->xy_uxvx_image_mask,
+  key->xy_uxvx_image_mask);
+
 
for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
   found |= key_debug(brw, "textureGather workarounds",
@@ -412,6 +416,9 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 case __DRI_IMAGE_COMPONENTS_Y_XUXV:
key->yx_xuxv_image_mask |= 1 << s;
break;
+case __DRI_IMAGE_COMPONENTS_Y_UXVX:
+   key->xy_uxvx_image_mask |= 1 << s;
+   break;
 default:
break;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 83b8a24509a4..4ffedf1cc07f 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -278,17 +278,20 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interp

[Mesa-dev] [PATCH v3 2/3] nir: Add a lowering pass for UYVY textures

2017-06-20 Thread Johnson Lin
Similar with support for YUYV but with byte order difference in sampler
---
 src/compiler/nir/nir.h   |  1 +
 src/compiler/nir/nir_lower_tex.c | 18 ++
 2 files changed, 19 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ab7ba14303b7..1b4e47058d4d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2449,6 +2449,7 @@ typedef struct nir_lower_tex_options {
unsigned lower_y_uv_external;
unsigned lower_y_u_v_external;
unsigned lower_yx_xuxv_external;
+   unsigned lower_xy_uxvx_external;
 
/**
 * To emulate certain texture wrap modes, this can be used
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 4ef81955513e..65681decb1c0 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -301,6 +301,20 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
   nir_channel(b, xuxv, 3));
 }
 
+static void
+lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex)
+{
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *y = sample_plane(b, tex, 0);
+  nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+
+  convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, uxvx, 0),
+ nir_channel(b, uxvx, 2));
+}
+
 /*
  * Emits a textureLod operation used to replace an existing
  * textureGrad instruction.
@@ -760,6 +774,10 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
  progress = true;
   }
 
+  if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
+ lower_xy_uxvx_external(b, tex);
+ progress = true;
+  }
 
   if (sat_mask) {
  saturate_src(b, tex, sat_mask);
-- 
1.9.1

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


[Mesa-dev] [PATCH v2 3/3] i965/i915: Add UYVY as the supported format

2017-06-19 Thread Johnson Lin
Trigger the correct sampler options for it. Similar with YUYV
---
 src/intel/compiler/brw_compiler.h| 1 +
 src/intel/compiler/brw_nir.c | 1 +
 src/mesa/drivers/dri/i915/intel_screen.c | 7 +--
 src/mesa/drivers/dri/i965/brw_wm.c   | 7 +++
 src/mesa/drivers/dri/i965/intel_screen.c | 7 +--
 5 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/intel/compiler/brw_compiler.h 
b/src/intel/compiler/brw_compiler.h
index 78873744ce5f..3f383403883c 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -168,6 +168,7 @@ struct brw_sampler_prog_key_data {
uint32_t y_u_v_image_mask;
uint32_t y_uv_image_mask;
uint32_t yx_xuxv_image_mask;
+   uint32_t xy_uxvx_image_mask;
 };
 
 /**
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index de8f519b4e10..49d3cf365647 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -770,6 +770,7 @@ brw_nir_apply_sampler_key(nir_shader *nir,
tex_options.lower_y_uv_external = key_tex->y_uv_image_mask;
tex_options.lower_y_u_v_external = key_tex->y_u_v_image_mask;
tex_options.lower_yx_xuxv_external = key_tex->yx_xuxv_image_mask;
+   tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask;
 
if (nir_lower_tex(nir, &tex_options)) {
   nir_validate_shader(nir);
diff --git a/src/mesa/drivers/dri/i915/intel_screen.c 
b/src/mesa/drivers/dri/i915/intel_screen.c
index cba5434b5e1b..03f79e242c67 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -227,16 +227,19 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interpolate U and V correctly when
 * sampling from plane 1. */
{ __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
+   { __DRI_IMAGE_FOURCC_UYVY, __DRI_IMAGE_COMPONENTS_Y_UXVX, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } }
 };
 
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index 0f075a11f756..a8ec1f5c2368 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -270,6 +270,10 @@ brw_debug_recompile_sampler_key(struct brw_context *brw,
found |= key_debug(brw, "yx_xuxv image bound",
   old_key->yx_xuxv_image_mask,
   key->yx_xuxv_image_mask);
+   found |= key_debug(brw, "xy_uxvx image bound",
+  old_key->xy_uxvx_image_mask,
+  key->xy_uxvx_image_mask);
+
 
for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
   found |= key_debug(brw, "textureGather workarounds",
@@ -412,6 +416,9 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 case __DRI_IMAGE_COMPONENTS_Y_XUXV:
key->yx_xuxv_image_mask |= 1 << s;
break;
+case __DRI_IMAGE_COMPONENTS_Y_UXVX:
+   key->xy_uxvx_image_mask |= 1 << s;
+   break;
 default:
break;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 83b8a24509a4..4258e54e78ca 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -278,16 +278,19 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interpolate U and V correctly when
 * sampling from plane 1. */
{ __DRI_IMAGE_F

[Mesa-dev] [PATCH v2 1/3] dri: Add UYVY as available format

2017-06-19 Thread Johnson Lin
UYVY is diffrent with YUYV in byte order.
YUYV is already declared in dri_interface.h,
this CL add the difinitions for UYVY.
Drivers can add UYVY as supported format
---
 include/GL/internal/dri_interface.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bbe22ef..6992da16d5f8 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1211,6 +1211,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV120x3231564e
 #define __DRI_IMAGE_FOURCC_NV160x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV0x56595559
+#define __DRI_IMAGE_FOURCC_UYVY0x59565955
 
 #define __DRI_IMAGE_FOURCC_YVU410  0x39555659
 #define __DRI_IMAGE_FOURCC_YVU411  0x31315659
@@ -1224,7 +1225,7 @@ struct __DRIdri2ExtensionRec {
  * RGB and RGBA are may be usable directly as images but its still
  * recommended to call fromPlanar with plane == 0.
  *
- * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create
+ * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
  * usable sub-images, sampling from images return raw YUV data and
  * color conversion needs to be done in the shader.
  *
@@ -1236,6 +1237,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V   0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV  0x3005
+#define __DRI_IMAGE_COMPONENTS_Y_UXVX  0x3008
 #define __DRI_IMAGE_COMPONENTS_R   0x3006
 #define __DRI_IMAGE_COMPONENTS_RG  0x3007
 
-- 
1.9.1

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


[Mesa-dev] [PATCH v2 2/3] nir: Add a lowering pass for UYVY textures

2017-06-19 Thread Johnson Lin
Similar with support for YUYV but with byte order difference in sampler
---
 src/compiler/nir/nir.h   |  1 +
 src/compiler/nir/nir_lower_tex.c | 16 
 2 files changed, 17 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ab7ba14303b7..1b4e47058d4d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2449,6 +2449,7 @@ typedef struct nir_lower_tex_options {
unsigned lower_y_uv_external;
unsigned lower_y_u_v_external;
unsigned lower_yx_xuxv_external;
+   unsigned lower_xy_uxvx_external;
 
/**
 * To emulate certain texture wrap modes, this can be used
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 4ef81955513e..5593f9890b28 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -301,6 +301,18 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
   nir_channel(b, xuxv, 3));
 }
 
+static void lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex) {
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *y = sample_plane(b, tex, 0);
+  nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+
+  convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, uxvx, 2),
+ nir_channel(b, uxvx, 0));
+}
+
 /*
  * Emits a textureLod operation used to replace an existing
  * textureGrad instruction.
@@ -760,6 +772,10 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
  progress = true;
   }
 
+  if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
+ lower_xy_uxvx_external(b, tex);
+ progress = true;
+  }
 
   if (sat_mask) {
  saturate_src(b, tex, sat_mask);
-- 
1.9.1

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


[Mesa-dev] [PATCH v1 1/3] dri: Add UYVY as available format UYVY is diffrent with YUYV in byte order. YUYV is already declared in dri_interface.h, this CL add the difinitions for UYVY. Drivers can add

2017-06-15 Thread Johnson Lin
---
 include/GL/internal/dri_interface.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bbe22ef..6992da16d5f8 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1211,6 +1211,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV120x3231564e
 #define __DRI_IMAGE_FOURCC_NV160x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV0x56595559
+#define __DRI_IMAGE_FOURCC_UYVY0x59565955
 
 #define __DRI_IMAGE_FOURCC_YVU410  0x39555659
 #define __DRI_IMAGE_FOURCC_YVU411  0x31315659
@@ -1224,7 +1225,7 @@ struct __DRIdri2ExtensionRec {
  * RGB and RGBA are may be usable directly as images but its still
  * recommended to call fromPlanar with plane == 0.
  *
- * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create
+ * Y_U_V, Y_UV,Y_XUXV and Y_UXVX all requires call to fromPlanar to create
  * usable sub-images, sampling from images return raw YUV data and
  * color conversion needs to be done in the shader.
  *
@@ -1236,6 +1237,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V   0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV  0x3005
+#define __DRI_IMAGE_COMPONENTS_Y_UXVX  0x3008
 #define __DRI_IMAGE_COMPONENTS_R   0x3006
 #define __DRI_IMAGE_COMPONENTS_RG  0x3007
 
-- 
1.9.1

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


[Mesa-dev] [PATCH v1 2/3] nir: Add a lowering pass for UYVY textures Similar with support for YUYV but with byte order difference in sampler

2017-06-15 Thread Johnson Lin
---
 src/compiler/nir/nir.h   |  1 +
 src/compiler/nir/nir_lower_tex.c | 16 
 2 files changed, 17 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ab7ba14303b7..1b4e47058d4d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2449,6 +2449,7 @@ typedef struct nir_lower_tex_options {
unsigned lower_y_uv_external;
unsigned lower_y_u_v_external;
unsigned lower_yx_xuxv_external;
+   unsigned lower_xy_uxvx_external;
 
/**
 * To emulate certain texture wrap modes, this can be used
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 4ef81955513e..5593f9890b28 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -301,6 +301,18 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
   nir_channel(b, xuxv, 3));
 }
 
+static void lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex) {
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *y = sample_plane(b, tex, 0);
+  nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+
+  convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, uxvx, 2),
+ nir_channel(b, uxvx, 0));
+}
+
 /*
  * Emits a textureLod operation used to replace an existing
  * textureGrad instruction.
@@ -760,6 +772,10 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
  progress = true;
   }
 
+  if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
+ lower_xy_uxvx_external(b, tex);
+ progress = true;
+  }
 
   if (sat_mask) {
  saturate_src(b, tex, sat_mask);
-- 
1.9.1

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


[Mesa-dev] [PATCH v1 3/3] i965/i915: Add UYVY as the supported format Trigger the correct sampler options for it. Similar with YUYV

2017-06-15 Thread Johnson Lin
---
 src/intel/compiler/brw_compiler.h| 1 +
 src/intel/compiler/brw_nir.c | 1 +
 src/mesa/drivers/dri/i915/intel_screen.c | 7 +--
 src/mesa/drivers/dri/i965/brw_wm.c   | 7 +++
 src/mesa/drivers/dri/i965/intel_screen.c | 7 +--
 5 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/intel/compiler/brw_compiler.h 
b/src/intel/compiler/brw_compiler.h
index 78873744ce5f..3f383403883c 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -168,6 +168,7 @@ struct brw_sampler_prog_key_data {
uint32_t y_u_v_image_mask;
uint32_t y_uv_image_mask;
uint32_t yx_xuxv_image_mask;
+   uint32_t xy_uxvx_image_mask;
 };
 
 /**
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index de8f519b4e10..49d3cf365647 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -770,6 +770,7 @@ brw_nir_apply_sampler_key(nir_shader *nir,
tex_options.lower_y_uv_external = key_tex->y_uv_image_mask;
tex_options.lower_y_u_v_external = key_tex->y_u_v_image_mask;
tex_options.lower_yx_xuxv_external = key_tex->yx_xuxv_image_mask;
+   tex_options.lower_xy_uxvx_external = key_tex->xy_uxvx_image_mask;
 
if (nir_lower_tex(nir, &tex_options)) {
   nir_validate_shader(nir);
diff --git a/src/mesa/drivers/dri/i915/intel_screen.c 
b/src/mesa/drivers/dri/i915/intel_screen.c
index cba5434b5e1b..03f79e242c67 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -227,16 +227,19 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interpolate U and V correctly when
 * sampling from plane 1. */
{ __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
+   { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
+   { __DRI_IMAGE_FOURCC_UYVY, __DRI_IMAGE_COMPONENTS_Y_UXVX, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } }
 };
 
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index 0f075a11f756..a8ec1f5c2368 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -270,6 +270,10 @@ brw_debug_recompile_sampler_key(struct brw_context *brw,
found |= key_debug(brw, "yx_xuxv image bound",
   old_key->yx_xuxv_image_mask,
   key->yx_xuxv_image_mask);
+   found |= key_debug(brw, "xy_uxvx image bound",
+  old_key->xy_uxvx_image_mask,
+  key->xy_uxvx_image_mask);
+
 
for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
   found |= key_debug(brw, "textureGather workarounds",
@@ -412,6 +416,9 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 case __DRI_IMAGE_COMPONENTS_Y_XUXV:
key->yx_xuxv_image_mask |= 1 << s;
break;
+case __DRI_IMAGE_COMPONENTS_Y_UXVX:
+   key->xy_uxvx_image_mask |= 1 << s;
+   break;
 default:
break;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 83b8a24509a4..4258e54e78ca 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -278,16 +278,19 @@ static struct intel_image_format intel_image_formats[] = {
  { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
{ 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
 
-   /* For YUYV buffers, we set up two overlapping DRI images and treat
+   /* For YUYV&UYVY buffers, we set up two overlapping DRI images and treat
 * them as planar buffers in the compositors.  Plane 0 is GR88 and
 * samples YU or YV pairs and places Y into the R component, while
-* plane 1 is ARGB and samples YUYV clusters and places pairs and
+* plane 1 is ARGB and samples YUYV/UYVY clusters and places pairs and
 * places U into the G component and V into A.  This lets the
 * texture sampler interpolate the Y components correctly when
 * sampling from plane 0, and interpolate U and V correctly when
 * sampling from plane 1. */
{ __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONENTS_Y_XUXV, 2,
  { { 0, 0, 

[Mesa-dev] [PATCH] nir/lower_tex: Fix minor error in YUV color conversion matrix

2017-05-03 Thread Johnson Lin
The matrix used for YCbCr to RGB is listed in:

https://en.wikipedia.org/wiki/YCbCr

There was an error in converting the offsets from integers to unorm
values: 0.0625=16/256 should be 16.0/255,and 0.5=128.0/256 should be
128.0/255.  With this fix, the CSC result is bit aligned with wikipedia's
conversion result and FFMPeg's result.
---
 src/compiler/nir/nir_lower_tex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 352d1499bc8d..4ef81955513e 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -244,9 +244,9 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *yuv =
   nir_vec4(b,
nir_fmul(b, nir_imm_float(b, 1.16438356f),
-nir_fadd(b, y, nir_imm_float(b, -0.0625f))),
-   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -0.5f)), 0),
-   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -0.5f)), 0),
+nir_fadd(b, y, nir_imm_float(b, -16.0f / 255.0f))),
+   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -128.0f / 
255.0f)), 0),
+   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -128.0f / 
255.0f)), 0),
nir_imm_float(b, 0.0));

nir_ssa_def *red = nir_fdot4(b, yuv, nir_build_imm(b, 4, 32, m[0]));
--
1.9.1

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


[Mesa-dev] [PATCH] nir/lower_tex: Fix minor error in YUV color conversion matrix

2017-05-02 Thread Johnson Lin
The matrix used for YCbCr to RGB is listed in:

https://en.wikipedia.org/wiki/YCbCr

There was an error in converting the offsets from integers to unorm
values: 0.0625=16/256 should be 16.0/255,and 0.5=128.0/256 should be
128.0/255.  With this fix, the CSC result is bit aligned with wikipedia's
conversion result and FFMPeg's result.
---
 src/compiler/nir/nir_lower_tex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 352d1499bc8d..4ef81955513e 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -244,9 +244,9 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *yuv =
   nir_vec4(b,
nir_fmul(b, nir_imm_float(b, 1.16438356f),
-nir_fadd(b, y, nir_imm_float(b, -0.0625f))),
-   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -0.5f)), 0),
-   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -0.5f)), 0),
+nir_fadd(b, y, nir_imm_float(b, -16.0f / 255.0f))),
+   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -128.0f / 
255.0f)), 0),
+   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -128.0f / 
255.0f)), 0),
nir_imm_float(b, 0.0));

nir_ssa_def *red = nir_fdot4(b, yuv, nir_build_imm(b, 4, 32, m[0]));
--
1.9.1

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


[Mesa-dev] [PATCH] fix minor error in YUV2RGB matrix used in shader

2017-05-02 Thread Johnson Lin
The matrix used for YCbCr to RGB is listed in Wiki https://en.wikipedia.org/
wiki/YCbCr; There is minor error in the matrix constant: 0.0625=16/256 should
 be 16.0/255,and 0.5=128.0/256 should be 128.0/255.
Note that conversion from a 0-255 byte number to 0-1.0 float is to divide by
255 instead of 256. That's we get 255=1.0f.
By the constant change we can see the CSC result is bit aligned with Wiki
conversion result and FFMPeg result.Otherwise in some situation, there will be
 one bit difference

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100854
---
 src/compiler/nir/nir_lower_tex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 352d1499bc8d..f20425e84aab 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -244,9 +244,9 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *yuv =
   nir_vec4(b,
nir_fmul(b, nir_imm_float(b, 1.16438356f),
-nir_fadd(b, y, nir_imm_float(b, -0.0625f))),
-   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -0.5f)), 0),
-   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -0.5f)), 0),
+nir_fadd(b, y, nir_imm_float(b, -16.0f/255))),
+   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -128.0f/255)), 
0),
+   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -128.0f/255)), 
0),
nir_imm_float(b, 0.0));
 
nir_ssa_def *red = nir_fdot4(b, yuv, nir_build_imm(b, 4, 32, m[0]));
-- 
1.9.1

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


[Mesa-dev] [PATCH] fix minor error in YUV2RGB matrix used in shader

2017-04-28 Thread Johnson Lin
The matrix used for YCbCr to RGB is listed in Wiki 
https://en.wikipedia.org/wiki/YCbCr;
There is minor error in the matrix constant: 0.0625=16/256 should be 16.0/255,
 and 0.5=128.0/256 should be 128.0/255.
Note that conversion from a 0-255 byte number to 0-1.0 float is to divide by 255
 instead of 256. That's we get 255=1.0f.
By the constant change we can see the CSC result is bit aligned with
Wiki conversion result and FFMPeg result.
Otherwise in some situation, there will be one bit difference

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100854
---
 src/compiler/nir/nir_lower_tex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 352d1499bc8d..f20425e84aab 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -244,9 +244,9 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *yuv =
   nir_vec4(b,
nir_fmul(b, nir_imm_float(b, 1.16438356f),
-nir_fadd(b, y, nir_imm_float(b, -0.0625f))),
-   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -0.5f)), 0),
-   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -0.5f)), 0),
+nir_fadd(b, y, nir_imm_float(b, -16.0f/255))),
+   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -128.0f/255)), 
0),
+   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -128.0f/255)), 
0),
nir_imm_float(b, 0.0));
 
nir_ssa_def *red = nir_fdot4(b, yuv, nir_build_imm(b, 4, 32, m[0]));
-- 
1.9.1

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


[Mesa-dev] [PATCH] fix minor error in YUV2RGB matrix used in shader

2017-04-28 Thread Johnson Lin
The matrix used for YCbCr to RGB is listed in Wiki 
https://en.wikipedia.org/wiki/YCbCr;
There is minor error in the matrix constant: 0.0625=16/256 should be 16.0/255,
 and 0.5=128.0/256 should be 128.0/255.
Note that conversion from a 0-255 byte number to 0-1.0 float is to divide by 255
 instead of 256. That's we get 255=1.0f.
By the constant change we can see the CSC result is bit aligned with
Wiki conversion result and FFMPeg result.
Otherwise in some situation, there will be one bit difference

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100854
---
 src/compiler/nir/nir_lower_tex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 352d1499bc8d..385739a56a71 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -244,9 +244,9 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
nir_ssa_def *yuv =
   nir_vec4(b,
nir_fmul(b, nir_imm_float(b, 1.16438356f),
-nir_fadd(b, y, nir_imm_float(b, -0.0625f))),
-   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, -0.5f)), 0),
-   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, -0.5f)), 0),
+nir_fadd(b, y, nir_imm_float(b, -0.0627451f))),
+   nir_channel(b, nir_fadd(b, u, nir_imm_float(b, 
-0.50196078431f)), 0),
+   nir_channel(b, nir_fadd(b, v, nir_imm_float(b, 
-0.50196078431f)), 0),
nir_imm_float(b, 0.0));
 
nir_ssa_def *red = nir_fdot4(b, yuv, nir_build_imm(b, 4, 32, m[0]));
-- 
1.9.1

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