nir: Add floating point atomic add instrinsics
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 10 Apr 2018 01:36:22 +0000 (18:36 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 23 Aug 2018 03:31:32 +0000 (20:31 -0700)
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/nir/nir_intrinsics.py
src/compiler/nir/nir_lower_atomics_to_ssbo.c
src/compiler/nir/nir_lower_io.c

index aae64c9f3f9d53b5794e111d27f9257fd4a024ec..9ff5708f503e990dc5372cf65c390995c9db8c47 100644 (file)
@@ -240,6 +240,7 @@ lower_intrinsic(nir_intrinsic_instr *instr,
        instr->intrinsic == nir_intrinsic_image_deref_atomic_xor ||
        instr->intrinsic == nir_intrinsic_image_deref_atomic_exchange ||
        instr->intrinsic == nir_intrinsic_image_deref_atomic_comp_swap ||
+       instr->intrinsic == nir_intrinsic_image_deref_atomic_fadd ||
        instr->intrinsic == nir_intrinsic_image_deref_size) {
 
       b->cursor = nir_before_instr(&instr->instr);
index b1d1da891111752bcaaddc0e942ee27130bdab49..aba8d70a8a03b132f8dafc1dee8449d86f972ee5 100644 (file)
@@ -650,7 +650,9 @@ nir_visitor::visit(ir_call *ir)
          op = nir_intrinsic_image_deref_store;
          break;
       case ir_intrinsic_image_atomic_add:
-         op = nir_intrinsic_image_deref_atomic_add;
+         op = ir->return_deref->type->is_integer_32_64()
+            ? nir_intrinsic_image_deref_atomic_add
+            : nir_intrinsic_image_deref_atomic_fadd;
          break;
       case ir_intrinsic_image_atomic_min:
          op = nir_intrinsic_image_deref_atomic_min;
@@ -689,7 +691,8 @@ nir_visitor::visit(ir_call *ir)
          op = nir_intrinsic_load_ssbo;
          break;
       case ir_intrinsic_ssbo_atomic_add:
-         op = nir_intrinsic_ssbo_atomic_add;
+         op = ir->return_deref->type->is_integer_32_64()
+            ? nir_intrinsic_ssbo_atomic_add : nir_intrinsic_ssbo_atomic_fadd;
          break;
       case ir_intrinsic_ssbo_atomic_and:
          op = nir_intrinsic_ssbo_atomic_and;
@@ -755,7 +758,9 @@ nir_visitor::visit(ir_call *ir)
          op = nir_intrinsic_store_shared;
          break;
       case ir_intrinsic_shared_atomic_add:
-         op = nir_intrinsic_shared_atomic_add;
+         op = ir->return_deref->type->is_integer_32_64()
+            ? nir_intrinsic_shared_atomic_add
+            : nir_intrinsic_shared_atomic_fadd;
          break;
       case ir_intrinsic_shared_atomic_and:
          op = nir_intrinsic_shared_atomic_and;
@@ -865,6 +870,7 @@ nir_visitor::visit(ir_call *ir)
       case nir_intrinsic_image_deref_atomic_xor:
       case nir_intrinsic_image_deref_atomic_exchange:
       case nir_intrinsic_image_deref_atomic_comp_swap:
+      case nir_intrinsic_image_deref_atomic_fadd:
       case nir_intrinsic_image_deref_samples:
       case nir_intrinsic_image_deref_size: {
          nir_ssa_undef_instr *instr_undef =
@@ -1035,7 +1041,8 @@ nir_visitor::visit(ir_call *ir)
       case nir_intrinsic_ssbo_atomic_or:
       case nir_intrinsic_ssbo_atomic_xor:
       case nir_intrinsic_ssbo_atomic_exchange:
-      case nir_intrinsic_ssbo_atomic_comp_swap: {
+      case nir_intrinsic_ssbo_atomic_comp_swap:
+      case nir_intrinsic_ssbo_atomic_fadd: {
          int param_count = ir->actual_parameters.length();
          assert(param_count == 3 || param_count == 4);
 
@@ -1118,7 +1125,8 @@ nir_visitor::visit(ir_call *ir)
       case nir_intrinsic_shared_atomic_or:
       case nir_intrinsic_shared_atomic_xor:
       case nir_intrinsic_shared_atomic_exchange:
-      case nir_intrinsic_shared_atomic_comp_swap: {
+      case nir_intrinsic_shared_atomic_comp_swap:
+      case nir_intrinsic_shared_atomic_fadd: {
          int param_count = ir->actual_parameters.length();
          assert(param_count == 2 || param_count == 3);
 
index d688a57181b06908b98f3680694c66c9c5ed6134..836cb34d74a7a7aa8824be77aafbe313b98bc347 100644 (file)
@@ -307,6 +307,7 @@ intrinsic("image_deref_atomic_or",   src_comp=[1, 4, 1, 1], dest_comp=1)
 intrinsic("image_deref_atomic_xor",  src_comp=[1, 4, 1, 1], dest_comp=1)
 intrinsic("image_deref_atomic_exchange",  src_comp=[1, 4, 1, 1], dest_comp=1)
 intrinsic("image_deref_atomic_comp_swap", src_comp=[1, 4, 1, 1, 1], dest_comp=1)
+intrinsic("image_deref_atomic_fadd",  src_comp=[1, 4, 1, 1], dest_comp=1)
 intrinsic("image_deref_size",    src_comp=[1], dest_comp=0, flags=[CAN_ELIMINATE, CAN_REORDER])
 intrinsic("image_deref_samples", src_comp=[1], dest_comp=1, flags=[CAN_ELIMINATE, CAN_REORDER])
 
@@ -357,6 +358,7 @@ intrinsic("deref_atomic_or",   src_comp=[1, 1], dest_comp=1)
 intrinsic("deref_atomic_xor",  src_comp=[1, 1], dest_comp=1)
 intrinsic("deref_atomic_exchange", src_comp=[1, 1], dest_comp=1)
 intrinsic("deref_atomic_comp_swap", src_comp=[1, 1, 1], dest_comp=1)
+intrinsic("deref_atomic_fadd",  src_comp=[1, 1], dest_comp=1)
 
 # SSBO atomic intrinsics
 #
@@ -383,6 +385,7 @@ intrinsic("ssbo_atomic_or",   src_comp=[1, 1, 1], dest_comp=1)
 intrinsic("ssbo_atomic_xor",  src_comp=[1, 1, 1], dest_comp=1)
 intrinsic("ssbo_atomic_exchange", src_comp=[1, 1, 1], dest_comp=1)
 intrinsic("ssbo_atomic_comp_swap", src_comp=[1, 1, 1, 1], dest_comp=1)
+intrinsic("ssbo_atomic_fadd",  src_comp=[1, 1, 1], dest_comp=1)
 
 # CS shared variable atomic intrinsics
 #
@@ -408,6 +411,7 @@ intrinsic("shared_atomic_or",   src_comp=[1, 1], dest_comp=1, indices=[BASE])
 intrinsic("shared_atomic_xor",  src_comp=[1, 1], dest_comp=1, indices=[BASE])
 intrinsic("shared_atomic_exchange", src_comp=[1, 1], dest_comp=1, indices=[BASE])
 intrinsic("shared_atomic_comp_swap", src_comp=[1, 1, 1], dest_comp=1, indices=[BASE])
+intrinsic("shared_atomic_fadd",  src_comp=[1, 1], dest_comp=1, indices=[BASE])
 
 def system_value(name, dest_comp, indices=[]):
     intrinsic("load_" + name, [], dest_comp, indices,
index 6ebd3632288f67acf01bb9ebe90a99864965d59a..72686624329e5db8be048be08cae0a89f82afc84 100644 (file)
@@ -57,6 +57,7 @@ lower_instr(nir_intrinsic_instr *instr, unsigned ssbo_offset, nir_builder *b)
    case nir_intrinsic_ssbo_atomic_xor:
    case nir_intrinsic_ssbo_atomic_exchange:
    case nir_intrinsic_ssbo_atomic_comp_swap:
+   case nir_intrinsic_ssbo_atomic_fadd:
    case nir_intrinsic_store_ssbo:
    case nir_intrinsic_load_ssbo:
    case nir_intrinsic_get_buffer_size:
index 9500a3091c4cfe1f078779e8b6aaa82490069665..3d4451e36024d4e6e3dc114458b182da953fe868 100644 (file)
@@ -280,6 +280,7 @@ lower_atomic(nir_intrinsic_instr *intrin, struct lower_io_state *state,
    OP(atomic_and)
    OP(atomic_or)
    OP(atomic_xor)
+   OP(atomic_fadd)
 #undef OP
    default:
       unreachable("Invalid atomic");
@@ -380,6 +381,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_deref_atomic_xor:
       case nir_intrinsic_deref_atomic_exchange:
       case nir_intrinsic_deref_atomic_comp_swap:
+      case nir_intrinsic_deref_atomic_fadd:
          /* We can lower the io for this nir instrinsic */
          break;
       case nir_intrinsic_interp_deref_at_centroid:
@@ -441,6 +443,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_deref_atomic_xor:
       case nir_intrinsic_deref_atomic_exchange:
       case nir_intrinsic_deref_atomic_comp_swap:
+      case nir_intrinsic_deref_atomic_fadd:
          assert(vertex_index == NULL);
          replacement = lower_atomic(intrin, state, var, offset);
          break;