nir/spirv: Break variable creation out into a helper
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
parent
2e92d6a392
commit
4c21e6b7f8
|
@ -1327,27 +1327,18 @@ is_per_vertex_inout(const struct vtn_variable *var, gl_shader_stage stage)
|
|||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
||||
const uint32_t *w, unsigned count)
|
||||
static void
|
||||
vtn_create_variable(struct vtn_builder *b, struct vtn_value *val,
|
||||
struct vtn_type *type, SpvStorageClass storage_class,
|
||||
nir_constant *initializer)
|
||||
{
|
||||
switch (opcode) {
|
||||
case SpvOpUndef: {
|
||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_undef);
|
||||
val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||
break;
|
||||
}
|
||||
|
||||
case SpvOpVariable: {
|
||||
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||
|
||||
struct vtn_type *without_array = type;
|
||||
while(glsl_type_is_array(without_array->type))
|
||||
without_array = without_array->array_element;
|
||||
|
||||
enum vtn_variable_mode mode;
|
||||
nir_variable_mode nir_mode;
|
||||
mode = vtn_storage_class_to_mode(w[3], without_array, &nir_mode);
|
||||
mode = vtn_storage_class_to_mode(storage_class, without_array, &nir_mode);
|
||||
|
||||
switch (mode) {
|
||||
case vtn_variable_mode_ubo:
|
||||
|
@ -1374,7 +1365,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||
var->type = type;
|
||||
var->mode = mode;
|
||||
|
||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
|
||||
assert(val->value_type == vtn_value_type_pointer);
|
||||
val->pointer = vtn_pointer_for_variable(b, var);
|
||||
|
||||
switch (var->mode) {
|
||||
|
@ -1492,12 +1483,9 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||
break;
|
||||
}
|
||||
|
||||
if (count > 4) {
|
||||
assert(count == 5);
|
||||
nir_constant *constant =
|
||||
vtn_value(b, w[4], vtn_value_type_constant)->constant;
|
||||
if (initializer) {
|
||||
var->var->constant_initializer =
|
||||
nir_constant_clone(constant, var->var);
|
||||
nir_constant_clone(initializer, var->var);
|
||||
}
|
||||
|
||||
vtn_foreach_decoration(b, val, var_decoration_cb, var);
|
||||
|
@ -1531,6 +1519,30 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
|||
var->mode == vtn_variable_mode_ssbo ||
|
||||
var->mode == vtn_variable_mode_push_constant);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
|
||||
const uint32_t *w, unsigned count)
|
||||
{
|
||||
switch (opcode) {
|
||||
case SpvOpUndef: {
|
||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_undef);
|
||||
val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
||||
break;
|
||||
}
|
||||
|
||||
case SpvOpVariable: {
|
||||
struct vtn_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_pointer);
|
||||
|
||||
SpvStorageClass storage_class = w[3];
|
||||
nir_constant *initializer = NULL;
|
||||
if (count > 4)
|
||||
initializer = vtn_value(b, w[4], vtn_value_type_constant)->constant;
|
||||
|
||||
vtn_create_variable(b, val, type, storage_class, initializer);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue