vkd3d-shader/hlsl: Add a hlsl_block_add_simple_store() helper.

This commit is contained in:
Elizabeth Figura
2024-12-09 13:12:12 -06:00
committed by Henri Verbeet
parent fc4f440245
commit e76c596d56
Notes: Henri Verbeet 2025-03-03 18:05:08 +01:00
Approved-by: Francisco Casas (@fcasas)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1394
4 changed files with 33 additions and 63 deletions

View File

@ -1541,6 +1541,15 @@ void hlsl_block_add_store_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
append_new_instr(ctx, block, hlsl_new_store_index(ctx, lhs, idx, rhs, writemask, loc)); append_new_instr(ctx, block, hlsl_new_store_index(ctx, lhs, idx, rhs, writemask, loc));
} }
void hlsl_block_add_simple_store(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
{
struct hlsl_deref lhs_deref;
hlsl_init_simple_deref_from_var(&lhs_deref, lhs);
hlsl_block_add_store_index(ctx, block, &lhs_deref, NULL, rhs, 0, &rhs->loc);
}
bool hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block, bool hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs) const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs)
{ {
@ -2739,8 +2748,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, struct hlsl_type *return_type, const struct hlsl_func_parameters *parameters,
const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc) 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_function_decl *decl;
struct hlsl_ir_node *constant;
if (!(decl = hlsl_alloc(ctx, sizeof(*decl)))) if (!(decl = hlsl_alloc(ctx, sizeof(*decl))))
return NULL; return NULL;
@ -2768,9 +2777,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx,
return decl; return decl;
hlsl_block_add_instr(&decl->body, constant); hlsl_block_add_instr(&decl->body, constant);
if (!(store = hlsl_new_simple_store(ctx, decl->early_return_var, constant))) hlsl_block_add_simple_store(ctx, &decl->body, decl->early_return_var, constant);
return decl;
hlsl_block_add_instr(&decl->body, store);
return decl; return decl;
} }

View File

@ -1518,6 +1518,8 @@ struct hlsl_ir_node *hlsl_block_add_int_constant(struct hlsl_ctx *ctx, struct hl
int32_t n, const struct vkd3d_shader_location *loc); int32_t n, const struct vkd3d_shader_location *loc);
struct hlsl_ir_node *hlsl_block_add_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *hlsl_block_add_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc); const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc);
void hlsl_block_add_simple_store(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs);
void hlsl_block_add_store_index(struct hlsl_ctx *ctx, struct hlsl_block *block, void hlsl_block_add_store_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
const struct hlsl_deref *lhs, struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, const struct hlsl_deref *lhs, struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs,
unsigned int writemask, const struct vkd3d_shader_location *loc); unsigned int writemask, const struct vkd3d_shader_location *loc);

View File

