vkd3d-shader/hlsl: Add a parameter for jump nodes and use it for 'discard'.

This commit is contained in:
Nikolay Sivov 2023-06-08 09:42:58 +02:00 committed by Alexandre Julliard
parent 7e1fcdca89
commit b40179da3a
Notes: Alexandre Julliard 2023-06-27 23:33:43 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/211
5 changed files with 28 additions and 18 deletions

View File

@ -1432,7 +1432,7 @@ struct hlsl_ir_node *hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *v
}
struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
const struct vkd3d_shader_location *loc)
struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_jump *jump;
@ -1440,6 +1440,7 @@ struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type
return NULL;
init_node(&jump->node, HLSL_IR_JUMP, NULL, loc);
jump->type = type;
hlsl_src_from_node(&jump->condition, condition);
return &jump->node;
}
@ -1585,9 +1586,9 @@ static struct hlsl_ir_node *clone_if(struct hlsl_ctx *ctx, struct clone_instr_ma
return dst;
}
static struct hlsl_ir_node *clone_jump(struct hlsl_ctx *ctx, struct hlsl_ir_jump *src)
static struct hlsl_ir_node *clone_jump(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_jump *src)
{
return hlsl_new_jump(ctx, src->type, &src->node.loc);
return hlsl_new_jump(ctx, src->type, map_instr(map, src->condition.node), &src->node.loc);
}
static struct hlsl_ir_node *clone_load(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_load *src)
@ -1728,7 +1729,7 @@ static struct hlsl_ir_node *clone_instr(struct hlsl_ctx *ctx,
return clone_index(ctx, map, hlsl_ir_index(instr));
case HLSL_IR_JUMP:
return clone_jump(ctx, hlsl_ir_jump(instr));
return clone_jump(ctx, map, hlsl_ir_jump(instr));
case HLSL_IR_LOAD:
return clone_load(ctx, map, hlsl_ir_load(instr));
@ -2703,6 +2704,7 @@ static void free_ir_if(struct hlsl_ir_if *if_node)
static void free_ir_jump(struct hlsl_ir_jump *jump)
{
hlsl_src_remove(&jump->condition);
vkd3d_free(jump);
}

View File

@ -566,6 +566,8 @@ struct hlsl_ir_jump
{
struct hlsl_ir_node node;
enum hlsl_ir_jump_type type;
/* Argument used for HLSL_IR_JUMP_DISCARD. */
struct hlsl_src condition;
};
struct hlsl_ir_swizzle
@ -1120,7 +1122,7 @@ struct hlsl_ir_node *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *cond
struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc);
struct hlsl_ir_node *hlsl_new_int_constant(struct hlsl_ctx *ctx, int32_t n, const struct vkd3d_shader_location *loc);
struct hlsl_ir_node *hlsl_new_jump(struct hlsl_ctx *ctx,
enum hlsl_ir_jump_type type, const struct vkd3d_shader_location *loc);
enum hlsl_ir_jump_type type, struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc);
void hlsl_init_simple_deref_from_var(struct hlsl_deref *deref, struct hlsl_ir_var *var);

View File

@ -421,7 +421,7 @@ static bool append_conditional_break(struct hlsl_ctx *ctx, struct list *cond_lis
hlsl_block_init(&then_block);
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, &condition->loc)))
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &condition->loc)))
return false;
hlsl_block_add_instr(&then_block, jump);
@ -656,7 +656,7 @@ static bool add_return(struct hlsl_ctx *ctx, struct list *instrs,
hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_RETURN, "Void functions cannot return a value.");
}
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_RETURN, loc)))
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_RETURN, NULL, loc)))
return false;
list_add_tail(instrs, &jump->entry);
@ -5736,11 +5736,16 @@ jump_statement:
discard_statement:
KW_DISCARD ';'
{
struct hlsl_ir_node *discard;
struct hlsl_ir_node *discard, *c;
if (!($$ = make_empty_list(ctx)))
YYABORT;
if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD, &@1)))
if (!(c = hlsl_new_uint_constant(ctx, ~0u, &@1)))
return false;
list_add_tail($$, &c->entry);
if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD, c, &@1)))
return false;
list_add_tail($$, &discard->entry);
}

View File

@ -666,7 +666,7 @@ static void insert_early_return_break(struct hlsl_ctx *ctx,
return;
list_add_after(&cf_instr->entry, &load->node.entry);
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, &cf_instr->loc)))
if (!(jump = hlsl_new_jump(ctx, HLSL_IR_JUMP_BREAK, NULL, &cf_instr->loc)))
return;
hlsl_block_add_instr(&then_block, jump);
@ -2848,8 +2848,15 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop
index->idx.node->last_read = last_read;
break;
}
case HLSL_IR_CONSTANT:
case HLSL_IR_JUMP:
{
struct hlsl_ir_jump *jump = hlsl_ir_jump(instr);
if (jump->condition.node)
jump->condition.node->last_read = last_read;
break;
}
case HLSL_IR_CONSTANT:
break;
}
}

View File

@ -4782,17 +4782,11 @@ static void write_sm4_jump(struct hlsl_ctx *ctx,
case HLSL_IR_JUMP_DISCARD:
{
struct sm4_register *reg = &instr.srcs[0].reg;
instr.opcode = VKD3D_SM4_OP_DISCARD | VKD3D_SM4_CONDITIONAL_NZ;
memset(&instr.srcs[0], 0, sizeof(*instr.srcs));
instr.srcs[0].swizzle_type = VKD3D_SM4_SWIZZLE_NONE;
instr.src_count = 1;
reg->type = VKD3D_SM4_RT_IMMCONST;
reg->dim = VKD3D_SM4_DIMENSION_SCALAR;
reg->immconst_uint[0] = ~0u;
sm4_src_from_node(&instr.srcs[0], jump->condition.node, VKD3DSP_WRITEMASK_ALL);
break;
}