diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 4f794926..c7ecf926 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -845,13 +845,7 @@ static bool init_deref_from_component_index(struct hlsl_ctx *ctx, struct hlsl_bl { unsigned int next_index = traverse_path_from_component_index(ctx, &path_type, &path_index); - if (!(c = hlsl_new_uint_constant(ctx, next_index, loc))) - { - hlsl_block_cleanup(block); - return false; - } - hlsl_block_add_instr(block, c); - + c = hlsl_block_add_uint_constant(ctx, block, next_index, loc); hlsl_src_from_node(&deref->path[deref_path_len++], c); } @@ -1324,6 +1318,18 @@ bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type) return true; } +static struct hlsl_ir_node *append_new_instr(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *instr) +{ + if (!instr) + { + block->value = ctx->error_instr; + return ctx->error_instr; + } + + hlsl_block_add_instr(block, instr); + return instr; +} + struct hlsl_ir_node *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, const struct vkd3d_shader_location *loc) { @@ -1601,6 +1607,12 @@ struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n return hlsl_new_constant(ctx, hlsl_get_scalar_type(ctx, HLSL_TYPE_UINT), &value, loc); } +struct hlsl_ir_node *hlsl_block_add_uint_constant(struct hlsl_ctx *ctx, struct hlsl_block *block, + unsigned int n, const struct vkd3d_shader_location *loc) +{ + return append_new_instr(ctx, block, hlsl_new_uint_constant(ctx, n, loc)); +} + struct hlsl_ir_node *hlsl_new_string_constant(struct hlsl_ctx *ctx, const char *str, const struct vkd3d_shader_location *loc) { diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 8e58f20a..86328af5 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1505,6 +1505,8 @@ struct hlsl_ir_node *hlsl_add_conditional(struct hlsl_ctx *ctx, struct hlsl_bloc void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl); void hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl); +struct hlsl_ir_node *hlsl_block_add_uint_constant(struct hlsl_ctx *ctx, struct hlsl_block *block, + unsigned int n, const struct vkd3d_shader_location *loc); void hlsl_block_cleanup(struct hlsl_block *block); bool hlsl_clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block, const struct hlsl_block *src_block); diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 7afc9274..64090497 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -925,9 +925,7 @@ static bool add_record_access(struct hlsl_ctx *ctx, struct hlsl_block *block, st VKD3D_ASSERT(idx < record->data_type->e.record.field_count); - if (!(c = hlsl_new_uint_constant(ctx, idx, loc))) - return false; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, idx, loc); if (!(index = hlsl_new_index(ctx, record, c, loc))) return false; @@ -2275,9 +2273,7 @@ static bool add_assignment(struct hlsl_ctx *ctx, struct hlsl_block *block, struc if (!(writemask & (1 << i))) continue; - if (!(c = hlsl_new_uint_constant(ctx, i, &lhs->loc))) - return false; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, i, &lhs->loc); if (!(cell = hlsl_new_index(ctx, &row->node, c, &lhs->loc))) return false; @@ -2869,12 +2865,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var continue; } - if (!(zero = hlsl_new_uint_constant(ctx, 0, &var->loc))) - { - free_parse_variable_def(v); - continue; - } - hlsl_block_add_instr(&ctx->static_initializers, zero); + zero = hlsl_block_add_uint_constant(ctx, &ctx->static_initializers, 0, &var->loc); if (!(cast = add_cast(ctx, &ctx->static_initializers, zero, var->data_type, &var->loc))) { @@ -6377,8 +6368,8 @@ static bool add_getdimensions_method_call(struct hlsl_ctx *ctx, struct hlsl_bloc bool uint_resinfo, has_uint_arg, has_float_arg; struct hlsl_resource_load_params load_params; struct hlsl_ir_node *sample_info, *res_info; - struct hlsl_ir_node *zero = NULL, *void_ret; struct hlsl_type *uint_type, *float_type; + struct hlsl_ir_node *void_ret; unsigned int i, j; enum func_argument { @@ -6478,12 +6469,7 @@ static bool add_getdimensions_method_call(struct hlsl_ctx *ctx, struct hlsl_bloc } if (!args[ARG_MIP_LEVEL]) - { - if (!(zero = hlsl_new_uint_constant(ctx, 0, loc))) - return false; - hlsl_block_add_instr(block, zero); - args[ARG_MIP_LEVEL] = zero; - } + args[ARG_MIP_LEVEL] = hlsl_block_add_uint_constant(ctx, block, 0, loc); memset(&load_params, 0, sizeof(load_params)); load_params.type = HLSL_RESOURCE_RESINFO; @@ -9177,9 +9163,7 @@ jump_statement: if (!($$ = make_empty_block(ctx))) YYABORT; - if (!(c = hlsl_new_uint_constant(ctx, ~0u, &@1))) - return false; - hlsl_block_add_instr($$, c); + c = hlsl_block_add_uint_constant(ctx, $$, ~0u, &@1); if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD_NZ, c, &@1))) return false; @@ -9401,12 +9385,9 @@ primary_expr: } | C_UNSIGNED { - struct hlsl_ir_node *c; - - if (!(c = hlsl_new_uint_constant(ctx, $1, &@1))) - YYABORT; - if (!($$ = make_block(ctx, c))) + if (!($$ = make_empty_block(ctx))) YYABORT; + hlsl_block_add_uint_constant(ctx, $$, $1, &@1); } | boolean { diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index ea5029df..798ad862 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -62,9 +62,7 @@ static struct hlsl_ir_node *new_offset_from_path_index(struct hlsl_ctx *ctx, str size /= 4; } - if (!(c = hlsl_new_uint_constant(ctx, size, loc))) - return NULL; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, size, loc); if (!(idx_offset = hlsl_new_binary_expr(ctx, HLSL_OP2_MUL, c, idx))) return NULL; @@ -86,12 +84,7 @@ static struct hlsl_ir_node *new_offset_from_path_index(struct hlsl_ctx *ctx, str field_offset /= 4; } - if (!(c = hlsl_new_uint_constant(ctx, field_offset, loc))) - return NULL; - hlsl_block_add_instr(block, c); - - idx_offset = c; - + idx_offset = hlsl_block_add_uint_constant(ctx, block, field_offset, loc); break; } @@ -122,9 +115,7 @@ static struct hlsl_ir_node *new_offset_instr_from_deref(struct hlsl_ctx *ctx, st hlsl_block_init(block); - if (!(offset = hlsl_new_uint_constant(ctx, 0, loc))) - return NULL; - hlsl_block_add_instr(block, offset); + offset = hlsl_block_add_uint_constant(ctx, block, 0, loc); VKD3D_ASSERT(deref->var); type = deref->var->data_type; @@ -448,9 +439,7 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct hlsl_ir_function_dec return; hlsl_init_simple_deref_from_var(&patch_deref, input); - if (!(idx = hlsl_new_uint_constant(ctx, patch_index, &var->loc))) - return; - hlsl_block_add_instr(block, idx); + idx = hlsl_block_add_uint_constant(ctx, block, patch_index, &var->loc); if (!(load = hlsl_new_load_index(ctx, &patch_deref, idx, loc))) return; @@ -473,9 +462,7 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct hlsl_ir_function_dec if (type->class == HLSL_CLASS_MATRIX) { - if (!(c = hlsl_new_uint_constant(ctx, i, &var->loc))) - return; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, i, &var->loc); if (!(store = hlsl_new_store_index(ctx, &lhs->src, c, cast, 0, &var->loc))) return; @@ -538,9 +525,7 @@ static void prepend_input_copy_recurse(struct hlsl_ctx *ctx, struct hlsl_ir_func force_align = (i == 0); } - if (!(c = hlsl_new_uint_constant(ctx, i, &var->loc))) - return; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, i, &var->loc); /* This redundant load is expected to be deleted later by DCE. */ if (!(element_load = hlsl_new_load_index(ctx, &lhs->src, c, loc))) @@ -615,9 +600,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct hlsl_ir_function_dec if (type->class == HLSL_CLASS_MATRIX) { - if (!(c = hlsl_new_uint_constant(ctx, i, &var->loc))) - return; - hlsl_block_add_instr(&func->body, c); + c = hlsl_block_add_uint_constant(ctx, &func->body, i, &var->loc); if (!(load = hlsl_new_load_index(ctx, &rhs->src, c, &var->loc))) return; @@ -678,9 +661,7 @@ static void append_output_copy_recurse(struct hlsl_ctx *ctx, force_align = (i == 0); } - if (!(c = hlsl_new_uint_constant(ctx, i, &var->loc))) - return; - hlsl_block_add_instr(&func->body, c); + c = hlsl_block_add_uint_constant(ctx, &func->body, i, &var->loc); if (!(element_load = hlsl_new_load_index(ctx, &rhs->src, c, loc))) return; @@ -1127,9 +1108,7 @@ static struct hlsl_ir_node *add_zero_mipmap_level(struct hlsl_ctx *ctx, struct h return NULL; hlsl_block_add_instr(block, store); - if (!(zero = hlsl_new_uint_constant(ctx, 0, loc))) - return NULL; - hlsl_block_add_instr(block, zero); + zero = hlsl_block_add_uint_constant(ctx, block, 0, loc); if (!(store = hlsl_new_store_index(ctx, &coords_deref, NULL, zero, 1u << dim_count, loc))) return NULL; @@ -1341,9 +1320,7 @@ static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, { struct hlsl_ir_node *c; - if (!(c = hlsl_new_uint_constant(ctx, i, &instr->loc))) - return false; - hlsl_block_add_instr(block, c); + c = hlsl_block_add_uint_constant(ctx, block, i, &instr->loc); if (!(load = hlsl_new_load_index(ctx, &var_deref, c, &instr->loc))) return false; @@ -2977,9 +2954,7 @@ static bool lower_nonconstant_array_loads(struct hlsl_ctx *ctx, struct hlsl_ir_n struct hlsl_ir_load *var_load, *specific_load; struct hlsl_deref deref_copy = {0}; - if (!(const_i = hlsl_new_uint_constant(ctx, i, &cut_index->loc))) - return false; - hlsl_block_add_instr(block, const_i); + const_i = hlsl_block_add_uint_constant(ctx, block, i, &cut_index->loc); operands[0] = cut_index; operands[1] = const_i;