glsl: Replace atomic_ssbo and ssbo_atomic with atomic
authorJordan Justen <jordan.l.justen@intel.com>
Fri, 9 Oct 2015 22:55:34 +0000 (15:55 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 10 Dec 2015 07:50:38 +0000 (23:50 -0800)
The atomic functions can also be used with shared variables in compute
shaders.

When lowering the intrinsic in lower_ubo_reference, we still create an
SSBO specific intrinsic since SSBO accesses can be indirectly
addressed, whereas all compute shader shared variable live in a single
shared variable area.

v2:
 * Also remove the _internal suffix from ssbo atomic intrinsic names (Iago)

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
src/glsl/builtin_functions.cpp
src/glsl/lower_ubo_reference.cpp
src/glsl/nir/glsl_to_nir.cpp

index 88f9a713368ffd4f08d76268ded9c308889adb71..4462bfd2324c0cda7816122f08b95c100489a8fa 100644 (file)
@@ -774,16 +774,16 @@ private:
    ir_function_signature *_atomic_counter_op(const char *intrinsic,
                                              builtin_available_predicate avail);
 
-   ir_function_signature *_atomic_ssbo_intrinsic2(builtin_available_predicate avail,
-                                                  const glsl_type *type);
-   ir_function_signature *_atomic_ssbo_op2(const char *intrinsic,
-                                           builtin_available_predicate avail,
-                                           const glsl_type *type);
-   ir_function_signature *_atomic_ssbo_intrinsic3(builtin_available_predicate avail,
-                                                  const glsl_type *type);
-   ir_function_signature *_atomic_ssbo_op3(const char *intrinsic,
-                                           builtin_available_predicate avail,
-                                           const glsl_type *type);
+   ir_function_signature *_atomic_intrinsic2(builtin_available_predicate avail,
+                                             const glsl_type *type);
+   ir_function_signature *_atomic_op2(const char *intrinsic,
+                                      builtin_available_predicate avail,
+                                      const glsl_type *type);
+   ir_function_signature *_atomic_intrinsic3(builtin_available_predicate avail,
+                                             const glsl_type *type);
+   ir_function_signature *_atomic_op3(const char *intrinsic,
+                                      builtin_available_predicate avail,
+                                      const glsl_type *type);
 
    B1(min3)
    B1(max3)
@@ -930,53 +930,53 @@ builtin_builder::create_intrinsics()
                 _atomic_counter_intrinsic(shader_atomic_counters),
                 NULL);
 
-   add_function("__intrinsic_ssbo_atomic_add",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_min",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_max",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_and",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_or",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_xor",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_exchange",
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
-                                        glsl_type::int_type),
-                NULL);
-   add_function("__intrinsic_ssbo_atomic_comp_swap",
-                _atomic_ssbo_intrinsic3(shader_storage_buffer_object,
-                                        glsl_type::uint_type),
-                _atomic_ssbo_intrinsic3(shader_storage_buffer_object,
-                                        glsl_type::int_type),
+   add_function("__intrinsic_atomic_add",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_min",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_max",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_and",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_or",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_xor",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_exchange",
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic2(shader_storage_buffer_object,
+                                   glsl_type::int_type),
+                NULL);
+   add_function("__intrinsic_atomic_comp_swap",
+                _atomic_intrinsic3(shader_storage_buffer_object,
+                                   glsl_type::uint_type),
+                _atomic_intrinsic3(shader_storage_buffer_object,
+                                   glsl_type::int_type),
                 NULL);
 
    add_image_functions(false);
@@ -2682,68 +2682,68 @@ builtin_builder::create_builtins()
                 NULL);
 
    add_function("atomicAdd",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_add",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_add",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_add",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_add",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicMin",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_min",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_min",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_min",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_min",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicMax",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_max",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_max",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_max",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_max",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicAnd",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_and",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_and",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_and",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_and",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicOr",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_or",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_or",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_or",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_or",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicXor",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_xor",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_xor",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_xor",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_xor",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicExchange",
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_exchange",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op2("__intrinsic_ssbo_atomic_exchange",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op2("__intrinsic_atomic_exchange",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op2("__intrinsic_atomic_exchange",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
    add_function("atomicCompSwap",
-                _atomic_ssbo_op3("__intrinsic_ssbo_atomic_comp_swap",
-                                 shader_storage_buffer_object,
-                                 glsl_type::uint_type),
-                _atomic_ssbo_op3("__intrinsic_ssbo_atomic_comp_swap",
-                                 shader_storage_buffer_object,
-                                 glsl_type::int_type),
+                _atomic_op3("__intrinsic_atomic_comp_swap",
+                            shader_storage_buffer_object,
+                            glsl_type::uint_type),
+                _atomic_op3("__intrinsic_atomic_comp_swap",
+                            shader_storage_buffer_object,
+                            glsl_type::int_type),
                 NULL);
 
    add_function("min3",
@@ -5097,8 +5097,8 @@ builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail)
 }
 
 ir_function_signature *
