From: Zebediah Figura zfigura@codeweavers.com
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 | 30 ++++++++++++++++++++++++------ libs/vkd3d-shader/hlsl.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 3bc0ac3c..9fde78c2 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,29 @@ 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; + TRACE("Pushing a new scope.\n"); + 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) @@ -2571,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 53ac3363..b2e36e7c 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -697,6 +697,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.