Very simple shaders don't actually use GLSL built-ins. For example:
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- gl_FragColor = vec4(0.0);
Both of the shaders used by _mesa_meta_glsl_Clear() also qualify.
By waiting to initialize the built-ins until the first time we need to
look for a signature, we can avoid the overhead entirely in these cases.
Makes piglit run roughly 18% faster (255 vs. 312 seconds).
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
/* The current shader doesn't contain a matching function or signature.
* Before giving up, look for the prototype in the built-in functions.
*/
+ _mesa_glsl_initialize_functions(state);
for (unsigned i = 0; i < state->num_builtins_to_link; i++) {
ir_function *builtin;
builtin = state->builtins_to_link[i]->symbols->get_function(name);
_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
{
_mesa_glsl_initialize_variables(instructions, state);
- _mesa_glsl_initialize_functions(state);
state->symbols->language_version = state->language_version;
void
_mesa_glsl_initialize_functions(struct _mesa_glsl_parse_state *state)
{
+ /* If we've already initialized the built-ins, bail early. */
+ if (state->num_builtins_to_link > 0)
+ return;
+
if (builtin_mem_ctx == NULL) {
builtin_mem_ctx = ralloc_context(NULL); // "GLSL built-in functions"
memset(&builtin_profiles, 0, sizeof(builtin_profiles));
}
-
- state->num_builtins_to_link = 0;
"""
i = 0
this->error = false;
this->loop_or_switch_nesting = NULL;
+ this->num_builtins_to_link = 0;
+
/* Set default language version and extensions */
this->language_version = 110;
this->es_shader = false;