[15/20] pan/midgard: Use type-appropriate swizzle for texture coordinate

Submitted by Alyssa Rosenzweig on Aug. 16, 2019, 3:35 p.m.

Details

Message ID 20190816153600.10519-16-alyssa.rosenzweig@collabora.com
State New
Headers show
Series "panfrost: Fix Midgard liveness analysis" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alyssa Rosenzweig Aug. 16, 2019, 3:35 p.m.
The texture coordinate for a 2D texture could be a vec2 or a vec3,
depending if it's an array texture or not. If it's vec2 (non-array
texture), we should not reference the z component; otherwise, liveness
analysis will get very confused when z is never written.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
---
 src/panfrost/midgard/midgard_compile.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index 67c5c848214..0be9cc32dc2 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -1753,6 +1753,7 @@  emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
         for (unsigned i = 0; i < instr->num_srcs; ++i) {
                 int index = nir_src_index(ctx, &instr->src[i].src);
                 midgard_vector_alu_src alu_src = blank_alu_src;
+                unsigned nr_components = nir_src_num_components(instr->src[i].src);
 
                 switch (instr->src[i].src_type) {
                 case nir_tex_src_coord: {
@@ -1804,7 +1805,12 @@  emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
 
                         if (instr->sampler_dim == GLSL_SAMPLER_DIM_2D) {
                                 /* Array component in w but NIR wants it in z */
-                                ins.texture.in_reg_swizzle = SWIZZLE_XYZZ;
+                                if (nr_components == 3)
+                                        ins.texture.in_reg_swizzle = SWIZZLE_XYZZ;
+                                else if (nr_components == 2)
+                                        ins.texture.in_reg_swizzle = SWIZZLE_XYXX;
+                                else
+                                        unreachable("Invalid texture 2D componens");
                         }
 
                         break;

Comments

On Fri, Aug 16, 2019 at 11:38 AM Alyssa Rosenzweig
<alyssa.rosenzweig@collabora.com> wrote:
>
> The texture coordinate for a 2D texture could be a vec2 or a vec3,
> depending if it's an array texture or not. If it's vec2 (non-array
> texture), we should not reference the z component; otherwise, liveness
> analysis will get very confused when z is never written.
>
> Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
> ---
>  src/panfrost/midgard/midgard_compile.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
> index 67c5c848214..0be9cc32dc2 100644
> --- a/src/panfrost/midgard/midgard_compile.c
> +++ b/src/panfrost/midgard/midgard_compile.c
> @@ -1753,6 +1753,7 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
>          for (unsigned i = 0; i < instr->num_srcs; ++i) {
>                  int index = nir_src_index(ctx, &instr->src[i].src);
>                  midgard_vector_alu_src alu_src = blank_alu_src;
> +                unsigned nr_components = nir_src_num_components(instr->src[i].src);
>
>                  switch (instr->src[i].src_type) {
>                  case nir_tex_src_coord: {
> @@ -1804,7 +1805,12 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr,
>
>                          if (instr->sampler_dim == GLSL_SAMPLER_DIM_2D) {
>                                  /* Array component in w but NIR wants it in z */
> -                                ins.texture.in_reg_swizzle = SWIZZLE_XYZZ;
> +                                if (nr_components == 3)
> +                                        ins.texture.in_reg_swizzle = SWIZZLE_XYZZ;
> +                                else if (nr_components == 2)
> +                                        ins.texture.in_reg_swizzle = SWIZZLE_XYXX;
> +                                else
> +                                        unreachable("Invalid texture 2D componens");

Just a drive-by review: components

  -ilia