[PATCH vkd3d 3/3] vkd3d-shader/hlsl: Access the type name directly.
Zebediah Figura
zfigura at codeweavers.com
Sun Oct 3 20:51:44 CDT 2021
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
libs/vkd3d-shader/hlsl.c | 28 +--------
libs/vkd3d-shader/hlsl.h | 2 -
libs/vkd3d-shader/hlsl.y | 103 +++++++------------------------
libs/vkd3d-shader/hlsl_codegen.c | 6 +-
libs/vkd3d-shader/hlsl_sm4.c | 13 +---
5 files changed, 30 insertions(+), 122 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
index 077cd4799..39a2f1f24 100644
--- a/libs/vkd3d-shader/hlsl.c
+++ b/libs/vkd3d-shader/hlsl.c
@@ -814,30 +814,6 @@ static int compare_function_decl_rb(const void *key, const struct rb_entry *entr
return 0;
}
-struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type)
-{
- struct vkd3d_string_buffer *string;
-
- if (!(string = hlsl_get_string_buffer(ctx)))
- return NULL;
-
- 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)
-{
- struct vkd3d_string_buffer *string;
- const char *ret;
-
- if (!(string = hlsl_type_to_string(ctx, type)))
- return NULL;
- ret = vkd3d_dbg_sprintf("%s", string->buffer);
- hlsl_release_string_buffer(ctx, string);
- return ret;
-}
-
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct hlsl_ctx *ctx, unsigned int modifiers)
{
struct vkd3d_string_buffer *string;
@@ -930,7 +906,7 @@ static void dump_ir_var(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer
vkd3d_string_buffer_printf(buffer, "%s ", string->buffer);
hlsl_release_string_buffer(ctx, string);
}
- vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(ctx, var->data_type), var->name);
+ vkd3d_string_buffer_printf(buffer, "%s %s", var->data_type->name, var->name);
if (var->semantic.name)
vkd3d_string_buffer_printf(buffer, " : %s%u", var->semantic.name, var->semantic.index);
}
@@ -1150,7 +1126,7 @@ static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer,
else
vkd3d_string_buffer_printf(buffer, "%p: ", instr);
- vkd3d_string_buffer_printf(buffer, "%10s | ", instr->data_type ? debug_hlsl_type(ctx, instr->data_type) : "");
+ vkd3d_string_buffer_printf(buffer, "%10s | ", instr->data_type ? instr->data_type->name : "");
switch (instr->type)
{
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h
index 77b4ce928..f22c2b616 100644
--- a/libs/vkd3d-shader/hlsl.h
+++ b/libs/vkd3d-shader/hlsl.h
@@ -608,10 +608,8 @@ static inline void hlsl_release_string_buffer(struct hlsl_ctx *ctx, struct vkd3d
}
const char *debug_hlsl_expr_op(enum hlsl_ir_expr_op op);
-const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type);
const char *debug_hlsl_writemask(unsigned int writemask);
-struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type);
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct hlsl_ctx *ctx, unsigned int modifiers);
const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type);
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 585331062..dd67e85c0 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -268,15 +268,8 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
if (!implicit_compatible_data_types(src_type, dst_type))
{
- struct vkd3d_string_buffer *src_string, *dst_string;
-
- src_string = hlsl_type_to_string(ctx, src_type);
- dst_string = hlsl_type_to_string(ctx, dst_type);
- if (src_string && dst_string)
- hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Can't implicitly convert from %s to %s.", src_string->buffer, dst_string->buffer);
- hlsl_release_string_buffer(ctx, src_string);
- hlsl_release_string_buffer(ctx, dst_string);
+ hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Can't implicitly convert from %s to %s.", src_type->name, dst_type->name);
return NULL;
}
@@ -915,23 +908,15 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
if (t1->type > HLSL_CLASS_LAST_NUMERIC)
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, t1)))
- hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Expression of type \"%s\" cannot be used in a numeric expression.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Expression of type \"%s\" cannot be used in a numeric expression.", t1->name);
return NULL;
}
if (t2->type > HLSL_CLASS_LAST_NUMERIC)
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, t2)))
- hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Expression of type \"%s\" cannot be used in a numeric expression.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Expression of type \"%s\" cannot be used in a numeric expression.", t2->name);
return NULL;
}
@@ -940,15 +925,8 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
if (!expr_compatible_data_types(t1, t2))
{
- struct vkd3d_string_buffer *t1_string = hlsl_type_to_string(ctx, t1);
- struct vkd3d_string_buffer *t2_string = hlsl_type_to_string(ctx, t2);
-
- if (t1_string && t2_string)
- hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Expression data types \"%s\" and \"%s\" are incompatible.",
- t1_string->buffer, t2_string->buffer);
- hlsl_release_string_buffer(ctx, t1_string);
- hlsl_release_string_buffer(ctx, t2_string);
+ hlsl_error(ctx, *loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Expression data types \"%s\" and \"%s\" are incompatible.", t1->name, t2->name);
return NULL;
}
@@ -1668,13 +1646,9 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name,
{
if (params->args[i]->data_type->type > HLSL_CLASS_LAST_NUMERIC)
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, params->args[i]->data_type)))
- hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Wrong type for argument %u of '%s': expected a numeric type, but got '%s'.\n",
- i + 1, name, string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Wrong type for argument %u of '%s': expected a numeric type, but got '%s'.\n",
+ i + 1, name, params->args[i]->data_type->name);
free_parse_initializer(params);
return NULL;
}
@@ -1721,12 +1695,8 @@ static struct list *add_constructor(struct hlsl_ctx *ctx, struct hlsl_type *type
if (arg->data_type->type == HLSL_CLASS_OBJECT)
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, arg->data_type)))
- hlsl_error(ctx, arg->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Invalid type %s for constructor argument.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, arg->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Invalid type %s for constructor argument.", arg->data_type->name);
continue;
}
width = hlsl_type_component_count(arg->data_type);
@@ -2386,13 +2356,8 @@ type:
{
if ($3->type != HLSL_CLASS_SCALAR)
{
- struct vkd3d_string_buffer *string;
-
- string = hlsl_type_to_string(ctx, $3);
- if (string)
- hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Vector base type %s is not scalar.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Vector base type %s is not scalar.", $3->name);
YYABORT;
}
if ($5 < 1 || $5 > 4)
@@ -2408,13 +2373,8 @@ type:
{
if ($3->type != HLSL_CLASS_SCALAR)
{
- struct vkd3d_string_buffer *string;
-
- string = hlsl_type_to_string(ctx, $3);
- if (string)
- hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Matrix base type %s is not scalar.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Matrix base type %s is not scalar.", $3->name);
YYABORT;
}
if ($5 < 1 || $5 > 4)
@@ -2779,14 +2739,8 @@ selection_statement:
vkd3d_free($5.then_instrs);
vkd3d_free($5.else_instrs);
if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1)
- {
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, condition->data_type)))
- hlsl_error(ctx, instr->node.loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "if condition type %s is not scalar.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
- }
+ hlsl_error(ctx, instr->node.loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "if condition type %s is not scalar.", condition->data_type->name);
$$ = $3;
list_add_tail($$, &instr->node.entry);
}
@@ -3023,12 +2977,8 @@ postfix_expr:
}
if ($2->type > HLSL_CLASS_LAST_NUMERIC)
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, $2)))
- hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Constructor data type %s is not numeric.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Constructor data type %s is not numeric.", $2->name);
free_parse_initializer(&$4);
YYABORT;
}
@@ -3105,15 +3055,8 @@ unary_expr:
if (!compatible_data_types(src_type, dst_type))
{
- struct vkd3d_string_buffer *src_string, *dst_string;
-
- src_string = hlsl_type_to_string(ctx, src_type);
- dst_string = hlsl_type_to_string(ctx, dst_type);
- if (src_string && dst_string)
- hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Can't cast from %s to %s.",
- src_string->buffer, dst_string->buffer);
- hlsl_release_string_buffer(ctx, src_string);
- hlsl_release_string_buffer(ctx, dst_string);
+ hlsl_error(ctx, @3, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE, "Can't cast from %s to %s.",
+ src_type->name, dst_type->name);
YYABORT;
}
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c
index 9c9a38379..d73807624 100644
--- a/libs/vkd3d-shader/hlsl_codegen.c
+++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -403,8 +403,7 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
if (instr->data_type->dimx != arg1->node.data_type->dimx
|| instr->data_type->dimy != arg1->node.data_type->dimy)
{
- FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
- debug_hlsl_type(ctx, instr->data_type));
+ FIXME("Cast from %s to %s.\n", arg1->node.data_type->name, instr->data_type->name);
vkd3d_free(res);
return false;
}
@@ -422,8 +421,7 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
break;
default:
- FIXME("Cast from %s to %s.\n", debug_hlsl_type(ctx, arg1->node.data_type),
- debug_hlsl_type(ctx, instr->data_type));
+ FIXME("Cast from %s to %s.\n", arg1->node.data_type->name, instr->data_type->name);
vkd3d_free(res);
return false;
}
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c
index 8c2bc8f84..c6dedef06 100644
--- a/libs/vkd3d-shader/hlsl_sm4.c
+++ b/libs/vkd3d-shader/hlsl_sm4.c
@@ -122,7 +122,6 @@ bool hlsl_sm4_usage_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semant
static void write_sm4_signature(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc, bool output)
{
struct vkd3d_bytecode_buffer buffer = {0};
- struct vkd3d_string_buffer *string;
const struct hlsl_ir_var *var;
size_t count_position;
unsigned int i;
@@ -185,10 +184,8 @@ static void write_sm4_signature(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc,
break;
default:
- if ((string = hlsl_type_to_string(ctx, var->data_type)))
- hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
- "Invalid data type %s for semantic variable %s.", string->buffer, var->name);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_TYPE,
+ "Invalid data type %s for semantic variable %s.", var->data_type->name, var->name);
put_u32(&buffer, D3D_REGISTER_COMPONENT_UNKNOWN);
}
put_u32(&buffer, reg_idx);
@@ -1159,11 +1156,7 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
default:
{
- struct vkd3d_string_buffer *string;
-
- if ((string = hlsl_type_to_string(ctx, expr->node.data_type)))
- hlsl_fixme(ctx, expr->node.loc, "SM4 %s expression.", string->buffer);
- hlsl_release_string_buffer(ctx, string);
+ hlsl_fixme(ctx, expr->node.loc, "SM4 %s expression.", expr->node.data_type->name);
break;
}
}
--
2.33.0
More information about the wine-devel
mailing list