From 29a2b87f54bab694aee372a86657de5707e29e70 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Thu, 10 Nov 2022 20:55:03 -0600 Subject: [PATCH] vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_simple_store(). --- libs/vkd3d-shader/hlsl.c | 12 +++++++----- libs/vkd3d-shader/hlsl.h | 2 +- libs/vkd3d-shader/hlsl.y | 30 +++++++++++++----------------- libs/vkd3d-shader/hlsl_codegen.c | 26 ++++++++++++-------------- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 54bfd3ba..58d5c514 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1065,12 +1065,15 @@ static void init_node(struct hlsl_ir_node *node, enum hlsl_ir_node_type type, list_init(&node->uses); } -struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs) +struct hlsl_ir_node *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs) { + struct hlsl_ir_store *store; struct hlsl_deref lhs_deref; hlsl_init_simple_deref_from_var(&lhs_deref, lhs); - return hlsl_new_store_index(ctx, &lhs_deref, NULL, rhs, 0, &rhs->loc); + if (!(store = hlsl_new_store_index(ctx, &lhs_deref, NULL, rhs, 0, &rhs->loc))) + return NULL; + return &store->node; } struct hlsl_ir_store *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hlsl_deref *lhs, @@ -1765,9 +1768,8 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, const struct hlsl_func_parameters *parameters, const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc) { + struct hlsl_ir_node *constant, *store; struct hlsl_ir_function_decl *decl; - struct hlsl_ir_node *constant; - struct hlsl_ir_store *store; if (!(decl = hlsl_alloc(ctx, sizeof(*decl)))) return NULL; @@ -1796,7 +1798,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, if (!(store = hlsl_new_simple_store(ctx, decl->early_return_var, constant))) return decl; - hlsl_block_add_instr(&decl->body, &store->node); + hlsl_block_add_instr(&decl->body, store); return decl; } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index fc410e26..f5d73d48 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1122,7 +1122,7 @@ struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl struct hlsl_ir_node *hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block, const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc); -struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs); +struct hlsl_ir_node *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs); struct hlsl_ir_store *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hlsl_deref *lhs, struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, unsigned int writemask, const struct vkd3d_shader_location *loc); bool hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 58aef12e..e3c0a831 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -635,14 +635,14 @@ static bool add_return(struct hlsl_ctx *ctx, struct list *instrs, { if (return_value) { - struct hlsl_ir_store *store; + struct hlsl_ir_node *store; if (!(return_value = add_implicit_conversion(ctx, instrs, return_value, return_type, loc))) return false; if (!(store = hlsl_new_simple_store(ctx, ctx->cur_function->return_var, return_value))) return false; - list_add_after(&return_value->entry, &store->node.entry); + list_add_after(&return_value->entry, &store->entry); } else { @@ -666,22 +666,20 @@ static bool add_return(struct hlsl_ctx *ctx, struct list *instrs, static struct hlsl_ir_node *add_load_component(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_instr, unsigned int comp, const struct vkd3d_shader_location *loc) { - const struct hlsl_deref *src; - struct hlsl_ir_store *store; - struct hlsl_ir_node *load; + struct hlsl_ir_node *load, *store; struct hlsl_block block; struct hlsl_ir_var *var; + struct hlsl_deref src; if (!(var = hlsl_new_synthetic_var(ctx, "deref", var_instr->data_type, &var_instr->loc))) return NULL; if (!(store = hlsl_new_simple_store(ctx, var, var_instr))) return NULL; - list_add_tail(instrs, &store->node.entry); + list_add_tail(instrs, &store->entry); - src = &store->lhs; - - if (!(load = hlsl_new_load_component(ctx, &block, src, comp, loc))) + hlsl_init_simple_deref_from_var(&src, var); + if (!(load = hlsl_new_load_component(ctx, &block, &src, comp, loc))) return NULL; list_move_tail(instrs, &block.instrs); @@ -2164,9 +2162,8 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t } else if (var->storage_modifiers & HLSL_STORAGE_STATIC) { + struct hlsl_ir_node *cast, *store; struct hlsl_ir_constant *zero; - struct hlsl_ir_store *store; - struct hlsl_ir_node *cast; /* Initialize statics to zero by default. */ @@ -2194,7 +2191,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t vkd3d_free(v); continue; } - list_add_tail(&ctx->static_initializers, &store->node.entry); + list_add_tail(&ctx->static_initializers, &store->entry); } vkd3d_free(v); } @@ -2826,9 +2823,8 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, const struct parse_initializer *params, const struct vkd3d_shader_location *loc) { struct hlsl_ir_node *n_l_neg, *n_h_neg, *specular_or, *specular_pow; - struct hlsl_ir_node *n_l, *n_h, *m, *diffuse, *zero; + struct hlsl_ir_node *n_l, *n_h, *m, *diffuse, *zero, *store; struct hlsl_ir_constant *init; - struct hlsl_ir_store *store; struct hlsl_deref var_deref; struct hlsl_type *ret_type; struct hlsl_ir_load *load; @@ -2868,7 +2864,7 @@ static bool intrinsic_lit(struct hlsl_ctx *ctx, if (!(store = hlsl_new_simple_store(ctx, var, &init->node))) return false; - list_add_tail(params->instrs, &store->node.entry); + list_add_tail(params->instrs, &store->entry); if (!(zero = hlsl_new_float_constant(ctx, 0.0f, loc))) return false; @@ -3561,11 +3557,11 @@ static struct list *add_call(struct hlsl_ctx *ctx, const char *name, if (param->storage_modifiers & HLSL_STORAGE_IN) { - struct hlsl_ir_store *store; + struct hlsl_ir_node *store; if (!(store = hlsl_new_simple_store(ctx, param, arg))) goto fail; - list_add_tail(args->instrs, &store->node.entry); + list_add_tail(args->instrs, &store->entry); } } diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 078e87a2..40d19eed 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -191,7 +191,7 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru { struct vkd3d_string_buffer *name; struct hlsl_ir_var *uniform; - struct hlsl_ir_store *store; + struct hlsl_ir_node *store; struct hlsl_ir_load *load; /* Use the synthetic name for the temp, rather than the uniform, so that we @@ -218,7 +218,7 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru if (!(store = hlsl_new_simple_store(ctx, temp, &load->node))) return; - list_add_after(&load->node.entry, &store->node.entry); + list_add_after(&load->node.entry, &store->entry); } static void validate_field_semantic(struct hlsl_ctx *ctx, struct hlsl_struct_field *field) @@ -480,7 +480,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct for (i = 0; i < hlsl_type_major_size(type); ++i) { - struct hlsl_ir_store *store; + struct hlsl_ir_node *store; struct hlsl_ir_var *output; struct hlsl_ir_load *load; @@ -508,7 +508,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct if (!(store = hlsl_new_simple_store(ctx, output, &load->node))) return; - list_add_tail(instrs, &store->node.entry); + list_add_tail(instrs, &store->entry); } } @@ -760,8 +760,7 @@ static bool lower_return(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fun else if (instr->type == HLSL_IR_JUMP) { struct hlsl_ir_jump *jump = hlsl_ir_jump(instr); - struct hlsl_ir_node *constant; - struct hlsl_ir_store *store; + struct hlsl_ir_node *constant, *store; if (jump->type == HLSL_IR_JUMP_RETURN) { @@ -771,7 +770,7 @@ static bool lower_return(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *fun if (!(store = hlsl_new_simple_store(ctx, func->early_return_var, constant))) return false; - list_add_after(&constant->entry, &store->node.entry); + list_add_after(&constant->entry, &store->entry); has_early_return = true; if (in_loop) @@ -906,11 +905,10 @@ static struct hlsl_ir_node *add_zero_mipmap_level(struct hlsl_ctx *ctx, struct h * resource access. */ static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) { + struct hlsl_ir_node *val, *store; struct hlsl_deref var_deref; struct hlsl_ir_index *index; - struct hlsl_ir_store *store; struct hlsl_ir_load *load; - struct hlsl_ir_node *val; struct hlsl_ir_var *var; if (instr->type != HLSL_IR_INDEX) @@ -950,7 +948,7 @@ static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, if (!(store = hlsl_new_simple_store(ctx, var, val))) return false; - list_add_before(&instr->entry, &store->node.entry); + list_add_before(&instr->entry, &store->entry); if (hlsl_index_is_noncontiguous(index)) { @@ -966,6 +964,7 @@ static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, for (i = 0; i < mat->data_type->dimx; ++i) { + struct hlsl_ir_store *store; struct hlsl_ir_constant *c; if (!(c = hlsl_new_uint_constant(ctx, i, &instr->loc))) @@ -2192,9 +2191,8 @@ struct hlsl_ir_load *hlsl_add_conditional(struct hlsl_ctx *ctx, struct list *ins struct hlsl_ir_node *condition, struct hlsl_ir_node *if_true, struct hlsl_ir_node *if_false) { struct hlsl_block then_block, else_block; - struct hlsl_ir_store *store; + struct hlsl_ir_node *iff, *store; struct hlsl_ir_load *load; - struct hlsl_ir_node *iff; struct hlsl_ir_var *var; assert(hlsl_types_are_equal(if_true->data_type, if_false->data_type)); @@ -2207,11 +2205,11 @@ struct hlsl_ir_load *hlsl_add_conditional(struct hlsl_ctx *ctx, struct list *ins if (!(store = hlsl_new_simple_store(ctx, var, if_true))) return NULL; - hlsl_block_add_instr(&then_block, &store->node); + hlsl_block_add_instr(&then_block, store); if (!(store = hlsl_new_simple_store(ctx, var, if_false))) return NULL; - hlsl_block_add_instr(&else_block, &store->node); + hlsl_block_add_instr(&else_block, store); if (!(iff = hlsl_new_if(ctx, condition, &then_block, &else_block, &condition->loc))) return NULL;