nir/spirv: add a vtn_type struct
This will handle decorations that aren't in the glsl_type.
This commit is contained in:
parent
f9bb95ad4a
commit
23c179be75
|
@ -139,9 +139,8 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
||||||
val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
|
||||||
val->ssa = rzalloc(b, struct vtn_ssa_value);
|
val->ssa = rzalloc(b, struct vtn_ssa_value);
|
||||||
val->ssa->type = val->type;
|
val->ssa->type = vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
|
|
||||||
/* Collect the various SSA sources */
|
/* Collect the various SSA sources */
|
||||||
unsigned num_inputs = count - 5;
|
unsigned num_inputs = count - 5;
|
||||||
|
@ -257,7 +256,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
|
|
||||||
nir_alu_instr *instr = nir_alu_instr_create(b->shader, op);
|
nir_alu_instr *instr = nir_alu_instr_create(b->shader, op);
|
||||||
nir_ssa_dest_init(&instr->instr, &instr->dest.dest,
|
nir_ssa_dest_init(&instr->instr, &instr->dest.dest,
|
||||||
glsl_get_vector_elements(val->type), val->name);
|
glsl_get_vector_elements(val->ssa->type), val->name);
|
||||||
val->ssa->def = &instr->dest.dest.ssa;
|
val->ssa->def = &instr->dest.dest.ssa;
|
||||||
|
|
||||||
for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
|
for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
|
||||||
|
|
|
@ -312,51 +312,66 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[1], vtn_value_type_type);
|
struct vtn_value *val = vtn_push_value(b, w[1], vtn_value_type_type);
|
||||||
|
|
||||||
|
val->type = ralloc(b, struct vtn_type);
|
||||||
|
val->type->is_builtin = false;
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SpvOpTypeVoid:
|
case SpvOpTypeVoid:
|
||||||
val->type = glsl_void_type();
|
val->type->type = glsl_void_type();
|
||||||
return;
|
return;
|
||||||
case SpvOpTypeBool:
|
case SpvOpTypeBool:
|
||||||
val->type = glsl_bool_type();
|
val->type->type = glsl_bool_type();
|
||||||
return;
|
return;
|
||||||
case SpvOpTypeInt:
|
case SpvOpTypeInt:
|
||||||
val->type = glsl_int_type();
|
val->type->type = glsl_int_type();
|
||||||
return;
|
return;
|
||||||
case SpvOpTypeFloat:
|
case SpvOpTypeFloat:
|
||||||
val->type = glsl_float_type();
|
val->type->type = glsl_float_type();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case SpvOpTypeVector: {
|
case SpvOpTypeVector: {
|
||||||
const struct glsl_type *base =
|
const struct glsl_type *base =
|
||||||
vtn_value(b, w[2], vtn_value_type_type)->type;
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
||||||
unsigned elems = w[3];
|
unsigned elems = w[3];
|
||||||
|
|
||||||
assert(glsl_type_is_scalar(base));
|
assert(glsl_type_is_scalar(base));
|
||||||
val->type = glsl_vector_type(glsl_get_base_type(base), elems);
|
val->type->type = glsl_vector_type(glsl_get_base_type(base), elems);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SpvOpTypeMatrix: {
|
case SpvOpTypeMatrix: {
|
||||||
const struct glsl_type *base =
|
const struct glsl_type *base =
|
||||||
vtn_value(b, w[2], vtn_value_type_type)->type;
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
||||||
unsigned columns = w[3];
|
unsigned columns = w[3];
|
||||||
|
|
||||||
assert(glsl_type_is_vector(base));
|
assert(glsl_type_is_vector(base));
|
||||||
val->type = glsl_matrix_type(glsl_get_base_type(base),
|
val->type->type = glsl_matrix_type(glsl_get_base_type(base),
|
||||||
glsl_get_vector_elements(base),
|
glsl_get_vector_elements(base),
|
||||||
columns);
|
columns);
|
||||||
|
val->type->row_major = false;
|
||||||
|
val->type->stride = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SpvOpTypeArray:
|
case SpvOpTypeArray: {
|
||||||
val->type = glsl_array_type(b->values[w[2]].type, w[3]);
|
struct vtn_type *array_element =
|
||||||
|
vtn_value(b, w[2], vtn_value_type_type)->type;
|
||||||
|
val->type->type = glsl_array_type(array_element->type, w[3]);
|
||||||
|
val->type->array_element = array_element;
|
||||||
|
val->type->stride = 0;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case SpvOpTypeStruct: {
|
case SpvOpTypeStruct: {
|
||||||
|
unsigned num_fields = count - 2;
|
||||||
|
val->type->members = ralloc_array(b, struct vtn_type *, num_fields);
|
||||||
|
|
||||||
NIR_VLA(struct glsl_struct_field, fields, count);
|
NIR_VLA(struct glsl_struct_field, fields, count);
|
||||||
for (unsigned i = 0; i < count - 2; i++) {
|
for (unsigned i = 0; i < num_fields; i++) {
|
||||||
/* TODO: Handle decorators */
|
/* TODO: Handle decorators */
|
||||||
fields[i].type = vtn_value(b, w[i + 2], vtn_value_type_type)->type;
|
val->type->members[i] =
|
||||||
|
vtn_value(b, w[i + 2], vtn_value_type_type)->type;
|
||||||
|
fields[i].type = val->type->members[i]->type;
|
||||||
fields[i].name = ralloc_asprintf(b, "field%d", i);
|
fields[i].name = ralloc_asprintf(b, "field%d", i);
|
||||||
fields[i].location = -1;
|
fields[i].location = -1;
|
||||||
fields[i].interpolation = 0;
|
fields[i].interpolation = 0;
|
||||||
|
@ -370,21 +385,22 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
||||||
|
|
||||||
const char *name = val->name ? val->name : "struct";
|
const char *name = val->name ? val->name : "struct";
|
||||||
|
|
||||||
val->type = glsl_struct_type(fields, count, name);
|
val->type->type = glsl_struct_type(fields, count, name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SpvOpTypeFunction: {
|
case SpvOpTypeFunction: {
|
||||||
const struct glsl_type *return_type = b->values[w[2]].type;
|
const struct glsl_type *return_type =
|
||||||
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
||||||
NIR_VLA(struct glsl_function_param, params, count - 3);
|
NIR_VLA(struct glsl_function_param, params, count - 3);
|
||||||
for (unsigned i = 0; i < count - 3; i++) {
|
for (unsigned i = 0; i < count - 3; i++) {
|
||||||
params[i].type = vtn_value(b, w[i + 3], vtn_value_type_type)->type;
|
params[i].type = vtn_value(b, w[i + 3], vtn_value_type_type)->type->type;
|
||||||
|
|
||||||
/* FIXME: */
|
/* FIXME: */
|
||||||
params[i].in = true;
|
params[i].in = true;
|
||||||
params[i].out = true;
|
params[i].out = true;
|
||||||
}
|
}
|
||||||
val->type = glsl_function_type(return_type, params, count - 3);
|
val->type->type = glsl_function_type(return_type, params, count - 3);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +414,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
||||||
|
|
||||||
case SpvOpTypeSampler: {
|
case SpvOpTypeSampler: {
|
||||||
const struct glsl_type *sampled_type =
|
const struct glsl_type *sampled_type =
|
||||||
vtn_value(b, w[2], vtn_value_type_type)->type;
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
||||||
|
|
||||||
assert(glsl_type_is_vector_or_scalar(sampled_type));
|
assert(glsl_type_is_vector_or_scalar(sampled_type));
|
||||||
|
|
||||||
|
@ -422,8 +438,8 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
||||||
|
|
||||||
assert(w[7] == 0 && "FIXME: Handl multi-sampled textures");
|
assert(w[7] == 0 && "FIXME: Handl multi-sampled textures");
|
||||||
|
|
||||||
val->type = glsl_sampler_type(dim, is_shadow, is_array,
|
val->type->type = glsl_sampler_type(dim, is_shadow, is_array,
|
||||||
glsl_get_base_type(sampled_type));
|
glsl_get_base_type(sampled_type));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +460,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_constant);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_constant);
|
||||||
val->const_type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
val->const_type = vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
val->constant = ralloc(b, nir_constant);
|
val->constant = ralloc(b, nir_constant);
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SpvOpConstantTrue:
|
case SpvOpConstantTrue:
|
||||||
|
@ -864,7 +880,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SpvOpVariable: {
|
case SpvOpVariable: {
|
||||||
const struct glsl_type *type =
|
const struct glsl_type *type =
|
||||||
vtn_value(b, w[1], vtn_value_type_type)->type;
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_deref);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_deref);
|
||||||
|
|
||||||
nir_variable *var = ralloc(b->shader, nir_variable);
|
nir_variable *var = ralloc(b->shader, nir_variable);
|
||||||
|
@ -1442,7 +1458,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
||||||
const struct glsl_type *type =
|
const struct glsl_type *type =
|
||||||
vtn_value(b, w[1], vtn_value_type_type)->type;
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
val->ssa = vtn_create_ssa_value(b, type);
|
val->ssa = vtn_create_ssa_value(b, type);
|
||||||
|
|
||||||
/* Collect the various SSA sources */
|
/* Collect the various SSA sources */
|
||||||
|
@ -1792,7 +1808,8 @@ vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
||||||
const struct glsl_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
const struct glsl_type *type =
|
||||||
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
val->ssa = vtn_create_ssa_value(b, type);
|
val->ssa = vtn_create_ssa_value(b, type);
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
@ -1880,7 +1897,8 @@ static void
|
||||||
vtn_handle_phi_first_pass(struct vtn_builder *b, const uint32_t *w)
|
vtn_handle_phi_first_pass(struct vtn_builder *b, const uint32_t *w)
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
||||||
const struct glsl_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
const struct glsl_type *type =
|
||||||
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
val->ssa = vtn_phi_node_create(b, type);
|
val->ssa = vtn_phi_node_create(b, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2068,10 +2086,10 @@ vtn_handle_first_cfg_pass_instruction(struct vtn_builder *b, SpvOp opcode,
|
||||||
b->func = rzalloc(b, struct vtn_function);
|
b->func = rzalloc(b, struct vtn_function);
|
||||||
|
|
||||||
const struct glsl_type *result_type =
|
const struct glsl_type *result_type =
|
||||||
vtn_value(b, w[1], vtn_value_type_type)->type;
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_function);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_function);
|
||||||
const struct glsl_type *func_type =
|
const struct glsl_type *func_type =
|
||||||
vtn_value(b, w[4], vtn_value_type_type)->type;
|
vtn_value(b, w[4], vtn_value_type_type)->type->type;
|
||||||
|
|
||||||
assert(glsl_get_function_return_type(func_type) == result_type);
|
assert(glsl_get_function_return_type(func_type) == result_type);
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,30 @@ struct vtn_ssa_value {
|
||||||
const struct glsl_type *type;
|
const struct glsl_type *type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct vtn_type {
|
||||||
|
const struct glsl_type *type;
|
||||||
|
|
||||||
|
/* for matrices, whether the matrix is stored row-major */
|
||||||
|
bool row_major;
|
||||||
|
|
||||||
|
/* for structs, the offset of each member */
|
||||||
|
unsigned *offsets;
|
||||||
|
|
||||||
|
/* for arrays and matrices, the array stride */
|
||||||
|
unsigned stride;
|
||||||
|
|
||||||
|
/* for arrays, the vtn_type for the elements of the array */
|
||||||
|
struct vtn_type *array_element;
|
||||||
|
|
||||||
|
/* for structures, the vtn_type for each member */
|
||||||
|
struct vtn_type **members;
|
||||||
|
|
||||||
|
/* Whether this type, or a parent type, has been decorated as a builtin */
|
||||||
|
bool is_builtin;
|
||||||
|
|
||||||
|
SpvBuiltIn builtin;
|
||||||
|
};
|
||||||
|
|
||||||
struct vtn_value {
|
struct vtn_value {
|
||||||
enum vtn_value_type value_type;
|
enum vtn_value_type value_type;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -88,7 +112,7 @@ struct vtn_value {
|
||||||
union {
|
union {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
char *str;
|
char *str;
|
||||||
const struct glsl_type *type;
|
struct vtn_type *type;
|
||||||
struct {
|
struct {
|
||||||
nir_constant *constant;
|
nir_constant *constant;
|
||||||
const struct glsl_type *const_type;
|
const struct glsl_type *const_type;
|
||||||
|
|
Loading…
Reference in New Issue