Zebediah Figura : vkd3d-shader: Add predefined macros to the macro list.

Alexandre Julliard julliard at winehq.org
Tue Jan 26 15:53:16 CST 2021


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Jan 25 11:23:57 2021 -0600

vkd3d-shader: Add predefined macros to the macro list.

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/preproc.h |  2 ++
 libs/vkd3d-shader/preproc.l | 31 +++++++++++++++++++++++++------
 libs/vkd3d-shader/preproc.y |  4 ++--
 tests/hlsl_d3d12.c          | 10 +++++-----
 4 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/libs/vkd3d-shader/preproc.h b/libs/vkd3d-shader/preproc.h
index eff70f6..15d173a 100644
--- a/libs/vkd3d-shader/preproc.h
+++ b/libs/vkd3d-shader/preproc.h
@@ -130,6 +130,8 @@ struct preproc_ctx
     bool error;
 };
 
+bool preproc_add_macro(struct preproc_ctx *ctx, const struct vkd3d_shader_location *loc, char *name, char **arg_names,
+        size_t arg_count, const struct vkd3d_shader_location *body_loc, struct vkd3d_string_buffer *body) DECLSPEC_HIDDEN;
 void preproc_close_include(struct preproc_ctx *ctx, const struct vkd3d_shader_code *code) DECLSPEC_HIDDEN;
 struct preproc_macro *preproc_find_macro(struct preproc_ctx *ctx, const char *name) DECLSPEC_HIDDEN;
 void preproc_free_macro(struct preproc_macro *macro) DECLSPEC_HIDDEN;
diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l
index 0ce75f0..c17b9d6 100644
--- a/libs/vkd3d-shader/preproc.l
+++ b/libs/vkd3d-shader/preproc.l
@@ -717,8 +717,9 @@ int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
 {
     static const struct vkd3d_shader_preprocess_info default_preprocess_info = {0};
     struct preproc_ctx ctx = {0};
-    char *source_name;
+    char *source_name = NULL;
     void *output_code;
+    unsigned int i;
 
     vkd3d_string_buffer_init(&ctx.buffer);
     rb_init(&ctx.macros, preproc_macro_compare);
@@ -727,18 +728,30 @@ int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
     ctx.message_context = message_context;
 
     if (!(source_name = vkd3d_strdup(compile_info->source_name ? compile_info->source_name : "<anonymous>")))
+        goto fail;
+
+    for (i = 0; i < ctx.preprocess_info->macro_count; ++i)
     {
-        vkd3d_string_buffer_cleanup(&ctx.buffer);
-        return VKD3D_ERROR_OUT_OF_MEMORY;
+        const struct vkd3d_shader_location loc = {.source_name = source_name};
+        struct vkd3d_string_buffer body;
+        char *name;
+
+        vkd3d_string_buffer_init(&body);
+        vkd3d_string_buffer_printf(&body, "%s", ctx.preprocess_info->macros[i].value);
+        if (!(name = vkd3d_strdup(ctx.preprocess_info->macros[i].name)))
+            goto fail;
+        if (!preproc_add_macro(&ctx, &loc, name, NULL, 0, &loc, &body))
+        {
+            vkd3d_free(name);
+            goto fail;
+        }
     }
 
     yylex_init_extra(&ctx, &ctx.scanner);
     if (!preproc_push_include(&ctx, source_name, &compile_info->source))
     {
         yylex_destroy(ctx.scanner);
-        vkd3d_free(source_name);
-        vkd3d_string_buffer_cleanup(&ctx.buffer);
-        return VKD3D_ERROR_OUT_OF_MEMORY;
+        goto fail;
     }
 
     preproc_yyparse(ctx.scanner, &ctx);
@@ -789,4 +802,10 @@ int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
     vkd3d_string_buffer_trace(&ctx.buffer);
     vkd3d_string_buffer_cleanup(&ctx.buffer);
     return VKD3D_OK;
+
+fail:
+    rb_destroy(&ctx.macros, preproc_macro_rb_free, NULL);
+    vkd3d_free(source_name);
+    vkd3d_string_buffer_cleanup(&ctx.buffer);
+    return VKD3D_ERROR_OUT_OF_MEMORY;
 }
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y
index 01437b2..ac6f647 100644
--- a/libs/vkd3d-shader/preproc.y
+++ b/libs/vkd3d-shader/preproc.y
@@ -83,8 +83,8 @@ struct preproc_macro *preproc_find_macro(struct preproc_ctx *ctx, const char *na
     return NULL;
 }
 
-static bool preproc_add_macro(struct preproc_ctx *ctx, const struct vkd3d_shader_location *loc, char *name,
-        char **arg_names, size_t arg_count, const struct vkd3d_shader_location *body_loc, struct vkd3d_string_buffer *body)
+bool preproc_add_macro(struct preproc_ctx *ctx, const struct vkd3d_shader_location *loc, char *name, char **arg_names,
+        size_t arg_count, const struct vkd3d_shader_location *body_loc, struct vkd3d_string_buffer *body)
 {
     struct preproc_macro *macro;
     unsigned int i;
diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c
index 837476d..da8e0ea 100644
--- a/tests/hlsl_d3d12.c
+++ b/tests/hlsl_d3d12.c
@@ -358,7 +358,7 @@ static void test_preprocess(void)
     macros[0].Definition = "value";
     macros[1].Name = NULL;
     macros[1].Definition = NULL;
-    todo check_preprocess("KEY", macros, NULL, "value", "KEY");
+    check_preprocess("KEY", macros, NULL, "value", "KEY");
 
     check_preprocess("#undef KEY\nKEY", macros, NULL, "KEY", "value");
 
@@ -367,7 +367,7 @@ static void test_preprocess(void)
 
     macros[0].Name = "KEY";
     macros[0].Definition = NULL;
-    todo check_preprocess("KEY", macros, NULL, NULL, "KEY");
+    check_preprocess("KEY", macros, NULL, NULL, "KEY");
 
     macros[0].Name = "0";
     macros[0].Definition = "value";
@@ -383,19 +383,19 @@ static void test_preprocess(void)
     macros[1].Definition = "value2";
     macros[2].Name = NULL;
     macros[2].Definition = NULL;
-    todo check_preprocess("KEY", macros, NULL, "value2", NULL);
+    check_preprocess("KEY", macros, NULL, "value2", NULL);
 
     macros[0].Name = "KEY";
     macros[0].Definition = "KEY2";
     macros[1].Name = "KEY2";
     macros[1].Definition = "value";
-    todo check_preprocess("KEY", macros, NULL, "value", NULL);
+    check_preprocess("KEY", macros, NULL, "value", NULL);
 
     macros[0].Name = "KEY2";
     macros[0].Definition = "value";
     macros[1].Name = "KEY";
     macros[1].Definition = "KEY2";
-    todo check_preprocess("KEY", macros, NULL, "value", NULL);
+    check_preprocess("KEY", macros, NULL, "value", NULL);
 
     check_preprocess(test_include_top, NULL, &test_include, "pass", "fail");
     ok(!refcount_file1, "Got %d references to file1.\n", refcount_file1);




More information about the wine-cvs mailing list