Module: Mesa
Branch: master
Commit: 7f852831030378923311b7b4c17eb16829406d28
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7f852831030378923311b7b4c17eb16829406d28

Author: Karol Herbst <[email protected]>
Date:   Fri Oct 26 00:42:52 2018 +0200

spirv/cl: support vload/vstore

Signed-off-by: Karol Herbst <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>

---

 src/compiler/spirv/vtn_opencl.c | 55 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c
index 5d37eeb64ea..f60878819f5 100644
--- a/src/compiler/spirv/vtn_opencl.c
+++ b/src/compiler/spirv/vtn_opencl.c
@@ -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;

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to