mesa: add ARB_shading_language_include infrastructure to gl_shared_state
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 15 Aug 2019 04:34:39 +0000 (14:34 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 20 Nov 2019 05:05:55 +0000 (05:05 +0000)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
src/mesa/main/mtypes.h
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h
src/mesa/main/shared.c

index ae93dff40dac496798b2bef85394ceafca066604..9facc022ceca1faf6a95f9f8f9b62296cac6ed58 100644 (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
     *
index 7781609bc57baf1530f1929d0d349566b7867cad..760d046dcdeb73cb34446e9a20012dca284bc9de 100644 (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)
index 81318ca932bac694d58a08a25e1c396e40508963..8a9d94e1c1fceacc83701385e0d28abd6ee98382 100644 (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
index b6de835acefb3315094e32a73d5c64c25fa3ac68..07fdc76ee5650c169f9ad43e78eaf5cb8bb6367b 100644 (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);