mesa: add _mesa_lookup_shader_include() helper
authorTimothy Arceri <tarceri@itsqueeze.com>
Fri, 23 Aug 2019 04:36:53 +0000 (14:36 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 20 Nov 2019 05:05:55 +0000 (05:05 +0000)
This will be used both by the glsl compiler and the GL API.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h

index c7f5ac797e77593e088f256e70655be8ca5bb9db..7fe3d0d0a0e5df2f0120a3f7eb662ac5fd4b42a7 100644 (file)
@@ -3275,6 +3275,40 @@ validate_and_tokenise_sh_incl(struct gl_context *ctx,
    return true;
 }
 
+const char *
+_mesa_lookup_shader_include(struct gl_context *ctx, char *path)
+{
+   void *mem_ctx = ralloc_context(NULL);
+   struct sh_incl_path_entry *path_list;
+
+   if (!validate_and_tokenise_sh_incl(ctx, mem_ctx, &path_list, path)) {
+      ralloc_free(mem_ctx);
+      return NULL;
+   }
+
+   struct sh_incl_path_ht_entry *sh_incl_ht_entry = NULL;
+   struct hash_table *path_ht =
+      ctx->Shared->ShaderIncludes->shader_include_tree;
+
+   struct sh_incl_path_entry *entry;
+   foreach(entry, path_list) {
+      struct hash_entry *ht_entry =
+         _mesa_hash_table_search(path_ht, entry->path);
+
+      if (!ht_entry) {
+         return NULL;
+      } else {
+         sh_incl_ht_entry = (struct sh_incl_path_ht_entry *) ht_entry->data;
+      }
+
+      path_ht = sh_incl_ht_entry->path;
+   }
+
+   ralloc_free(mem_ctx);
+
+   return sh_incl_ht_entry ? sh_incl_ht_entry->shader_source : NULL;
+}
+
 GLvoid GLAPIENTRY
 _mesa_NamedStringARB(GLenum type, GLint namelen, const GLchar *name,
                      GLint stringlen, const GLchar *string)
index 8a9d94e1c1fceacc83701385e0d28abd6ee98382..05048672089658de642fce5ac42435ce599d34f4 100644 (file)
@@ -415,6 +415,9 @@ _mesa_init_shader_includes(struct gl_shared_state *shared);
 void
 _mesa_destroy_shader_includes(struct gl_shared_state *shared);
 
+const char *
+_mesa_lookup_shader_include(struct gl_context *ctx, char *path);
+
 #ifdef __cplusplus
 }
 #endif