<div dir="ltr"><div>Wow, that was rather annoying...  Still, I haven't got much better.<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 6, 2016 at 1:44 PM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:llandwerlin@gmail.com" target="_blank">llandwerlin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Fixes new CTS tests :<br>
<br>
dEQP-VK.spirv_assembly.<wbr>instruction.compute.opatomic.<wbr>load<br>
dEQP-VK.spirv_assembly.<wbr>instruction.compute.opatomic.<wbr>store<br>
<br>
</span>v2: don't handle images like ssbo/ubo (Jason)<br>
<span class=""><br>
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
Cc: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
---<br>
</span> src/compiler/spirv/spirv_to_<wbr>nir.c | 124 ++++++++++++++++++++++++++++++<wbr>++++----<br>
 1 file changed, 113 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/spirv_to_<wbr>nir.c b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
index fda38f9..1fcd70f 100644<br>
--- a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
+++ b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
@@ -1640,6 +1640,18 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,<br>
       image = *vtn_value(b, w[3], vtn_value_type_image_pointer)-<wbr>>image;<br>
       break;<br>
<br>
+   case SpvOpAtomicLoad: {<br>
+      image.image =<br>
<span class="">+         vtn_value(b, w[3], vtn_value_type_access_chain)-><wbr>access_chain;<br>
</span>+      break;<br>
+   }<br>
+<br>
+   case SpvOpAtomicStore: {<br>
+      image.image =<br>
<span class="">+         vtn_value(b, w[1], vtn_value_type_access_chain)-><wbr>access_chain;<br>
</span>+      break;<br>
+   }<br>
+<br>
    case SpvOpImageQuerySize:<br>
       image.image =<br>
          vtn_value(b, w[3], vtn_value_type_access_chain)-><wbr>access_chain;<br>
@@ -1685,6 +1697,8 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,<br>
    OP(ImageQuerySize,         size)<br>
    OP(ImageRead,              load)<br>
    OP(ImageWrite,             store)<br>
+   OP(AtomicLoad,             load)<br>
+   OP(AtomicStore,            store)<br>
    OP(AtomicExchange,         atomic_exchange)<br>
    OP(AtomicCompareExchange,  atomic_comp_swap)<br>
    OP(AtomicIIncrement,       atomic_add)<br>
@@ -1723,9 +1737,13 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,<br>
    }<br>
<br>
    switch (opcode) {<br>
+   case SpvOpAtomicLoad:<br>
    case SpvOpImageQuerySize:<br>
    case SpvOpImageRead:<br>
       break;<br>
+   case SpvOpAtomicStore:<br>
+      intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(<wbr>b, w[4])->def);<br>
+      break;<br>
    case SpvOpImageWrite:<br>
       intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(<wbr>b, w[3])->def);<br>
       break;<br>
