This fixes DCE.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- I'm sure I had a reason for using a separate field here, but I can't remember it now, nor find any reason why it would matter.
libs/vkd3d-shader/hlsl.h | 1 - libs/vkd3d-shader/hlsl_codegen.c | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 31b7ddbb6..93191e56b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -240,7 +240,6 @@ struct hlsl_ir_var uint32_t is_output_semantic : 1; uint32_t is_uniform : 1; uint32_t is_param : 1; - uint32_t has_resource_access : 1; };
struct hlsl_ir_function diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index bf93a03df..b7b0cd1b8 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -591,6 +591,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) { + const unsigned int var_last_read = loop_last ? max(instr->index, loop_last) : instr->index; + switch (instr->type) { case HLSL_IR_STORE: @@ -628,7 +630,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs struct hlsl_ir_load *load = hlsl_ir_load(instr);
var = load->src.var; - var->last_read = max(var->last_read, loop_last ? max(instr->index, loop_last) : instr->index); + var->last_read = max(var->last_read, var_last_read); if (load->src.offset.node) load->src.offset.node->last_read = instr->index; break; @@ -645,7 +647,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs { struct hlsl_ir_resource_load *load = hlsl_ir_resource_load(instr);
- load->resource.var->has_resource_access = 1; + var = load->resource.var; + var->last_read = max(var->last_read, var_last_read); if (load->resource.offset.node) load->resource.offset.node->last_read = instr->index; load->coords.node->last_read = instr->index; @@ -676,10 +679,7 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) { LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry) - { var->first_write = var->last_read = 0; - var->has_resource_access = 0; - } }
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) @@ -1203,7 +1203,7 @@ static const struct hlsl_ir_var *get_reserved_texture(struct hlsl_ctx *ctx, uint
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, const struct hlsl_ir_var, extern_entry) { - if (var->has_resource_access && var->reg_reservation.type == 't' && var->reg_reservation.index == index) + if (var->last_read && var->reg_reservation.type == 't' && var->reg_reservation.index == index) return var; } return NULL; @@ -1216,7 +1216,7 @@ static void allocate_textures(struct hlsl_ctx *ctx)
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) { - if (!var->has_resource_access || var->data_type->type != HLSL_CLASS_OBJECT + if (!var->last_read || var->data_type->type != HLSL_CLASS_OBJECT || var->data_type->base_type != HLSL_TYPE_TEXTURE) continue;
These can be assigned to when compatibility mode is used.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_codegen.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index b7b0cd1b8..03c098fe1 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1310,35 +1310,26 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) { - if (var->data_type->type == HLSL_CLASS_OBJECT) - list_add_tail(&ctx->extern_vars, &var->extern_entry); - else if (var->modifiers & HLSL_STORAGE_UNIFORM) + if (var->modifiers & HLSL_STORAGE_UNIFORM) prepend_uniform_copy(ctx, entry_func->body, var); }
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry) { - if (var->data_type->type == HLSL_CLASS_OBJECT) + if (var->data_type->type == HLSL_CLASS_OBJECT || (var->modifiers & HLSL_STORAGE_UNIFORM)) { - list_add_tail(&ctx->extern_vars, &var->extern_entry); + prepend_uniform_copy(ctx, entry_func->body, var); } else { - if (var->modifiers & HLSL_STORAGE_UNIFORM) - { - prepend_uniform_copy(ctx, entry_func->body, var); - } - else - { - if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic.name) - hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, - "Parameter "%s" is missing a semantic.", var->name); - - if (var->modifiers & HLSL_STORAGE_IN) - prepend_input_var_copy(ctx, entry_func->body, var); - if (var->modifiers & HLSL_STORAGE_OUT) - append_output_var_copy(ctx, entry_func->body, var); - } + if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic.name) + hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, + "Parameter "%s" is missing a semantic.", var->name); + + if (var->modifiers & HLSL_STORAGE_IN) + prepend_input_var_copy(ctx, entry_func->body, var); + if (var->modifiers & HLSL_STORAGE_OUT) + append_output_var_copy(ctx, entry_func->body, var); } } if (entry_func->return_var)
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 15/10/21 23:54, Zebediah Figura ha scritto:
These can be assigned to when compatibility mode is used.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_codegen.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index b7b0cd1b8..03c098fe1 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1310,35 +1310,26 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) {
if (var->data_type->type == HLSL_CLASS_OBJECT)
list_add_tail(&ctx->extern_vars, &var->extern_entry);
else if (var->modifiers & HLSL_STORAGE_UNIFORM)
if (var->modifiers & HLSL_STORAGE_UNIFORM) prepend_uniform_copy(ctx, entry_func->body, var); } LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry) {
if (var->data_type->type == HLSL_CLASS_OBJECT)
if (var->data_type->type == HLSL_CLASS_OBJECT || (var->modifiers & HLSL_STORAGE_UNIFORM)) {
list_add_tail(&ctx->extern_vars, &var->extern_entry);
prepend_uniform_copy(ctx, entry_func->body, var); } else {
if (var->modifiers & HLSL_STORAGE_UNIFORM)
{
prepend_uniform_copy(ctx, entry_func->body, var);
}
else
{
if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic.name)
hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
"Parameter \"%s\" is missing a semantic.", var->name);
if (var->modifiers & HLSL_STORAGE_IN)
prepend_input_var_copy(ctx, entry_func->body, var);
if (var->modifiers & HLSL_STORAGE_OUT)
append_output_var_copy(ctx, entry_func->body, var);
}
if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic.name)
hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC,
"Parameter \"%s\" is missing a semantic.", var->name);
if (var->modifiers & HLSL_STORAGE_IN)
prepend_input_var_copy(ctx, entry_func->body, var);
if (var->modifiers & HLSL_STORAGE_OUT)
append_output_var_copy(ctx, entry_func->body, var); } } if (entry_func->return_var)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
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) {
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 15/10/21 23:54, Zebediah Figura ha scritto:
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) {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
This doesn't hold anything other than a list, nor do I have any immediate plans for it to hold anything other than a list, but I'm adding it for some degree of clarity. Passing around untyped list pointers is not my favourite hobby.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 24 +++++++++++----------- libs/vkd3d-shader/hlsl.h | 13 ++++++++---- libs/vkd3d-shader/hlsl.y | 16 +++++++-------- libs/vkd3d-shader/hlsl_codegen.c | 34 ++++++++++++++++---------------- libs/vkd3d-shader/hlsl_sm1.c | 2 +- libs/vkd3d-shader/hlsl_sm4.c | 2 +- 6 files changed, 48 insertions(+), 43 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 641e05471..a72e0a18f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -602,8 +602,8 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condit return NULL; init_node(&iff->node, HLSL_IR_IF, NULL, loc); hlsl_src_from_node(&iff->condition, condition); - list_init(&iff->then_instrs); - list_init(&iff->else_instrs); + list_init(&iff->then_instrs.instrs); + list_init(&iff->else_instrs.instrs); return iff; }
@@ -674,7 +674,7 @@ struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_loc if (!(loop = hlsl_alloc(ctx, sizeof(*loop)))) return NULL; init_node(&loop->node, HLSL_IR_LOOP, NULL, loc); - list_init(&loop->body); + list_init(&loop->body.instrs); return loop; }
@@ -685,7 +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); + list_init(&decl->body.instrs); decl->return_type = return_type; decl->parameters = parameters; decl->loc = loc; @@ -1199,9 +1199,9 @@ static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, vkd3d_string_buffer_printf(buffer, "if ("); dump_src(buffer, &if_node->condition); vkd3d_string_buffer_printf(buffer, ")\n{\n"); - dump_instr_list(ctx, buffer, &if_node->then_instrs); + dump_instr_list(ctx, buffer, &if_node->then_instrs.instrs); vkd3d_string_buffer_printf(buffer, "}\nelse\n{\n"); - dump_instr_list(ctx, buffer, &if_node->else_instrs); + dump_instr_list(ctx, buffer, &if_node->else_instrs.instrs); vkd3d_string_buffer_printf(buffer, "}\n"); }
@@ -1230,7 +1230,7 @@ static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_i 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(ctx, buffer, &loop->body); + dump_instr_list(ctx, buffer, &loop->body.instrs); vkd3d_string_buffer_printf(buffer, "}\n"); }
@@ -1342,7 +1342,7 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl vkd3d_string_buffer_printf(&buffer, "\n"); } if (func->has_body) - dump_instr_list(ctx, &buffer, &func->body); + dump_instr_list(ctx, &buffer, &func->body.instrs);
vkd3d_string_buffer_trace(&buffer); vkd3d_string_buffer_cleanup(&buffer); @@ -1393,8 +1393,8 @@ static void free_ir_expr(struct hlsl_ir_expr *expr)
static void free_ir_if(struct hlsl_ir_if *if_node) { - hlsl_free_instr_list(&if_node->then_instrs); - hlsl_free_instr_list(&if_node->else_instrs); + hlsl_free_instr_list(&if_node->then_instrs.instrs); + hlsl_free_instr_list(&if_node->else_instrs.instrs); hlsl_src_remove(&if_node->condition); vkd3d_free(if_node); } @@ -1412,7 +1412,7 @@ static void free_ir_load(struct hlsl_ir_load *load)
static void free_ir_loop(struct hlsl_ir_loop *loop) { - hlsl_free_instr_list(&loop->body); + hlsl_free_instr_list(&loop->body.instrs); vkd3d_free(loop); }
@@ -1483,7 +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); + hlsl_free_instr_list(&decl->body.instrs); vkd3d_free(decl); }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 99e00b081..a7503d5c8 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -189,6 +189,11 @@ struct hlsl_ir_node struct hlsl_reg reg; };
+struct hlsl_block +{ + struct list instrs; +}; + struct hlsl_src { struct hlsl_ir_node *node; @@ -258,7 +263,7 @@ struct hlsl_ir_function_decl struct rb_entry entry; struct hlsl_ir_function *func; struct list *parameters; - struct list body; + struct hlsl_block body; bool has_body; };
@@ -266,15 +271,15 @@ struct hlsl_ir_if { struct hlsl_ir_node node; struct hlsl_src condition; - struct list then_instrs; - struct list else_instrs; + struct hlsl_block then_instrs; + struct hlsl_block else_instrs; };
struct hlsl_ir_loop { struct hlsl_ir_node node; /* loop condition is stored in the body (as "if (!condition) break;") */ - struct list body; + struct hlsl_block body; unsigned int next_index; /* liveness index of the end of the loop */ };
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 27ebf0722..aae0ebcea 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -340,7 +340,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_lis
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, condition->loc))) return false; - list_add_head(&iff->then_instrs, &jump->node.entry); + list_add_head(&iff->then_instrs.instrs, &jump->node.entry); return true; }
@@ -372,15 +372,15 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, struc goto oom;
if (type != LOOP_DO_WHILE) - list_move_tail(&loop->body, cond); + list_move_tail(&loop->body.instrs, cond);
- list_move_tail(&loop->body, body); + list_move_tail(&loop->body.instrs, body);
if (iter) - list_move_tail(&loop->body, iter); + list_move_tail(&loop->body.instrs, iter);
if (type == LOOP_DO_WHILE) - list_move_tail(&loop->body, cond); + list_move_tail(&loop->body.instrs, cond);
vkd3d_free(init); vkd3d_free(cond); @@ -2248,7 +2248,7 @@ func_declaration: { $$ = $1; $$.decl->has_body = true; - list_move_tail(&$$.decl->body, $2); + list_move_tail(&$$.decl->body.instrs, $2); vkd3d_free($2); hlsl_pop_scope(ctx); } @@ -2876,9 +2876,9 @@ selection_statement:
if (!(instr = hlsl_new_if(ctx, condition, @1))) YYABORT; - list_move_tail(&instr->then_instrs, $5.then_instrs); + list_move_tail(&instr->then_instrs.instrs, $5.then_instrs); if ($5.else_instrs) - list_move_tail(&instr->else_instrs, $5.else_instrs); + list_move_tail(&instr->else_instrs.instrs, $5.else_instrs); vkd3d_free($5.then_instrs); vkd3d_free($5.else_instrs); if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index a96c701d7..a48777645 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -201,12 +201,12 @@ static void append_output_var_copy(struct hlsl_ctx *ctx, struct list *instrs, st }
static bool transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *), - struct list *instrs, void *context) + struct hlsl_block *block, void *context) { struct hlsl_ir_node *instr, *next; bool progress = 0;
- LIST_FOR_EACH_ENTRY_SAFE(instr, next, instrs, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY_SAFE(instr, next, &block->instrs, struct hlsl_ir_node, entry) { if (instr->type == HLSL_IR_IF) { @@ -538,11 +538,11 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
/* Allocate a unique, ordered index to each instruction, which will be used for * computing liveness ranges. */ -static unsigned int index_instructions(struct list *instrs, unsigned int index) +static unsigned int index_instructions(struct hlsl_block *block, unsigned int index) { struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { instr->index = index++;
@@ -584,12 +584,12 @@ static void dump_function(struct rb_entry *entry, void *context) * to at least the range of the entire loop. Note that we don't need to do this * for anonymous nodes, since there's currently no way to use a node which was * calculated in an earlier iteration of the loop. */ -static void compute_liveness_recurse(struct list *instrs, unsigned int loop_first, unsigned int loop_last) +static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop_first, unsigned int loop_last) { struct hlsl_ir_node *instr; struct hlsl_ir_var *var;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { const unsigned int var_last_read = loop_last ? max(instr->index, loop_last) : instr->index;
@@ -836,11 +836,11 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir } }
-static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness) +static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness) { struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { if (!instr->reg.allocated && instr->last_read) { @@ -893,12 +893,12 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *i } }
-static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness) +static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness) { struct hlsl_constant_defs *defs = &ctx->constant_defs; struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { switch (instr->type) { @@ -1303,23 +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_block *const body = &entry_func->body; struct hlsl_ir_var *var; bool progress;
- list_move_head(body, &ctx->static_initializers); + list_move_head(&body->instrs, &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, body, var); + prepend_uniform_copy(ctx, &body->instrs, 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, body, var); + prepend_uniform_copy(ctx, &body->instrs, var); } else { @@ -1328,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, body, var); + prepend_input_var_copy(ctx, &body->instrs, var); if (var->modifiers & HLSL_STORAGE_OUT) - append_output_var_copy(ctx, body, var); + append_output_var_copy(ctx, &body->instrs, var); } } if (entry_func->return_var) @@ -1339,7 +1339,7 @@ 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, body, entry_func->return_var); + append_output_var_copy(ctx, &body->instrs, entry_func->return_var); }
while (transform_ir(ctx, fold_redundant_casts, body, NULL)); diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index f7ccf742f..c3d27eea1 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.instrs, 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 aee06b004..9d45e1633 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.instrs, struct hlsl_ir_node, entry) { if (instr->data_type) {
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- Absolutely agree with this one.
Let me just notice that it becomes a little odd to have stuff like then_instrs.instrs. Maybe "then_instrs" could be replaced with "then_branch" or "then_body", given that with the new typing it refers to the block as a whole, not to a list of instructions (even though the block is nothing else than a list of instructions).
Il 15/10/21 23:54, Zebediah Figura ha scritto:
This doesn't hold anything other than a list, nor do I have any immediate plans for it to hold anything other than a list, but I'm adding it for some degree of clarity. Passing around untyped list pointers is not my favourite hobby.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.c | 24 +++++++++++----------- libs/vkd3d-shader/hlsl.h | 13 ++++++++---- libs/vkd3d-shader/hlsl.y | 16 +++++++-------- libs/vkd3d-shader/hlsl_codegen.c | 34 ++++++++++++++++---------------- libs/vkd3d-shader/hlsl_sm1.c | 2 +- libs/vkd3d-shader/hlsl_sm4.c | 2 +- 6 files changed, 48 insertions(+), 43 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 641e05471..a72e0a18f 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -602,8 +602,8 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condit return NULL; init_node(&iff->node, HLSL_IR_IF, NULL, loc); hlsl_src_from_node(&iff->condition, condition);
- list_init(&iff->then_instrs);
- list_init(&iff->else_instrs);
- list_init(&iff->then_instrs.instrs);
- list_init(&iff->else_instrs.instrs); return iff; }
@@ -674,7 +674,7 @@ struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_loc if (!(loop = hlsl_alloc(ctx, sizeof(*loop)))) return NULL; init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
- list_init(&loop->body);
- list_init(&loop->body.instrs); return loop; }
@@ -685,7 +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);
- list_init(&decl->body.instrs); decl->return_type = return_type; decl->parameters = parameters; decl->loc = loc;
@@ -1199,9 +1199,9 @@ static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, vkd3d_string_buffer_printf(buffer, "if ("); dump_src(buffer, &if_node->condition); vkd3d_string_buffer_printf(buffer, ")\n{\n");
- dump_instr_list(ctx, buffer, &if_node->then_instrs);
- dump_instr_list(ctx, buffer, &if_node->then_instrs.instrs); vkd3d_string_buffer_printf(buffer, "}\nelse\n{\n");
- dump_instr_list(ctx, buffer, &if_node->else_instrs);
- dump_instr_list(ctx, buffer, &if_node->else_instrs.instrs); vkd3d_string_buffer_printf(buffer, "}\n"); }
@@ -1230,7 +1230,7 @@ static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_i 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(ctx, buffer, &loop->body);
- dump_instr_list(ctx, buffer, &loop->body.instrs); vkd3d_string_buffer_printf(buffer, "}\n"); }
@@ -1342,7 +1342,7 @@ void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl vkd3d_string_buffer_printf(&buffer, "\n"); } if (func->has_body)
dump_instr_list(ctx, &buffer, &func->body);
dump_instr_list(ctx, &buffer, &func->body.instrs); vkd3d_string_buffer_trace(&buffer); vkd3d_string_buffer_cleanup(&buffer);
@@ -1393,8 +1393,8 @@ static void free_ir_expr(struct hlsl_ir_expr *expr)
static void free_ir_if(struct hlsl_ir_if *if_node) {
- hlsl_free_instr_list(&if_node->then_instrs);
- hlsl_free_instr_list(&if_node->else_instrs);
- hlsl_free_instr_list(&if_node->then_instrs.instrs);
- hlsl_free_instr_list(&if_node->else_instrs.instrs); hlsl_src_remove(&if_node->condition); vkd3d_free(if_node); }
@@ -1412,7 +1412,7 @@ static void free_ir_load(struct hlsl_ir_load *load)
static void free_ir_loop(struct hlsl_ir_loop *loop) {
- hlsl_free_instr_list(&loop->body);
- hlsl_free_instr_list(&loop->body.instrs); vkd3d_free(loop); }
@@ -1483,7 +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);
- hlsl_free_instr_list(&decl->body.instrs); vkd3d_free(decl); }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 99e00b081..a7503d5c8 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -189,6 +189,11 @@ struct hlsl_ir_node struct hlsl_reg reg; };
+struct hlsl_block +{
- struct list instrs;
+};
- struct hlsl_src { struct hlsl_ir_node *node;
@@ -258,7 +263,7 @@ struct hlsl_ir_function_decl struct rb_entry entry; struct hlsl_ir_function *func; struct list *parameters;
- struct list body;
- struct hlsl_block body; bool has_body; };
@@ -266,15 +271,15 @@ struct hlsl_ir_if { struct hlsl_ir_node node; struct hlsl_src condition;
- struct list then_instrs;
- struct list else_instrs;
struct hlsl_block then_instrs;
struct hlsl_block else_instrs; };
struct hlsl_ir_loop { struct hlsl_ir_node node; /* loop condition is stored in the body (as "if (!condition) break;") */
- struct list body;
- struct hlsl_block body; unsigned int next_index; /* liveness index of the end of the loop */ };
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 27ebf0722..aae0ebcea 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -340,7 +340,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_lis
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, condition->loc))) return false;
- list_add_head(&iff->then_instrs, &jump->node.entry);
- list_add_head(&iff->then_instrs.instrs, &jump->node.entry); return true; }
@@ -372,15 +372,15 @@ static struct list *create_loop(struct hlsl_ctx *ctx, enum loop_type type, struc goto oom;
if (type != LOOP_DO_WHILE)
list_move_tail(&loop->body, cond);
list_move_tail(&loop->body.instrs, cond);
- list_move_tail(&loop->body, body);
list_move_tail(&loop->body.instrs, body);
if (iter)
list_move_tail(&loop->body, iter);
list_move_tail(&loop->body.instrs, iter); if (type == LOOP_DO_WHILE)
list_move_tail(&loop->body, cond);
list_move_tail(&loop->body.instrs, cond); vkd3d_free(init); vkd3d_free(cond);
@@ -2248,7 +2248,7 @@ func_declaration: { $$ = $1; $$.decl->has_body = true;
list_move_tail(&$$.decl->body, $2);
list_move_tail(&$$.decl->body.instrs, $2); vkd3d_free($2); hlsl_pop_scope(ctx); }
@@ -2876,9 +2876,9 @@ selection_statement:
if (!(instr = hlsl_new_if(ctx, condition, @1))) YYABORT;
list_move_tail(&instr->then_instrs, $5.then_instrs);
list_move_tail(&instr->then_instrs.instrs, $5.then_instrs); if ($5.else_instrs)
list_move_tail(&instr->else_instrs, $5.else_instrs);
list_move_tail(&instr->else_instrs.instrs, $5.else_instrs); vkd3d_free($5.then_instrs); vkd3d_free($5.else_instrs); if (condition->data_type->dimx > 1 || condition->data_type->dimy > 1)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index a96c701d7..a48777645 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -201,12 +201,12 @@ static void append_output_var_copy(struct hlsl_ctx *ctx, struct list *instrs, st }
static bool transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *),
struct list *instrs, void *context)
{ struct hlsl_ir_node *instr, *next; bool progress = 0;struct hlsl_block *block, void *context)
- LIST_FOR_EACH_ENTRY_SAFE(instr, next, instrs, struct hlsl_ir_node, entry)
- LIST_FOR_EACH_ENTRY_SAFE(instr, next, &block->instrs, struct hlsl_ir_node, entry) { if (instr->type == HLSL_IR_IF) {
@@ -538,11 +538,11 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
/* Allocate a unique, ordered index to each instruction, which will be used for
- computing liveness ranges. */
-static unsigned int index_instructions(struct list *instrs, unsigned int index) +static unsigned int index_instructions(struct hlsl_block *block, unsigned int index) { struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
- LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { instr->index = index++;
@@ -584,12 +584,12 @@ static void dump_function(struct rb_entry *entry, void *context)
- to at least the range of the entire loop. Note that we don't need to do this
- for anonymous nodes, since there's currently no way to use a node which was
- calculated in an earlier iteration of the loop. */
-static void compute_liveness_recurse(struct list *instrs, unsigned int loop_first, unsigned int loop_last) +static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop_first, unsigned int loop_last) { struct hlsl_ir_node *instr; struct hlsl_ir_var *var;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
- LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { const unsigned int var_last_read = loop_last ? max(instr->index, loop_last) : instr->index;
@@ -836,11 +836,11 @@ static void allocate_variable_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir } }
-static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness) +static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness) { struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
- LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { if (!instr->reg.allocated && instr->last_read) {
@@ -893,12 +893,12 @@ static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *i } }
-static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness) +static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block, struct liveness *liveness) { struct hlsl_constant_defs *defs = &ctx->constant_defs; struct hlsl_ir_node *instr;
- LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry)
- LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) { switch (instr->type) {
@@ -1303,23 +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_block *const body = &entry_func->body; struct hlsl_ir_var *var; bool progress;
- list_move_head(body, &ctx->static_initializers);
list_move_head(&body->instrs, &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, body, var);
prepend_uniform_copy(ctx, &body->instrs, 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, body, var);
prepend_uniform_copy(ctx, &body->instrs, var); } else {
@@ -1328,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, body, var);
prepend_input_var_copy(ctx, &body->instrs, var); if (var->modifiers & HLSL_STORAGE_OUT)
append_output_var_copy(ctx, body, var);
append_output_var_copy(ctx, &body->instrs, var); } } if (entry_func->return_var)
@@ -1339,7 +1339,7 @@ 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, body, entry_func->return_var);
append_output_var_copy(ctx, &body->instrs, entry_func->return_var); } while (transform_ir(ctx, fold_redundant_casts, body, NULL));
diff --git a/libs/vkd3d-shader/hlsl_sm1.c b/libs/vkd3d-shader/hlsl_sm1.c index f7ccf742f..c3d27eea1 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.instrs, 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 aee06b004..9d45e1633 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.instrs, struct hlsl_ir_node, entry) { if (instr->data_type) {
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
The return variable was already added to the extern_vars list and marked as an output semantic by the append_output_var_copy() call above, so the preceding loop will take care of setting the last_read field.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_codegen.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index a48777645..df10ca272 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -690,9 +690,6 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl var->last_read = UINT_MAX; }
- if (entry_func->return_var) - entry_func->return_var->last_read = UINT_MAX; - compute_liveness_recurse(&entry_func->body, 0, 0); }
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 15/10/21 23:54, Zebediah Figura ha scritto:
The return variable was already added to the extern_vars list and marked as an output semantic by the append_output_var_copy() call above, so the preceding loop will take care of setting the last_read field.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_codegen.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index a48777645..df10ca272 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -690,9 +690,6 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl var->last_read = UINT_MAX; }
- if (entry_func->return_var)
entry_func->return_var->last_read = UINT_MAX;
}compute_liveness_recurse(&entry_func->body, 0, 0);
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
On Fri, Oct 15, 2021 at 11:54 PM Zebediah Figura zfigura@codeweavers.com wrote:
The return variable was already added to the extern_vars list and marked as an output semantic by the append_output_var_copy() call above, so the preceding loop will take care of setting the last_read field.
The "above" in the commit message is a bit vague / inaccurate. Just mentioning it, certainly nothing worth a resend or any other kind of action.
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
As a cheap substitute for actual variable copy-prop.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_codegen.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index df10ca272..495ba7c47 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -34,6 +34,13 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru /* Use the synthetic name for the temp, rather than the uniform, so that we * can write the uniform name into the shader reflection data. */
+ if (!temp->first_write) + { + temp->is_uniform = 1; + list_add_tail(&ctx->extern_vars, &temp->extern_entry); + return; + } + if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, &temp->reg_reservation))) return; list_add_before(&temp->scope_entry, &uniform->scope_entry); @@ -67,6 +74,14 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_load *load; struct hlsl_ir_var *input;
+ /* We still need to split up non-vector types. */ + if (!var->first_write && var->data_type->type <= HLSL_CLASS_VECTOR) + { + var->is_input_semantic = 1; + list_add_tail(&ctx->extern_vars, &var->extern_entry); + return; + } + if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index); @@ -138,6 +153,14 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_var *output; struct hlsl_ir_load *load;
+ /* We still need to split up non-vector types. */ + if (!var->last_read && var->data_type->type <= HLSL_CLASS_VECTOR) + { + var->is_output_semantic = 1; + list_add_tail(&ctx->extern_vars, &var->extern_entry); + return; + } + if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index); @@ -1306,6 +1329,12 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
list_move_head(&body->instrs, &ctx->static_initializers);
+ /* Do an initial liveness pass for externs so that we don't create + * unnecessary temps. Note that we might modify the instruction stream + * during the pass, but we're only checking whether a variable was read to + * or written from at all, so it's okay. */ + compute_liveness(ctx, entry_func); + LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) { if (var->modifiers & HLSL_STORAGE_UNIFORM)
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- Again, some nitpicking about the commit message: like "DCE", "copy-prop" doesn't necessarily mean something to people who might like to learn about this code, and search engine do not seem to unilaterally associate it with "copy propagation". I think the few additional bytes are totally worth the value they bring.
On the other hand, I would suggest to keep the first line a bit shorter, because the general agreement is that it should be in the whereabouts of 80 characters and user interfaces are usually tuned on that. Also, while in general I'm all for anthropomorphize whatever in the universe in colloquial language, I don't think it does well when clarity is needed. At the same time, I don't think that compilers are particularly bothered by having to synthesize temporaries: it's their job, and they'd better be fine with it, or find some other way to bring home their bacon.
Therefore I would suggest something like: "vkd3d-shader/hlsl: Don't synthesize unnecessary temporaries", and perhaps explain in greater detail in the commit message.
Il 15/10/21 23:54, Zebediah Figura ha scritto:
As a cheap substitute for actual variable copy-prop.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_codegen.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index df10ca272..495ba7c47 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -34,6 +34,13 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru /* Use the synthetic name for the temp, rather than the uniform, so that we * can write the uniform name into the shader reflection data. */
- if (!temp->first_write)
- {
temp->is_uniform = 1;
list_add_tail(&ctx->extern_vars, &temp->extern_entry);
return;
- }
if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, &temp->reg_reservation))) return; list_add_before(&temp->scope_entry, &uniform->scope_entry);
@@ -67,6 +74,14 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_load *load; struct hlsl_ir_var *input;
- /* We still need to split up non-vector types. */
- if (!var->first_write && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_input_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index);
@@ -138,6 +153,14 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_var *output; struct hlsl_ir_load *load;
- /* We still need to split up non-vector types. */
- if (!var->last_read && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_output_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index);
@@ -1306,6 +1329,12 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
list_move_head(&body->instrs, &ctx->static_initializers);
- /* Do an initial liveness pass for externs so that we don't create
* unnecessary temps. Note that we might modify the instruction stream
* during the pass, but we're only checking whether a variable was read to
* or written from at all, so it's okay. */
- compute_liveness(ctx, entry_func);
LIST_FOR_EACH_ENTRY(var, &ctx->globals->vars, struct hlsl_ir_var, scope_entry) { if (var->modifiers & HLSL_STORAGE_UNIFORM)
On Fri, Oct 15, 2021 at 11:54 PM Zebediah Figura zfigura@codeweavers.com wrote:
As a cheap substitute for actual variable copy-prop.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_codegen.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index df10ca272..495ba7c47 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -34,6 +34,13 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru /* Use the synthetic name for the temp, rather than the uniform, so that we * can write the uniform name into the shader reflection data. */
- if (!temp->first_write)
- {
temp->is_uniform = 1;
list_add_tail(&ctx->extern_vars, &temp->extern_entry);
return;
- }
- if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, &temp->reg_reservation))) return; list_add_before(&temp->scope_entry, &uniform->scope_entry);
Technically this hunk is not covered by the patch subject.
I'm not sure I love these checks being in the functions rather than in the caller. It might just be about function naming... I guess what's bugging me is that, for "good" uniforms, prepend_uniform_copy() will NOT prepend any copy but still do something significant.
@@ -67,6 +74,14 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_load *load; struct hlsl_ir_var *input;
- /* We still need to split up non-vector types. */
- if (!var->first_write && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_input_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
- if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index);
It's not obvious what splitting up input matrices (which is not there at all at the moment) has to do with adding a copy from an input variable.
@@ -138,6 +153,14 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_var *output; struct hlsl_ir_load *load;
- /* We still need to split up non-vector types. */
- if (!var->last_read && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_output_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
- if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index);
@@ -1306,6 +1329,12 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
list_move_head(&body->instrs, &ctx->static_initializers);
- /* Do an initial liveness pass for externs so that we don't create
* unnecessary temps. Note that we might modify the instruction stream
* during the pass, but we're only checking whether a variable was read to
* or written from at all, so it's okay. */
- compute_liveness(ctx, entry_func);
We shouldn't be modifying the instructions (aside from liveness data, of course) in compute_liveness(). I guess you mean that we can safely keep using liveness data that potentially becomes somewhat invalid during / after calling prepend_uniform_copy() / prepend_input_var_copy() / append_output_var_copy() but I'm having a hard time parsing the comment.
On 10/26/21 07:48, Matteo Bruni wrote:
On Fri, Oct 15, 2021 at 11:54 PM Zebediah Figura zfigura@codeweavers.com wrote:
As a cheap substitute for actual variable copy-prop.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_codegen.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index df10ca272..495ba7c47 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -34,6 +34,13 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru /* Use the synthetic name for the temp, rather than the uniform, so that we * can write the uniform name into the shader reflection data. */
- if (!temp->first_write)
- {
temp->is_uniform = 1;
list_add_tail(&ctx->extern_vars, &temp->extern_entry);
return;
- }
if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, &temp->reg_reservation))) return; list_add_before(&temp->scope_entry, &uniform->scope_entry);
Technically this hunk is not covered by the patch subject.
I'm not sure I love these checks being in the functions rather than in the caller. It might just be about function naming... I guess what's bugging me is that, for "good" uniforms, prepend_uniform_copy() will NOT prepend any copy but still do something significant.
It's a fair cop.
I suppose it could be renamed to lower_uniform_writes() etc...
@@ -67,6 +74,14 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_load *load; struct hlsl_ir_var *input;
- /* We still need to split up non-vector types. */
- if (!var->first_write && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_input_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index);
It's not obvious what splitting up input matrices (which is not there at all at the moment) has to do with adding a copy from an input variable.
Are input matrices even possible?
I'll have to clarify the comment in any case...
@@ -138,6 +153,14 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct struct hlsl_ir_var *output; struct hlsl_ir_load *load;
- /* We still need to split up non-vector types. */
- if (!var->last_read && var->data_type->type <= HLSL_CLASS_VECTOR)
- {
var->is_output_semantic = 1;
list_add_tail(&ctx->extern_vars, &var->extern_entry);
return;
- }
if (!(name = hlsl_get_string_buffer(ctx))) return; vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index);
@@ -1306,6 +1329,12 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
list_move_head(&body->instrs, &ctx->static_initializers);
- /* Do an initial liveness pass for externs so that we don't create
* unnecessary temps. Note that we might modify the instruction stream
* during the pass, but we're only checking whether a variable was read to
* or written from at all, so it's okay. */
- compute_liveness(ctx, entry_func);
We shouldn't be modifying the instructions (aside from liveness data, of course) in compute_liveness(). I guess you mean that we can safely keep using liveness data that potentially becomes somewhat invalid during / after calling prepend_uniform_copy() / prepend_input_var_copy() / append_output_var_copy() but I'm having a hard time parsing the comment.
Er, right, "the pass" means the pass after compute_liveness()...
Clearly this patch needs more clarity.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 - libs/vkd3d-shader/hlsl_sm4.c | 95 +++++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/Makefile.am b/Makefile.am index eaa4f8168..5a6dd6318 100644 --- a/Makefile.am +++ b/Makefile.am @@ -302,8 +302,6 @@ XFAIL_TESTS = \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/math.shader_test \ tests/max.shader_test \ - tests/texture-load.shader_test \ - tests/texture-load-typed.shader_test \ tests/trigonometry.shader_test \ tests/writemask-assignop-1.shader_test endif diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 9d45e1633..246aeebfe 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -763,6 +763,7 @@ static unsigned int sm4_swizzle_type(enum vkd3d_sm4_register_type type)
case VKD3D_SM4_RT_CONSTBUFFER: case VKD3D_SM4_RT_INPUT: + case VKD3D_SM4_RT_RESOURCE: case VKD3D_SM4_RT_TEMP: return VKD3D_SM4_SWIZZLE_VEC4;
@@ -779,14 +780,26 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
if (var->is_uniform) { - unsigned int offset = hlsl_offset_from_deref(deref) + var->buffer_offset; + if (data_type->type == HLSL_CLASS_OBJECT && data_type->base_type == HLSL_TYPE_TEXTURE) + { + reg->type = VKD3D_SM4_RT_RESOURCE; + reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->idx[0] = var->reg.id; + reg->idx_count = 1; + *writemask = VKD3DSP_WRITEMASK_ALL; + } + else + { + unsigned int offset = hlsl_offset_from_deref(deref) + var->buffer_offset;
- reg->type = VKD3D_SM4_RT_CONSTBUFFER; - reg->dim = VKD3D_SM4_DIMENSION_VEC4; - reg->idx[0] = var->buffer->reg.id; - reg->idx[1] = offset / 4; - reg->idx_count = 2; - *writemask = ((1u << data_type->dimx) - 1) << (offset & 3); + assert(data_type->type <= HLSL_CLASS_VECTOR); + reg->type = VKD3D_SM4_RT_CONSTBUFFER; + reg->dim = VKD3D_SM4_DIMENSION_VEC4; + reg->idx[0] = var->buffer->reg.id; + reg->idx[1] = offset / 4; + reg->idx_count = 2; + *writemask = ((1u << data_type->dimx) - 1) << (offset & 3); + } } else if (var->is_input_semantic) { @@ -1154,6 +1167,50 @@ static void write_sm4_constant(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, + const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst, + const struct hlsl_deref *resource, const struct hlsl_ir_node *coords) +{ + struct sm4_instruction instr; + unsigned int writemask; + + memset(&instr, 0, sizeof(instr)); + instr.opcode = VKD3D_SM4_OP_LD; + + sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst); + instr.dst_count = 1; + + sm4_register_from_node(&instr.srcs[0].reg, &writemask, coords); + instr.srcs[0].swizzle = hlsl_swizzle_from_writemask(writemask); + + /* Mipmap level is in the last component in the IR, but needs to be in the W + * component in the instruction. */ + switch (resource_type->sampler_dim) + { + case HLSL_SAMPLER_DIM_1D: + instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, X, X, Y), 4); + break; + + case HLSL_SAMPLER_DIM_2D: + instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, Y, X, Z), 4); + break; + + case HLSL_SAMPLER_DIM_3D: + case HLSL_SAMPLER_DIM_CUBE: + break; + + case HLSL_SAMPLER_DIM_GENERIC: + assert(0); + } + + sm4_register_from_deref(ctx, &instr.srcs[1].reg, &writemask, resource, resource_type); + instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask); + + instr.src_count = 2; + + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_expr *expr) { @@ -1375,6 +1432,26 @@ static void write_sm4_load(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_resource_load(struct hlsl_ctx *ctx, + struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_resource_load *load) +{ + const struct hlsl_type *resource_type = load->resource.var->data_type; + const struct hlsl_ir_node *coords = load->coords.node; + + if (!load->resource.var->is_uniform) + { + hlsl_fixme(ctx, load->node.loc, "Load from non-uniform resource variable."); + return; + } + + switch (load->load_type) + { + case HLSL_RESOURCE_LOAD: + write_sm4_ld(ctx, buffer, resource_type, &load->node, &load->resource, coords); + break; + } +} + static void write_sm4_store(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_store *store) { @@ -1504,6 +1581,10 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, write_sm4_load(ctx, &buffer, hlsl_ir_load(instr)); break;
+ case HLSL_IR_RESOURCE_LOAD: + write_sm4_resource_load(ctx, &buffer, hlsl_ir_resource_load(instr)); + break; + case HLSL_IR_STORE: write_sm4_store(ctx, &buffer, hlsl_ir_store(instr)); break;
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 15/10/21 23:54, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 2 - libs/vkd3d-shader/hlsl_sm4.c | 95 +++++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 9 deletions(-)
diff --git a/Makefile.am b/Makefile.am index eaa4f8168..5a6dd6318 100644 --- a/Makefile.am +++ b/Makefile.am @@ -302,8 +302,6 @@ XFAIL_TESTS = \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/math.shader_test \ tests/max.shader_test \
- tests/texture-load.shader_test \
- tests/texture-load-typed.shader_test \ tests/trigonometry.shader_test \ tests/writemask-assignop-1.shader_test endif
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 9d45e1633..246aeebfe 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -763,6 +763,7 @@ static unsigned int sm4_swizzle_type(enum vkd3d_sm4_register_type type)
case VKD3D_SM4_RT_CONSTBUFFER: case VKD3D_SM4_RT_INPUT:
case VKD3D_SM4_RT_RESOURCE: case VKD3D_SM4_RT_TEMP: return VKD3D_SM4_SWIZZLE_VEC4;
@@ -779,14 +780,26 @@ static void sm4_register_from_deref(struct hlsl_ctx *ctx, struct sm4_register *r
if (var->is_uniform) {
unsigned int offset = hlsl_offset_from_deref(deref) + var->buffer_offset;
if (data_type->type == HLSL_CLASS_OBJECT && data_type->base_type == HLSL_TYPE_TEXTURE)
{
reg->type = VKD3D_SM4_RT_RESOURCE;
reg->dim = VKD3D_SM4_DIMENSION_VEC4;
reg->idx[0] = var->reg.id;
reg->idx_count = 1;
*writemask = VKD3DSP_WRITEMASK_ALL;
}
else
{
unsigned int offset = hlsl_offset_from_deref(deref) + var->buffer_offset;
reg->type = VKD3D_SM4_RT_CONSTBUFFER;
reg->dim = VKD3D_SM4_DIMENSION_VEC4;
reg->idx[0] = var->buffer->reg.id;
reg->idx[1] = offset / 4;
reg->idx_count = 2;
*writemask = ((1u << data_type->dimx) - 1) << (offset & 3);
assert(data_type->type <= HLSL_CLASS_VECTOR);
reg->type = VKD3D_SM4_RT_CONSTBUFFER;
reg->dim = VKD3D_SM4_DIMENSION_VEC4;
reg->idx[0] = var->buffer->reg.id;
reg->idx[1] = offset / 4;
reg->idx_count = 2;
*writemask = ((1u << data_type->dimx) - 1) << (offset & 3);
} } else if (var->is_input_semantic) {
@@ -1154,6 +1167,50 @@ static void write_sm4_constant(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_ld(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
const struct hlsl_type *resource_type, const struct hlsl_ir_node *dst,
const struct hlsl_deref *resource, const struct hlsl_ir_node *coords)
+{
- struct sm4_instruction instr;
- unsigned int writemask;
- memset(&instr, 0, sizeof(instr));
- instr.opcode = VKD3D_SM4_OP_LD;
- sm4_register_from_node(&instr.dsts[0].reg, &instr.dsts[0].writemask, dst);
- instr.dst_count = 1;
- sm4_register_from_node(&instr.srcs[0].reg, &writemask, coords);
- instr.srcs[0].swizzle = hlsl_swizzle_from_writemask(writemask);
- /* Mipmap level is in the last component in the IR, but needs to be in the W
* component in the instruction. */
- switch (resource_type->sampler_dim)
- {
case HLSL_SAMPLER_DIM_1D:
instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, X, X, Y), 4);
break;
case HLSL_SAMPLER_DIM_2D:
instr.srcs[0].swizzle = hlsl_combine_swizzles(instr.srcs[0].swizzle, HLSL_SWIZZLE(X, Y, X, Z), 4);
break;
case HLSL_SAMPLER_DIM_3D:
case HLSL_SAMPLER_DIM_CUBE:
break;
case HLSL_SAMPLER_DIM_GENERIC:
assert(0);
- }
- sm4_register_from_deref(ctx, &instr.srcs[1].reg, &writemask, resource, resource_type);
- instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dsts[0].writemask);
- instr.src_count = 2;
- write_sm4_instruction(buffer, &instr);
+}
- static void write_sm4_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_expr *expr) {
@@ -1375,6 +1432,26 @@ static void write_sm4_load(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_resource_load(struct hlsl_ctx *ctx,
struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_resource_load *load)
+{
- const struct hlsl_type *resource_type = load->resource.var->data_type;
- const struct hlsl_ir_node *coords = load->coords.node;
- if (!load->resource.var->is_uniform)
- {
hlsl_fixme(ctx, load->node.loc, "Load from non-uniform resource variable.");
return;
- }
- switch (load->load_type)
- {
case HLSL_RESOURCE_LOAD:
write_sm4_ld(ctx, buffer, resource_type, &load->node, &load->resource, coords);
break;
- }
+}
- static void write_sm4_store(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_store *store) {
@@ -1504,6 +1581,10 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, write_sm4_load(ctx, &buffer, hlsl_ir_load(instr)); break;
case HLSL_IR_RESOURCE_LOAD:
write_sm4_resource_load(ctx, &buffer, hlsl_ir_resource_load(instr));
break;
case HLSL_IR_STORE: write_sm4_store(ctx, &buffer, hlsl_ir_store(instr)); break;
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- I would suggest to write commit messages in a more terse way, though: they can be useful not only for future developers looking at the evolution of some feature, but also to people who try to learn about the code and might not know what "DCE" stands for (note that a search engine might not necessarily help a lot: "DCE" stands for many different things; knowing that it is "Dead Code Elimination" quickly leads to a useful Wikipedia article). In general, I think it's useful to err on the side of verbosity in commit messages.
Il 15/10/21 23:54, Zebediah Figura ha scritto:
This fixes DCE.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
I'm sure I had a reason for using a separate field here, but I can't remember it now, nor find any reason why it would matter.
libs/vkd3d-shader/hlsl.h | 1 - libs/vkd3d-shader/hlsl_codegen.c | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 31b7ddbb6..93191e56b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -240,7 +240,6 @@ struct hlsl_ir_var uint32_t is_output_semantic : 1; uint32_t is_uniform : 1; uint32_t is_param : 1;
uint32_t has_resource_access : 1; };
struct hlsl_ir_function
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index bf93a03df..b7b0cd1b8 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -591,6 +591,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs
LIST_FOR_EACH_ENTRY(instr, instrs, struct hlsl_ir_node, entry) {
const unsigned int var_last_read = loop_last ? max(instr->index, loop_last) : instr->index;
switch (instr->type) { case HLSL_IR_STORE:
@@ -628,7 +630,7 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs struct hlsl_ir_load *load = hlsl_ir_load(instr);
var = load->src.var;
var->last_read = max(var->last_read, loop_last ? max(instr->index, loop_last) : instr->index);
var->last_read = max(var->last_read, var_last_read); if (load->src.offset.node) load->src.offset.node->last_read = instr->index; break;
@@ -645,7 +647,8 @@ static void compute_liveness_recurse(struct list *instrs, unsigned int loop_firs { struct hlsl_ir_resource_load *load = hlsl_ir_resource_load(instr);
load->resource.var->has_resource_access = 1;
var = load->resource.var;
var->last_read = max(var->last_read, var_last_read); if (load->resource.offset.node) load->resource.offset.node->last_read = instr->index; load->coords.node->last_read = instr->index;
@@ -676,10 +679,7 @@ static void compute_liveness(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl LIST_FOR_EACH_ENTRY(scope, &ctx->scopes, struct hlsl_scope, entry) { LIST_FOR_EACH_ENTRY(var, &scope->vars, struct hlsl_ir_var, scope_entry)
{ var->first_write = var->last_read = 0;
var->has_resource_access = 0;
} } LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry)
@@ -1203,7 +1203,7 @@ static const struct hlsl_ir_var *get_reserved_texture(struct hlsl_ctx *ctx, uint
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, const struct hlsl_ir_var, extern_entry) {
if (var->has_resource_access && var->reg_reservation.type == 't' && var->reg_reservation.index == index)
if (var->last_read && var->reg_reservation.type == 't' && var->reg_reservation.index == index) return var; } return NULL;
@@ -1216,7 +1216,7 @@ static void allocate_textures(struct hlsl_ctx *ctx)
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) {
if (!var->has_resource_access || var->data_type->type != HLSL_CLASS_OBJECT
if (!var->last_read || var->data_type->type != HLSL_CLASS_OBJECT || var->data_type->base_type != HLSL_TYPE_TEXTURE) continue;
On Wed, Oct 20, 2021 at 1:39 PM Giovanni Mascellani gmascellani@codeweavers.com wrote:
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
I would suggest to write commit messages in a more terse way, though:
I guess you meant the opposite of "terse" :)