mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader/hlsl: Add a hlsl_block_add_index() helper.
This commit is contained in:
committed by
Henri Verbeet
parent
e5cabeafe5
commit
e7ff5da5b1
Notes:
Henri Verbeet
2025-03-10 15:23:02 +01:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1404
@@ -2212,7 +2212,7 @@ bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val,
|
static struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val,
|
||||||
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
|
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_type *type = val->data_type;
|
struct hlsl_type *type = val->data_type;
|
||||||
@@ -2234,6 +2234,12 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v
|
|||||||
return &index->node;
|
return &index->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct hlsl_ir_node *hlsl_block_add_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
|
struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
|
||||||
|
{
|
||||||
|
return append_new_instr(ctx, block, hlsl_new_index(ctx, val, idx, loc));
|
||||||
|
}
|
||||||
|
|
||||||
static struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
|
static struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
|
||||||
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
|
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
|
@@ -1517,6 +1517,8 @@ struct hlsl_ir_node *hlsl_block_add_float_constant(struct hlsl_ctx *ctx, struct
|
|||||||
float f, const struct vkd3d_shader_location *loc);
|
float f, const struct vkd3d_shader_location *loc);
|
||||||
void hlsl_block_add_if(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *condition,
|
void hlsl_block_add_if(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *condition,
|
||||||
struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc);
|
struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc);
|
||||||
|
struct hlsl_ir_node *hlsl_block_add_index(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
|
struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc);
|
||||||
struct hlsl_ir_node *hlsl_block_add_int_constant(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
struct hlsl_ir_node *hlsl_block_add_int_constant(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
int32_t n, const struct vkd3d_shader_location *loc);
|
int32_t n, const struct vkd3d_shader_location *loc);
|
||||||
void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_jump_type type,
|
void hlsl_block_add_jump(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_jump_type type,
|
||||||
@@ -1644,8 +1646,6 @@ bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index);
|
|||||||
struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type,
|
struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type,
|
||||||
const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count,
|
const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count,
|
||||||
struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc);
|
struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc);
|
||||||
struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val,
|
|
||||||
struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc);
|
|
||||||
struct hlsl_ir_node *hlsl_new_interlocked(struct hlsl_ctx *ctx, enum hlsl_interlocked_op op, struct hlsl_type *type,
|
struct hlsl_ir_node *hlsl_new_interlocked(struct hlsl_ctx *ctx, enum hlsl_interlocked_op op, struct hlsl_type *type,
|
||||||
const struct hlsl_deref *dst, struct hlsl_ir_node *coords, struct hlsl_ir_node *cmp_value,
|
const struct hlsl_deref *dst, struct hlsl_ir_node *coords, struct hlsl_ir_node *cmp_value,
|
||||||
struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc);
|
struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc);
|
||||||
|
@@ -889,20 +889,15 @@ struct hlsl_ir_node *hlsl_add_load_component(struct hlsl_ctx *ctx, struct hlsl_b
|
|||||||
return hlsl_block_add_load_component(ctx, block, &src, comp, loc);
|
return hlsl_block_add_load_component(ctx, block, &src, comp, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_record_access(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *record,
|
static void add_record_access(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_ir_node *record,
|
||||||
unsigned int idx, const struct vkd3d_shader_location *loc)
|
unsigned int idx, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *index, *c;
|
struct hlsl_ir_node *c;
|
||||||
|
|
||||||
VKD3D_ASSERT(idx < record->data_type->e.record.field_count);
|
VKD3D_ASSERT(idx < record->data_type->e.record.field_count);
|
||||||
|
|
||||||
c = hlsl_block_add_uint_constant(ctx, block, idx, loc);
|
c = hlsl_block_add_uint_constant(ctx, block, idx, loc);
|
||||||
|
hlsl_block_add_index(ctx, block, record, c, loc);
|
||||||
if (!(index = hlsl_new_index(ctx, record, c, loc)))
|
|
||||||
return false;
|
|
||||||
hlsl_block_add_instr(block, index);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_ir_node *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
static struct hlsl_ir_node *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
@@ -913,7 +908,6 @@ static bool add_array_access(struct hlsl_ctx *ctx, struct hlsl_block *block, str
|
|||||||
struct hlsl_ir_node *index, const struct vkd3d_shader_location *loc)
|
struct hlsl_ir_node *index, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
const struct hlsl_type *expr_type = array->data_type, *index_type = index->data_type;
|
const struct hlsl_type *expr_type = array->data_type, *index_type = index->data_type;
|
||||||
struct hlsl_ir_node *return_index;
|
|
||||||
|
|
||||||
if (array->data_type->class == HLSL_CLASS_ERROR || index->data_type->class == HLSL_CLASS_ERROR)
|
if (array->data_type->class == HLSL_CLASS_ERROR || index->data_type->class == HLSL_CLASS_ERROR)
|
||||||
{
|
{
|
||||||
@@ -941,10 +935,7 @@ static bool add_array_access(struct hlsl_ctx *ctx, struct hlsl_block *block, str
|
|||||||
hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, dim_count), &index->loc)))
|
hlsl_get_vector_type(ctx, HLSL_TYPE_UINT, dim_count), &index->loc)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(return_index = hlsl_new_index(ctx, array, index, loc)))
|
hlsl_block_add_index(ctx, block, array, index, loc);
|
||||||
return false;
|
|
||||||
hlsl_block_add_instr(block, return_index);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,10 +956,7 @@ static bool add_array_access(struct hlsl_ctx *ctx, struct hlsl_block *block, str
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(return_index = hlsl_new_index(ctx, array, index, loc)))
|
hlsl_block_add_index(ctx, block, array, index, loc);
|
||||||
return false;
|
|
||||||
hlsl_block_add_instr(block, return_index);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1110,31 +1098,34 @@ static bool gen_struct_fields(struct hlsl_ctx *ctx, struct parse_fields *fields,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_record_access_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
static void add_record_access_recurse(struct hlsl_ctx *ctx, struct hlsl_block *block,
|
||||||
const char *name, const struct vkd3d_shader_location *loc)
|
const char *name, const struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *record = node_from_block(block);
|
struct hlsl_ir_node *record = node_from_block(block);
|
||||||
const struct hlsl_type *type = record->data_type;
|
const struct hlsl_type *type = record->data_type;
|
||||||
const struct hlsl_struct_field *field, *base;
|
const struct hlsl_struct_field *field, *base;
|
||||||
|
|
||||||
|
if (type->class == HLSL_CLASS_ERROR)
|
||||||
|
return;
|
||||||
|
|
||||||
if ((field = get_struct_field(type->e.record.fields, type->e.record.field_count, name)))
|
if ((field = get_struct_field(type->e.record.fields, type->e.record.field_count, name)))
|
||||||
{
|
{
|
||||||
unsigned int field_idx = field - type->e.record.fields;
|
unsigned int field_idx = field - type->e.record.fields;
|
||||||
|
|
||||||
return add_record_access(ctx, block, record, field_idx, loc);
|
add_record_access(ctx, block, record, field_idx, loc);
|
||||||
}
|
}
|
||||||
else if ((base = get_struct_field(type->e.record.fields, type->e.record.field_count, "$super")))
|
else if ((base = get_struct_field(type->e.record.fields, type->e.record.field_count, "$super")))
|
||||||
{
|
{
|
||||||
unsigned int base_idx = base - type->e.record.fields;
|
unsigned int base_idx = base - type->e.record.fields;
|
||||||
|
|
||||||
if (!add_record_access(ctx, block, record, base_idx, loc))
|
add_record_access(ctx, block, record, base_idx, loc);
|
||||||
return false;
|
add_record_access_recurse(ctx, block, name, loc);
|
||||||
return add_record_access_recurse(ctx, block, name, loc);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Field \"%s\" is not defined.", name);
|
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED, "Field \"%s\" is not defined.", name);
|
||||||
block->value = ctx->error_instr;
|
block->value = ctx->error_instr;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type, struct list *list)
|
static bool add_typedef(struct hlsl_ctx *ctx, struct hlsl_type *const orig_type, struct list *list)
|
||||||
@@ -2199,10 +2190,7 @@ static bool add_assignment(struct hlsl_ctx *ctx, struct hlsl_block *block, struc
|
|||||||
|
|
||||||
c = hlsl_block_add_uint_constant(ctx, block, i, &lhs->loc);
|
c = hlsl_block_add_uint_constant(ctx, block, i, &lhs->loc);
|
||||||
|
|
||||||
if (!(cell = hlsl_new_index(ctx, &row->node, c, &lhs->loc)))
|
cell = hlsl_block_add_index(ctx, block, &row->node, c, &lhs->loc);
|
||||||
return false;
|
|
||||||
hlsl_block_add_instr(block, cell);
|
|
||||||
|
|
||||||
load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc);
|
load = hlsl_add_load_component(ctx, block, rhs, k++, &rhs->loc);
|
||||||
|
|
||||||
if (!hlsl_init_deref_from_index_chain(ctx, &deref, cell))
|
if (!hlsl_init_deref_from_index_chain(ctx, &deref, cell))
|
||||||
@@ -9358,12 +9346,7 @@ postfix_expr:
|
|||||||
|
|
||||||
if (node->data_type->class == HLSL_CLASS_STRUCT)
|
if (node->data_type->class == HLSL_CLASS_STRUCT)
|
||||||
{
|
{
|
||||||
if (!add_record_access_recurse(ctx, $1, $3, &@2))
|
add_record_access_recurse(ctx, $1, $3, &@2);
|
||||||
{
|
|
||||||
destroy_block($1);
|
|
||||||
vkd3d_free($3);
|
|
||||||
YYABORT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (hlsl_is_numeric_type(node->data_type))
|
else if (hlsl_is_numeric_type(node->data_type))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user