nir/spirv: plumb through the type of dereferences
We need this to know if a deref is of a builtin.
This commit is contained in:
@@ -398,14 +398,15 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SpvOpTypeMatrix: {
|
case SpvOpTypeMatrix: {
|
||||||
const struct glsl_type *base =
|
struct vtn_type *base =
|
||||||
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
vtn_value(b, w[2], vtn_value_type_type)->type;
|
||||||
unsigned columns = w[3];
|
unsigned columns = w[3];
|
||||||
|
|
||||||
assert(glsl_type_is_vector(base));
|
assert(glsl_type_is_vector(base->type));
|
||||||
val->type->type = glsl_matrix_type(glsl_get_base_type(base),
|
val->type->type = glsl_matrix_type(glsl_get_base_type(base->type),
|
||||||
glsl_get_vector_elements(base),
|
glsl_get_vector_elements(base->type),
|
||||||
columns);
|
columns);
|
||||||
|
val->type->array_element = base;
|
||||||
val->type->row_major = false;
|
val->type->row_major = false;
|
||||||
val->type->stride = 0;
|
val->type->stride = 0;
|
||||||
return;
|
return;
|
||||||
@@ -942,13 +943,13 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
{
|
{
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case SpvOpVariable: {
|
case SpvOpVariable: {
|
||||||
const struct glsl_type *type =
|
struct vtn_type *type =
|
||||||
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
vtn_value(b, w[1], vtn_value_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);
|
||||||
|
|
||||||
var->type = type;
|
var->type = type->type;
|
||||||
var->name = ralloc_strdup(var, val->name);
|
var->name = ralloc_strdup(var, val->name);
|
||||||
|
|
||||||
switch ((SpvStorageClass)w[3]) {
|
switch ((SpvStorageClass)w[3]) {
|
||||||
@@ -956,7 +957,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
case SpvStorageClassUniformConstant:
|
case SpvStorageClassUniformConstant:
|
||||||
var->data.mode = nir_var_uniform;
|
var->data.mode = nir_var_uniform;
|
||||||
var->data.read_only = true;
|
var->data.read_only = true;
|
||||||
var->interface_type = type;
|
var->interface_type = type->type;
|
||||||
break;
|
break;
|
||||||
case SpvStorageClassInput:
|
case SpvStorageClassInput:
|
||||||
var->data.mode = nir_var_shader_in;
|
var->data.mode = nir_var_shader_in;
|
||||||
@@ -987,6 +988,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val->deref = nir_deref_var_create(b, var);
|
val->deref = nir_deref_var_create(b, var);
|
||||||
|
val->deref_type = type;
|
||||||
|
|
||||||
vtn_foreach_decoration(b, val, var_decoration_cb, var);
|
vtn_foreach_decoration(b, val, var_decoration_cb, var);
|
||||||
|
|
||||||
@@ -1029,6 +1031,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
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_deref_var *base = vtn_value(b, w[3], vtn_value_type_deref)->deref;
|
nir_deref_var *base = vtn_value(b, w[3], vtn_value_type_deref)->deref;
|
||||||
val->deref = nir_deref_as_var(nir_copy_deref(b, &base->deref));
|
val->deref = nir_deref_as_var(nir_copy_deref(b, &base->deref));
|
||||||
|
val->deref_type = vtn_value(b, w[3], vtn_value_type_deref)->deref_type;
|
||||||
|
|
||||||
nir_deref *tail = &val->deref->deref;
|
nir_deref *tail = &val->deref->deref;
|
||||||
while (tail->child)
|
while (tail->child)
|
||||||
@@ -1047,15 +1050,17 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
case GLSL_TYPE_BOOL:
|
case GLSL_TYPE_BOOL:
|
||||||
case GLSL_TYPE_ARRAY: {
|
case GLSL_TYPE_ARRAY: {
|
||||||
nir_deref_array *deref_arr = nir_deref_array_create(b);
|
nir_deref_array *deref_arr = nir_deref_array_create(b);
|
||||||
if (base_type == GLSL_TYPE_ARRAY) {
|
if (base_type == GLSL_TYPE_ARRAY ||
|
||||||
deref_arr->deref.type = glsl_get_array_element(tail->type);
|
glsl_type_is_matrix(tail->type)) {
|
||||||
} else if (glsl_type_is_matrix(tail->type)) {
|
val->deref_type = val->deref_type->array_element;
|
||||||
deref_arr->deref.type = glsl_get_column_type(tail->type);
|
|
||||||
} else {
|
} else {
|
||||||
assert(glsl_type_is_vector(tail->type));
|
assert(glsl_type_is_vector(tail->type));
|
||||||
deref_arr->deref.type = glsl_scalar_type(base_type);
|
val->deref_type = ralloc(b, struct vtn_type);
|
||||||
|
val->deref_type->type = glsl_scalar_type(base_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deref_arr->deref.type = val->deref_type->type;
|
||||||
|
|
||||||
if (idx_val->value_type == vtn_value_type_constant) {
|
if (idx_val->value_type == vtn_value_type_constant) {
|
||||||
unsigned idx = idx_val->constant->value.u[0];
|
unsigned idx = idx_val->constant->value.u[0];
|
||||||
deref_arr->deref_array_type = nir_deref_array_type_direct;
|
deref_arr->deref_array_type = nir_deref_array_type_direct;
|
||||||
@@ -1074,8 +1079,9 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||||||
case GLSL_TYPE_STRUCT: {
|
case GLSL_TYPE_STRUCT: {
|
||||||
assert(idx_val->value_type == vtn_value_type_constant);
|
assert(idx_val->value_type == vtn_value_type_constant);
|
||||||
unsigned idx = idx_val->constant->value.u[0];
|
unsigned idx = idx_val->constant->value.u[0];
|
||||||
|
val->deref_type = val->deref_type->members[idx];
|
||||||
nir_deref_struct *deref_struct = nir_deref_struct_create(b, idx);
|
nir_deref_struct *deref_struct = nir_deref_struct_create(b, idx);
|
||||||
deref_struct->deref.type = glsl_get_struct_field(tail->type, idx);
|
deref_struct->deref.type = val->deref_type->type;
|
||||||
tail->child = &deref_struct->deref;
|
tail->child = &deref_struct->deref;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -117,7 +117,10 @@ struct vtn_value {
|
|||||||
nir_constant *constant;
|
nir_constant *constant;
|
||||||
const struct glsl_type *const_type;
|
const struct glsl_type *const_type;
|
||||||
};
|
};
|
||||||
nir_deref_var *deref;
|
struct {
|
||||||
|
nir_deref_var *deref;
|
||||||
|
struct vtn_type *deref_type;
|
||||||
|
};
|
||||||
struct vtn_function *func;
|
struct vtn_function *func;
|
||||||
struct vtn_block *block;
|
struct vtn_block *block;
|
||||||
struct vtn_ssa_value *ssa;
|
struct vtn_ssa_value *ssa;
|
||||||
|
Reference in New Issue
Block a user