[Mesa-dev] [PATCH 01/12] glsl: Refactor code to find NIR opcode for an intrinsic and add unit test

Ian Romanick idr at freedesktop.org
Tue Jul 19 20:13:03 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

The next patches are going to significantly change the implementation,
so I really want a unit test.

   text	   data	    bss	    dec	    hex	filename
7529123	 273096	  28584	7830803	 777d13	/tmp/i965_dri-64bit-before.so
7529283	 273096	  28584	7830963	 777db3	/tmp/i965_dri-64bit-after.so

I'm honestly not sure why it grew by 160 bytes.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
---
 src/compiler/Makefile.glsl.am                      |  11 +
 src/compiler/glsl/glsl_to_nir.cpp                  | 238 +++++++++++----------
 .../glsl/tests/get_intrinsic_opcode_test.cpp       | 157 ++++++++++++++
 3 files changed, 293 insertions(+), 113 deletions(-)
 create mode 100644 src/compiler/glsl/tests/get_intrinsic_opcode_test.cpp

diff --git a/src/compiler/Makefile.glsl.am b/src/compiler/Makefile.glsl.am
index 4e90f16..1132aae 100644
--- a/src/compiler/Makefile.glsl.am
+++ b/src/compiler/Makefile.glsl.am
@@ -47,6 +47,7 @@ check_PROGRAMS +=					\
 	glsl/glsl_test					\
 	glsl/tests/blob-test				\
 	glsl/tests/general-ir-test			\
+	glsl/tests/get-intrinsic-opcode-test		\
 	glsl/tests/sampler-types-test			\
 	glsl/tests/uniform-initializer-test
 
@@ -94,6 +95,16 @@ glsl_tests_sampler_types_test_LDADD =			\
 	$(top_builddir)/src/libglsl_util.la		\
 	$(PTHREAD_LIBS)
 
+glsl_tests_get_intrinsic_opcode_test_SOURCES =		\
+	glsl/tests/get_intrinsic_opcode_test.cpp
+glsl_tests_get_intrinsic_opcode_test_CFLAGS =		\
+	$(PTHREAD_CFLAGS)
+glsl_tests_get_intrinsic_opcode_test_LDADD =		\
+	$(top_builddir)/src/gtest/libgtest.la		\
+	glsl/libglsl.la					\
+	$(top_builddir)/src/libglsl_util.la		\
+	$(PTHREAD_LIBS)
+
 noinst_LTLIBRARIES += glsl/libglsl.la glsl/libglcpp.la glsl/libstandalone.la
 
 glsl_libglcpp_la_LIBADD =				\
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index 20302e3..266f150 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -602,123 +602,135 @@ nir_visitor::visit(ir_return *ir)
    nir_builder_instr_insert(&b, &instr->instr);
 }
 
