mesa/compiler: rework tear down of builtin/types

The issue we're running into when running CTS is that glsl types are
deleted while builtins depending on them are not.

This happens because on one hand we have glsl types ref counted, but
builtins are not. Instead builtins are destroyed when unloading libGL
or explicitly calling glReleaseShaderCompiler().

This change removes almost entirely any dealing with glsl types
ref/unref by letting the builtins deal with it instead. In turn we
introduce a builtin ref count mechanism. Each GL context takes a
reference on the builtins when compiling a shader for the first time.
It releases the reference when the context is destroyed. It can also
explicitly release those when glReleaseShaderCompiler() is called.

Finally we also take a reference on the glsl types when loading libGL
to avoid recreating glsl types too often.

v2: Ensure we take a reference if we don't have one in link step (Lionel)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110796
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
This commit is contained in:
Lionel Landwerlin
2019-07-31 12:12:10 +03:00
parent 9f37bc419c
commit e4da8b9c33
11 changed files with 65 additions and 79 deletions

View File

@@ -149,6 +149,7 @@
#endif
#include "compiler/glsl_types.h"
#include "compiler/glsl/builtin_functions.h"
#include "compiler/glsl/glsl_parser_extras.h"
#include <stdbool.h>
@@ -360,7 +361,7 @@ mtx_t OneTimeLock = _MTX_INITIALIZER_NP;
static void
one_time_fini(void)
{
_mesa_destroy_shader_compiler();
glsl_type_singleton_decref();
_mesa_locale_fini();
}
@@ -408,6 +409,11 @@ one_time_init( struct gl_context *ctx )
_mesa_debug(ctx, "Mesa " PACKAGE_VERSION " DEBUG build" MESA_GIT_SHA1 "\n");
}
#endif
/* Take a glsl type reference for the duration of libGL's life to avoid
* unecessary creation/destruction of glsl types.
*/
glsl_type_singleton_init_or_ref();
}
/* per-API one-time init */
@@ -1205,8 +1211,6 @@ _mesa_initialize_context(struct gl_context *ctx,
/* misc one-time initializations */
one_time_init(ctx);
_mesa_init_shader_compiler_types();
/* Plug in driver functions and context pointer here.
* This is important because when we call alloc_shared_state() below
* we'll call ctx->Driver.NewTextureObject() to create the default
@@ -1394,9 +1398,6 @@ _mesa_free_context_data(struct gl_context *ctx, bool destroy_compiler_types)
free(ctx->VersionString);
if (destroy_compiler_types)
_mesa_destroy_shader_compiler_types();
ralloc_free(ctx->SoftFP64);
/* unbind the context if it's currently bound */
@@ -1404,6 +1405,12 @@ _mesa_free_context_data(struct gl_context *ctx, bool destroy_compiler_types)
_mesa_make_current(NULL, NULL, NULL);
}
/* Do this after unbinding context to ensure any thread is finished. */
if (ctx->shader_builtin_ref) {
_mesa_glsl_builtin_functions_decref();
ctx->shader_builtin_ref = false;
}
free(ctx->Const.SpirVExtensions);
}