[PATCH vkd3d 2/3] vkd3d-shader/hlsl: Set the name for array types at creation time.

Zebediah Figura zfigura at codeweavers.com
Sun Oct 3 20:51:43 CDT 2021


Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 libs/vkd3d-shader/hlsl.c | 91 +++++++++++-----------------------------
 1 file changed, 24 insertions(+), 67 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index f03777a65..077cd4799 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -223,19 +223,33 @@ static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, e
     return type;
 }
 
-struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size)
+struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *element_type, unsigned int array_size)
 {
-    struct hlsl_type *type;
+    struct hlsl_type *type, *named_type, *t;
+    struct vkd3d_string_buffer *string;
+    char *name;
 
-    if (!(type = hlsl_alloc(ctx, sizeof(*type))))
+    if (!(string = hlsl_get_string_buffer(ctx)))
         return NULL;
 
+    for (named_type = element_type; strchr(named_type->name, '['); named_type = named_type->e.array.type)
+        ;
+    vkd3d_string_buffer_printf(string, "%s[%u]", named_type->name, array_size);
+    for (t = element_type; t != named_type; t = t->e.array.type)
+        vkd3d_string_buffer_printf(string, "[%u]", t->e.array.elements_count);
+    if (!(name = hlsl_strdup(ctx, string->buffer)))
+        return NULL;
+    hlsl_release_string_buffer(ctx, string);
+
+    if (!(type = hlsl_alloc(ctx, sizeof(*type))))
+        return NULL;
+    type->name = name;
     type->type = HLSL_CLASS_ARRAY;
-    type->modifiers = basic_type->modifiers;
+    type->modifiers = element_type->modifiers;
     type->e.array.elements_count = array_size;
-    type->e.array.type = basic_type;
-    type->dimx = basic_type->dimx;
-    type->dimy = basic_type->dimy;
+    type->e.array.type = element_type;
+    type->dimx = element_type->dimx;
+    type->dimy = element_type->dimy;
     hlsl_type_calculate_reg_size(ctx, type);
 
     list_add_tail(&ctx->types, &type->entry);
@@ -804,69 +818,12 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru
 {
     struct vkd3d_string_buffer *string;
 
-    static const char base_types[HLSL_TYPE_LAST_SCALAR + 1][7] =
-    {
-        "float",
-        "half",
-        "double",
-        "int",
-        "uint",
-        "bool",
-    };
-
     if (!(string = hlsl_get_string_buffer(ctx)))
         return NULL;
 
-    if (type->name)
-    {
-        vkd3d_string_buffer_printf(string, "%s", type->name);
-        return string;
-    }
-
-    switch (type->type)
-    {
-        case HLSL_CLASS_SCALAR:
-            assert(type->base_type < ARRAY_SIZE(base_types));
-            vkd3d_string_buffer_printf(string, "%s", base_types[type->base_type]);
-            return string;
-
-        case HLSL_CLASS_VECTOR:
-            assert(type->base_type < ARRAY_SIZE(base_types));
-            vkd3d_string_buffer_printf(string, "%s%u", base_types[type->base_type], type->dimx);
-            return string;
-
-        case HLSL_CLASS_MATRIX:
-            assert(type->base_type < ARRAY_SIZE(base_types));
-            vkd3d_string_buffer_printf(string, "%s%ux%u", base_types[type->base_type], type->dimx, type->dimy);
-            return string;
-
-        case HLSL_CLASS_ARRAY:
-        {
-            struct vkd3d_string_buffer *inner_string;
-            const struct hlsl_type *t;
-
-            for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type)
-                ;
-
-            if ((inner_string = hlsl_type_to_string(ctx, t)))
-            {
-                vkd3d_string_buffer_printf(string, "%s", inner_string->buffer);
-                hlsl_release_string_buffer(ctx, inner_string);
-            }
-
-            for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type)
-                vkd3d_string_buffer_printf(string, "[%u]", t->e.array.elements_count);
-            return string;
-        }
-
-        case HLSL_CLASS_STRUCT:
-            vkd3d_string_buffer_printf(string, "<anonymous struct>");
-            return string;
-
-        default:
-            vkd3d_string_buffer_printf(string, "<unexpected type>");
-            return string;
-    }
+    assert(type->name);
+    vkd3d_string_buffer_printf(string, "%s", type->name);
+    return string;
 }
 
 const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type)
-- 
2.33.0




More information about the wine-devel mailing list