@ -857,17 +857,13 @@ static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block,
{ {
if (return_value) if (return_value)
{ {
struct hlsl_ir_node *store;
if (return_value->data_type->class == HLSL_CLASS_ERROR) if (return_value->data_type->class == HLSL_CLASS_ERROR)
return true; return true;
if (!(return_value = add_implicit_conversion(ctx, block, return_value, return_type, loc))) if (!(return_value = add_implicit_conversion(ctx, block, return_value, return_type, loc)))
return false; return false;
if (!(store = hlsl_new_simple_store(ctx, ctx->cur_function->return_var, return_value))) hlsl_block_add_simple_store(ctx, block, ctx->cur_function->return_var, return_value);
return false;
list_add_after(&return_value->entry, &store->entry);
} }
else else
{ {
@ -891,16 +887,13 @@ static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct hlsl_ir_node *hlsl_add_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *hlsl_add_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block,
struct hlsl_ir_node *var_instr, unsigned int comp, const struct vkd3d_shader_location *loc) struct hlsl_ir_node *var_instr, unsigned int comp, const struct vkd3d_shader_location *loc)
{ {
struct hlsl_ir_node *store;
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
struct hlsl_deref src; struct hlsl_deref src;
if (!(var = hlsl_new_synthetic_var(ctx, "deref", var_instr->data_type, &var_instr->loc))) if (!(var = hlsl_new_synthetic_var(ctx, "deref", var_instr->data_type, &var_instr->loc)))
return NULL; return NULL;
if (!(store = hlsl_new_simple_store(ctx, var, var_instr))) hlsl_block_add_simple_store(ctx, block, var, var_instr);
return NULL;
hlsl_block_add_instr(block, store);
hlsl_init_simple_deref_from_var(&src, var); hlsl_init_simple_deref_from_var(&src, var);
return hlsl_block_add_load_component(ctx, block, &src, comp, loc); return hlsl_block_add_load_component(ctx, block, &src, comp, loc);
@ -2822,7 +2815,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
} }
else if (var->storage_modifiers & HLSL_STORAGE_STATIC) else if (var->storage_modifiers & HLSL_STORAGE_STATIC)
{ {
struct hlsl_ir_node *cast, *store, *zero; struct hlsl_ir_node *cast, *zero;
/* Initialize statics to zero by default. */ /* Initialize statics to zero by default. */
@ -2840,12 +2833,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var
continue; continue;
} }
if (!(store = hlsl_new_simple_store(ctx, var, cast))) hlsl_block_add_simple_store(ctx, &ctx->static_initializers, var, cast);
{
free_parse_variable_def(v);
continue;
}
hlsl_block_add_instr(&ctx->static_initializers, store);
} }
free_parse_variable_def(v); free_parse_variable_def(v);
} }
@ -3113,8 +3101,6 @@ static struct hlsl_ir_node *add_user_call(struct hlsl_ctx *ctx,
if (param->storage_modifiers & HLSL_STORAGE_IN) if (param->storage_modifiers & HLSL_STORAGE_IN)
{ {
struct hlsl_ir_node *store;
if (!hlsl_types_are_equal(arg->data_type, param->data_type)) if (!hlsl_types_are_equal(arg->data_type, param->data_type))
{ {
struct hlsl_ir_node *cast; struct hlsl_ir_node *cast;
@ -3124,9 +3110,7 @@ static struct hlsl_ir_node *add_user_call(struct hlsl_ctx *ctx,
arg = cast; arg = cast;
} }
if (!(store = hlsl_new_simple_store(ctx, param, arg))) hlsl_block_add_simple_store(ctx, args->instrs, param, arg);
return NULL;
hlsl_block_add_instr(args->instrs, store);
} }
++k; ++k;

View File

@ -568,7 +568,6 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct hlsl_ir_function_dec
for (i = 0; i < hlsl_type_major_size(type); ++i) for (i = 0; i < hlsl_type_major_size(type); ++i)
{ {
struct hlsl_ir_node *store;
struct hlsl_ir_var *output; struct hlsl_ir_var *output;
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
@ -593,9 +592,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct hlsl_ir_function_dec
hlsl_block_add_instr(&func->body, &load->node); hlsl_block_add_instr(&func->body, &load->node);
} }
if (!(store = hlsl_new_simple_store(ctx, output, &load->node))) hlsl_block_add_simple_store(ctx, &func->body, output, &load->node);
return;
hlsl_block_add_instr(&func->body, store);
} }
} }
@ -1230,10 +1227,10 @@ static bool lower_matrix_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins
* resource access. */ * resource access. */
static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block) static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, struct hlsl_block *block)
{ {
struct hlsl_ir_node *val, *store;
struct hlsl_deref var_deref; struct hlsl_deref var_deref;
struct hlsl_ir_index *index; struct hlsl_ir_index *index;
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
struct hlsl_ir_node *val;
struct hlsl_ir_var *var; struct hlsl_ir_var *var;
if (instr->type != HLSL_IR_INDEX) if (instr->type != HLSL_IR_INDEX)
@ -1270,9 +1267,7 @@ static bool lower_index_loads(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
return false; return false;
hlsl_init_simple_deref_from_var(&var_deref, var); hlsl_init_simple_deref_from_var(&var_deref, var);
if (!(store = hlsl_new_simple_store(ctx, var, val))) hlsl_block_add_simple_store(ctx, block, var, val);
return false;
hlsl_block_add_instr(block, store);
if (hlsl_index_is_noncontiguous(index)) if (hlsl_index_is_noncontiguous(index))
{ {
@ -2852,7 +2847,7 @@ static bool lower_nonconstant_array_loads(struct hlsl_ctx *ctx, struct hlsl_ir_n
struct hlsl_block *block) struct hlsl_block *block)
{ {
struct hlsl_constant_value zero_value = {0}; struct hlsl_constant_value zero_value = {0};
struct hlsl_ir_node *cut_index, *zero, *store; struct hlsl_ir_node *cut_index, *zero;
unsigned int i, i_cut, element_count; unsigned int i, i_cut, element_count;
const struct hlsl_deref *deref; const struct hlsl_deref *deref;
struct hlsl_type *cut_type; struct hlsl_type *cut_type;
@ -2895,9 +2890,7 @@ static bool lower_nonconstant_array_loads(struct hlsl_ctx *ctx, struct hlsl_ir_n
return false; return false;
hlsl_block_add_instr(block, zero); hlsl_block_add_instr(block, zero);
if (!(store = hlsl_new_simple_store(ctx, var, zero))) hlsl_block_add_simple_store(ctx, block, var, zero);
return false;
hlsl_block_add_instr(block, store);
TRACE("Lowering non-constant %s load on variable '%s'.\n", row_major ? "row_major" : "array", deref->var->name); TRACE("Lowering non-constant %s load on variable '%s'.\n", row_major ? "row_major" : "array", deref->var->name);
@ -2906,7 +2899,7 @@ static bool lower_nonconstant_array_loads(struct hlsl_ctx *ctx, struct hlsl_ir_n
{ {
struct hlsl_type *btype = hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL); struct hlsl_type *btype = hlsl_get_scalar_type(ctx, HLSL_TYPE_BOOL);
struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0}; struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0};
struct hlsl_ir_node *const_i, *equals, *ternary, *var_store; struct hlsl_ir_node *const_i, *equals, *ternary;
struct hlsl_ir_load *var_load, *specific_load; struct hlsl_ir_load *var_load, *specific_load;
struct hlsl_deref deref_copy = {0}; struct hlsl_deref deref_copy = {0};
@ -2944,9 +2937,7 @@ static bool lower_nonconstant_array_loads(struct hlsl_ctx *ctx, struct hlsl_ir_n
operands[2] = &var_load->node; operands[2] = &var_load->node;
ternary = hlsl_block_add_expr(ctx, block, HLSL_OP3_TERNARY, operands, instr->data_type, &cut_index->loc); ternary = hlsl_block_add_expr(ctx, block, HLSL_OP3_TERNARY, operands, instr->data_type, &cut_index->loc);
if (!(var_store = hlsl_new_simple_store(ctx, var, ternary))) hlsl_block_add_simple_store(ctx, block, var, ternary);
return false;
hlsl_block_add_instr(block, var_store);
} }
if (!(load = hlsl_new_var_load(ctx, var, &instr->loc))) if (!(load = hlsl_new_var_load(ctx, var, &instr->loc)))
@ -11362,16 +11353,13 @@ static void sm4_generate_rdef(struct hlsl_ctx *ctx, struct vkd3d_shader_code *rd
static bool loop_unrolling_generate_const_bool_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, static bool loop_unrolling_generate_const_bool_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
bool val, struct hlsl_block *block, struct vkd3d_shader_location *loc) bool val, struct hlsl_block *block, struct vkd3d_shader_location *loc)
{ {
struct hlsl_ir_node *const_node, *store; struct hlsl_ir_node *const_node;
if (!(const_node = hlsl_new_bool_constant(ctx, val, loc))) if (!(const_node = hlsl_new_bool_constant(ctx, val, loc)))
return false; return false;
hlsl_block_add_instr(block, const_node); hlsl_block_add_instr(block, const_node);
if (!(store = hlsl_new_simple_store(ctx, var, const_node))) hlsl_block_add_simple_store(ctx, block, var, const_node);
return false;
hlsl_block_add_instr(block, store);
return true; return true;
} }
@ -11777,8 +11765,8 @@ static void loop_unrolling_execute(struct hlsl_ctx *ctx, struct hlsl_block *bloc
static bool lower_f16tof32(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block) static bool lower_f16tof32(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block)
{ {
struct hlsl_ir_node *call, *rhs, *store;
struct hlsl_ir_function_decl *func; struct hlsl_ir_function_decl *func;
struct hlsl_ir_node *call, *rhs;
unsigned int component_count; unsigned int component_count;
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
@ -11843,10 +11831,7 @@ static bool lower_f16tof32(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, stru
return false; return false;
lhs = func->parameters.vars[0]; lhs = func->parameters.vars[0];
hlsl_block_add_simple_store(ctx, block, lhs, rhs);
if (!(store = hlsl_new_simple_store(ctx, lhs, rhs)))
return false;
hlsl_block_add_instr(block, store);
if (!(call = hlsl_new_call(ctx, func, &node->loc))) if (!(call = hlsl_new_call(ctx, func, &node->loc)))
return false; return false;
@ -11861,8 +11846,8 @@ static bool lower_f16tof32(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, stru
static bool lower_f32tof16(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block) static bool lower_f32tof16(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block)
{ {
struct hlsl_ir_node *call, *rhs, *store;
struct hlsl_ir_function_decl *func; struct hlsl_ir_function_decl *func;
struct hlsl_ir_node *call, *rhs;
unsigned int component_count; unsigned int component_count;
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
@ -11915,10 +11900,7 @@ static bool lower_f32tof16(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, stru
return false; return false;
lhs = func->parameters.vars[0]; lhs = func->parameters.vars[0];
hlsl_block_add_simple_store(ctx, block, lhs, rhs);
if (!(store = hlsl_new_simple_store(ctx, lhs, rhs)))
return false;
hlsl_block_add_instr(block, store);
if (!(call = hlsl_new_call(ctx, func, &node->loc))) if (!(call = hlsl_new_call(ctx, func, &node->loc)))
return false; return false;
@ -11933,12 +11915,11 @@ static bool lower_f32tof16(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, stru
static bool lower_isinf(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block) static bool lower_isinf(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_block *block)
{ {
struct hlsl_ir_node *call, *rhs, *store;
struct hlsl_ir_function_decl *func; struct hlsl_ir_function_decl *func;
struct hlsl_ir_node *call, *rhs;
unsigned int component_count; unsigned int component_count;
struct hlsl_ir_load *load; struct hlsl_ir_load *load;
struct hlsl_ir_expr *expr; struct hlsl_ir_expr *expr;
struct hlsl_ir_var *lhs;
const char *template; const char *template;
char *body; char *body;
@ -12003,11 +11984,7 @@ static bool lower_isinf(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct
if (!(func = hlsl_compile_internal_function(ctx, "isinf", body))) if (!(func = hlsl_compile_internal_function(ctx, "isinf", body)))
return false; return false;
lhs = func->parameters.vars[0]; hlsl_block_add_simple_store(ctx, block, func->parameters.vars[0], rhs);
if (!(store = hlsl_new_simple_store(ctx, lhs, rhs)))
return false;
hlsl_block_add_instr(block, store);
if (!(call = hlsl_new_call(ctx, func, &node->loc))) if (!(call = hlsl_new_call(ctx, func, &node->loc)))
return false; return false;