vkd3d-shader/hlsl: Store SM4 jumps in the vsir program.

This commit is contained in:
Francisco Casas 2024-11-08 15:57:13 -03:00 committed by Henri Verbeet
parent 2c3a7b0dd9
commit 28ad600b43
Notes: Henri Verbeet 2024-11-27 14:11:33 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1280
2 changed files with 45 additions and 40 deletions

View File

@ -9280,6 +9280,37 @@ static bool sm4_generate_vsir_instr_resource_load(struct hlsl_ctx *ctx,
} }
} }
static bool sm4_generate_vsir_instr_jump(struct hlsl_ctx *ctx,
struct vsir_program *program, const struct hlsl_ir_jump *jump)
{
const struct hlsl_ir_node *instr = &jump->node;
struct vkd3d_shader_instruction *ins;
switch (jump->type)
{
case HLSL_IR_JUMP_BREAK:
return generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_BREAK, 0, 0);
case HLSL_IR_JUMP_CONTINUE:
return generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_CONTINUE, 0, 0);
case HLSL_IR_JUMP_DISCARD_NZ:
if (!(ins = generate_vsir_add_program_instruction(ctx, program, &instr->loc, VKD3DSIH_DISCARD, 0, 1)))
return false;
ins->flags = VKD3D_SHADER_CONDITIONAL_OP_NZ;
vsir_src_from_hlsl_node(&ins->src[0], ctx, jump->condition.node, VKD3DSP_WRITEMASK_ALL);
return true;
case HLSL_IR_JUMP_RETURN:
vkd3d_unreachable();
default:
hlsl_fixme(ctx, &jump->node.loc, "Jump type %s.", hlsl_jump_type_to_string(jump->type));
return false;
}
}
static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *block, struct vsir_program *program) static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *block, struct vsir_program *program)
{ {
struct vkd3d_string_buffer *dst_type_string; struct vkd3d_string_buffer *dst_type_string;
@ -9340,6 +9371,11 @@ static void sm4_generate_vsir_block(struct hlsl_ctx *ctx, struct hlsl_block *blo
replace_instr_with_last_vsir_instr(ctx, program, instr); replace_instr_with_last_vsir_instr(ctx, program, instr);
break; break;
case HLSL_IR_JUMP:
if (sm4_generate_vsir_instr_jump(ctx, program, hlsl_ir_jump(instr)))
replace_instr_with_last_vsir_instr(ctx, program, instr);
break;
case HLSL_IR_STORE: case HLSL_IR_STORE:
if (sm4_generate_vsir_instr_store(ctx, program, hlsl_ir_store(instr))) if (sm4_generate_vsir_instr_store(ctx, program, hlsl_ir_store(instr)))
replace_instr_with_last_vsir_instr(ctx, program, instr); replace_instr_with_last_vsir_instr(ctx, program, instr);

View File

@ -4804,42 +4804,6 @@ static void write_sm4_if(struct tpf_compiler *tpf, const struct hlsl_ir_if *iff)
write_sm4_instruction(tpf, &instr); write_sm4_instruction(tpf, &instr);
} }
static void write_sm4_jump(const struct tpf_compiler *tpf, const struct hlsl_ir_jump *jump)
{
struct sm4_instruction instr = {0};
switch (jump->type)
{
case HLSL_IR_JUMP_BREAK:
instr.opcode = VKD3D_SM4_OP_BREAK;
break;
case HLSL_IR_JUMP_CONTINUE:
instr.opcode = VKD3D_SM4_OP_CONTINUE;
break;
case HLSL_IR_JUMP_DISCARD_NZ:
{
instr.opcode = VKD3D_SM4_OP_DISCARD;
instr.extra_bits = VKD3D_SM4_CONDITIONAL_NZ;
memset(&instr.srcs[0], 0, sizeof(*instr.srcs));
instr.src_count = 1;
sm4_src_from_node(tpf, &instr.srcs[0], jump->condition.node, VKD3DSP_WRITEMASK_ALL);
break;
}
case HLSL_IR_JUMP_RETURN:
vkd3d_unreachable();
default:
hlsl_fixme(tpf->ctx, &jump->node.loc, "Jump type %s.", hlsl_jump_type_to_string(jump->type));
return;
}
write_sm4_instruction(tpf, &instr);
}
static void write_sm4_loop(struct tpf_compiler *tpf, const struct hlsl_ir_loop *loop) static void write_sm4_loop(struct tpf_compiler *tpf, const struct hlsl_ir_loop *loop)
{ {
struct sm4_instruction instr = struct sm4_instruction instr =
@ -4953,6 +4917,12 @@ static void tpf_simple_instruction(struct tpf_compiler *tpf, const struct vkd3d_
modifier->u.aoffimmi.w = ins->texel_offset.w; modifier->u.aoffimmi.w = ins->texel_offset.w;
} }
if (ins->opcode == VKD3DSIH_DISCARD)
{
if (ins->flags == VKD3D_SHADER_CONDITIONAL_OP_NZ)
instr.extra_bits = VKD3D_SM4_CONDITIONAL_NZ;
}
write_sm4_instruction(tpf, &instr); write_sm4_instruction(tpf, &instr);
} }
@ -5002,6 +4972,9 @@ static void tpf_handle_instruction(struct tpf_compiler *tpf, const struct vkd3d_
case VKD3DSIH_ADD: case VKD3DSIH_ADD:
case VKD3DSIH_AND: case VKD3DSIH_AND:
case VKD3DSIH_BREAK:
case VKD3DSIH_CONTINUE:
case VKD3DSIH_DISCARD:
case VKD3DSIH_DIV: case VKD3DSIH_DIV:
case VKD3DSIH_DP2: case VKD3DSIH_DP2:
case VKD3DSIH_DP3: case VKD3DSIH_DP3:
@ -5119,10 +5092,6 @@ static void write_sm4_block(struct tpf_compiler *tpf, const struct hlsl_block *b
write_sm4_if(tpf, hlsl_ir_if(instr)); write_sm4_if(tpf, hlsl_ir_if(instr));
break; break;
case HLSL_IR_JUMP:
write_sm4_jump(tpf, hlsl_ir_jump(instr));
break;
case HLSL_IR_LOOP: case HLSL_IR_LOOP:
write_sm4_loop(tpf, hlsl_ir_loop(instr)); write_sm4_loop(tpf, hlsl_ir_loop(instr));
break; break;