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

Alexandre Julliard julliard at winehq.org
Wed Jun 23 16:09:59 CDT 2021


Module: vkd3d
Branch: master
Commit: dbfe63d6a1f6b9f7ac5052ecd6efcd5b29f5a410
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=dbfe63d6a1f6b9f7ac5052ecd6efcd5b29f5a410

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Jun 21 23:37:10 2021 -0500

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

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 libs/vkd3d-shader/hlsl.c         |  6 ++++++
 libs/vkd3d-shader/hlsl.h         |  2 ++
 libs/vkd3d-shader/hlsl.y         | 16 +++++++++++-----
 libs/vkd3d-shader/hlsl_codegen.c |  1 +
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index aa95a43..c36fe60 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -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->extern_vars);
+
     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;
 }
 
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 16ec976..e2ac0a7 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -222,6 +222,7 @@ struct hlsl_ir_var
     struct vkd3d_shader_location loc;
     const char *name;
     struct hlsl_semantic semantic;
+    struct hlsl_buffer *buffer;
     unsigned int modifiers;
     struct hlsl_reg_reservation reg_reservation;
     struct list scope_entry, param_entry, extern_entry;
@@ -451,6 +452,7 @@ struct hlsl_ctx
     struct list extern_vars;
 
     struct list buffers;
+    struct hlsl_buffer *cur_buffer, *globals_buffer;
     struct list types;
     struct rb_tree functions;
     const struct hlsl_ir_function_decl *cur_function;
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 6f83648..4355b9a 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1393,6 +1393,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
             continue;
         }
 
+        var->buffer = ctx->cur_buffer;
+
         if (ctx->cur_scope == ctx->globals)
         {
             local = false;
@@ -1779,7 +1781,7 @@ hlsl_prog:
 
             hlsl_add_function(ctx, $2.name, $2.decl, false);
         }
-    | hlsl_prog buffer_declaration
+    | hlsl_prog buffer_declaration buffer_body
     | hlsl_prog declaration_statement
         {
             if (!list_empty($2))
@@ -1790,17 +1792,21 @@ hlsl_prog:
     | hlsl_prog ';'
 
 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)
                 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;
         }
 
+buffer_body:
+      '{' declaration_statement_list '}'
+        {
+            ctx->cur_buffer = ctx->globals_buffer;
+        }
+
 buffer_type:
       KW_CBUFFER
         {
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 54c91bf..068fb16 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -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);
     uniform->is_uniform = 1;
     uniform->is_param = temp->is_param;
+    uniform->buffer = temp->buffer;
 
     if (!(name = hlsl_get_string_buffer(ctx)))
         return;




More information about the wine-cvs mailing list