glsl: pass mem_ctx to constant_expression_value(...) and friends

The main motivation for this is that threaded compilation can fall
over if we were to allocate IR inside constant_expression_value()
when calling it on a builtin. This is because builtins are shared
across the whole OpenGL context.

f81ede4699 worked around the problem by cloning the entire
builtin before constant_expression_value() could be called on
it. However cloning the whole function each time we referenced
it lead to a significant reduction in the GLSL IR compiler
performance. This change along with the following patch
helps fix that performance regression.

Other advantages are that we reduce the number of calls to
ralloc_parent(), and for loop unrolling we free constants after
they are used rather than leaving them hanging around.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Timothy Arceri
2017-08-10 20:42:29 +10:00
parent d4f79e995f
commit 77f5221233
22 changed files with 168 additions and 90 deletions
+11 -6
View File
@@ -37,6 +37,7 @@ process_parameters(exec_list *instructions, exec_list *actual_parameters,
exec_list *parameters,
struct _mesa_glsl_parse_state *state)
{
void *mem_ctx = state;
unsigned count = 0;
foreach_list_typed(ast_node, ast, link, parameters) {
@@ -48,7 +49,9 @@ process_parameters(exec_list *instructions, exec_list *actual_parameters,
ast->set_is_lhs(true);
ir_rvalue *result = ast->hir(instructions, state);
ir_constant *const constant = result->constant_expression_value();
ir_constant *const constant =
result->constant_expression_value(mem_ctx);
if (constant != NULL)
result = constant;
@@ -518,7 +521,8 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
* instructions; just generate an ir_constant.
*/
if (state->is_version(120, 100)) {
ir_constant *value = sig->constant_expression_value(actual_parameters,
ir_constant *value = sig->constant_expression_value(ctx,
actual_parameters,
NULL);
if (value != NULL) {
return value;
@@ -939,7 +943,7 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
assert(result->type == desired_type);
/* Try constant folding; it may fold in the conversion we just added. */
ir_constant *const constant = result->constant_expression_value();
ir_constant *const constant = result->constant_expression_value(ctx);
return (constant != NULL) ? (ir_rvalue *) constant : (ir_rvalue *) result;
}
@@ -967,6 +971,7 @@ static bool
implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
struct _mesa_glsl_parse_state *state)
{
void *mem_ctx = state;
ir_rvalue *result = from;
if (to != from->type->base_type) {
@@ -985,7 +990,7 @@ implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
}
}
ir_rvalue *const constant = result->constant_expression_value();
ir_rvalue *const constant = result->constant_expression_value(mem_ctx);
if (constant != NULL)
result = constant;
@@ -2154,7 +2159,7 @@ ast_function_expression::hir(exec_list *instructions,
instructions->push_tail(
new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var),
matrix, NULL));
var->constant_value = matrix->constant_expression_value();
var->constant_value = matrix->constant_expression_value(ctx);
/* Replace the matrix with dereferences of its columns. */
for (int i = 0; i < matrix->type->matrix_columns; i++) {
@@ -2221,7 +2226,7 @@ ast_function_expression::hir(exec_list *instructions,
* After doing so, track whether or not all the parameters to the
* constructor are trivially constant valued expressions.
*/
ir_rvalue *const constant = result->constant_expression_value();
ir_rvalue *const constant = result->constant_expression_value(ctx);
if (constant != NULL)
result = constant;