Module: vkd3d Branch: master Commit: 25d49b518daee771b725224a73df9be71b19ad0e URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/25d49b518daee771b725224a73df9b...
Author: Zebediah Figura zfigura@codeweavers.com Date: Tue Jan 31 22:18:35 2023 -0600
vkd3d-shader/hlsl: Put synthetic variables into a dummy scope.
Prevent them from being ever looked up.
Our naming scheme for synthetic variables already effectively prevents this, but this is better for clarity. We also will need to be able to move some named variables into a dummy scope to account for complexities around function definition and declarations.
---
libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++------ libs/vkd3d-shader/hlsl.h | 2 ++ 2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 5f4bd01a..0c51a57d 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -804,7 +804,7 @@ struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *tem var = hlsl_new_var(ctx, name, type, *loc, NULL, 0, NULL); hlsl_release_string_buffer(ctx, string); if (var) - list_add_tail(&ctx->globals->vars, &var->scope_entry); + list_add_tail(&ctx->dummy_scope->vars, &var->scope_entry); return var; }
@@ -1258,18 +1258,28 @@ static int compare_hlsl_types_rb(const void *key, const struct rb_entry *entry) return strcmp(name, type->name); }
+static struct hlsl_scope *hlsl_new_scope(struct hlsl_ctx *ctx, struct hlsl_scope *upper) +{ + struct hlsl_scope *scope; + + if (!(scope = hlsl_alloc(ctx, sizeof(*scope)))) + return NULL; + list_init(&scope->vars); + rb_init(&scope->types, compare_hlsl_types_rb); + scope->upper = upper; + list_add_tail(&ctx->scopes, &scope->entry); + return scope; +} + void hlsl_push_scope(struct hlsl_ctx *ctx) { struct hlsl_scope *new_scope;
- if (!(new_scope = hlsl_alloc(ctx, sizeof(*new_scope)))) + if (!(new_scope = hlsl_new_scope(ctx, ctx->cur_scope))) return; + TRACE("Pushing a new scope.\n"); - list_init(&new_scope->vars); - rb_init(&new_scope->types, compare_hlsl_types_rb); - new_scope->upper = ctx->cur_scope; ctx->cur_scope = new_scope; - list_add_tail(&ctx->scopes, &new_scope->entry); }
void hlsl_pop_scope(struct hlsl_ctx *ctx) @@ -2572,6 +2582,13 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const char *source_name, ctx->matrix_majority = HLSL_COLUMN_MAJOR;
list_init(&ctx->scopes); + + if (!(ctx->dummy_scope = hlsl_new_scope(ctx, NULL))) + { + vkd3d_free((void *)ctx->source_files[0]); + vkd3d_free(ctx->source_files); + return false; + } hlsl_push_scope(ctx); ctx->globals = ctx->cur_scope;
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index f6696e4e..567e3ad3 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -698,6 +698,8 @@ struct hlsl_ctx struct hlsl_scope *cur_scope; /* Scope of global variables. */ struct hlsl_scope *globals; + /* Dummy scope for variables which should never be looked up by name. */ + struct hlsl_scope *dummy_scope; /* List of all the scopes in the program; linked by the hlsl_scope.entry fields. */ struct list scopes; /* List of all the extern variables; linked by the hlsl_ir_var.extern_entry fields.