mesa: add ARB_shading_language_include infrastructure to gl_shared_state

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
This commit is contained in:
Timothy Arceri
2019-08-15 14:34:39 +10:00
parent 35108caa71
commit 06f33d82ca
4 changed files with 77 additions and 0 deletions
+8
View File
@@ -77,6 +77,7 @@ struct prog_instruction;
struct gl_program_parameter_list;
struct gl_shader_spirv_data;
struct set;
struct shader_includes;
struct vbo_context;
/*@}*/
@@ -3322,6 +3323,13 @@ struct gl_shared_state
struct hash_table_u64 *ImageHandles;
mtx_t HandlesMutex; /**< For texture/image handles safety */
/* GL_ARB_shading_language_include */
struct shader_includes *ShaderIncludes;
/* glCompileShaderInclude expects ShaderIncludes not to change while it is
* in progress.
*/
mtx_t ShaderIncludeMutex;
/**
* Some context in this share group was affected by a GPU reset
*
+55
View File
@@ -3138,6 +3138,61 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype,
}
}
/* This is simple list entry that will be used to hold a list of string
* tokens of a parsed shader include path.
*/
struct sh_incl_path_entry
{
struct sh_incl_path_entry *next;
struct sh_incl_path_entry *prev;
char *path;
};
/* Nodes of the shader include tree */
struct sh_incl_path_ht_entry
{
struct hash_table *path;
char *shader_source;
};
struct shader_includes {
/* Array to hold include paths given to glCompileShaderIncludeARB() */
struct sh_incl_path_entry **include_paths;
size_t num_include_paths;
/* Root hash table holding the shader include tree */
struct hash_table *shader_include_tree;
};
void
_mesa_init_shader_includes(struct gl_shared_state *shared)
{
shared->ShaderIncludes = calloc(1, sizeof(struct shader_includes));
shared->ShaderIncludes->shader_include_tree =
_mesa_hash_table_create(NULL, _mesa_hash_string,
_mesa_key_string_equal);
}
static void
destroy_shader_include(struct hash_entry *entry)
{
struct sh_incl_path_ht_entry *sh_incl_ht_entry =
(struct sh_incl_path_ht_entry *) entry->data;
_mesa_hash_table_destroy(sh_incl_ht_entry->path, destroy_shader_include);
free(sh_incl_ht_entry->shader_source);
free(sh_incl_ht_entry);
}
void
_mesa_destroy_shader_includes(struct gl_shared_state *shared)
{
_mesa_hash_table_destroy(shared->ShaderIncludes->shader_include_tree,
destroy_shader_include);
free(shared->ShaderIncludes);
}
GLvoid GLAPIENTRY
_mesa_NamedStringARB(GLenum type, GLint namelen, const GLchar *name,
GLint stringlen, const GLchar *string)
+6
View File
@@ -409,6 +409,12 @@ _mesa_read_shader_source(const gl_shader_stage stage, const char *source);
void
_mesa_dump_shader_source(const gl_shader_stage stage, const char *source);
void
_mesa_init_shader_includes(struct gl_shared_state *shared);
void
_mesa_destroy_shader_includes(struct gl_shared_state *shared);
#ifdef __cplusplus
}
#endif
+8
View File
@@ -91,6 +91,10 @@ _mesa_alloc_shared_state(struct gl_context *ctx)
/* GL_ARB_bindless_texture */
_mesa_init_shared_handles(shared);
/* ARB_shading_language_include */
_mesa_init_shader_includes(shared);
mtx_init(&shared->ShaderIncludeMutex, mtx_plain);
/* Allocate the default buffer object */
shared->NullBufferObj = ctx->Driver.NewBufferObject(ctx, 0);
if (!shared->NullBufferObj)
@@ -441,6 +445,10 @@ free_shared_state(struct gl_context *ctx, struct gl_shared_state *shared)
_mesa_free_shared_handles(shared);
/* ARB_shading_language_include */
_mesa_destroy_shader_includes(shared);
mtx_destroy(&shared->ShaderIncludeMutex);
if (shared->MemoryObjects) {
_mesa_HashDeleteAll(shared->MemoryObjects, delete_memory_object_cb, ctx);
_mesa_DeleteHashTable(shared->MemoryObjects);