diff options
author | Timothy Arceri <[email protected]> | 2019-08-15 14:34:39 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2019-11-20 05:05:55 +0000 |
commit | 06f33d82caffa71d40eb0189967b3183f0ff2eed (patch) | |
tree | ddffe57ff672fbac38aa3616a14be8bc7780296a /src | |
parent | 35108caa71d4da02303335ee52a0833fe650d85a (diff) |
mesa: add ARB_shading_language_include infrastructure to gl_shared_state
Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Reviewed-by: Witold Baryluk <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/main/mtypes.h | 8 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.c | 55 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.h | 6 | ||||
-rw-r--r-- | src/mesa/main/shared.c | 8 |
4 files changed, 77 insertions, 0 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index ae93dff40da..9facc022cec 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -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 * diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 7781609bc57..760d046dcde 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -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) diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h index 81318ca932b..8a9d94e1c1f 100644 --- a/src/mesa/main/shaderapi.h +++ b/src/mesa/main/shaderapi.h @@ -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 diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index b6de835acef..07fdc76ee56 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -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); |