Zebediah Figura : vkd3d-shader: Avoid using debugging utilities in debug_hlsl_type().
Alexandre Julliard
julliard at winehq.org
Tue Feb 16 15:53:08 CST 2021
Module: vkd3d
Branch: master
Commit: b57ad006c25f024144db9d6010befb0f95eefecf
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=b57ad006c25f024144db9d6010befb0f95eefecf
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Fri Feb 12 14:38:50 2021 -0600
vkd3d-shader: Avoid using debugging utilities in debug_hlsl_type().
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 | 65 ++++++++++++++++++++++++++++++------------------
libs/vkd3d-shader/hlsl.h | 4 ++-
libs/vkd3d-shader/hlsl.y | 16 +++++++++---
3 files changed, 56 insertions(+), 29 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 4bdcd18..f181439 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -667,31 +667,55 @@ const char *hlsl_base_type_to_string(const struct hlsl_type *type)
return name;
}
-const char *debug_hlsl_type(const struct hlsl_type *type)
+char *hlsl_type_to_string(const struct hlsl_type *type)
{
const char *name;
+ char *string;
if (type->name)
- return debugstr_a(type->name);
-
- if (type->type == HLSL_CLASS_STRUCT)
- return "<anonymous struct>";
+ return vkd3d_strdup(type->name);
- if (type->type == HLSL_CLASS_ARRAY)
+ switch (type->type)
{
- return vkd3d_dbg_sprintf("%s[%u]", hlsl_base_type_to_string(type->e.array.type),
- type->e.array.elements_count);
+ case HLSL_CLASS_SCALAR:
+ return vkd3d_strdup(hlsl_base_type_to_string(type));
+
+ case HLSL_CLASS_VECTOR:
+ name = hlsl_base_type_to_string(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);
+ if ((string = malloc(strlen(name) + 4)))
+ sprintf(string, "%s%ux%u", name, type->dimx, type->dimy);
+ return string;
+
+ case HLSL_CLASS_ARRAY:
+ name = hlsl_base_type_to_string(type->e.array.type);
+ if ((string = malloc(strlen(name) + 15)))
+ sprintf(string, "%s[%u]", name, type->e.array.elements_count);
+ return string;
+
+ case HLSL_CLASS_STRUCT:
+ return vkd3d_strdup("<anonymous struct>");
+
+ default:
+ return vkd3d_strdup("<unexpected type>");
}
+}
- name = hlsl_base_type_to_string(type);
+const char *debug_hlsl_type(const struct hlsl_type *type)
+{
+ const char *ret;
+ char *string;
- if (type->type == HLSL_CLASS_SCALAR)
- return vkd3d_dbg_sprintf("%s", name);
- if (type->type == HLSL_CLASS_VECTOR)
- return vkd3d_dbg_sprintf("%s%u", name, type->dimx);
- if (type->type == HLSL_CLASS_MATRIX)
- return vkd3d_dbg_sprintf("%s%ux%u", name, type->dimx, type->dimy);
- return "unexpected_type";
+ if (!(string = hlsl_type_to_string(type)))
+ return NULL;
+ ret = vkd3d_dbg_sprintf("%s", string);
+ vkd3d_free(string);
+ return ret;
}
char *hlsl_modifiers_to_string(unsigned int modifiers)
@@ -795,11 +819,7 @@ static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir
static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_deref *deref)
{
- if (deref->offset.node)
- /* Print the variable's type for convenience. */
- vkd3d_string_buffer_printf(buffer, "(%s %s)", debug_hlsl_type(deref->var->data_type), deref->var->name);
- else
- vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
+ vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
if (deref->offset.node)
{
vkd3d_string_buffer_printf(buffer, "[");
@@ -948,9 +968,6 @@ static const char *debug_expr_op(const struct hlsl_ir_expr *expr)
",",
};
- if (expr->op == HLSL_IR_UNOP_CAST)
- return debug_hlsl_type(expr->node.data_type);
-
return op_names[expr->op];
}
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 2ca432a..b2b7daf 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -494,8 +494,10 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
src->node = NULL;
}
-const char *hlsl_base_type_to_string(const struct hlsl_type *type) DECLSPEC_HIDDEN;
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 32a37e2..8b91ff5 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -254,8 +254,12 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
if (!implicit_compatible_data_types(src_type, dst_type))
{
- hlsl_error(ctx, *loc, "can't implicitly convert %s to %s",
- debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
+ char *src_string = hlsl_type_to_string(src_type), *dst_string = hlsl_type_to_string(dst_type);
+
+ if (src_string && dst_string)
+ hlsl_error(ctx, *loc, "Can't implicitly convert from %s to %s.", src_string, dst_string);
+ vkd3d_free(src_string);
+ vkd3d_free(dst_string);
return NULL;
}
@@ -2728,8 +2732,12 @@ unary_expr:
if (!compatible_data_types(src_type, dst_type))
{
- hlsl_error(ctx, @3, "can't cast from %s to %s",
- debug_hlsl_type(src_type), debug_hlsl_type(dst_type));
+ char *src_string = hlsl_type_to_string(src_type), *dst_string = hlsl_type_to_string(dst_type);
+
+ if (src_string && dst_string)
+ hlsl_error(ctx, @3, "Can't cast from %s to %s.", src_string, dst_string);
+ vkd3d_free(src_string);
+ vkd3d_free(dst_string);
YYABORT;
}
More information about the wine-cvs
mailing list