glsl: Make accessor functions for ir_variable::interface_type.
In a future patch, this will allow us to enforce invariants when the interface type is updated. Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
This commit is contained in:
@@ -4725,7 +4725,7 @@ ast_interface_block::hir(exec_list *instructions,
|
|||||||
var_mode);
|
var_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
var->interface_type = block_type;
|
var->init_interface_type(block_type);
|
||||||
if (state->target == geometry_shader && var_mode == ir_var_shader_in)
|
if (state->target == geometry_shader && var_mode == ir_var_shader_in)
|
||||||
handle_geometry_shader_input_decl(state, loc, var);
|
handle_geometry_shader_input_decl(state, loc, var);
|
||||||
state->symbols->add_variable(var);
|
state->symbols->add_variable(var);
|
||||||
@@ -4741,7 +4741,7 @@ ast_interface_block::hir(exec_list *instructions,
|
|||||||
new(state) ir_variable(fields[i].type,
|
new(state) ir_variable(fields[i].type,
|
||||||
ralloc_strdup(state, fields[i].name),
|
ralloc_strdup(state, fields[i].name),
|
||||||
var_mode);
|
var_mode);
|
||||||
var->interface_type = block_type;
|
var->init_interface_type(block_type);
|
||||||
|
|
||||||
/* Propagate the "binding" keyword into this UBO's fields;
|
/* Propagate the "binding" keyword into this UBO's fields;
|
||||||
* the UBO declaration itself doesn't get an ir_variable unless it
|
* the UBO declaration itself doesn't get an ir_variable unless it
|
||||||
|
@@ -831,7 +831,7 @@ builtin_variable_generator::generate_varyings()
|
|||||||
"gl_in");
|
"gl_in");
|
||||||
ir_variable *var = add_variable("gl_in", array(per_vertex_type, 0),
|
ir_variable *var = add_variable("gl_in", array(per_vertex_type, 0),
|
||||||
ir_var_shader_in, 0);
|
ir_var_shader_in, 0);
|
||||||
var->interface_type = per_vertex_type;
|
var->init_interface_type(per_vertex_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -391,6 +391,20 @@ public:
|
|||||||
|| (t->is_array() && t->fields.array == this->interface_type);
|
|| (t->is_array() && t->fields.array == this->interface_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this->interface_type on a newly created variable.
|
||||||
|
*/
|
||||||
|
void init_interface_type(const struct glsl_type *type)
|
||||||
|
{
|
||||||
|
assert(this->interface_type == NULL);
|
||||||
|
this->interface_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const glsl_type *get_interface_type() const
|
||||||
|
{
|
||||||
|
return this->interface_type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declared type of the variable
|
* Declared type of the variable
|
||||||
*/
|
*/
|
||||||
@@ -582,6 +596,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
ir_constant *constant_initializer;
|
ir_constant *constant_initializer;
|
||||||
|
|
||||||
|
private:
|
||||||
/**
|
/**
|
||||||
* For variables that are in an interface block or are an instance of an
|
* For variables that are in an interface block or are an instance of an
|
||||||
* interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
|
* interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
|
||||||
|
@@ -47,7 +47,7 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog,
|
|||||||
if (!var)
|
if (!var)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const glsl_type *iface_type = var->interface_type;
|
const glsl_type *iface_type = var->get_interface_type();
|
||||||
|
|
||||||
if (iface_type == NULL)
|
if (iface_type == NULL)
|
||||||
continue;
|
continue;
|
||||||
@@ -81,32 +81,33 @@ validate_interstage_interface_blocks(struct gl_shader_program *prog,
|
|||||||
/* Add non-output interfaces from the consumer to the symbol table. */
|
/* Add non-output interfaces from the consumer to the symbol table. */
|
||||||
foreach_list(node, consumer->ir) {
|
foreach_list(node, consumer->ir) {
|
||||||
ir_variable *var = ((ir_instruction *) node)->as_variable();
|
ir_variable *var = ((ir_instruction *) node)->as_variable();
|
||||||
if (!var || !var->interface_type || var->mode == ir_var_shader_out)
|
if (!var || !var->get_interface_type() || var->mode == ir_var_shader_out)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
interfaces.add_interface(var->interface_type->name,
|
interfaces.add_interface(var->get_interface_type()->name,
|
||||||
var->interface_type,
|
var->get_interface_type(),
|
||||||
(enum ir_variable_mode) var->mode);
|
(enum ir_variable_mode) var->mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify that the producer's interfaces match. */
|
/* Verify that the producer's interfaces match. */
|
||||||
foreach_list(node, producer->ir) {
|
foreach_list(node, producer->ir) {
|
||||||
ir_variable *var = ((ir_instruction *) node)->as_variable();
|
ir_variable *var = ((ir_instruction *) node)->as_variable();
|
||||||
if (!var || !var->interface_type || var->mode == ir_var_shader_in)
|
if (!var || !var->get_interface_type() || var->mode == ir_var_shader_in)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
enum ir_variable_mode consumer_mode =
|
enum ir_variable_mode consumer_mode =
|
||||||
var->mode == ir_var_uniform ? ir_var_uniform : ir_var_shader_in;
|
var->mode == ir_var_uniform ? ir_var_uniform : ir_var_shader_in;
|
||||||
const glsl_type *expected_type =
|
const glsl_type *expected_type =
|
||||||
interfaces.get_interface(var->interface_type->name, consumer_mode);
|
interfaces.get_interface(var->get_interface_type()->name,
|
||||||
|
consumer_mode);
|
||||||
|
|
||||||
/* The consumer doesn't use this output block. Ignore it. */
|
/* The consumer doesn't use this output block. Ignore it. */
|
||||||
if (expected_type == NULL)
|
if (expected_type == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (var->interface_type != expected_type) {
|
if (var->get_interface_type() != expected_type) {
|
||||||
linker_error(prog, "definitions of interface block `%s' do not "
|
linker_error(prog, "definitions of interface block `%s' do not "
|
||||||
"match\n", var->interface_type->name);
|
"match\n", var->get_interface_type()->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,12 @@
|
|||||||
link_uniform_block_active *
|
link_uniform_block_active *
|
||||||
process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var)
|
process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var)
|
||||||
{
|
{
|
||||||
const uint32_t h = _mesa_hash_string(var->interface_type->name);
|
const uint32_t h = _mesa_hash_string(var->get_interface_type()->name);
|
||||||
const hash_entry *const existing_block =
|
const hash_entry *const existing_block =
|
||||||
_mesa_hash_table_search(ht, h, var->interface_type->name);
|
_mesa_hash_table_search(ht, h, var->get_interface_type()->name);
|
||||||
|
|
||||||
const glsl_type *const block_type = var->is_interface_instance()
|
const glsl_type *const block_type = var->is_interface_instance()
|
||||||
? var->type : var->interface_type;
|
? var->type : var->get_interface_type();
|
||||||
|
|
||||||
|
|
||||||
/* If a block with this block-name has not previously been seen, add it.
|
/* If a block with this block-name has not previously been seen, add it.
|
||||||
@@ -46,7 +46,7 @@ process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var)
|
|||||||
b->type = block_type;
|
b->type = block_type;
|
||||||
b->has_instance_name = var->is_interface_instance();
|
b->has_instance_name = var->is_interface_instance();
|
||||||
|
|
||||||
_mesa_hash_table_insert(ht, h, var->interface_type->name,
|
_mesa_hash_table_insert(ht, h, var->get_interface_type()->name,
|
||||||
(void *) b);
|
(void *) b);
|
||||||
return b;
|
return b;
|
||||||
} else {
|
} else {
|
||||||
@@ -90,7 +90,7 @@ link_uniform_block_active_visitor::visit_enter(ir_dereference_array *ir)
|
|||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
linker_error(prog,
|
linker_error(prog,
|
||||||
"uniform block `%s' has mismatching definitions",
|
"uniform block `%s' has mismatching definitions",
|
||||||
var->interface_type->name);
|
var->get_interface_type()->name);
|
||||||
this->success = false;
|
this->success = false;
|
||||||
return visit_stop;
|
return visit_stop;
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ link_uniform_block_active_visitor::visit(ir_dereference_variable *ir)
|
|||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
linker_error(this->prog,
|
linker_error(this->prog,
|
||||||
"uniform block `%s' has mismatching definitions",
|
"uniform block `%s' has mismatching definitions",
|
||||||
var->interface_type->name);
|
var->get_interface_type()->name);
|
||||||
this->success = false;
|
this->success = false;
|
||||||
return visit_stop;
|
return visit_stop;
|
||||||
}
|
}
|
||||||
|
@@ -199,8 +199,8 @@ public:
|
|||||||
{
|
{
|
||||||
this->is_ubo_var = var->is_in_uniform_block();
|
this->is_ubo_var = var->is_in_uniform_block();
|
||||||
if (var->is_interface_instance())
|
if (var->is_interface_instance())
|
||||||
program_resource_visitor::process(var->interface_type,
|
program_resource_visitor::process(var->get_interface_type(),
|
||||||
var->interface_type->name);
|
var->get_interface_type()->name);
|
||||||
else
|
else
|
||||||
program_resource_visitor::process(var);
|
program_resource_visitor::process(var);
|
||||||
}
|
}
|
||||||
@@ -317,10 +317,10 @@ public:
|
|||||||
ubo_block_index = -1;
|
ubo_block_index = -1;
|
||||||
if (var->is_in_uniform_block()) {
|
if (var->is_in_uniform_block()) {
|
||||||
if (var->is_interface_instance() && var->type->is_array()) {
|
if (var->is_interface_instance() && var->type->is_array()) {
|
||||||
unsigned l = strlen(var->interface_type->name);
|
unsigned l = strlen(var->get_interface_type()->name);
|
||||||
|
|
||||||
for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
|
for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
|
||||||
if (strncmp(var->interface_type->name,
|
if (strncmp(var->get_interface_type()->name,
|
||||||
prog->UniformBlocks[i].Name,
|
prog->UniformBlocks[i].Name,
|
||||||
l) == 0
|
l) == 0
|
||||||
&& prog->UniformBlocks[i].Name[l] == '[') {
|
&& prog->UniformBlocks[i].Name[l] == '[') {
|
||||||
@@ -330,7 +330,7 @@ public:
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
|
for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
|
||||||
if (strcmp(var->interface_type->name,
|
if (strcmp(var->get_interface_type()->name,
|
||||||
prog->UniformBlocks[i].Name) == 0) {
|
prog->UniformBlocks[i].Name) == 0) {
|
||||||
ubo_block_index = i;
|
ubo_block_index = i;
|
||||||
break;
|
break;
|
||||||
@@ -362,7 +362,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (var->is_interface_instance())
|
if (var->is_interface_instance())
|
||||||
process(var->interface_type, var->interface_type->name);
|
process(var->get_interface_type(),
|
||||||
|
var->get_interface_type()->name);
|
||||||
else
|
else
|
||||||
process(var);
|
process(var);
|
||||||
} else
|
} else
|
||||||
|
@@ -972,8 +972,8 @@ public:
|
|||||||
this->toplevel_var = var;
|
this->toplevel_var = var;
|
||||||
this->varying_floats = 0;
|
this->varying_floats = 0;
|
||||||
if (var->is_interface_instance())
|
if (var->is_interface_instance())
|
||||||
program_resource_visitor::process(var->interface_type,
|
program_resource_visitor::process(var->get_interface_type(),
|
||||||
var->interface_type->name);
|
var->get_interface_type()->name);
|
||||||
else
|
else
|
||||||
program_resource_visitor::process(var);
|
program_resource_visitor::process(var);
|
||||||
}
|
}
|
||||||
@@ -1083,10 +1083,10 @@ assign_varying_locations(struct gl_context *ctx,
|
|||||||
((ir_instruction *) node)->as_variable();
|
((ir_instruction *) node)->as_variable();
|
||||||
|
|
||||||
if ((input_var != NULL) && (input_var->mode == ir_var_shader_in)) {
|
if ((input_var != NULL) && (input_var->mode == ir_var_shader_in)) {
|
||||||
if (input_var->interface_type != NULL) {
|
if (input_var->get_interface_type() != NULL) {
|
||||||
char *const iface_field_name =
|
char *const iface_field_name =
|
||||||
ralloc_asprintf(mem_ctx, "%s.%s",
|
ralloc_asprintf(mem_ctx, "%s.%s",
|
||||||
input_var->interface_type->name,
|
input_var->get_interface_type()->name,
|
||||||
input_var->name);
|
input_var->name);
|
||||||
hash_table_insert(consumer_interface_inputs, input_var,
|
hash_table_insert(consumer_interface_inputs, input_var,
|
||||||
iface_field_name);
|
iface_field_name);
|
||||||
@@ -1108,10 +1108,10 @@ assign_varying_locations(struct gl_context *ctx,
|
|||||||
g.process(output_var);
|
g.process(output_var);
|
||||||
|
|
||||||
ir_variable *input_var;
|
ir_variable *input_var;
|
||||||
if (output_var->interface_type != NULL) {
|
if (output_var->get_interface_type() != NULL) {
|
||||||
char *const iface_field_name =
|
char *const iface_field_name =
|
||||||
ralloc_asprintf(mem_ctx, "%s.%s",
|
ralloc_asprintf(mem_ctx, "%s.%s",
|
||||||
output_var->interface_type->name,
|
output_var->get_interface_type()->name,
|
||||||
output_var->name);
|
output_var->name);
|
||||||
input_var =
|
input_var =
|
||||||
(ir_variable *) hash_table_find(consumer_interface_inputs,
|
(ir_variable *) hash_table_find(consumer_interface_inputs,
|
||||||
|
@@ -152,7 +152,7 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
|
|||||||
}
|
}
|
||||||
new_var->location = iface_t->fields.structure[i].location;
|
new_var->location = iface_t->fields.structure[i].location;
|
||||||
|
|
||||||
new_var->interface_type = iface_t;
|
new_var->init_interface_type(iface_t);
|
||||||
hash_table_insert(interface_namespace, new_var,
|
hash_table_insert(interface_namespace, new_var,
|
||||||
iface_field_name);
|
iface_field_name);
|
||||||
insert_pos->insert_after(new_var);
|
insert_pos->insert_after(new_var);
|
||||||
@@ -208,9 +208,9 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue)
|
|||||||
if (var->mode == ir_var_uniform)
|
if (var->mode == ir_var_uniform)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (var->interface_type != NULL) {
|
if (var->get_interface_type() != NULL) {
|
||||||
char *iface_field_name =
|
char *iface_field_name =
|
||||||
ralloc_asprintf(mem_ctx, "%s.%s", var->interface_type->name,
|
ralloc_asprintf(mem_ctx, "%s.%s", var->get_interface_type()->name,
|
||||||
ir->field);
|
ir->field);
|
||||||
/* Find the variable in the set of flattened interface blocks */
|
/* Find the variable in the set of flattened interface blocks */
|
||||||
ir_variable *found_var =
|
ir_variable *found_var =
|
||||||
|
@@ -132,7 +132,8 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
|
|||||||
mem_ctx = ralloc_parent(*rvalue);
|
mem_ctx = ralloc_parent(*rvalue);
|
||||||
|
|
||||||
const char *const field_name =
|
const char *const field_name =
|
||||||
interface_field_name(mem_ctx, (char *) var->interface_type->name, deref);
|
interface_field_name(mem_ctx, (char *) var->get_interface_type()->name,
|
||||||
|
deref);
|
||||||
|
|
||||||
this->uniform_block = -1;
|
this->uniform_block = -1;
|
||||||
for (unsigned i = 0; i < shader->NumUniformBlocks; i++) {
|
for (unsigned i = 0; i < shader->NumUniformBlocks; i++) {
|
||||||
|
Reference in New Issue
Block a user