mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Return an error expr from hlsl_add_load_component() on allocation failure.
This commit is contained in:
committed by
Henri Verbeet
parent
009f5765df
commit
7b486fe239
Notes:
Henri Verbeet
2025-03-05 14:16:50 +01:00
Approved-by: Henri Verbeet (@hverbeet) Approved-by: Francisco Casas (@fcasas) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1401
@@ -891,7 +891,10 @@ struct hlsl_ir_node *hlsl_add_load_component(struct hlsl_ctx *ctx, struct hlsl_b
|
|||||||
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;
|
{
|
||||||
|
block->value = ctx->error_instr;
|
||||||
|
return ctx->error_instr;
|
||||||
|
}
|
||||||
|
|
||||||
hlsl_block_add_simple_store(ctx, block, var, var_instr);
|
hlsl_block_add_simple_store(ctx, block, var, var_instr);
|
||||||
|
|
||||||
@@ -1583,7 +1586,6 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct hlsl_block *bl
|
|||||||
struct hlsl_type *scalar_type;
|
struct hlsl_type *scalar_type;
|
||||||
struct hlsl_ir_load *var_load;
|
struct hlsl_ir_load *var_load;
|
||||||
struct hlsl_deref var_deref;
|
struct hlsl_deref var_deref;
|
||||||
struct hlsl_ir_node *load;
|
|
||||||
struct hlsl_ir_var *var;
|
struct hlsl_ir_var *var;
|
||||||
|
|
||||||
scalar_type = hlsl_get_scalar_type(ctx, type->e.numeric.type);
|
scalar_type = hlsl_get_scalar_type(ctx, type->e.numeric.type);
|
||||||
@@ -1600,12 +1602,7 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct hlsl_block *bl
|
|||||||
for (j = 0; j < HLSL_MAX_OPERANDS; j++)
|
for (j = 0; j < HLSL_MAX_OPERANDS; j++)
|
||||||
{
|
{
|
||||||
if (operands[j])
|
if (operands[j])
|
||||||
{
|
cell_operands[j] = hlsl_add_load_component(ctx, block, operands[j], i, loc);
|
||||||
if (!(load = hlsl_add_load_component(ctx, block, operands[j], i, loc)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cell_operands[j] = load;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(value = add_expr(ctx, block, op, cell_operands, scalar_type, loc)))
|
if (!(value = add_expr(ctx, block, op, cell_operands, scalar_type, loc)))
|
||||||
@@ -2209,12 +2206,7 @@ static bool add_assignment(struct hlsl_ctx *ctx, struct hlsl_block *block, struc
|
|||||||
if (!(writemask & (1 << idx)))
|
if (!(writemask & (1 << idx)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc)))
|
load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc);
|
||||||
{
|
|
||||||
hlsl_cleanup_deref(&deref);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
hlsl_block_add_store_component(ctx, block, &deref, component, load);
|
hlsl_block_add_store_component(ctx, block, &deref, component, load);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2243,8 +2235,7 @@ static bool add_assignment(struct hlsl_ctx *ctx, struct hlsl_block *block, struc
|
|||||||
return false;
|
return false;
|
||||||
hlsl_block_add_instr(block, cell);
|
hlsl_block_add_instr(block, cell);
|
||||||
|
|
||||||
if (!(load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc)))
|
load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!hlsl_init_deref_from_index_chain(ctx, &deref, cell))
|
if (!hlsl_init_deref_from_index_chain(ctx, &deref, cell))
|
||||||
return false;
|
return false;
|
||||||
@@ -2318,8 +2309,7 @@ static void initialize_var_components(struct hlsl_ctx *ctx, struct hlsl_block *i
|
|||||||
struct hlsl_type *dst_comp_type;
|
struct hlsl_type *dst_comp_type;
|
||||||
struct hlsl_block block;
|
struct hlsl_block block;
|
||||||
|
|
||||||
if (!(load = hlsl_add_load_component(ctx, instrs, src, k, &src->loc)))
|
load = hlsl_add_load_component(ctx, instrs, src, k, &src->loc);
|
||||||
return;
|
|
||||||
|
|
||||||
dst_comp_type = hlsl_type_get_component_type(ctx, dst->data_type, *store_index);
|
dst_comp_type = hlsl_type_get_component_type(ctx, dst->data_type, *store_index);
|
||||||
|
|
||||||
@@ -3363,7 +3353,7 @@ static struct hlsl_type *convert_numeric_type(const struct hlsl_ctx *ctx,
|
|||||||
return hlsl_get_numeric_type(ctx, type->class, base_type, type->e.numeric.dimx, type->e.numeric.dimy);
|
return hlsl_get_numeric_type(ctx, type->class, base_type, type->e.numeric.dimx, type->e.numeric.dimy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_combine_components(struct hlsl_ctx *ctx, const struct parse_initializer *params,
|
static void add_combine_components(struct hlsl_ctx *ctx, const struct parse_initializer *params,
|
||||||
struct hlsl_ir_node *arg, enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc)
|
struct hlsl_ir_node *arg, enum hlsl_ir_expr_op op, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *res, *load;
|
struct hlsl_ir_node *res, *load;
|
||||||
@@ -3371,18 +3361,13 @@ static bool add_combine_components(struct hlsl_ctx *ctx, const struct parse_init
|
|||||||
|
|
||||||
count = hlsl_type_component_count(arg->data_type);
|
count = hlsl_type_component_count(arg->data_type);
|
||||||
|
|
||||||
if (!(res = hlsl_add_load_component(ctx, params->instrs, arg, 0, loc)))
|
res = hlsl_add_load_component(ctx, params->instrs, arg, 0, loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
for (i = 1; i < count; ++i)
|
for (i = 1; i < count; ++i)
|
||||||
{
|
{
|
||||||
if (!(load = hlsl_add_load_component(ctx, params->instrs, arg, i, loc)))
|
load = hlsl_add_load_component(ctx, params->instrs, arg, i, loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
res = hlsl_block_add_binary_expr(ctx, params->instrs, op, res, load);
|
res = hlsl_block_add_binary_expr(ctx, params->instrs, op, res, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool intrinsic_all(struct hlsl_ctx *ctx,
|
static bool intrinsic_all(struct hlsl_ctx *ctx,
|
||||||
@@ -3395,7 +3380,8 @@ static bool intrinsic_all(struct hlsl_ctx *ctx,
|
|||||||
if (!(cast = add_cast(ctx, params->instrs, arg, bool_type, loc)))
|
if (!(cast = add_cast(ctx, params->instrs, arg, bool_type, loc)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return add_combine_components(ctx, params, cast, HLSL_OP2_LOGIC_AND, loc);
|
add_combine_components(ctx, params, cast, HLSL_OP2_LOGIC_AND, loc);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool intrinsic_any(struct hlsl_ctx *ctx, const struct parse_initializer *params,
|
static bool intrinsic_any(struct hlsl_ctx *ctx, const struct parse_initializer *params,
|
||||||
@@ -3408,7 +3394,8 @@ static bool intrinsic_any(struct hlsl_ctx *ctx, const struct parse_initializer *
|
|||||||
if (!(cast = add_cast(ctx, params->instrs, arg, bool_type, loc)))
|
if (!(cast = add_cast(ctx, params->instrs, arg, bool_type, loc)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return add_combine_components(ctx, params, cast, HLSL_OP2_LOGIC_OR, loc);
|
add_combine_components(ctx, params, cast, HLSL_OP2_LOGIC_OR, loc);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool intrinsic_asin(struct hlsl_ctx *ctx,
|
static bool intrinsic_asin(struct hlsl_ctx *ctx,
|
||||||
@@ -4425,13 +4412,10 @@ static bool intrinsic_mul(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
struct hlsl_ir_node *value1, *value2, *mul;
|
struct hlsl_ir_node *value1, *value2, *mul;
|
||||||
|
|
||||||
if (!(value1 = hlsl_add_load_component(ctx, params->instrs,
|
value1 = hlsl_add_load_component(ctx, params->instrs,
|
||||||
cast1, j * cast1->data_type->e.numeric.dimx + k, loc)))
|
cast1, j * cast1->data_type->e.numeric.dimx + k, loc);
|
||||||
return false;
|
value2 = hlsl_add_load_component(ctx, params->instrs,
|
||||||
|
cast2, k * cast2->data_type->e.numeric.dimx + i, loc);
|
||||||
if (!(value2 = hlsl_add_load_component(ctx, params->instrs,
|
|
||||||
cast2, k * cast2->data_type->e.numeric.dimx + i, loc)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, value1, value2, loc)))
|
if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, value1, value2, loc)))
|
||||||
return false;
|
return false;
|
||||||
@@ -5100,10 +5084,8 @@ static bool intrinsic_transpose(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
for (j = 0; j < arg_type->e.numeric.dimy; ++j)
|
for (j = 0; j < arg_type->e.numeric.dimy; ++j)
|
||||||
{
|
{
|
||||||
if (!(load = hlsl_add_load_component(ctx, params->instrs, arg,
|
load = hlsl_add_load_component(ctx, params->instrs, arg,
|
||||||
j * arg->data_type->e.numeric.dimx + i, loc)))
|
j * arg->data_type->e.numeric.dimx + i, loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
hlsl_block_add_store_component(ctx, params->instrs, &var_deref,
|
hlsl_block_add_store_component(ctx, params->instrs, &var_deref,
|
||||||
i * var->data_type->e.numeric.dimx + j, load);
|
i * var->data_type->e.numeric.dimx + j, load);
|
||||||
}
|
}
|
||||||
@@ -6238,9 +6220,7 @@ static bool add_assignment_from_component(struct hlsl_ctx *ctx, struct hlsl_bloc
|
|||||||
if (!dest)
|
if (!dest)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!(load = hlsl_add_load_component(ctx, instrs, src, component, loc)))
|
load = hlsl_add_load_component(ctx, instrs, src, component, loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!add_assignment(ctx, instrs, dest, ASSIGN_OP_ASSIGN, load, false))
|
if (!add_assignment(ctx, instrs, dest, ASSIGN_OP_ASSIGN, load, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@@ -1153,10 +1153,7 @@ static bool lower_complex_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
|
|||||||
}
|
}
|
||||||
|
|
||||||
dst_comp_type = hlsl_type_get_component_type(ctx, dst_type, dst_idx);
|
dst_comp_type = hlsl_type_get_component_type(ctx, dst_type, dst_idx);
|
||||||
|
component_load = hlsl_add_load_component(ctx, block, arg, src_idx, &arg->loc);
|
||||||
if (!(component_load = hlsl_add_load_component(ctx, block, arg, src_idx, &arg->loc)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
cast = hlsl_block_add_cast(ctx, block, component_load, dst_comp_type, &arg->loc);
|
cast = hlsl_block_add_cast(ctx, block, component_load, dst_comp_type, &arg->loc);
|
||||||
|
|
||||||
hlsl_block_add_store_component(ctx, block, &var_deref, dst_idx, cast);
|
hlsl_block_add_store_component(ctx, block, &var_deref, dst_idx, cast);
|
||||||
@@ -1200,9 +1197,7 @@ static bool lower_matrix_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *ins
|
|||||||
|
|
||||||
k = swizzle->u.matrix.components[i].y * matrix_type->e.numeric.dimx + swizzle->u.matrix.components[i].x;
|
k = swizzle->u.matrix.components[i].y * matrix_type->e.numeric.dimx + swizzle->u.matrix.components[i].x;
|
||||||
|
|
||||||
if (!(load = hlsl_add_load_component(ctx, block, swizzle->val.node, k, &instr->loc)))
|
load = hlsl_add_load_component(ctx, block, swizzle->val.node, k, &instr->loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
hlsl_block_add_store_component(ctx, block, &var_deref, i, load);
|
hlsl_block_add_store_component(ctx, block, &var_deref, i, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4168,9 +4163,7 @@ static bool lower_discard_neg(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
|
|||||||
count = hlsl_type_component_count(cmp_type);
|
count = hlsl_type_component_count(cmp_type);
|
||||||
for (i = 0; i < count; ++i)
|
for (i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
if (!(load = hlsl_add_load_component(ctx, &block, cmp, i, &instr->loc)))
|
load = hlsl_add_load_component(ctx, &block, cmp, i, &instr->loc);
|
||||||
return false;
|
|
||||||
|
|
||||||
or = hlsl_block_add_binary_expr(ctx, &block, HLSL_OP2_LOGIC_OR, or, load);
|
or = hlsl_block_add_binary_expr(ctx, &block, HLSL_OP2_LOGIC_OR, or, load);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user