glsl: Add ir_binop_vector_extract in NIR
authorJuan A. Suarez Romero <jasuarez@igalia.com>
Wed, 9 May 2018 15:17:59 +0000 (15:17 +0000)
committerJuan A. Suarez Romero <jasuarez@igalia.com>
Fri, 1 Jun 2018 16:09:22 +0000 (18:09 +0200)
Implement ir_binop_vector_extract using NIR operations. Based on SPIR-V
to NIR approach.

This fixes:
dEQP-GLES3.functional.shaders.indexing.moredynamic.with_value_from_indexing_expression_fragment
Piglit's glsl-fs-vec4-indexing-8.shader_test

CC: mesa-stable@lists.freedesktop.org
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Iago Toral <itoral@igalia.com>
src/compiler/glsl/glsl_to_nir.cpp

index dc3e822308b5c727e804a4fd7480543110714b30..baaa3affed907d6f0090d6fe34012293bee251a7 100644 (file)
@@ -1940,6 +1940,15 @@ nir_visitor::visit(ir_expression *ir)
             unreachable("not reached");
       }
       break;
+   case ir_binop_vector_extract: {
+      result = nir_channel(&b, srcs[0], 0);
+      for (unsigned i = 1; i < ir->operands[0]->type->vector_elements; i++) {
+         nir_ssa_def *swizzled = nir_channel(&b, srcs[0], i);
+         result = nir_bcsel(&b, nir_ieq(&b, srcs[1], nir_imm_int(&b, i)),
+                            swizzled, result);
+      }
+      break;
+   }
 
    case ir_binop_ldexp: result = nir_ldexp(&b, srcs[0], srcs[1]); break;
    case ir_triop_fma: