vkd3d-shader: Keep track of the buffer in which a variable was defined.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-06-21 23:37:10 -05:00 committed by Alexandre Julliard
parent 4695690ac8
commit dbfe63d6a1
4 changed files with 20 additions and 5 deletions

View File

@ -1599,8 +1599,14 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct hlsl_profile_info *
list_init(&ctx->static_initializers); list_init(&ctx->static_initializers);
list_init(&ctx->extern_vars); list_init(&ctx->extern_vars);
list_init(&ctx->buffers); list_init(&ctx->buffers);
if (!(ctx->globals_buffer = hlsl_new_buffer(ctx, HLSL_BUFFER_CONSTANT,
hlsl_strdup(ctx, "$Globals"), NULL, ctx->location)))
return false;
ctx->cur_buffer = ctx->globals_buffer;
return true; return true;
} }

View File

@ -222,6 +222,7 @@ struct hlsl_ir_var
struct vkd3d_shader_location loc; struct vkd3d_shader_location loc;
const char *name; const char *name;
struct hlsl_semantic semantic; struct hlsl_semantic semantic;
struct hlsl_buffer *buffer;
unsigned int modifiers; unsigned int modifiers;
struct hlsl_reg_reservation reg_reservation; struct hlsl_reg_reservation reg_reservation;
struct list scope_entry, param_entry, extern_entry; struct list scope_entry, param_entry, extern_entry;
@ -451,6 +452,7 @@ struct hlsl_ctx
struct list extern_vars; struct list extern_vars;
struct list buffers; struct list buffers;
struct hlsl_buffer *cur_buffer, *globals_buffer;
struct list types; struct list types;
struct rb_tree functions; struct rb_tree functions;
const struct hlsl_ir_function_decl *cur_function; const struct hlsl_ir_function_decl *cur_function;

View File

@ -1393,6 +1393,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
continue; continue;
} }
var->buffer = ctx->cur_buffer;
if (ctx->cur_scope == ctx->globals) if (ctx->cur_scope == ctx->globals)
{ {
local = false; local = false;
@ -1779,7 +1781,7 @@ hlsl_prog:
hlsl_add_function(ctx, $2.name, $2.decl, false); hlsl_add_function(ctx, $2.name, $2.decl, false);
} }
| hlsl_prog buffer_declaration | hlsl_prog buffer_declaration buffer_body
| hlsl_prog declaration_statement | hlsl_prog declaration_statement
{ {
if (!list_empty($2)) if (!list_empty($2))
@ -1790,17 +1792,21 @@ hlsl_prog:
| hlsl_prog ';' | hlsl_prog ';'
buffer_declaration: buffer_declaration:
buffer_type any_identifier colon_attribute '{' declaration_statement_list '}' buffer_type any_identifier colon_attribute
{ {
struct hlsl_buffer *buffer;
if ($3.semantic.name) if ($3.semantic.name)
hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC, "Semantics are not allowed on buffers."); hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC, "Semantics are not allowed on buffers.");
if (!(buffer = hlsl_new_buffer(ctx, $1, $2, &$3.reg_reservation, @2))) if (!(ctx->cur_buffer = hlsl_new_buffer(ctx, $1, $2, &$3.reg_reservation, @2)))
YYABORT; YYABORT;
} }
buffer_body:
'{' declaration_statement_list '}'
{
ctx->cur_buffer = ctx->globals_buffer;
}
buffer_type: buffer_type:
KW_CBUFFER KW_CBUFFER
{ {

View File

@ -41,6 +41,7 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru
list_add_tail(&ctx->extern_vars, &uniform->extern_entry); list_add_tail(&ctx->extern_vars, &uniform->extern_entry);
uniform->is_uniform = 1; uniform->is_uniform = 1;
uniform->is_param = temp->is_param; uniform->is_param = temp->is_param;
uniform->buffer = temp->buffer;
if (!(name = hlsl_get_string_buffer(ctx))) if (!(name = hlsl_get_string_buffer(ctx)))
return; return;