[Mesa-dev] [PATCH 2/2] spirv: implement support for OpAtomicLoad for image pointers

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Jul 4 08:11:00 UTC 2018


Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
 src/compiler/spirv/spirv_to_nir.c | 33 +++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index e8ab48012f5..dc00d853c39 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2480,6 +2480,39 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
       return;
    }
 
+   if (opcode == SpvOpAtomicLoad) {
+      struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
+      struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
+
+      unsigned dest_components = nir_intrinsic_dest_components(intrin);
+      if (intrin->intrinsic == nir_intrinsic_image_deref_size) {
+         dest_components = intrin->num_components =
+            glsl_get_vector_elements(type->type);
+      }
+
+      nir_ssa_dest_init(&intrin->instr, &intrin->dest,
+                        dest_components, 32, NULL);
+
+      nir_builder_instr_insert(&b->nb, &intrin->instr);
+
+      /* Copy the vec4 value and get first component */
+      nir_ssa_dest_init(&intrin->instr, &intrin->dest,
+                        dest_components, 32, NULL);
+
+      nir_alu_instr *mov = nir_alu_instr_create(b->shader, nir_op_imov);
+      nir_ssa_dest_init(&mov->instr, &mov->dest.dest, 1,
+                        32, NULL);
+      mov->dest.write_mask = (1 << 1) - 1;
+      mov->src[0].src = nir_src_for_ssa(&intrin->dest.ssa);
+      mov->src[0].swizzle[0] = 0;
+      nir_builder_instr_insert(&b->nb, &mov->instr);
+
+      val->ssa = vtn_create_ssa_value(b, type->type);
+      val->ssa->def = &mov->dest.dest.ssa;
+
+      return;
+   }
+
    if (opcode != SpvOpImageWrite) {
       struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
       struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
-- 
2.17.1



More information about the mesa-dev mailing list