-builtin_builder::_atomic_ssbo_intrinsic2(builtin_available_predicate avail,
-                                         const glsl_type *type)
+builtin_builder::_atomic_intrinsic2(builtin_available_predicate avail,
+                                    const glsl_type *type)
 {
    ir_variable *atomic = in_var(type, "atomic");
    ir_variable *data = in_var(type, "data");
@@ -5107,8 +5107,8 @@ builtin_builder::_atomic_ssbo_intrinsic2(builtin_available_predicate avail,
 }
 
 ir_function_signature *
-builtin_builder::_atomic_ssbo_intrinsic3(builtin_available_predicate avail,
-                                         const glsl_type *type)
+builtin_builder::_atomic_intrinsic3(builtin_available_predicate avail,
+                                    const glsl_type *type)
 {
    ir_variable *atomic = in_var(type, "atomic");
    ir_variable *data1 = in_var(type, "data1");
@@ -5132,9 +5132,9 @@ builtin_builder::_atomic_counter_op(const char *intrinsic,
 }
 
 ir_function_signature *
-builtin_builder::_atomic_ssbo_op2(const char *intrinsic,
-                                  builtin_available_predicate avail,
-                                  const glsl_type *type)
+builtin_builder::_atomic_op2(const char *intrinsic,
+                             builtin_available_predicate avail,
+                             const glsl_type *type)
 {
    ir_variable *atomic = in_var(type, "atomic_var");
    ir_variable *data = in_var(type, "atomic_data");
@@ -5148,9 +5148,9 @@ builtin_builder::_atomic_ssbo_op2(const char *intrinsic,
 }
 
 ir_function_signature *
-builtin_builder::_atomic_ssbo_op3(const char *intrinsic,
-                                  builtin_available_predicate avail,
-                                  const glsl_type *type)
+builtin_builder::_atomic_op3(const char *intrinsic,
+                             builtin_available_predicate avail,
+                             const glsl_type *type)
 {
    ir_variable *atomic = in_var(type, "atomic_var");
    ir_variable *data1 = in_var(type, "atomic_data1");
index 34c1f2cf7f239337dbd9c6d588678d9024c34697..bbaf46160da1ce4b992763d1f802f763d2907c44 100644 (file)
@@ -955,7 +955,7 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
    sig->is_intrinsic = true;
 
    char func_name[64];
-   sprintf(func_name, "%s_internal", ir->callee_name());
+   sprintf(func_name, "%s_ssbo", ir->callee_name());
    ir_function *f = new(mem_ctx) ir_function(func_name);
    f->add_signature(sig);
 
@@ -980,14 +980,14 @@ ir_call *
 lower_ubo_reference_visitor::check_for_ssbo_atomic_intrinsic(ir_call *ir)
 {
    const char *callee = ir->callee_name();
-   if (!strcmp("__intrinsic_ssbo_atomic_add", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_min", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_max", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_and", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_or", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_xor", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_exchange", callee) ||
-       !strcmp("__intrinsic_ssbo_atomic_comp_swap", callee)) {
+   if (!strcmp("__intrinsic_atomic_add", callee) ||
+       !strcmp("__intrinsic_atomic_min", callee) ||
+       !strcmp("__intrinsic_atomic_max", callee) ||
+       !strcmp("__intrinsic_atomic_and", callee) ||
+       !strcmp("__intrinsic_atomic_or", callee) ||
+       !strcmp("__intrinsic_atomic_xor", callee) ||
+       !strcmp("__intrinsic_atomic_exchange", callee) ||
+       !strcmp("__intrinsic_atomic_comp_swap", callee)) {
       return lower_ssbo_atomic_intrinsic(ir);
    }
 
index 779364b9abc6530fb620465a741163af5c024898..42f0ca5a90406f5272741b3cec9dececac18026d 100644 (file)
@@ -687,15 +687,15 @@ nir_visitor::visit(ir_call *ir)
          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_ssbo_atomic_add_internal") == 0) {
+      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_add_ssbo") == 0) {
          op = nir_intrinsic_ssbo_atomic_add;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_and_internal") == 0) {
+      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_and_ssbo") == 0) {
          op = nir_intrinsic_ssbo_atomic_and;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_or_internal") == 0) {
+      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_or_ssbo") == 0) {
          op = nir_intrinsic_ssbo_atomic_or;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_xor_internal") == 0) {
+      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_xor_ssbo") == 0) {
          op = nir_intrinsic_ssbo_atomic_xor;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_min_internal") == 0) {
+      } 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;
@@ -703,7 +703,7 @@ nir_visitor::visit(ir_call *ir)
             op = nir_intrinsic_ssbo_atomic_umin;
          else
             unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_max_internal") == 0) {
+      } 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;
@@ -711,9 +711,9 @@ nir_visitor::visit(ir_call *ir)
             op = nir_intrinsic_ssbo_atomic_umax;
          else
             unreachable("Invalid type");
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_exchange_internal") == 0) {
+      } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_exchange_ssbo") == 0) {
          op = nir_intrinsic_ssbo_atomic_exchange;
-      } else if (strcmp(ir->callee_name(), "__intrinsic_ssbo_atomic_comp_swap_internal") == 0) {
+      } 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;