+namespace _glsl_to_nir {
+
+nir_intrinsic_op
+get_intrinsic_opcode(const char *name, const ir_dereference *return_deref)
+{
+   nir_intrinsic_op op;
+
+   if (strcmp(name, "__intrinsic_atomic_read") == 0) {
+      op = nir_intrinsic_atomic_counter_read_var;
+   } else if (strcmp(name, "__intrinsic_atomic_increment") == 0) {
+      op = nir_intrinsic_atomic_counter_inc_var;
+   } else if (strcmp(name, "__intrinsic_atomic_predecrement") == 0) {
+      op = nir_intrinsic_atomic_counter_dec_var;
+   } else if (strcmp(name, "__intrinsic_image_load") == 0) {
+      op = nir_intrinsic_image_load;
+   } else if (strcmp(name, "__intrinsic_image_store") == 0) {
+      op = nir_intrinsic_image_store;
+   } else if (strcmp(name, "__intrinsic_image_atomic_add") == 0) {
+      op = nir_intrinsic_image_atomic_add;
+   } else if (strcmp(name, "__intrinsic_image_atomic_min") == 0) {
+      op = nir_intrinsic_image_atomic_min;
+   } else if (strcmp(name, "__intrinsic_image_atomic_max") == 0) {
+      op = nir_intrinsic_image_atomic_max;
+   } else if (strcmp(name, "__intrinsic_image_atomic_and") == 0) {
+      op = nir_intrinsic_image_atomic_and;
+   } else if (strcmp(name, "__intrinsic_image_atomic_or") == 0) {
+      op = nir_intrinsic_image_atomic_or;
+   } else if (strcmp(name, "__intrinsic_image_atomic_xor") == 0) {
+      op = nir_intrinsic_image_atomic_xor;
+   } else if (strcmp(name, "__intrinsic_image_atomic_exchange") == 0) {
+      op = nir_intrinsic_image_atomic_exchange;
+   } else if (strcmp(name, "__intrinsic_image_atomic_comp_swap") == 0) {
+      op = nir_intrinsic_image_atomic_comp_swap;
+   } else if (strcmp(name, "__intrinsic_memory_barrier") == 0) {
+      op = nir_intrinsic_memory_barrier;
+   } else if (strcmp(name, "__intrinsic_image_size") == 0) {
+      op = nir_intrinsic_image_size;
+   } else if (strcmp(name, "__intrinsic_image_samples") == 0) {
+      op = nir_intrinsic_image_samples;
+   } else if (strcmp(name, "__intrinsic_store_ssbo") == 0) {
+      op = nir_intrinsic_store_ssbo;
+   } else if (strcmp(name, "__intrinsic_load_ssbo") == 0) {
+      op = nir_intrinsic_load_ssbo;
+   } else if (strcmp(name, "__intrinsic_atomic_add_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_add;
+   } else if (strcmp(name, "__intrinsic_atomic_and_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_and;
+   } else if (strcmp(name, "__intrinsic_atomic_or_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_or;
+   } else if (strcmp(name, "__intrinsic_atomic_xor_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_xor;
+   } else if (strcmp(name, "__intrinsic_atomic_min_ssbo") == 0) {
+      assert(return_deref);
+      if (return_deref->type == glsl_type::int_type)
+         op = nir_intrinsic_ssbo_atomic_imin;
+      else if (return_deref->type == glsl_type::uint_type)
+         op = nir_intrinsic_ssbo_atomic_umin;
+      else
+         unreachable("Invalid type");
+   } else if (strcmp(name, "__intrinsic_atomic_max_ssbo") == 0) {
+      assert(return_deref);
+      if (return_deref->type == glsl_type::int_type)
+         op = nir_intrinsic_ssbo_atomic_imax;
+      else if (return_deref->type == glsl_type::uint_type)
+         op = nir_intrinsic_ssbo_atomic_umax;
+      else
+         unreachable("Invalid type");
+   } else if (strcmp(name, "__intrinsic_atomic_exchange_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_exchange;
+   } else if (strcmp(name, "__intrinsic_atomic_comp_swap_ssbo") == 0) {
+      op = nir_intrinsic_ssbo_atomic_comp_swap;
+   } else if (strcmp(name, "__intrinsic_shader_clock") == 0) {
+      op = nir_intrinsic_shader_clock;
+   } else if (strcmp(name, "__intrinsic_group_memory_barrier") == 0) {
+      op = nir_intrinsic_group_memory_barrier;
+   } else if (strcmp(name, "__intrinsic_memory_barrier_atomic_counter") == 0) {
+      op = nir_intrinsic_memory_barrier_atomic_counter;
+   } else if (strcmp(name, "__intrinsic_memory_barrier_buffer") == 0) {
+      op = nir_intrinsic_memory_barrier_buffer;
+   } else if (strcmp(name, "__intrinsic_memory_barrier_image") == 0) {
+      op = nir_intrinsic_memory_barrier_image;
+   } else if (strcmp(name, "__intrinsic_memory_barrier_shared") == 0) {
+      op = nir_intrinsic_memory_barrier_shared;
+   } else if (strcmp(name, "__intrinsic_load_shared") == 0) {
+      op = nir_intrinsic_load_shared;
+   } else if (strcmp(name, "__intrinsic_store_shared") == 0) {
+      op = nir_intrinsic_store_shared;
+   } else if (strcmp(name, "__intrinsic_atomic_add_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_add;
+   } else if (strcmp(name, "__intrinsic_atomic_and_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_and;
+   } else if (strcmp(name, "__intrinsic_atomic_or_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_or;
+   } else if (strcmp(name, "__intrinsic_atomic_xor_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_xor;
+   } else if (strcmp(name, "__intrinsic_atomic_min_shared") == 0) {
+      assert(return_deref);
+      if (return_deref->type == glsl_type::int_type)
+         op = nir_intrinsic_shared_atomic_imin;
+      else if (return_deref->type == glsl_type::uint_type)
+         op = nir_intrinsic_shared_atomic_umin;
+      else
+         unreachable("Invalid type");
+   } else if (strcmp(name, "__intrinsic_atomic_max_shared") == 0) {
+      assert(return_deref);
+      if (return_deref->type == glsl_type::int_type)
+         op = nir_intrinsic_shared_atomic_imax;
+      else if (return_deref->type == glsl_type::uint_type)
+         op = nir_intrinsic_shared_atomic_umax;
+      else
+         unreachable("Invalid type");
+   } else if (strcmp(name, "__intrinsic_atomic_exchange_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_exchange;
+   } else if (strcmp(name, "__intrinsic_atomic_comp_swap_shared") == 0) {
+      op = nir_intrinsic_shared_atomic_comp_swap;
+   } else {
+      unreachable("not reached");
+   }
+
+   return op;
+}
+}
+
 void
 nir_visitor::visit(ir_call *ir)
 {
    if (ir->callee->is_intrinsic) {
-      nir_intrinsic_op op;
-      if (strcmp(ir->callee_name(), "__intrinsic_atomic_read") == 0) {
-         op = nir_intrinsic_atomic_counter_read_var;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_increment") == 0) {
-         op = nir_intrinsic_atomic_counter_inc_var;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_predecrement") == 0) {
-         op = nir_intrinsic_atomic_counter_dec_var;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_load") == 0) {
-         op = nir_intrinsic_image_load;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_store") == 0) {
-         op = nir_intrinsic_image_store;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_add") == 0) {
-         op = nir_intrinsic_image_atomic_add;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_min") == 0) {
-         op = nir_intrinsic_image_atomic_min;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_max") == 0) {
-         op = nir_intrinsic_image_atomic_max;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_and") == 0) {
-         op = nir_intrinsic_image_atomic_and;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_or") == 0) {
-         op = nir_intrinsic_image_atomic_or;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_xor") == 0) {
-         op = nir_intrinsic_image_atomic_xor;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_exchange") == 0) {
-         op = nir_intrinsic_image_atomic_exchange;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_comp_swap") == 0) {
-         op = nir_intrinsic_image_atomic_comp_swap;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier") == 0) {
-         op = nir_intrinsic_memory_barrier;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_size") == 0) {
-         op = nir_intrinsic_image_size;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_image_samples") == 0) {
-         op = nir_intrinsic_image_samples;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_store_ssbo") == 0) {
-         op = nir_intrinsic_store_ssbo;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_load_ssbo") == 0) {
-         op = nir_intrinsic_load_ssbo;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_add_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_add;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_and_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_and;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_or_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_or;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_xor_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_xor;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_min_ssbo") == 0) {
-         assert(ir->return_deref);
-         if (ir->return_deref->type == glsl_type::int_type)
-            op = nir_intrinsic_ssbo_atomic_imin;
-         else if (ir->return_deref->type == glsl_type::uint_type)
-            op = nir_intrinsic_ssbo_atomic_umin;
-         else
-            unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_max_ssbo") == 0) {
-         assert(ir->return_deref);
-         if (ir->return_deref->type == glsl_type::int_type)
-            op = nir_intrinsic_ssbo_atomic_imax;
-         else if (ir->return_deref->type == glsl_type::uint_type)
-            op = nir_intrinsic_ssbo_atomic_umax;
-         else
-            unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_exchange_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_exchange;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_comp_swap_ssbo") == 0) {
-         op = nir_intrinsic_ssbo_atomic_comp_swap;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_shader_clock") == 0) {
-         op = nir_intrinsic_shader_clock;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_group_memory_barrier") == 0) {
-         op = nir_intrinsic_group_memory_barrier;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier_atomic_counter") == 0) {
-         op = nir_intrinsic_memory_barrier_atomic_counter;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier_buffer") == 0) {
-         op = nir_intrinsic_memory_barrier_buffer;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier_image") == 0) {
-         op = nir_intrinsic_memory_barrier_image;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier_shared") == 0) {
-         op = nir_intrinsic_memory_barrier_shared;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_load_shared") == 0) {
-         op = nir_intrinsic_load_shared;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_store_shared") == 0) {
-         op = nir_intrinsic_store_shared;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_add_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_add;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_and_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_and;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_or_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_or;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_xor_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_xor;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_min_shared") == 0) {
-         assert(ir->return_deref);
-         if (ir->return_deref->type == glsl_type::int_type)
-            op = nir_intrinsic_shared_atomic_imin;
-         else if (ir->return_deref->type == glsl_type::uint_type)
-            op = nir_intrinsic_shared_atomic_umin;
-         else
-            unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_max_shared") == 0) {
-         assert(ir->return_deref);
-         if (ir->return_deref->type == glsl_type::int_type)
-            op = nir_intrinsic_shared_atomic_imax;
-         else if (ir->return_deref->type == glsl_type::uint_type)
-            op = nir_intrinsic_shared_atomic_umax;
-         else
-            unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_exchange_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_exchange;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_comp_swap_shared") == 0) {
-         op = nir_intrinsic_shared_atomic_comp_swap;
-      } else {
-         unreachable("not reached");
-      }
-
+      const nir_intrinsic_op op =
+         _glsl_to_nir::get_intrinsic_opcode(ir->callee_name(), ir->return_deref);
       nir_intrinsic_instr *instr = nir_intrinsic_instr_create(shader, op);
       nir_dest *dest = &instr->dest;
 
diff --git a/src/compiler/glsl/tests/get_intrinsic_opcode_test.cpp b/src/compiler/glsl/tests/get_intrinsic_opcode_test.cpp
new file mode 100644
index 0000000..aeecf32
--- /dev/null
+++ b/src/compiler/glsl/tests/get_intrinsic_opcode_test.cpp
@@ -0,0 +1,157 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include <gtest/gtest.h>
+#include "main/compiler.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "compiler/glsl/ir.h"
+#include "compiler/nir/nir.h"
+
+static const struct test_vector {
+   const char *name;
+   nir_intrinsic_op uint_op;
+   nir_intrinsic_op int_op;
+
+   test_vector(const char *_name, nir_intrinsic_op _op)
+      : name(_name), uint_op(_op), int_op(nir_num_intrinsics)
+   { /* empty */ }
+
+   test_vector(const char *_name, nir_intrinsic_op _int_op,
+               nir_intrinsic_op _uint_op)
+      : name(_name), uint_op(_uint_op), int_op(_int_op)
+   { /* empty */ }
+
+} intrinsics[] = {
+   test_vector("__intrinsic_atomic_read", nir_intrinsic_atomic_counter_read_var),
+   test_vector("__intrinsic_atomic_increment", nir_intrinsic_atomic_counter_inc_var),
+   test_vector("__intrinsic_atomic_predecrement", nir_intrinsic_atomic_counter_dec_var),
+   test_vector("__intrinsic_image_load", nir_intrinsic_image_load),
+   test_vector("__intrinsic_image_store", nir_intrinsic_image_store),
+   test_vector("__intrinsic_image_atomic_add", nir_intrinsic_image_atomic_add),
+   test_vector("__intrinsic_image_atomic_min", nir_intrinsic_image_atomic_min),
+   test_vector("__intrinsic_image_atomic_max", nir_intrinsic_image_atomic_max),
+   test_vector("__intrinsic_image_atomic_and", nir_intrinsic_image_atomic_and),
+   test_vector("__intrinsic_image_atomic_or", nir_intrinsic_image_atomic_or),
+   test_vector("__intrinsic_image_atomic_xor", nir_intrinsic_image_atomic_xor),
+   test_vector("__intrinsic_image_atomic_exchange", nir_intrinsic_image_atomic_exchange),
+   test_vector("__intrinsic_image_atomic_comp_swap", nir_intrinsic_image_atomic_comp_swap),
+   test_vector("__intrinsic_memory_barrier", nir_intrinsic_memory_barrier),
+   test_vector("__intrinsic_image_size", nir_intrinsic_image_size),
+   test_vector("__intrinsic_image_samples", nir_intrinsic_image_samples),
+   test_vector("__intrinsic_store_ssbo", nir_intrinsic_store_ssbo),
+   test_vector("__intrinsic_load_ssbo", nir_intrinsic_load_ssbo),
+   test_vector("__intrinsic_atomic_add_ssbo", nir_intrinsic_ssbo_atomic_add),
+   test_vector("__intrinsic_atomic_and_ssbo", nir_intrinsic_ssbo_atomic_and),
+   test_vector("__intrinsic_atomic_or_ssbo", nir_intrinsic_ssbo_atomic_or),
+   test_vector("__intrinsic_atomic_xor_ssbo", nir_intrinsic_ssbo_atomic_xor),
+   test_vector("__intrinsic_atomic_min_ssbo", nir_intrinsic_ssbo_atomic_imin, nir_intrinsic_ssbo_atomic_umin),
+   test_vector("__intrinsic_atomic_max_ssbo", nir_intrinsic_ssbo_atomic_imax, nir_intrinsic_ssbo_atomic_umax),
+   test_vector("__intrinsic_atomic_exchange_ssbo", nir_intrinsic_ssbo_atomic_exchange),
+   test_vector("__intrinsic_atomic_comp_swap_ssbo", nir_intrinsic_ssbo_atomic_comp_swap),
+   test_vector("__intrinsic_shader_clock", nir_intrinsic_shader_clock),
+   test_vector("__intrinsic_group_memory_barrier", nir_intrinsic_group_memory_barrier),
+   test_vector("__intrinsic_memory_barrier_atomic_counter", nir_intrinsic_memory_barrier_atomic_counter),
+   test_vector("__intrinsic_memory_barrier_buffer", nir_intrinsic_memory_barrier_buffer),
+   test_vector("__intrinsic_memory_barrier_image", nir_intrinsic_memory_barrier_image),
+   test_vector("__intrinsic_memory_barrier_shared", nir_intrinsic_memory_barrier_shared),
+   test_vector("__intrinsic_load_shared", nir_intrinsic_load_shared),
+   test_vector("__intrinsic_store_shared", nir_intrinsic_store_shared),
+   test_vector("__intrinsic_atomic_add_shared", nir_intrinsic_shared_atomic_add),
+   test_vector("__intrinsic_atomic_and_shared", nir_intrinsic_shared_atomic_and),
+   test_vector("__intrinsic_atomic_or_shared", nir_intrinsic_shared_atomic_or),
+   test_vector("__intrinsic_atomic_xor_shared", nir_intrinsic_shared_atomic_xor),
+   test_vector("__intrinsic_atomic_min_shared", nir_intrinsic_shared_atomic_imin, nir_intrinsic_shared_atomic_umin),
+   test_vector("__intrinsic_atomic_max_shared", nir_intrinsic_shared_atomic_imax, nir_intrinsic_shared_atomic_umax),
+   test_vector("__intrinsic_atomic_exchange_shared", nir_intrinsic_shared_atomic_exchange),
+   test_vector("__intrinsic_atomic_comp_swap_shared", nir_intrinsic_shared_atomic_comp_swap)
+};
+
+namespace _glsl_to_nir {
+nir_intrinsic_op
+get_intrinsic_opcode(const char *name, const ir_dereference *return_deref);
+}
+
+class get_intrinsic_opcode : public ::testing::Test {
+public:
+   virtual void SetUp();
+   virtual void TearDown();
+
+   void *mem_ctx;
+};
+
+void
+get_intrinsic_opcode::SetUp()
+{
+   this->mem_ctx = ralloc_context(NULL);
+}
+
+void
+get_intrinsic_opcode::TearDown()
+{
+   ralloc_free(this->mem_ctx);
+   this->mem_ctx = NULL;
+}
+
+TEST_F(get_intrinsic_opcode, uint_only)
+{
+   for (unsigned i = 0; i < ARRAY_SIZE(intrinsics); i++) {
+      if (intrinsics[i].int_op != nir_num_intrinsics)
+         continue;
+
+      const nir_intrinsic_op op =
+         _glsl_to_nir::get_intrinsic_opcode(intrinsics[i].name, NULL);
+
+      EXPECT_EQ(intrinsics[i].uint_op, op)
+         << "Seeking uint version of " << intrinsics[i].name;
+   }
+}
+
+TEST_F(get_intrinsic_opcode, int_and_uint)
+{
+   ir_variable *const uint_var =
+      new(mem_ctx) ir_variable(glsl_type::uint_type, "a", ir_var_temporary);
+   const ir_dereference *const uint_deref =
+      new(mem_ctx) ir_dereference_variable(uint_var);
+
+   ir_variable *const int_var =
+      new(mem_ctx) ir_variable(glsl_type::int_type, "b", ir_var_temporary);
+   const ir_dereference *const int_deref =
+      new(mem_ctx) ir_dereference_variable(int_var);
+
+   for (unsigned i = 0; i < ARRAY_SIZE(intrinsics); i++) {
+      if (intrinsics[i].int_op == nir_num_intrinsics)
+         continue;
+
+      const nir_intrinsic_op uint_op =
+         _glsl_to_nir::get_intrinsic_opcode(intrinsics[i].name, uint_deref);
+
+      EXPECT_EQ(intrinsics[i].uint_op, uint_op)
+         << "Seeking uint version of " << intrinsics[i].name;
+
+      const nir_intrinsic_op int_op =
+         _glsl_to_nir::get_intrinsic_opcode(intrinsics[i].name, int_deref);
+
+      EXPECT_EQ(intrinsics[i].int_op, int_op)
+         << "Seeking int version of " << intrinsics[i].name;
+   }
+}
-- 
2.5.5



More information about the mesa-dev mailing list