spirv/cl: support vload/vstore
authorKarol Herbst <kherbst@redhat.com>
Thu, 25 Oct 2018 22:42:52 +0000 (00:42 +0200)
committerKarol Herbst <kherbst@redhat.com>
Sat, 4 May 2019 10:27:51 +0000 (12:27 +0200)
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/spirv/vtn_opencl.c

index 5d37eeb64ea7c7fcfe8f721092aedf7ccf931c42..f60878819f51e8575d891150da69f4fec88a8840 100644 (file)
@@ -182,6 +182,55 @@ handle_special(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
    }
 }
 
+static void
+_handle_v_load_store(struct vtn_builder *b, enum OpenCLstd opcode,
+                     const uint32_t *w, unsigned count, bool load)
+{
+   struct vtn_type *type;
+   if (load)
+      type = vtn_value(b, w[1], vtn_value_type_type)->type;
+   else
+      type = vtn_untyped_value(b, w[5])->type;
+   unsigned a = load ? 0 : 1;
+
+   const struct glsl_type *dest_type = type->type;
+   unsigned components = glsl_get_vector_elements(dest_type);
+   unsigned stride = components * glsl_get_bit_size(dest_type) / 8;
+
+   nir_ssa_def *offset = vtn_ssa_value(b, w[5 + a])->def;
+   struct vtn_value *p = vtn_value(b, w[6 + a], vtn_value_type_pointer);
+
+   nir_deref_instr *deref = vtn_pointer_to_deref(b, p->pointer);
+
+   /* 1. cast to vec type with adjusted stride */
+   deref = nir_build_deref_cast(&b->nb, &deref->dest.ssa, deref->mode,
+                                dest_type, stride);
+   /* 2. deref ptr_as_array */
+   deref = nir_build_deref_ptr_as_array(&b->nb, deref, offset);
+
+   if (load) {
+      struct vtn_ssa_value *val = vtn_local_load(b, deref, p->type->access);
+      vtn_push_ssa(b, w[2], type, val);
+   } else {
+      struct vtn_ssa_value *val = vtn_ssa_value(b, w[5]);
+      vtn_local_store(b, val, deref, p->type->access);
+   }
+}
+
+static void
+vtn_handle_opencl_vload(struct vtn_builder *b, enum OpenCLstd opcode,
+                        const uint32_t *w, unsigned count)
+{
+   _handle_v_load_store(b, opcode, w, count, true);
+}
+
+static void
+vtn_handle_opencl_vstore(struct vtn_builder *b, enum OpenCLstd opcode,
+                         const uint32_t *w, unsigned count)
+{
+   _handle_v_load_store(b, opcode, w, count, false);
+}
+
 static nir_ssa_def *
 handle_printf(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs,
               nir_ssa_def **srcs, const struct glsl_type *dest_type)
@@ -262,6 +311,12 @@ vtn_handle_opencl_instruction(struct vtn_builder *b, uint32_t ext_opcode,
    case U_Upsample:
       handle_instr(b, ext_opcode, w, count, handle_special);
       return true;
+   case Vloadn:
+      vtn_handle_opencl_vload(b, ext_opcode, w, count);
+      return true;
+   case Vstoren:
+      vtn_handle_opencl_vstore(b, ext_opcode, w, count);
+      return true;
    case Printf:
       handle_instr(b, ext_opcode, w, count, handle_printf);
       return true;