Zebediah Figura : vkd3d-shader: Get rid of hlsl_base_type_to_string().

Alexandre Julliard julliard at winehq.org
Fri Feb 19 16:42:49 CST 2021


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Tue Feb 16 23:52:05 2021 -0600

vkd3d-shader: Get rid of hlsl_base_type_to_string().

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 | 47 ++++++++++++++---------------------------------
 libs/vkd3d-shader/hlsl.h |  1 -
 libs/vkd3d-shader/hlsl.y |  3 ++-
 3 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 342fe6a..9e1eb7e 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -639,55 +639,37 @@ static int compare_function_decl_rb(const void *key, const struct rb_entry *entr
     return 0;
 }
 
-const char *hlsl_base_type_to_string(const struct hlsl_type *type)
-{
-    const char *name = "(unknown)";
-
-    switch (type->base_type)
-    {
-        case HLSL_TYPE_FLOAT:        name = "float";         break;
-        case HLSL_TYPE_HALF:         name = "half";          break;
-        case HLSL_TYPE_DOUBLE:       name = "double";        break;
-        case HLSL_TYPE_INT:          name = "int";           break;
-        case HLSL_TYPE_UINT:         name = "uint";          break;
-        case HLSL_TYPE_BOOL:         name = "bool";          break;
-        case HLSL_TYPE_SAMPLER:
-            switch (type->sampler_dim)
-            {
-                case HLSL_SAMPLER_DIM_GENERIC: name = "sampler";       break;
-                case HLSL_SAMPLER_DIM_1D:      name = "sampler1D";     break;
-                case HLSL_SAMPLER_DIM_2D:      name = "sampler2D";     break;
-                case HLSL_SAMPLER_DIM_3D:      name = "sampler3D";     break;
-                case HLSL_SAMPLER_DIM_CUBE:    name = "samplerCUBE";   break;
-            }
-            break;
-        default:
-            FIXME("Unhandled case %u.\n", type->base_type);
-    }
-    return name;
-}
-
 char *hlsl_type_to_string(const struct hlsl_type *type)
 {
     const char *name;
     char *string;
 
+    static const char base_types[HLSL_TYPE_LAST_SCALAR + 1][7] =
+    {
+        "float",
+        "half",
+        "double",
+        "int",
+        "uint",
+        "bool",
+    };
+
     if (type->name)
         return vkd3d_strdup(type->name);
 
     switch (type->type)
     {
         case HLSL_CLASS_SCALAR:
-            return vkd3d_strdup(hlsl_base_type_to_string(type));
+            return vkd3d_strdup(base_types[type->base_type]);
 
         case HLSL_CLASS_VECTOR:
-            name = hlsl_base_type_to_string(type);
+            name = base_types[type->base_type];
             if ((string = malloc(strlen(name) + 2)))
                 sprintf(string, "%s%u", name, type->dimx);
             return string;
 
         case HLSL_CLASS_MATRIX:
-            name = hlsl_base_type_to_string(type);
+            name = base_types[type->base_type];
             if ((string = malloc(strlen(name) + 4)))
                 sprintf(string, "%s%ux%u", name, type->dimx, type->dimy);
             return string;
@@ -907,8 +889,7 @@ static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hl
                 break;
 
             default:
-                vkd3d_string_buffer_printf(buffer, "Constants of type %s not supported\n",
-                        hlsl_base_type_to_string(type));
+                assert(0);
         }
     }
     if (type->dimx != 1)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index b2b7daf..56b8e2a 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -496,7 +496,6 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
 
 const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 
-const char *hlsl_base_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 char *hlsl_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
 char *hlsl_modifiers_to_string(unsigned int modifiers) DECLSPEC_HIDDEN;
 const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 8b91ff5..a3d4b4e 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -909,13 +909,14 @@ static unsigned int evaluate_array_dimension(struct hlsl_ir_node *node)
                 case HLSL_TYPE_INT:
                     return constant->value.i[0];
                 case HLSL_TYPE_FLOAT:
+                case HLSL_TYPE_HALF:
                     return constant->value.f[0];
                 case HLSL_TYPE_DOUBLE:
                     return constant->value.d[0];
                 case HLSL_TYPE_BOOL:
                     return constant->value.b[0];
                 default:
-                    WARN("Invalid type %s.\n", hlsl_base_type_to_string(constant->node.data_type));
+                    assert(0);
                     return 0;
             }
         }




More information about the wine-cvs mailing list