From 10593ad6538f48a737b277db2826f1086a2caa15 Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Fri, 5 Nov 2021 19:35:55 +0100 Subject: [PATCH] vkd3d-shader/hlsl: Write SM4 conditionals. Signed-off-by: Giovanni Mascellani Signed-off-by: Zebediah Figura Signed-off-by: Matteo Bruni Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- libs/vkd3d-shader/hlsl_sm4.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 9d4319b6..d48a41d1 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1415,6 +1415,33 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, } } +static void write_sm4_if(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_if *iff) +{ + struct sm4_instruction instr = + { + .opcode = VKD3D_SM4_OP_IF | VKD3D_SM4_CONDITIONAL_NZ, + .src_count = 1, + }; + unsigned int writemask; + + assert(iff->condition.node->data_type->dimx == 1); + + sm4_register_from_node(&instr.srcs[0].reg, &writemask, iff->condition.node); + instr.srcs[0].swizzle = hlsl_swizzle_from_writemask(writemask); + write_sm4_instruction(buffer, &instr); + + write_sm4_block(ctx, buffer, &iff->then_instrs); + + instr.opcode = VKD3D_SM4_OP_ELSE; + instr.src_count = 0; + write_sm4_instruction(buffer, &instr); + + write_sm4_block(ctx, buffer, &iff->else_instrs); + + instr.opcode = VKD3D_SM4_OP_ENDIF; + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_load(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_load *load) { @@ -1554,6 +1581,10 @@ static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer * write_sm4_expr(ctx, buffer, hlsl_ir_expr(instr)); break; + case HLSL_IR_IF: + write_sm4_if(ctx, buffer, hlsl_ir_if(instr)); + break; + case HLSL_IR_LOAD: write_sm4_load(ctx, buffer, hlsl_ir_load(instr)); break;