@@ -1784,6 +1802,8 @@ static nir_intrinsic_op<br>
 get_ssbo_nir_atomic_op(SpvOp opcode)<br>
 {<br>
    switch (opcode) {<br>
+   case SpvOpAtomicLoad:      return nir_intrinsic_load_ssbo;<br>
+   case SpvOpAtomicStore:     return nir_intrinsic_store_ssbo;<br>
 #define OP(S, N) case SpvOp##S: return nir_intrinsic_ssbo_##N;<br>
    OP(AtomicExchange,         atomic_exchange)<br>
    OP(AtomicCompareExchange,  atomic_comp_swap)<br>
@@ -1808,6 +1828,8 @@ static nir_intrinsic_op<br>
 get_shared_nir_atomic_op(SpvOp opcode)<br>
 {<br>
    switch (opcode) {<br>
+   case SpvOpAtomicLoad:      return nir_intrinsic_load_var;<br>
+   case SpvOpAtomicStore:     return nir_intrinsic_store_var;<br>
 #define OP(S, N) case SpvOp##S: return nir_intrinsic_var_##N;<br>
    OP(AtomicExchange,         atomic_exchange)<br>
    OP(AtomicCompareExchange,  atomic_comp_swap)<br>
@@ -1873,10 +1895,38 @@ static void<br>
<span class=""> vtn_handle_ssbo_or_shared_<wbr>atomic(struct vtn_builder *b, SpvOp opcode,<br>
</span><span class="">                                  const uint32_t *w, unsigned count)<br>
</span> {<br>
-   struct vtn_access_chain *chain =<br>
-      vtn_value(b, w[3], vtn_value_type_access_chain)-><wbr>access_chain;<br>
+   struct vtn_access_chain *chain;<br>
    nir_intrinsic_instr *atomic;<br>
<br>
+   switch (opcode) {<br>
+   case SpvOpAtomicLoad:<br>
+   case SpvOpAtomicExchange:<br>
+   case SpvOpAtomicCompareExchange:<br>
+   case SpvOpAtomicCompareExchangeWeak<wbr>:<br>
+   case SpvOpAtomicIIncrement:<br>
+   case SpvOpAtomicIDecrement:<br>
+   case SpvOpAtomicIAdd:<br>
+   case SpvOpAtomicISub:<br>
+   case SpvOpAtomicSMin:<br>
+   case SpvOpAtomicUMin:<br>
+   case SpvOpAtomicSMax:<br>
+   case SpvOpAtomicUMax:<br>
+   case SpvOpAtomicAnd:<br>
+   case SpvOpAtomicOr:<br>
+   case SpvOpAtomicXor:<br>
+      chain =<br>
<span class="">+         vtn_value(b, w[3], vtn_value_type_access_chain)-><wbr>access_chain;<br>
</span>+      break;<br>
+<br>
+   case SpvOpAtomicStore:<br>
+      chain =<br>
<span class="">+         vtn_value(b, w[1], vtn_value_type_access_chain)-><wbr>access_chain;<br>
</span>+      break;<br>
+<br>
+   default:<br>
+      unreachable("Invalid SPIR-V atomic");<br>
+   }<br>
+<br>
    /*<br>
    SpvScope scope = w[4];<br>
    SpvMemorySemanticsMask semantics = w[5];<br>
@@ -1897,18 +1947,58 @@ vtn_handle_ssbo_or_shared_<wbr>atomic(struct vtn_builder *b, SpvOp opcode,<br>
       nir_intrinsic_op op = get_ssbo_nir_atomic_op(opcode)<wbr>;<br>
<br>
       atomic = nir_intrinsic_instr_create(b-><wbr>nb.shader, op);<br>
-      atomic->src[0] = nir_src_for_ssa(index);<br>
-      atomic->src[1] = nir_src_for_ssa(offset);<br>
-      fill_common_atomic_sources(b, opcode, w, &atomic->src[2]);<br>
+<br>
+      switch (opcode) {<br>
+      case SpvOpAtomicLoad:<br>
+         atomic->num_components = glsl_get_vector_elements(type-<wbr>>type);<br>
+         atomic->src[0] = nir_src_for_ssa(index);<br>
+         atomic->src[1] = nir_src_for_ssa(offset);<br>
+         break;<br>
+<br>
+      case SpvOpAtomicStore:<br>
+         atomic->num_components = glsl_get_vector_elements(type-<wbr>>type);<br>
+         nir_intrinsic_set_write_mask(<wbr>atomic, (1 << atomic->num_components) - 1);<br>
+         atomic->src[0] = nir_src_for_ssa(vtn_ssa_value(<wbr>b, w[4])->def);<br>
+         atomic->src[1] = nir_src_for_ssa(index);<br>
+         atomic->src[2] = nir_src_for_ssa(offset);<br>
+         break;<br>
+<br>
+      case SpvOpAtomicExchange:<br>
+      case SpvOpAtomicCompareExchange:<br>
+      case SpvOpAtomicCompareExchangeWeak<wbr>:<br>
+      case SpvOpAtomicIIncrement:<br>
+      case SpvOpAtomicIDecrement:<br>
+      case SpvOpAtomicIAdd:<br>
+      case SpvOpAtomicISub:<br>
+      case SpvOpAtomicSMin:<br>
+      case SpvOpAtomicUMin:<br>
+      case SpvOpAtomicSMax:<br>
+      case SpvOpAtomicUMax:<br>
+      case SpvOpAtomicAnd:<br>
+      case SpvOpAtomicOr:<br>
+      case SpvOpAtomicXor:<br>
+         atomic->src[0] = nir_src_for_ssa(index);<br>
+         atomic->src[1] = nir_src_for_ssa(offset);<br>
+         fill_common_atomic_sources(b, opcode, w, &atomic->src[2]);<br>
+         break;<br>
+<br>
+      default:<br>
+         unreachable("Invalid SPIR-V atomic");<br>
+      }<br>
    }<br>
<br>
-   nir_ssa_dest_init(&atomic-><wbr>instr, &atomic->dest, 1, 32, NULL);<br>
+   if (opcode != SpvOpAtomicStore) {<br>
+      struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;<br>
+<br>
+      nir_ssa_dest_init(&atomic-><wbr>instr, &atomic->dest,<br>
+                        glsl_get_vector_elements(type-<wbr>>type),<br>
+                        glsl_get_bit_size(type->type), NULL);<br>
<br>
-   struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;<br>
-   struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);<br>
-   val->ssa = rzalloc(b, struct vtn_ssa_value);<br>
-   val->ssa->def = &atomic->dest.ssa;<br>
-   val->ssa->type = type->type;<br>
<span class="">+      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);<br>
</span>+      val->ssa = rzalloc(b, struct vtn_ssa_value);<br>
+      val->ssa->def = &atomic->dest.ssa;<br>
+      val->ssa->type = type->type;<br>
+   }<br>
<br>
    nir_builder_instr_insert(&b-><wbr>nb, &atomic->instr);<br>
 }<br>
@@ -2690,6 +2780,7 @@ vtn_handle_body_instruction(<wbr>struct vtn_builder *b, SpvOp opcode,<br>
       break;<br>
    }<br>
<br>
+   case SpvOpAtomicLoad:<br>
    case SpvOpAtomicExchange:<br>
    case SpvOpAtomicCompareExchange:<br>
    case SpvOpAtomicCompareExchangeWeak<wbr>:<br>
@@ -2714,6 +2805,17 @@ vtn_handle_body_instruction(<wbr>struct vtn_builder *b, SpvOp opcode,<br>
       break;<br>
    }<br>
<br>
+   case SpvOpAtomicStore: {<br>
+      struct vtn_value *pointer = vtn_untyped_value(b, w[1]);<br>
+      if (pointer->value_type == vtn_value_type_image_pointer) {<br>
+         vtn_handle_image(b, opcode, w, count);<br>
+      } else {<br>
+         assert(pointer->value_type == vtn_value_type_access_chain);<br>
+         vtn_handle_ssbo_or_shared_<wbr>atomic(b, opcode, w, count);<br>
+      }<br>
+      break;<br>
+   }<br>
+<br>
    case SpvOpSNegate:<br>
    case SpvOpFNegate:<br>
    case SpvOpNot:<br>
<div class="HOEnZb"><div class="h5">--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>