vkd3d-shader: Use the HLSL string buffer cache in hlsl_type_to_string() and hlsl_modifiers_to_string().

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-05-21 00:32:22 -05:00 committed by Alexandre Julliard
parent 4fe1e86310
commit ba1cc670e6
4 changed files with 73 additions and 80 deletions

View File

@ -219,7 +219,7 @@ unsigned int hlsl_type_component_count(struct hlsl_type *type)
}
if (type->type != HLSL_CLASS_STRUCT)
{
ERR("Unexpected data type %s.\n", debug_hlsl_type(type));
ERR("Unexpected data type %#x.\n", type->type);
return 0;
}
@ -706,8 +706,7 @@ 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 vkd3d_string_buffer_cache *string_buffers,
const struct hlsl_type *type)
struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type)
{
struct vkd3d_string_buffer *string;
@ -721,7 +720,7 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache
"bool",
};
if (!(string = vkd3d_string_buffer_get(string_buffers)))
if (!(string = hlsl_get_string_buffer(ctx)))
return NULL;
if (type->name)
@ -755,10 +754,10 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache
for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type)
;
if ((inner_string = hlsl_type_to_string(string_buffers, t)))
if ((inner_string = hlsl_type_to_string(ctx, t)))
{
vkd3d_string_buffer_printf(string, "%s", inner_string->buffer);
vkd3d_string_buffer_release(string_buffers, inner_string);
hlsl_release_string_buffer(ctx, inner_string);
}
for (t = type; t->type == HLSL_CLASS_ARRAY; t = t->e.array.type)
@ -776,27 +775,23 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache
}
}
const char *debug_hlsl_type(const struct hlsl_type *type)
const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type)
{
struct vkd3d_string_buffer_cache string_buffers;
struct vkd3d_string_buffer *string;
const char *ret;
vkd3d_string_buffer_cache_init(&string_buffers);
if (!(string = hlsl_type_to_string(&string_buffers, type)))
if (!(string = hlsl_type_to_string(ctx, type)))
return NULL;
ret = vkd3d_dbg_sprintf("%s", string->buffer);
vkd3d_string_buffer_release(&string_buffers, string);
vkd3d_string_buffer_cache_cleanup(&string_buffers);
hlsl_release_string_buffer(ctx, string);
return ret;
}
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct vkd3d_string_buffer_cache *string_buffers,
unsigned int modifiers)
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct hlsl_ctx *ctx, unsigned int modifiers)
{
struct vkd3d_string_buffer *string;
if (!(string = vkd3d_string_buffer_get(string_buffers)))
if (!(string = hlsl_get_string_buffer(ctx)))
return NULL;
if (modifiers & HLSL_STORAGE_EXTERN)
@ -853,15 +848,15 @@ const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type)
return names[type];
}
static void dump_instr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr);
static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr);
static void dump_instr_list(struct vkd3d_string_buffer *buffer, const struct list *list)
static void dump_instr_list(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct list *list)
{
struct hlsl_ir_node *instr;
LIST_FOR_EACH_ENTRY(instr, list, struct hlsl_ir_node, entry)
{
dump_instr(buffer, instr);
dump_instr(ctx, buffer, instr);
vkd3d_string_buffer_printf(buffer, "\n");
}
}
@ -874,20 +869,17 @@ static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *
vkd3d_string_buffer_printf(buffer, "%p", src->node);
}
static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
static void dump_ir_var(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
{
if (var->modifiers)
{
struct vkd3d_string_buffer_cache string_buffers;
struct vkd3d_string_buffer *string;
vkd3d_string_buffer_cache_init(&string_buffers);
if ((string = hlsl_modifiers_to_string(&string_buffers, var->modifiers)))
if ((string = hlsl_modifiers_to_string(ctx, var->modifiers)))
vkd3d_string_buffer_printf(buffer, "%s ", string->buffer);
vkd3d_string_buffer_release(&string_buffers, string);
vkd3d_string_buffer_cache_cleanup(&string_buffers);
hlsl_release_string_buffer(ctx, string);
}
vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name);
vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(ctx, var->data_type), var->name);
if (var->semantic.name)
vkd3d_string_buffer_printf(buffer, " : %s%u", var->semantic.name, var->semantic.index);
}
@ -1042,14 +1034,14 @@ static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_i
vkd3d_string_buffer_printf(buffer, ")");
}
static void dump_ir_if(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_if *if_node)
static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_if *if_node)
{
vkd3d_string_buffer_printf(buffer, "if (");
dump_src(buffer, &if_node->condition);
vkd3d_string_buffer_printf(buffer, ")\n{\n");
dump_instr_list(buffer, &if_node->then_instrs);
dump_instr_list(ctx, buffer, &if_node->then_instrs);
vkd3d_string_buffer_printf(buffer, "}\nelse\n{\n");
dump_instr_list(buffer, &if_node->else_instrs);
dump_instr_list(ctx, buffer, &if_node->else_instrs);
vkd3d_string_buffer_printf(buffer, "}\n");
}
@ -1075,10 +1067,10 @@ static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_i
}
}
static void dump_ir_loop(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop)
static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop)
{
vkd3d_string_buffer_printf(buffer, "for (;;)\n{\n");
dump_instr_list(buffer, &loop->body);
dump_instr_list(ctx, buffer, &loop->body);
vkd3d_string_buffer_printf(buffer, "}\n");
}
@ -1113,14 +1105,14 @@ static void dump_ir_swizzle(struct vkd3d_string_buffer *buffer, const struct hls
}
}
static void dump_instr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr)
static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr)
{
if (instr->index)
vkd3d_string_buffer_printf(buffer, "%4u: ", instr->index);
else
vkd3d_string_buffer_printf(buffer, "%p: ", instr);
vkd3d_string_buffer_printf(buffer, "%10s | ", instr->data_type ? debug_hlsl_type(instr->data_type) : "");
vkd3d_string_buffer_printf(buffer, "%10s | ", instr->data_type ? debug_hlsl_type(ctx, instr->data_type) : "");
switch (instr->type)
{
@ -1133,7 +1125,7 @@ static void dump_instr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_
break;
case HLSL_IR_IF:
dump_ir_if(buffer, hlsl_ir_if(instr));
dump_ir_if(ctx, buffer, hlsl_ir_if(instr));
break;
case HLSL_IR_JUMP:
@ -1145,7 +1137,7 @@ static void dump_instr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_
break;
case HLSL_IR_LOOP:
dump_ir_loop(buffer, hlsl_ir_loop(instr));
dump_ir_loop(ctx, buffer, hlsl_ir_loop(instr));
break;
case HLSL_IR_STORE:
@ -1161,7 +1153,7 @@ static void dump_instr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_
}
}
void hlsl_dump_function(const struct hlsl_ir_function_decl *func)
void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *func)
{
struct vkd3d_string_buffer buffer;
struct hlsl_ir_var *param;
@ -1171,11 +1163,11 @@ void hlsl_dump_function(const struct hlsl_ir_function_decl *func)
vkd3d_string_buffer_printf(&buffer, "Function parameters:\n");
LIST_FOR_EACH_ENTRY(param, func->parameters, struct hlsl_ir_var, param_entry)
{
dump_ir_var(&buffer, param);
dump_ir_var(ctx, &buffer, param);
vkd3d_string_buffer_printf(&buffer, "\n");
}
if (func->body)
dump_instr_list(&buffer, func->body);
dump_instr_list(ctx, &buffer, func->body);
vkd3d_string_buffer_trace(&buffer);
vkd3d_string_buffer_cleanup(&buffer);

View File

@ -581,20 +581,18 @@ static inline void hlsl_release_string_buffer(struct hlsl_ctx *ctx, struct vkd3d
vkd3d_string_buffer_release(&ctx->string_buffers, buffer);
}
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type) DECLSPEC_HIDDEN;
const char *debug_hlsl_writemask(unsigned int writemask) DECLSPEC_HIDDEN;
struct vkd3d_string_buffer *hlsl_type_to_string(struct vkd3d_string_buffer_cache *string_buffers,
const struct hlsl_type *type) DECLSPEC_HIDDEN;
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct vkd3d_string_buffer_cache *string_buffers,
unsigned int modifiers) DECLSPEC_HIDDEN;
struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type) DECLSPEC_HIDDEN;
struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct hlsl_ctx *ctx, 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 hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl,
bool intrinsic) DECLSPEC_HIDDEN;
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var) DECLSPEC_HIDDEN;
void hlsl_dump_function(const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *func) DECLSPEC_HIDDEN;
int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
struct vkd3d_shader_code *out) DECLSPEC_HIDDEN;

