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.
f81ede469910d 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.
Cc: Kenneth Graunke
Cc: Lionel Landwerlin
---
src/compiler/glsl/ast_array_index.cpp| 2 +-
src/compiler/glsl/ast_function.cpp | 17 ++--
src/compiler/glsl/ast_to_hir.cpp | 15 ++-
src/compiler/glsl/ast_type.cpp | 7 +-
src/compiler/glsl/ir.h | 37 +---
src/compiler/glsl/ir_constant_expression.cpp | 114 +++
src/compiler/glsl/linker.cpp | 2 +-
src/compiler/glsl/loop_controls.cpp | 6 +-
src/compiler/glsl/loop_unroll.cpp| 2 +-
src/compiler/glsl/lower_buffer_access.cpp| 2 +-
src/compiler/glsl/lower_distance.cpp | 3 +-
src/compiler/glsl/lower_tess_level.cpp | 3 +-
src/compiler/glsl/lower_vec_index_to_swizzle.cpp | 7 +-
src/compiler/glsl/lower_vector_derefs.cpp| 3 +-
src/compiler/glsl/lower_vector_insert.cpp| 3 +-
src/compiler/glsl/opt_algebraic.cpp | 9 +-
src/compiler/glsl/opt_constant_folding.cpp | 5 +-
src/compiler/glsl/opt_constant_propagation.cpp | 3 +-
src/compiler/glsl/opt_constant_variable.cpp | 2 +-
src/compiler/glsl/opt_if_simplification.cpp | 3 +-
src/mesa/program/ir_to_mesa.cpp | 6 +-
src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 7 +-
22 files changed, 168 insertions(+), 90 deletions(-)
diff --git a/src/compiler/glsl/ast_array_index.cpp
b/src/compiler/glsl/ast_array_index.cpp
index efddbed6ea..3b30f6858e 100644
--- a/src/compiler/glsl/ast_array_index.cpp
+++ b/src/compiler/glsl/ast_array_index.cpp
@@ -160,21 +160,21 @@ _mesa_ast_array_index_to_hir(void *mem_ctx,
} else if (!idx->type->is_scalar()) {
_mesa_glsl_error(& idx_loc, state, "array index must be scalar");
}
}
/* If the array index is a constant expression and the array has a
* declared size, ensure that the access is in-bounds. If the array
* index is not a constant expression, ensure that the array has a
* declared size.
*/
- ir_constant *const const_index = idx->constant_expression_value();
+ ir_constant *const const_index = idx->constant_expression_value(mem_ctx);
if (const_index != NULL && idx->type->is_integer()) {
const int idx = const_index->value.i[0];
const char *type_name = "error";
unsigned bound = 0;
/* From page 24 (page 30 of the PDF) of the GLSL 1.50 spec:
*
*"It is illegal to declare an array with a size, and then
*later (in the same shader) index the same array with an
*integral constant expression greater than or equal to the
diff --git a/src/compiler/glsl/ast_function.cpp
b/src/compiler/glsl/ast_function.cpp
index f7e90fba5b..b121ab9210 100644
--- a/src/compiler/glsl/ast_function.cpp
+++ b/src/compiler/glsl/ast_function.cpp
@@ -30,32 +30,35 @@
#include "builtin_functions.h"
static ir_rvalue *
convert_component(ir_rvalue *src, const glsl_type *desired_type);
static unsigned
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) {
/* We need to process the parameters first in order to know if we can
* raise or not a unitialized warning. Calling set_is_lhs silence the
* warning for now. Raising the warning or not will be checked at
* verify_parameter_modes.
*/
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;
actual_parameters->push_tail(result);
count++;
}
return count;
}
@@ -511,21 +514,22 @@ generate_call(exec_list *instructions,
ir_function_signature *sig,
* - a built-in function call whose arguments are all constant
* expressions, with the