Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 10 ++++----- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl.y | 6 ++++-- libs/vkd3d-shader/hlsl_codegen.c | 35 ++++++++++++++++---------------- libs/vkd3d-shader/hlsl_sm1.c | 2 +- libs/vkd3d-shader/hlsl_sm4.c | 2 +- 6 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8a56025d6..641e05471 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -685,6 +685,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl
if (!(decl = hlsl_alloc(ctx, sizeof(*decl)))) return NULL; + list_init(&decl->body); decl->return_type = return_type; decl->parameters = parameters; decl->loc = loc; @@ -1340,8 +1341,8 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl dump_ir_var(ctx, &buffer, param); vkd3d_string_buffer_printf(&buffer, "\n"); } - if (func->body) - dump_instr_list(ctx, &buffer, func->body); + if (func->has_body) + dump_instr_list(ctx, &buffer, &func->body);
vkd3d_string_buffer_trace(&buffer); vkd3d_string_buffer_cleanup(&buffer); @@ -1482,8 +1483,7 @@ void hlsl_free_instr(struct hlsl_ir_node *node) static void free_function_decl(struct hlsl_ir_function_decl *decl) { vkd3d_free(decl->parameters); - hlsl_free_instr_list(decl->body); - vkd3d_free(decl->body); + hlsl_free_instr_list(&decl->body); vkd3d_free(decl); }
@@ -1530,7 +1530,7 @@ void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function struct hlsl_ir_function_decl *old_decl = RB_ENTRY_VALUE(old_entry, struct hlsl_ir_function_decl, entry);
- if (!decl->body) + if (!decl->has_body) { free_function_decl(decl); vkd3d_free(name); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 93191e56b..99e00b081 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -258,7 +258,8 @@ struct hlsl_ir_function_decl struct rb_entry entry; struct hlsl_ir_function *func; struct list *parameters; - struct list *body; + struct list body; + bool has_body; };
struct hlsl_ir_if diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index e591af9bb..27ebf0722 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2053,7 +2053,7 @@ hlsl_prog: decl = get_func_decl(&ctx->functions, $2.name, $2.decl->parameters); if (decl && !decl->func->intrinsic) { - if (decl->body && $2.decl->body) + if (decl->has_body && $2.decl->has_body) { hlsl_error(ctx, $2.decl->loc, VKD3D_SHADER_ERROR_HLSL_REDEFINED, "Function "%s" is already defined.", $2.name); @@ -2247,7 +2247,9 @@ func_declaration: func_prototype compound_statement { $$ = $1; - $$.decl->body = $2; + $$.decl->has_body = true; + list_move_tail(&$$.decl->body, $2); + vkd3d_free($2); hlsl_pop_scope(ctx); } | func_prototype ';' diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 03c098fe1..a96c701d7 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -567,7 +567,7 @@ 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) + if (func->has_body) hlsl_dump_function(ctx, func); }
@@ -674,7 +674,7 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl struct hlsl_ir_var *var;
/* Index 0 means unused; index 1 means function entry, so start at 2. */ - index_instructions(entry_func->body, 2); + index_instructions(&entry_func->body, 2);
LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) { @@ -693,7 +693,7 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl if (entry_func->return_var) entry_func->return_var->last_read = UINT_MAX;
- compute_liveness_recurse(entry_func->body, 0, 0); + compute_liveness_recurse(&entry_func->body, 0, 0); }
struct liveness @@ -1001,7 +1001,7 @@ static void allocate_const_registers(struct hlsl_ctx *ctx, struct hlsl_ir_functi struct liveness liveness = {0}; struct hlsl_ir_var *var;
- allocate_const_registers_recurse(ctx, entry_func->body, &liveness); + allocate_const_registers_recurse(ctx, &entry_func->body, &liveness);
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) { @@ -1026,7 +1026,7 @@ static void allocate_const_registers(struct hlsl_ctx *ctx, struct hlsl_ir_functi static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func) { struct liveness liveness = {0}; - allocate_temp_registers_recurse(ctx, entry_func->body, &liveness); + allocate_temp_registers_recurse(ctx, &entry_func->body, &liveness); ctx->temp_count = liveness.reg_count; vkd3d_free(liveness.regs); } @@ -1303,22 +1303,23 @@ struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const struct
int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out) { + struct list *const body = &entry_func->body; struct hlsl_ir_var *var; bool progress;
- list_move_head(entry_func->body, &ctx->static_initializers); + list_move_head(body, &ctx->static_initializers);
LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) { if (var->modifiers & HLSL_STORAGE_UNIFORM) - prepend_uniform_copy(ctx, entry_func->body, var); + prepend_uniform_copy(ctx, body, var); }
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry) { if (var->data_type->type == HLSL_CLASS_OBJECT || (var->modifiers & HLSL_STORAGE_UNIFORM)) { - prepend_uniform_copy(ctx, entry_func->body, var); + prepend_uniform_copy(ctx, body, var); } else { @@ -1327,9 +1328,9 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun "Parameter "%s" is missing a semantic.", var->name);
if (var->modifiers & HLSL_STORAGE_IN) - prepend_input_var_copy(ctx, entry_func->body, var); + prepend_input_var_copy(ctx, body, var); if (var->modifiers & HLSL_STORAGE_OUT) - append_output_var_copy(ctx, entry_func->body, var); + append_output_var_copy(ctx, body, var); } } if (entry_func->return_var) @@ -1338,24 +1339,24 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, "Entry point "%s" is missing a return value semantic.", entry_func->func->name);
- append_output_var_copy(ctx, entry_func->body, entry_func->return_var); + append_output_var_copy(ctx, body, entry_func->return_var); }
- while (transform_ir(ctx, fold_redundant_casts, entry_func->body, NULL)); + while (transform_ir(ctx, fold_redundant_casts, body, NULL)); do { - progress = transform_ir(ctx, split_array_copies, entry_func->body, NULL); - progress |= transform_ir(ctx, split_struct_copies, entry_func->body, NULL); + progress = transform_ir(ctx, split_array_copies, body, NULL); + progress |= transform_ir(ctx, split_struct_copies, body, NULL); } while (progress); - while (transform_ir(ctx, fold_constants, entry_func->body, NULL)); + while (transform_ir(ctx, fold_constants, body, NULL));
if (ctx->profile->major_version < 4) - transform_ir(ctx, lower_division, entry_func->body, NULL); + transform_ir(ctx, lower_division, body, NULL);
do compute_liveness(ctx, entry_func); - while (transform_ir(ctx, dce, entry_func->body, NULL)); + while (transform_ir(ctx, dce, body, NULL));
compute_liveness(ctx, entry_func);
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index 9fc1b2210..f7ccf742f 100644 --- a/libs/vkd3d-shader/hlsl_sm1.c +++ b/libs/vkd3d-shader/hlsl_sm1.c @@ -768,7 +768,7 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct vkd3d_bytecode_b { const struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, entry_func->body, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &entry_func->body, struct hlsl_ir_node, entry) { if (instr->data_type) { diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index c979e14ac..aee06b004 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1472,7 +1472,7 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, if (ctx->temp_count) write_sm4_dcl_temps(&buffer, ctx->temp_count);
- LIST_FOR_EACH_ENTRY(instr, entry_func->body, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &entry_func->body, struct hlsl_ir_node, entry) { if (instr->data_type) {