+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_value_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;
+}
+
+static void
+ssa_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member,
+ const struct vtn_decoration *dec, void *void_ctx)
+{
+ switch (dec->decoration) {
+ case SpvDecorationNonUniformEXT:
+ if (val->value_type == vtn_value_type_ssa) {
+ val->ssa->access |= ACCESS_NON_UNIFORM;
+ } else if (val->value_type == vtn_value_type_pointer) {
+ val->pointer->access |= ACCESS_NON_UNIFORM;
+ } else if (val->value_type == vtn_value_type_sampled_image) {
+ val->sampled_image->image->access |= ACCESS_NON_UNIFORM;
+ } else if (val->value_type == vtn_value_type_image_pointer) {
+ val->image->image->access |= ACCESS_NON_UNIFORM;
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+struct vtn_value *
+vtn_push_ssa(struct vtn_builder *b, uint32_t value_id,
+ struct vtn_type *type, struct vtn_ssa_value *ssa)
+{
+ struct vtn_value *val;
+ if (type->base_type == vtn_base_type_pointer) {
+ val = vtn_push_value_pointer(b, value_id, vtn_pointer_from_ssa(b, ssa->def, type));
+ } else {
+ val = vtn_push_value(b, value_id, vtn_value_type_ssa);
+ val->ssa = ssa;
+ vtn_foreach_decoration(b, val, ssa_decoration_cb, NULL);
+ }
+ 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_push_value(b, dst_value_id, src->value_type);
+ struct vtn_value src_copy = *src;
+
+ 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;
+
+ vtn_foreach_decoration(b, dst, ssa_decoration_cb, NULL);
+}
+