From 59c63ec5841dc01fac15dd2a0772b61f55b77a03 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 20 Apr 2023 22:25:23 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Handle discard statement. Signed-off-by: Ethan Lee Signed-off-by: Nikolay Sivov --- libs/vkd3d-shader/hlsl.y | 14 ++++++++++++++ libs/vkd3d-shader/tpf.c | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 194d21f4..2074f365 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -4075,6 +4075,7 @@ static void validate_texture_format_type(struct hlsl_ctx *ctx, struct hlsl_type %type conditional_expr %type declaration %type declaration_statement +%type discard_statement %type equality_expr %type expr %type expr_optional @@ -5322,6 +5323,7 @@ statement: declaration_statement | expr_statement | compound_statement + | discard_statement | jump_statement | selection_statement | loop_statement @@ -5341,6 +5343,18 @@ jump_statement: YYABORT; } +discard_statement: + KW_DISCARD ';' + { + struct hlsl_ir_node *discard; + + if (!($$ = make_empty_list(ctx))) + YYABORT; + if (!(discard = hlsl_new_jump(ctx, HLSL_IR_JUMP_DISCARD, &@1))) + return false; + list_add_tail($$, &discard->entry); + } + selection_statement: KW_IF '(' expr ')' if_body { diff --git a/libs/vkd3d-shader/tpf.c b/libs/vkd3d-shader/tpf.c index f15593b0..f3a15305 100644 --- a/libs/vkd3d-shader/tpf.c +++ b/libs/vkd3d-shader/tpf.c @@ -4327,6 +4327,22 @@ static void write_sm4_jump(struct hlsl_ctx *ctx, instr.opcode = VKD3D_SM4_OP_BREAK; break; + 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; + + break; + } + case HLSL_IR_JUMP_RETURN: vkd3d_unreachable();