vkd3d-shader/hlsl: Support discard for SM1.

This commit is contained in:
Shaun Ren 2024-10-18 21:50:41 -04:00 committed by Henri Verbeet
parent 2a8c1b2823
commit f54797bae5
Notes: Henri Verbeet 2024-10-22 20:54:35 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1198
2 changed files with 43 additions and 1 deletions

View File

@ -4079,6 +4079,44 @@ static bool lower_discard_neg(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
return true;
}
static bool lower_discard_nz(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
struct hlsl_ir_node *cond, *cond_cast, *abs, *neg;
struct hlsl_type *float_type;
struct hlsl_ir_jump *jump;
struct hlsl_block block;
if (instr->type != HLSL_IR_JUMP)
return false;
jump = hlsl_ir_jump(instr);
if (jump->type != HLSL_IR_JUMP_DISCARD_NZ)
return false;
cond = jump->condition.node;
float_type = hlsl_get_vector_type(ctx, HLSL_TYPE_FLOAT, cond->data_type->dimx);
hlsl_block_init(&block);
if (!(cond_cast = hlsl_new_cast(ctx, cond, float_type, &instr->loc)))
return false;
hlsl_block_add_instr(&block, cond_cast);
if (!(abs = hlsl_new_unary_expr(ctx, HLSL_OP1_ABS, cond_cast, &instr->loc)))
return false;
hlsl_block_add_instr(&block, abs);
if (!(neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, abs, &instr->loc)))
return false;
hlsl_block_add_instr(&block, neg);
list_move_tail(&instr->entry, &block.instrs);
hlsl_src_remove(&jump->condition);
hlsl_src_from_node(&jump->condition, neg);
jump->type = HLSL_IR_JUMP_DISCARD_NEG;
return true;
}
static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
{
switch (instr->type)
@ -7903,6 +7941,10 @@ static void process_entry_function(struct hlsl_ctx *ctx,
{
hlsl_transform_ir(ctx, lower_discard_neg, body, NULL);
}
else
{
hlsl_transform_ir(ctx, lower_discard_nz, body, NULL);
}
transform_unroll_loops(ctx, body);
hlsl_run_const_passes(ctx, body);

View File

@ -21,7 +21,7 @@ shader model >= 3.0
% Check that derivatives are still computed after discarding
% other pixels in the same quad
[pixel shader todo(sm<4)]
[pixel shader]
float4 main(float4 pos : sv_position) : sv_target
{
if (frac((floor(pos.x) + floor(pos.y)) / 2) == 0.5)