Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- 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 342fe6af..9e1eb7ee 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 b2b7daf0..56b8e2a8 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 8b91ff5d..a3d4b4ed 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; } }