* behavior we want for the results of texture lookups, but probably not for
*/
-extern "C" {
#include "main/core.h"
-#include "intel_context.h"
-}
-#include "../glsl/ir.h"
-#include "../glsl/ir_visitor.h"
-#include "../glsl/ir_print_visitor.h"
-#include "../glsl/ir_rvalue_visitor.h"
-#include "../glsl/glsl_types.h"
+#include "brw_context.h"
+#include "glsl/ir.h"
+#include "glsl/ir_visitor.h"
+#include "glsl/ir_rvalue_visitor.h"
+#include "glsl/glsl_types.h"
static bool debug = false;
{
this->var = var;
this->whole_vector_access = 0;
- this->declaration = false;
this->mem_ctx = NULL;
}
/** Number of times the variable is referenced, including assignments. */
unsigned whole_vector_access;
- bool declaration; /* If the variable had a decl in the instruction stream */
-
ir_variable *components[4];
- /** talloc_parent(this->var) -- the shader's talloc context. */
+ /** ralloc_parent(this->var) -- the shader's ralloc context. */
void *mem_ctx;
};
public:
ir_vector_reference_visitor(void)
{
- this->mem_ctx = talloc_new(NULL);
+ this->mem_ctx = ralloc_context(NULL);
this->variable_list.make_empty();
}
~ir_vector_reference_visitor(void)
{
- talloc_free(mem_ctx);
+ ralloc_free(mem_ctx);
}
virtual ir_visitor_status visit(ir_variable *);
if (!var->type->is_vector())
return NULL;
- switch (var->mode) {
+ switch (var->data.mode) {
case ir_var_uniform:
- case ir_var_in:
- case ir_var_out:
- case ir_var_inout:
+ case ir_var_shader_in:
+ case ir_var_shader_out:
+ case ir_var_system_value:
+ case ir_var_function_in:
+ case ir_var_function_out:
+ case ir_var_function_inout:
/* Can't split varyings or uniforms. Function in/outs won't get split
- * either, so don't care about the ambiguity.
+ * either.
*/
return NULL;
case ir_var_auto:
break;
}
- foreach_iter(exec_list_iterator, iter, this->variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
+ foreach_in_list(variable_entry, entry, &variable_list) {
if (entry->var == var)
return entry;
}
ir_visitor_status
ir_vector_reference_visitor::visit(ir_variable *ir)
{
- variable_entry *entry = this->get_variable_entry(ir);
-
- if (entry)
- entry->declaration = true;
+ /* Make sure splitting looks at splitting this variable */
+ (void)this->get_variable_entry(ir);
return visit_continue;
}
virtual ir_visitor_status visit_leave(ir_assignment *);
void handle_rvalue(ir_rvalue **rvalue);
- struct variable_entry *get_splitting_entry(ir_variable *var);
+ variable_entry *get_splitting_entry(ir_variable *var);
exec_list *variable_list;
};
-struct variable_entry *
+variable_entry *
ir_vector_splitting_visitor::get_splitting_entry(ir_variable *var)
{
assert(var);
if (!var->type->is_vector())
return NULL;
- foreach_iter(exec_list_iterator, iter, *this->variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
+ foreach_in_list(variable_entry, entry, variable_list) {
if (entry->var == var) {
return entry;
}
elem = 3;
break;
default:
- ir->print();
- assert(!"not reached: non-channelwise dereference of LHS.");
+ ir->fprint(stderr);
+ unreachable("not reached: non-channelwise dereference of LHS.");
}
ir->lhs = new(mem_ctx) ir_dereference_variable(lhs->components[elem]);
visit_list_elements(&refs, instructions);
/* Trim out variables we can't split. */
- foreach_iter(exec_list_iterator, iter, refs.variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
-
+ foreach_in_list_safe(variable_entry, entry, &refs.variable_list) {
if (debug) {
- printf("vector %s@%p: decl %d, whole_access %d\n",
- entry->var->name, (void *) entry->var, entry->declaration,
- entry->whole_vector_access);
+ fprintf(stderr, "vector %s@%p: whole_access %d\n",
+ entry->var->name, (void *) entry->var,
+ entry->whole_vector_access);
}
- if (!entry->declaration || entry->whole_vector_access) {
+ if (entry->whole_vector_access) {
entry->remove();
}
}
if (refs.variable_list.is_empty())
return false;
- void *mem_ctx = talloc_new(NULL);
+ void *mem_ctx = ralloc_context(NULL);
/* Replace the decls of the vectors to be split with their split
* components.
*/
- foreach_iter(exec_list_iterator, iter, refs.variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
+ foreach_in_list(variable_entry, entry, &refs.variable_list) {
const struct glsl_type *type;
type = glsl_type::get_instance(entry->var->type->base_type, 1, 1);
- entry->mem_ctx = talloc_parent(entry->var);
+ entry->mem_ctx = ralloc_parent(entry->var);
for (unsigned int i = 0; i < entry->var->type->vector_elements; i++) {
- const char *name = talloc_asprintf(mem_ctx, "%s_%c",
- entry->var->name,
- "xyzw"[i]);
+ char *const name = ir_variable::temporaries_allocate_names
+ ? ralloc_asprintf(mem_ctx, "%s_%c",
+ entry->var->name,
+ "xyzw"[i])
+ : NULL;
entry->components[i] = new(entry->mem_ctx) ir_variable(type, name,
ir_var_temporary);
+
+ ralloc_free(name);
+
entry->var->insert_before(entry->components[i]);
}
ir_vector_splitting_visitor split(&refs.variable_list);
visit_list_elements(&split, instructions);
- talloc_free(mem_ctx);
+ ralloc_free(mem_ctx);
return true;
}