mirror of
				https://gitlab.winehq.org/wine/vkd3d.git
				synced 2025-09-12 18:50:22 -07:00 
			
		
		
		
	vkd3d-shader/hlsl: Add a hlsl_block_add_simple_store() helper.
This commit is contained in:
		
				
					committed by
					
						 Henri Verbeet
						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
| @@ -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)); | ||||
| } | ||||
|  | ||||
| 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, | ||||
|         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, | ||||
|         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; | ||||
|  | ||||
|     if (!(decl = hlsl_alloc(ctx, sizeof(*decl)))) | ||||
|         return NULL; | ||||
| @@ -2768,9 +2777,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, | ||||
|         return decl; | ||||
|     hlsl_block_add_instr(&decl->body, constant); | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, decl->early_return_var, constant))) | ||||
|         return decl; | ||||
|     hlsl_block_add_instr(&decl->body, store); | ||||
|     hlsl_block_add_simple_store(ctx, &decl->body, decl->early_return_var, constant); | ||||
|  | ||||
|     return decl; | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
| 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); | ||||
| 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, | ||||
|         const struct hlsl_deref *lhs, struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, | ||||
|         unsigned int writemask, const struct vkd3d_shader_location *loc); | ||||
|   | ||||
| @@ -857,17 +857,13 @@ static bool add_return(struct hlsl_ctx *ctx, struct hlsl_block *block, | ||||
|     { | ||||
|         if (return_value) | ||||
|         { | ||||
|             struct hlsl_ir_node *store; | ||||
|  | ||||
|             if (return_value->data_type->class == HLSL_CLASS_ERROR) | ||||
|                 return true; | ||||
|  | ||||
|             if (!(return_value = add_implicit_conversion(ctx, block, 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->entry); | ||||
|             hlsl_block_add_simple_store(ctx, block, ctx->cur_function->return_var, return_value); | ||||
|         } | ||||
|         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 *var_instr, unsigned int comp, const struct vkd3d_shader_location *loc) | ||||
| { | ||||
|     struct hlsl_ir_node *store; | ||||
|     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; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, var, var_instr); | ||||
|  | ||||
|     hlsl_init_simple_deref_from_var(&src, var); | ||||
|     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) | ||||
|         { | ||||
|             struct hlsl_ir_node *cast, *store, *zero; | ||||
|             struct hlsl_ir_node *cast, *zero; | ||||
|  | ||||
|             /* Initialize statics to zero by default. */ | ||||
|  | ||||
| @@ -2840,12 +2833,7 @@ static struct hlsl_block *initialize_vars(struct hlsl_ctx *ctx, struct list *var | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             if (!(store = hlsl_new_simple_store(ctx, var, cast))) | ||||
|             { | ||||
|                 free_parse_variable_def(v); | ||||
|                 continue; | ||||
|             } | ||||
|             hlsl_block_add_instr(&ctx->static_initializers, store); | ||||
|             hlsl_block_add_simple_store(ctx, &ctx->static_initializers, var, cast); | ||||
|         } | ||||
|         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) | ||||
|         { | ||||
|             struct hlsl_ir_node *store; | ||||
|  | ||||
|             if (!hlsl_types_are_equal(arg->data_type, param->data_type)) | ||||
|             { | ||||
|                 struct hlsl_ir_node *cast; | ||||
| @@ -3124,9 +3110,7 @@ static struct hlsl_ir_node *add_user_call(struct hlsl_ctx *ctx, | ||||
|                 arg = cast; | ||||
|             } | ||||
|  | ||||
|             if (!(store = hlsl_new_simple_store(ctx, param, arg))) | ||||
|                 return NULL; | ||||
|             hlsl_block_add_instr(args->instrs, store); | ||||
|             hlsl_block_add_simple_store(ctx, args->instrs, param, arg); | ||||
|         } | ||||
|  | ||||
|         ++k; | ||||
|   | ||||
| @@ -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) | ||||
|     { | ||||
|         struct hlsl_ir_node *store; | ||||
|         struct hlsl_ir_var *output; | ||||
|         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); | ||||
|         } | ||||
|  | ||||
|         if (!(store = hlsl_new_simple_store(ctx, output, &load->node))) | ||||
|             return; | ||||
|         hlsl_block_add_instr(&func->body, store); | ||||
|         hlsl_block_add_simple_store(ctx, &func->body, output, &load->node); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -1230,10 +1227,10 @@ static bool lower_matrix_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins | ||||
|  * resource access. */ | ||||
| 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_ir_index *index; | ||||
|     struct hlsl_ir_load *load; | ||||
|     struct hlsl_ir_node *val; | ||||
|     struct hlsl_ir_var *var; | ||||
|  | ||||
|     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; | ||||
|     hlsl_init_simple_deref_from_var(&var_deref, var); | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, var, val))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, var, val); | ||||
|  | ||||
|     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_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; | ||||
|     const struct hlsl_deref *deref; | ||||
|     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; | ||||
|     hlsl_block_add_instr(block, zero); | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, var, zero))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, var, zero); | ||||
|  | ||||
|     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_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_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; | ||||
|         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))) | ||||
|             return false; | ||||
|         hlsl_block_add_instr(block, var_store); | ||||
|         hlsl_block_add_simple_store(ctx, block, var, ternary); | ||||
|     } | ||||
|  | ||||
|     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, | ||||
|         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))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, const_node); | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, var, const_node))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|  | ||||
|     hlsl_block_add_simple_store(ctx, block, var, const_node); | ||||
|     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) | ||||
| { | ||||
|     struct hlsl_ir_node *call, *rhs, *store; | ||||
|     struct hlsl_ir_function_decl *func; | ||||
|     struct hlsl_ir_node *call, *rhs; | ||||
|     unsigned int component_count; | ||||
|     struct hlsl_ir_load *load; | ||||
|     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; | ||||
|  | ||||
|     lhs = func->parameters.vars[0]; | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, lhs, rhs))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, lhs, rhs); | ||||
|  | ||||
|     if (!(call = hlsl_new_call(ctx, func, &node->loc))) | ||||
|         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) | ||||
| { | ||||
|     struct hlsl_ir_node *call, *rhs, *store; | ||||
|     struct hlsl_ir_function_decl *func; | ||||
|     struct hlsl_ir_node *call, *rhs; | ||||
|     unsigned int component_count; | ||||
|     struct hlsl_ir_load *load; | ||||
|     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; | ||||
|  | ||||
|     lhs = func->parameters.vars[0]; | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, lhs, rhs))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, lhs, rhs); | ||||
|  | ||||
|     if (!(call = hlsl_new_call(ctx, func, &node->loc))) | ||||
|         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) | ||||
| { | ||||
|     struct hlsl_ir_node *call, *rhs, *store; | ||||
|     struct hlsl_ir_function_decl *func; | ||||
|     struct hlsl_ir_node *call, *rhs; | ||||
|     unsigned int component_count; | ||||
|     struct hlsl_ir_load *load; | ||||
|     struct hlsl_ir_expr *expr; | ||||
|     struct hlsl_ir_var *lhs; | ||||
|     const char *template; | ||||
|     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))) | ||||
|         return false; | ||||
|  | ||||
|     lhs = func->parameters.vars[0]; | ||||
|  | ||||
|     if (!(store = hlsl_new_simple_store(ctx, lhs, rhs))) | ||||
|         return false; | ||||
|     hlsl_block_add_instr(block, store); | ||||
|     hlsl_block_add_simple_store(ctx, block, func->parameters.vars[0], rhs); | ||||
|  | ||||
|     if (!(call = hlsl_new_call(ctx, func, &node->loc))) | ||||
|         return false; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user