}
}
+struct vtn_value *
+vtn_push_nir_ssa(struct vtn_builder *b, uint32_t value_id, nir_ssa_def *def)
+{
+ /* Types for all SPIR-V SSA values are set as part of a pre-pass so the
+ * type will be valid by the time we get here.
+ */
+ struct vtn_type *type = vtn_get_value_type(b, value_id);
+ vtn_fail_if(def->num_components != glsl_get_vector_elements(type->type) ||
+ def->bit_size != glsl_get_bit_size(type->type),
+ "Mismatch between NIR and SPIR-V type.");
+ struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, type->type);
+ ssa->def = def;
+ return vtn_push_ssa(b, value_id, type, ssa);
+}
+
static char *
vtn_string_literal(struct vtn_builder *b, const uint32_t *words,
unsigned word_count, unsigned *words_used)
}
}
- struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, ret_type->type);
- ssa->def = &instr->dest.ssa;
- vtn_push_ssa(b, w[2], ret_type, ssa);
-
nir_builder_instr_insert(&b->nb, &instr->instr);
+
+ vtn_push_nir_ssa(b, w[2], &instr->dest.ssa);
}
static void
if (nir_intrinsic_dest_components(intrin) != dest_components)
result = nir_channels(&b->nb, result, (1 << dest_components) - 1);
- struct vtn_value *val =
- vtn_push_ssa(b, w[2], type, vtn_create_ssa_value(b, type->type));
- val->ssa->def = result;
+ vtn_push_nir_ssa(b, w[2], result);
} else {
nir_builder_instr_insert(&b->nb, &intrin->instr);
}
glsl_get_vector_elements(type->type),
glsl_get_bit_size(type->type), NULL);
- struct vtn_ssa_value *ssa = rzalloc(b, struct vtn_ssa_value);
- ssa->def = &atomic->dest.ssa;
- ssa->type = type->type;
- vtn_push_ssa(b, w[2], type, ssa);
+ vtn_push_nir_ssa(b, w[2], &atomic->dest.ssa);
}
nir_builder_instr_insert(&b->nb, &atomic->instr);
unreachable("Invalid ptr operation");
}
- struct vtn_ssa_value *ssa_value = vtn_create_ssa_value(b, type);
- ssa_value->def = def;
- vtn_push_ssa(b, w[2], vtn_type, ssa_value);
+ vtn_push_nir_ssa(b, w[2], def);
}
static bool
nir_ssa_dest_init(&intrin->instr, &intrin->dest, 1, 1, NULL);
nir_builder_instr_insert(&b->nb, &intrin->instr);
- struct vtn_type *res_type = vtn_get_type(b, w[1]);
- struct vtn_ssa_value *val = vtn_create_ssa_value(b, res_type->type);
- val->def = &intrin->dest.ssa;
-
- vtn_push_ssa(b, w[2], res_type, val);
+ vtn_push_nir_ssa(b, w[2], &intrin->dest.ssa);
break;
}
result = nir_pack_64_2x32(&b->nb, &intrin->dest.ssa);
}
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->type = type;
- val->ssa = vtn_create_ssa_value(b, dest_type);
- val->ssa->def = result;
+ vtn_push_nir_ssa(b, w[2], result);
break;
}
struct vtn_type *type = vtn_get_type(b, w[1]);
struct vtn_ssa_value *vtn_src = vtn_ssa_value(b, w[3]);
struct nir_ssa_def *src = vtn_src->def;
- struct vtn_ssa_value *val = vtn_create_ssa_value(b, type->type);
vtn_assert(glsl_type_is_vector_or_scalar(vtn_src->type));
glsl_get_vector_elements(type->type) * glsl_get_bit_size(type->type),
"Source and destination of OpBitcast must have the same "
"total number of bits");
- val->def = nir_bitcast_vector(&b->nb, src, glsl_get_bit_size(type->type));
- vtn_push_ssa(b, w[2], type, val);
+ nir_ssa_def *val =
+ nir_bitcast_vector(&b->nb, src, glsl_get_bit_size(type->type));
+ vtn_push_nir_ssa(b, w[2], val);
}
handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,
const uint32_t *w, unsigned count)
{
- const struct glsl_type *dest_type = vtn_get_type(b, w[1])->type;
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = vtn_create_ssa_value(b, dest_type);
-
nir_intrinsic_op op;
switch (opcode) {
case GLSLstd450InterpolateAtCentroid:
nir_builder_instr_insert(&b->nb, &intrin->instr);
- if (vec_array_deref) {
- assert(vec_deref);
- val->ssa->def = nir_vector_extract(&b->nb, &intrin->dest.ssa,
- vec_deref->arr.index.ssa);
- } else {
- val->ssa->def = &intrin->dest.ssa;
- }
+ nir_ssa_def *def = &intrin->dest.ssa;
+ if (vec_array_deref)
+ def = nir_vector_extract(&b->nb, def, vec_deref->arr.index.ssa);
+
+ vtn_push_nir_ssa(b, w[2], def);
}
bool
{
switch ((enum GLSLstd450)ext_opcode) {
case GLSLstd450Determinant: {
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = rzalloc(b, struct vtn_ssa_value);
- val->ssa->type = vtn_get_type(b, w[1])->type;
- val->ssa->def = build_mat_det(b, vtn_ssa_value(b, w[5]));
+ vtn_push_nir_ssa(b, w[2], build_mat_det(b, vtn_ssa_value(b, w[5])));
break;
}
nir_ssa_def *result = handler(b, opcode, num_srcs, srcs, dest_type);
if (result) {
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = vtn_create_ssa_value(b, dest_type);
- val->ssa->def = result;
+ vtn_push_nir_ssa(b, w[2], result);
} else {
vtn_assert(dest_type == glsl_void_type());
}
}
}
if (load) {
- struct vtn_ssa_value *ssa = vtn_create_ssa_value(b, dest_type);
- ssa->def = nir_vec(&b->nb, ncomps, components);
- vtn_push_ssa(b, w[2], type, ssa);
+ vtn_push_nir_ssa(b, w[2], nir_vec(&b->nb, ncomps, components));
}
}
struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id);
+struct vtn_value *vtn_push_nir_ssa(struct vtn_builder *b, uint32_t value_id,
+ nir_ssa_def *def);
+
struct vtn_value *vtn_push_pointer(struct vtn_builder *b,
uint32_t value_id,
struct vtn_pointer *ptr);
nir_imm_int(&b->nb, 0u)),
nir_imm_int(&b->nb, stride));
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = vtn_create_ssa_value(b, glsl_uint_type());
- val->ssa->def = array_length;
+ vtn_push_nir_ssa(b, w[2], array_length);
break;
}