+static void
+ptr_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
+ const struct vtn_decoration *dec, void *void_ptr)
+{
+ struct vtn_pointer *ptr = void_ptr;
+
+ switch (dec->decoration) {
+ case SpvDecorationNonUniformEXT:
+ ptr->access |= ACCESS_NON_UNIFORM;
+ break;
+
+ default:
+ break;
+ }
+}
+
+static struct vtn_pointer*
+vtn_decorate_pointer(struct vtn_builder *b, struct vtn_value *val,
+ struct vtn_pointer *ptr)
+{
+ struct vtn_pointer dummy = { .access = 0 };
+ vtn_foreach_decoration(b, val, ptr_decoration_cb, &dummy);
+
+ /* If we're adding access flags, make a copy of the pointer. We could
+ * probably just OR them in without doing so but this prevents us from
+ * leaking them any further than actually specified in the SPIR-V.
+ */
+ if (dummy.access & ~ptr->access) {
+ struct vtn_pointer *copy = ralloc(b, struct vtn_pointer);
+ *copy = *ptr;
+ copy->access |= dummy.access;
+ return copy;
+ }
+
+ return ptr;
+}
+
+struct vtn_value *
+vtn_push_pointer(struct vtn_builder *b, uint32_t value_id,
+ struct vtn_pointer *ptr)
+{
+ struct vtn_value *val = vtn_push_value(b, value_id, vtn_value_type_pointer);
+ val->pointer = vtn_decorate_pointer(b, val, ptr);
+ return val;
+}
+
+void
+vtn_copy_value(struct vtn_builder *b, uint32_t src_value_id,
+ uint32_t dst_value_id)
+{
+ struct vtn_value *src = vtn_untyped_value(b, src_value_id);
+ struct vtn_value *dst = vtn_untyped_value(b, dst_value_id);
+ struct vtn_value src_copy = *src;
+
+ vtn_fail_if(dst->value_type != vtn_value_type_invalid,
+ "SPIR-V id %u has already been written by another instruction",
+ dst_value_id);
+
+ vtn_fail_if(dst->type->id != src->type->id,
+ "Result Type must equal Operand type");
+
+ src_copy.name = dst->name;
+ src_copy.decoration = dst->decoration;
+ src_copy.type = dst->type;
+ *dst = src_copy;
+
+ if (dst->value_type == vtn_value_type_pointer)
+ dst->pointer = vtn_decorate_pointer(b, dst, dst->pointer);
+}
+