[Mesa-dev] [PATCH 08/13] nir: Add floating point atomic add instrinsics

Ian Romanick idr at freedesktop.org
Sat Jun 23 05:03:53 UTC 2018


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

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/gl_nir_lower_samplers_as_deref.c |  1 +
 src/compiler/glsl/glsl_to_nir.cpp                  | 18 +++++++++++++-----
 src/compiler/nir/nir_intrinsics.py                 |  4 ++++
 src/compiler/nir/nir_lower_atomics_to_ssbo.c       |  1 +
 src/compiler/nir/nir_lower_io.c                    |  3 +++
 5 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
index 47115f943fe..dee413d0c05 100644
--- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
+++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c
@@ -193,6 +193,7 @@ lower_intrinsic(nir_intrinsic_instr *instr,
        instr->intrinsic == nir_intrinsic_image_var_atomic_xor ||
        instr->intrinsic == nir_intrinsic_image_var_atomic_exchange ||
        instr->intrinsic == nir_intrinsic_image_var_atomic_comp_swap ||
+       instr->intrinsic == nir_intrinsic_image_var_atomic_fadd ||
        instr->intrinsic == nir_intrinsic_image_var_size) {
       b->cursor = nir_before_instr(&instr->instr);
 
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index b10c1ff4eeb..90e960592a0 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -676,7 +676,9 @@ nir_visitor::visit(ir_call *ir)
          op = nir_intrinsic_image_var_store;
          break;
       case ir_intrinsic_image_atomic_add:
-         op = nir_intrinsic_image_var_atomic_add;
+         op = ir->return_deref->type->is_integer_32_64()
+            ? nir_intrinsic_image_var_atomic_add
+            : nir_intrinsic_image_var_atomic_fadd;
          break;
       case ir_intrinsic_image_atomic_min:
          op = nir_intrinsic_image_var_atomic_min;
@@ -715,7 +717,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;
@@ -781,7 +784,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;
@@ -891,6 +896,7 @@ nir_visitor::visit(ir_call *ir)
       case nir_intrinsic_image_var_atomic_xor:
       case nir_intrinsic_image_var_atomic_exchange:
       case nir_intrinsic_image_var_atomic_comp_swap:
+      case nir_intrinsic_image_var_atomic_fadd:
       case nir_intrinsic_image_var_samples:
       case nir_intrinsic_image_var_size: {
          nir_ssa_undef_instr *instr_undef =
@@ -1061,7 +1067,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);
 
@@ -1144,7 +1151,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);
 
diff --git a/src/compiler/nir/nir_intrinsics.py b/src/compiler/nir/nir_intrinsics.py
index 484b2d4fd68..f1726e54fb0 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -304,6 +304,7 @@ intrinsic("image_var_atomic_or",   src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
 intrinsic("image_var_atomic_xor",  src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
 intrinsic("image_var_atomic_exchange",  src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
 intrinsic("image_var_atomic_comp_swap", src_comp=[4, 1, 1, 1], dest_comp=1, num_vars=1)
+intrinsic("image_var_atomic_fadd",  src_comp=[4, 1, 1], dest_comp=1, num_vars=1)
 intrinsic("image_var_size",    dest_comp=0, num_vars=1, flags=[CAN_ELIMINATE, CAN_REORDER])
 intrinsic("image_var_samples", dest_comp=1, num_vars=1, flags=[CAN_ELIMINATE, CAN_REORDER])
 
@@ -355,6 +356,7 @@ intrinsic("var_atomic_or",   src_comp=[1], dest_comp=1, num_vars=1)
 intrinsic("var_atomic_xor",  src_comp=[1], dest_comp=1, num_vars=1)
 intrinsic("var_atomic_exchange", src_comp=[1], dest_comp=1, num_vars=1)
 intrinsic("var_atomic_comp_swap", src_comp=[1, 1], dest_comp=1, num_vars=1)
+intrinsic("var_atomic_fadd",  src_comp=[1], dest_comp=1, num_vars=1)
 
 # SSBO atomic intrinsics
 #
@@ -381,6 +383,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
 #
@@ -406,6 +409,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, 0, indices,
diff --git a/src/compiler/nir/nir_lower_atomics_to_ssbo.c b/src/compiler/nir/nir_lower_atomics_to_ssbo.c
index 934ae81d750..72af914fb47 100644
--- a/src/compiler/nir/nir_lower_atomics_to_ssbo.c
+++ b/src/compiler/nir/nir_lower_atomics_to_ssbo.c
@@ -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:
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index df91febd68d..9a30564d988 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -286,6 +286,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");
@@ -385,6 +386,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_var_atomic_xor:
       case nir_intrinsic_var_atomic_exchange:
       case nir_intrinsic_var_atomic_comp_swap:
+      case nir_intrinsic_var_atomic_fadd:
          /* We can lower the io for this nir instrinsic */
          break;
       case nir_intrinsic_interp_var_at_centroid:
@@ -445,6 +447,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_var_atomic_xor:
       case nir_intrinsic_var_atomic_exchange:
       case nir_intrinsic_var_atomic_comp_swap:
+      case nir_intrinsic_var_atomic_fadd:
          assert(vertex_index == NULL);
          replacement = lower_atomic(intrin, state, offset);
          break;
-- 
2.14.4



More information about the mesa-dev mailing list