[PATCH vkd3d 4/5] vkd3d-shader: Avoid using debugging utilities in hlsl_debug_modifiers().
Zebediah Figura
zfigura at codeweavers.com
Fri Feb 12 14:38:49 CST 2021
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
libs/vkd3d-shader/hlsl.c | 49 +++++++++++++++++++++++++---------------
libs/vkd3d-shader/hlsl.h | 2 +-
libs/vkd3d-shader/hlsl.y | 14 ++++++++++--
3 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index c4e06143..4bdcd184 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -694,41 +694,48 @@ const char *debug_hlsl_type(const struct hlsl_type *type)
return "unexpected_type";
}
-const char *hlsl_debug_modifiers(DWORD modifiers)
+char *hlsl_modifiers_to_string(unsigned int modifiers)
{
- char string[110];
+ char *string;
+ size_t len;
+
+ if (!(string = vkd3d_malloc(110)))
+ return NULL;
string[0] = 0;
if (modifiers & HLSL_STORAGE_EXTERN)
- strcat(string, " extern"); /* 7 */
+ strcat(string, "extern "); /* 7 */
if (modifiers & HLSL_STORAGE_NOINTERPOLATION)
- strcat(string, " nointerpolation"); /* 16 */
+ strcat(string, "nointerpolation "); /* 16 */
if (modifiers & HLSL_MODIFIER_PRECISE)
- strcat(string, " precise"); /* 8 */
+ strcat(string, "precise "); /* 8 */
if (modifiers & HLSL_STORAGE_SHARED)
- strcat(string, " shared"); /* 7 */
+ strcat(string, "shared "); /* 7 */
if (modifiers & HLSL_STORAGE_GROUPSHARED)
- strcat(string, " groupshared"); /* 12 */
+ strcat(string, "groupshared "); /* 12 */
if (modifiers & HLSL_STORAGE_STATIC)
- strcat(string, " static"); /* 7 */
+ strcat(string, "static "); /* 7 */
if (modifiers & HLSL_STORAGE_UNIFORM)
- strcat(string, " uniform"); /* 8 */
+ strcat(string, "uniform "); /* 8 */
if (modifiers & HLSL_STORAGE_VOLATILE)
- strcat(string, " volatile"); /* 9 */
+ strcat(string, "volatile "); /* 9 */
if (modifiers & HLSL_MODIFIER_CONST)
- strcat(string, " const"); /* 6 */
+ strcat(string, "const "); /* 6 */
if (modifiers & HLSL_MODIFIER_ROW_MAJOR)
- strcat(string, " row_major"); /* 10 */
+ strcat(string, "row_major "); /* 10 */
if (modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
- strcat(string, " column_major"); /* 13 */
+ strcat(string, "column_major "); /* 13 */
if ((modifiers & (HLSL_STORAGE_IN | HLSL_STORAGE_OUT)) == (HLSL_STORAGE_IN | HLSL_STORAGE_OUT))
- strcat(string, " inout"); /* 6 */
+ strcat(string, "inout "); /* 6 */
else if (modifiers & HLSL_STORAGE_IN)
- strcat(string, " in"); /* 3 */
+ strcat(string, "in "); /* 3 */
else if (modifiers & HLSL_STORAGE_OUT)
- strcat(string, " out"); /* 4 */
+ strcat(string, "out "); /* 4 */
+
+ if ((len = strlen(string)))
+ string[len - 1] = 0;
- return vkd3d_dbg_sprintf("%s", string[0] ? string + 1 : "");
+ return string;
}
const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type)
@@ -774,7 +781,13 @@ static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *
static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
{
if (var->modifiers)
- vkd3d_string_buffer_printf(buffer, "%s ", hlsl_debug_modifiers(var->modifiers));
+ {
+ char *string;
+
+ if ((string = hlsl_modifiers_to_string(var->modifiers)))
+ vkd3d_string_buffer_printf(buffer, "%s ", string);
+ vkd3d_free(string);
+ }
vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name);
if (var->semantic)
vkd3d_string_buffer_printf(buffer, " : %s", var->semantic);
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 88e7df5e..2ca432ab 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -496,7 +496,7 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
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_debug_modifiers(DWORD modifiers) 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;
void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl,
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 6e0669b4..32a37e2f 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -282,8 +282,14 @@ static bool declare_variable(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, boo
if (invalid)
{
- hlsl_error(ctx, decl->loc, "modifier '%s' invalid for local variables", hlsl_debug_modifiers(invalid));
+ char *string;
+
+ if ((string = hlsl_modifiers_to_string(invalid)))
+ hlsl_error(ctx, decl->loc,
+ "Modifiers '%s' are not allowed on local variables.", string);
+ vkd3d_free(string);
}
+
if (decl->semantic)
{
hlsl_error(ctx, decl->loc, "semantics are not allowed on local variables");
@@ -314,7 +320,11 @@ static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, con
{
if (modifiers & mod)
{
- hlsl_error(ctx, loc, "modifier '%s' already specified", hlsl_debug_modifiers(mod));
+ char *string;
+
+ if ((string = hlsl_modifiers_to_string(mod)))
+ hlsl_error(ctx, loc, "Modifier '%s' was already specified.", string);
+ vkd3d_free(string);
return modifiers;
}
if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
--
2.30.0
More information about the wine-devel
mailing list