View File

@ -272,13 +272,13 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
{
struct vkd3d_string_buffer *src_string, *dst_string;
src_string = hlsl_type_to_string(&ctx->string_buffers, src_type);
dst_string = hlsl_type_to_string(&ctx->string_buffers, dst_type);
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);
vkd3d_string_buffer_release(&ctx->string_buffers, src_string);
vkd3d_string_buffer_release(&ctx->string_buffers, dst_string);
hlsl_release_string_buffer(ctx, src_string);
hlsl_release_string_buffer(ctx, dst_string);
return NULL;
}
@ -298,10 +298,10 @@ static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, con
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, mod)))
if ((string = hlsl_modifiers_to_string(ctx, mod)))
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Modifier '%s' was already specified.", string->buffer);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
return modifiers;
}
if ((mod & HLSL_MODIFIERS_MAJORITY_MASK) && (modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
@ -974,10 +974,10 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(&ctx->string_buffers, t1)))
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
return NULL;
}
@ -985,10 +985,10 @@ static struct hlsl_type *expr_common_type(struct hlsl_ctx *ctx, struct hlsl_type
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(&ctx->string_buffers, t2)))
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
return NULL;
}
@ -997,15 +997,15 @@ 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->string_buffers, t1);
struct vkd3d_string_buffer *t2_string = hlsl_type_to_string(&ctx->string_buffers, 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);
vkd3d_string_buffer_release(&ctx->string_buffers, t1_string);
vkd3d_string_buffer_release(&ctx->string_buffers, t2_string);
hlsl_release_string_buffer(ctx, t1_string);
hlsl_release_string_buffer(ctx, t2_string);
return NULL;
}
@ -1450,10 +1450,10 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, modifiers & invalid)))
if ((string = hlsl_modifiers_to_string(ctx, modifiers & invalid)))
hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Modifiers '%s' are not allowed on local variables.", string->buffer);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
}
if (var->semantic.name)
hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SEMANTIC,
@ -1935,10 +1935,10 @@ field:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, modifiers)))
if ((string = hlsl_modifiers_to_string(ctx, modifiers)))
hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Modifiers '%s' are not allowed on struct fields.", string->buffer);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
}
$$ = gen_struct_fields(ctx, type, $3);
}
@ -2121,10 +2121,10 @@ input_mods:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_modifiers_to_string(&ctx->string_buffers, $2)))
if ((string = hlsl_modifiers_to_string(ctx, $2)))
hlsl_error(ctx, @2, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER,
"Modifier \"%s\" was already specified.", string->buffer);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
YYABORT;
}
$$ = $1 | $2;
@ -2155,11 +2155,11 @@ type:
{
struct vkd3d_string_buffer *string;
string = hlsl_type_to_string(&ctx->string_buffers, $3);
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
YYABORT;
}
if ($5 < 1 || $5 > 4)
@ -2177,11 +2177,11 @@ type:
{
struct vkd3d_string_buffer *string;
string = hlsl_type_to_string(&ctx->string_buffers, $3);
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
YYABORT;
}
if ($5 < 1 || $5 > 4)
@ -2530,10 +2530,10 @@ selection_statement:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(&ctx->string_buffers, condition->data_type)))
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
}
$$ = $3;
list_add_tail($$, &instr->node.entry);
@ -2745,10 +2745,10 @@ postfix_expr:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(&ctx->string_buffers, $2)))
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
YYABORT;
}
if ($2->dimx * $2->dimy != initializer_size(&$4))
@ -2774,10 +2774,10 @@ postfix_expr:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(&ctx->string_buffers, arg->data_type)))
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);
vkd3d_string_buffer_release(&ctx->string_buffers, string);
hlsl_release_string_buffer(ctx, string);
continue;
}
width = hlsl_type_component_count(arg->data_type);
@ -2857,13 +2857,13 @@ unary_expr:
{
struct vkd3d_string_buffer *src_string, *dst_string;
src_string = hlsl_type_to_string(&ctx->string_buffers, src_type);
dst_string = hlsl_type_to_string(&ctx->string_buffers, dst_type);
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);
vkd3d_string_buffer_release(&ctx->string_buffers, src_string);
vkd3d_string_buffer_release(&ctx->string_buffers, dst_string);
hlsl_release_string_buffer(ctx, src_string);
hlsl_release_string_buffer(ctx, dst_string);
YYABORT;
}

View File

@ -456,15 +456,18 @@ static unsigned int index_instructions(struct list *instrs, unsigned int index)
static void dump_function_decl(struct rb_entry *entry, void *context)
{
struct hlsl_ir_function_decl *func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function_decl, entry);
struct hlsl_ctx *ctx = context;
if (func->body)
hlsl_dump_function(func);
hlsl_dump_function(ctx, func);
}
static void dump_function(struct rb_entry *entry, void *context)
{
struct hlsl_ir_function *func = RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
rb_for_each_entry(&func->overloads, dump_function_decl, NULL);
struct hlsl_ctx *ctx = context;
rb_for_each_entry(&func->overloads, dump_function_decl, ctx);
}
/* Compute the earliest and latest liveness for each variable. In the case that
@ -1958,7 +1961,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
compute_liveness(ctx, entry_func);
if (TRACE_ON())
rb_for_each_entry(&ctx->functions, dump_function, NULL);
rb_for_each_entry(&ctx->functions, dump_function, ctx);
allocate_temp_registers(ctx, entry_func);
if (ctx->profile->major_version < 4)