diff options
author | Timothy Arceri <[email protected]> | 2019-09-02 12:31:17 +1000 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2019-11-20 05:05:56 +0000 |
commit | 1201d3377ef8665797bf00839fd49a76e3e44101 (patch) | |
tree | 0ec23d706882ba8f9fcced2bdf4f23675029f203 /src/compiler/glsl/glcpp | |
parent | db5197cec54e7926211acef2ff3b40344f01b4f9 (diff) |
mesa: add support cursor support for relative path shader includes
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 <[email protected]>
Diffstat (limited to 'src/compiler/glsl/glcpp')
-rw-r--r-- | src/compiler/glsl/glcpp/glcpp-parse.y | 14 | ||||
-rw-r--r-- | src/compiler/glsl/glcpp/pp_standalone_scaffolding.c | 16 | ||||
-rw-r--r-- | src/compiler/glsl/glcpp/pp_standalone_scaffolding.h | 7 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index 60323e449da..514dbe7a4c4 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -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 diff --git a/src/compiler/glsl/glcpp/pp_standalone_scaffolding.c b/src/compiler/glsl/glcpp/pp_standalone_scaffolding.c index ae5f63dc0b3..20a2252ee18 100644 --- a/src/compiler/glsl/glcpp/pp_standalone_scaffolding.c +++ b/src/compiler/glsl/glcpp/pp_standalone_scaffolding.c @@ -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; +} diff --git a/src/compiler/glsl/glcpp/pp_standalone_scaffolding.h b/src/compiler/glsl/glcpp/pp_standalone_scaffolding.h index de869d9b1a3..a35c04ee707 100644 --- a/src/compiler/glsl/glcpp/pp_standalone_scaffolding.h +++ b/src/compiler/glsl/glcpp/pp_standalone_scaffolding.h @@ -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 */ |