mesa: add support cursor support for relative path shader includes
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 2 Sep 2019 02:31:17 +0000 (12:31 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 20 Nov 2019 05:05:56 +0000 (05:05 +0000)
This will allow us to continue searching the current path for
relative shader includes.

From the ARB_shading_language_include spec:

   "If it is quoted with double quotes in a previously included
   string, then the first search point will be the tree location
   where the previously included string had been found."

Reviewed-by: Witold Baryluk <witold.baryluk@gmail.com>
src/compiler/glsl/glcpp/glcpp-parse.y
src/compiler/glsl/glcpp/pp_standalone_scaffolding.c
src/compiler/glsl/glcpp/pp_standalone_scaffolding.h
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h

index 60323e449da38cfef31964baabef83e8abfc7f05..514dbe7a4c43acb4a2d032c03a63a005b52cf847 100644 (file)
@@ -36,6 +36,12 @@ const char *
 _mesa_lookup_shader_include(struct gl_context *ctx, char *path,
                             bool error_check);
 
+size_t
+_mesa_get_shader_include_cursor(struct gl_shared_state *shared);
+
+void
+_mesa_set_shader_include_cursor(struct gl_shared_state *shared, size_t cursor);
+
 static void
 yyerror(YYLTYPE *locp, glcpp_parser_t *parser, const char *error);
 
@@ -344,10 +350,14 @@ control_line_success:
                }
        }
 |      HASH_TOKEN INCLUDE NEWLINE {
+               size_t include_cursor = _mesa_get_shader_include_cursor(parser->gl_ctx->Shared);
+
                /* Remove leading and trailing "" or <> */
                char *start = strchr($2, '"');
-               if (!start)
+               if (!start) {
+                       _mesa_set_shader_include_cursor(parser->gl_ctx->Shared, 0);
                        start = strchr($2, '<');
+               }
                char *path = strndup(start + 1, strlen(start + 1) - 1);
 
                const char *shader =
@@ -410,6 +420,8 @@ control_line_success:
                        glcpp_lex_destroy(tmp_parser->scanner);
                        _mesa_hash_table_destroy(tmp_parser->defines, NULL);
                }
+
+               _mesa_set_shader_include_cursor(parser->gl_ctx->Shared, include_cursor);
        }
 |      HASH_TOKEN IF pp_tokens NEWLINE {
                /* Be careful to only evaluate the 'if' expression if
index ae5f63dc0b385e6a7fe398710ef2010cb32237cb..20a2252ee18286459a2823428adc35ad7b495b03 100644 (file)
@@ -39,3 +39,19 @@ _mesa_lookup_shader_include(struct gl_context *ctx, char *path,
 
    return NULL;
 }
+
+size_t
+_mesa_get_shader_include_cursor(struct gl_shared_state *shared)
+{
+   (void) shared;
+
+   return 0;
+}
+
+void
+_mesa_set_shader_include_cursor(struct gl_shared_state *shared,
+                                 size_t cursor)
+{
+   (void) shared;
+   (void) cursor;
+}
index de869d9b1a36f128bf492d131eefed8d1d761ca1..a35c04ee707e6a5c72f02ce935ba38520989bcf6 100644 (file)
@@ -37,4 +37,11 @@ const char *
 _mesa_lookup_shader_include(struct gl_context *ctx, char *path,
                             bool error_check);
 
+size_t
+_mesa_get_shader_include_cursor(struct gl_shared_state *shared);
+
+void
+_mesa_set_shader_include_cursor(struct gl_shared_state *shared,
+                                size_t cursor);
+
 #endif /* PP_STANDALONE_SCAFFOLDING_H */
index efbdda4ddb093bf43dc3aa541107ba302d169e9f..f028653700d1279ddcb83e63a22c2a17bc5cebba 100644 (file)
@@ -3162,6 +3162,7 @@ struct shader_includes {
    /* Array to hold include paths given to glCompileShaderIncludeARB() */
    struct sh_incl_path_entry **include_paths;
    size_t num_include_paths;
+   size_t relative_path_cursor;
 
    /* Root hash table holding the shader include tree */
    struct hash_table *shader_include_tree;
@@ -3176,6 +3177,18 @@ _mesa_init_shader_includes(struct gl_shared_state *shared)
                               _mesa_key_string_equal);
 }
 
+size_t
+_mesa_get_shader_include_cursor(struct gl_shared_state *shared)
+{
+   return shared->ShaderIncludes->relative_path_cursor;
+}
+
+void
+_mesa_set_shader_include_cursor(struct gl_shared_state *shared, size_t cursor)
+{
+   shared->ShaderIncludes->relative_path_cursor = cursor;
+}
+
 static void
 destroy_shader_include(struct hash_entry *entry)
 {
index 13cde963ff86954e5f1938d182da29f5fc5e06e5..66acb6a9694db56a2e6163ccf07f697e5e0140d9 100644 (file)
@@ -412,6 +412,12 @@ _mesa_dump_shader_source(const gl_shader_stage stage, const char *source);
 void
 _mesa_init_shader_includes(struct gl_shared_state *shared);
 
+size_t
+_mesa_get_shader_include_cursor(struct gl_shared_state *shared);
+
+void
+_mesa_set_shader_include_cursor(struct gl_shared_state *shared, size_t cusor);
+
 void
 _mesa_destroy_shader_includes(struct gl_shared_state *shared);