From: Conor McCarthy cmccarthy@codeweavers.com
--- libs/vkd3d-shader/d3d_asm.c | 12 ++++++- libs/vkd3d-shader/dxil.c | 46 ++++++++++++++++++++++-- libs/vkd3d-shader/vkd3d_shader_private.h | 1 + 3 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/libs/vkd3d-shader/d3d_asm.c b/libs/vkd3d-shader/d3d_asm.c index 60a6337f7..61500dcc7 100644 --- a/libs/vkd3d-shader/d3d_asm.c +++ b/libs/vkd3d-shader/d3d_asm.c @@ -1650,7 +1650,17 @@ static void shader_dump_instruction(struct vkd3d_d3d_asm_compiler *compiler, case VKD3DSIH_BRANCH: { const struct vkd3d_shader_branch *branch = &ins->declaration.branch; - vkd3d_string_buffer_printf(buffer, " l%u", branch->true_id); + if (ins->src_count) + { + shader_dump_instruction_flags(compiler, ins); + vkd3d_string_buffer_printf(buffer, " "); + shader_dump_src_param(compiler, ins->src); + vkd3d_string_buffer_printf(buffer, " ? l%u : l%u", branch->true_id, branch->false_id); + } + else + { + vkd3d_string_buffer_printf(buffer, " l%u", branch->true_id); + } break; }
diff --git a/libs/vkd3d-shader/dxil.c b/libs/vkd3d-shader/dxil.c index c46c5ee6a..7fbdbc329 100644 --- a/libs/vkd3d-shader/dxil.c +++ b/libs/vkd3d-shader/dxil.c @@ -451,13 +451,16 @@ struct sm6_symbol enum sm6_block_terminator_type { TERMINATOR_UNCOND_BR, + TERMINATOR_COND_BR, TERMINATOR_RET, };
struct sm6_block_terminator { + struct vkd3d_shader_register conditional_reg; enum sm6_block_terminator_type type; struct sm6_block *true_block; + struct sm6_block *false_block; };
struct sm6_block @@ -3204,6 +3207,10 @@ static struct sm6_block *sm6_function_get_block(struct sm6_function *function, u static void sm6_parser_emit_br(struct sm6_parser *sm6, const struct dxil_record *record, struct sm6_function *function, struct sm6_block *code_block, struct vkd3d_shader_instruction *ins) { + const struct sm6_value *value; + unsigned int i = 2; + uint64_t index; + if (record->operand_count != 1 && record->operand_count < 3) { WARN("Invalid operand count %u.\n", record->operand_count); @@ -3219,9 +3226,29 @@ static void sm6_parser_emit_br(struct sm6_parser *sm6, const struct dxil_record } else { - FIXME("Conditional branch is not implemented.\n"); - vkd3d_shader_parser_error(&sm6->p, VKD3D_SHADER_ERROR_DXIL_INVALID_OPERAND_COUNT, - "Conditional branch is not implemented."); + if ((index = record->operands[0]) >= function->block_count + || (index = record->operands[1]) >= function->block_count) + { + WARN("Invalid block number %"PRIu64".\n", index); + return; + } + + if (!sm6->bool_type) + { + WARN("Bool type not found.\n"); + vkd3d_shader_parser_error(&sm6->p, VKD3D_SHADER_ERROR_DXIL_INVALID_MODULE, + "Module does not define a boolean type for conditions."); + return; + } + if (!(value = sm6_parser_get_value_by_ref(sm6, record, sm6->bool_type, &i)) + || !sm6_value_validate_is_bool(value, sm6)) + return; + dxil_record_validate_operand_max_count(record, i, sm6); + + code_block->terminator.type = TERMINATOR_COND_BR; + code_block->terminator.conditional_reg = value->u.reg; + code_block->terminator.true_block = sm6_function_get_block(function, record->operands[0], sm6); + code_block->terminator.false_block = sm6_function_get_block(function, record->operands[1], sm6); }
ins->handler_idx = VKD3DSIH_NOP; @@ -4395,6 +4422,7 @@ static enum vkd3d_result sm6_parser_function_init(struct sm6_parser *sm6, const
static void sm6_block_emit_terminator(struct sm6_block *block, struct sm6_parser *sm6) { + struct vkd3d_shader_src_param *src_param; struct vkd3d_shader_instruction *ins;
switch (block->terminator.type) @@ -4406,6 +4434,17 @@ static void sm6_block_emit_terminator(struct sm6_block *block, struct sm6_parser break; }
+ case TERMINATOR_COND_BR: + { + ins = sm6_parser_add_instruction(sm6, VKD3DSIH_BRANCH); + src_param = instruction_src_params_alloc(ins, 1, sm6); + src_param_init(src_param); + src_param->reg = block->terminator.conditional_reg; + ins->declaration.branch.true_id = block->terminator.true_block->synthetic_id; + ins->declaration.branch.false_id = block->terminator.false_block->synthetic_id; + break; + } + case TERMINATOR_RET: { sm6_parser_add_instruction(sm6, VKD3DSIH_RET); @@ -4497,6 +4536,7 @@ static void sm6_parser_emit_branch(struct sm6_parser *sm6, unsigned int block_id
ins = sm6_parser_add_instruction(sm6, VKD3DSIH_BRANCH); ins->declaration.branch.true_id = block_idx; + ins->declaration.branch.false_id = 0; }
static enum vkd3d_result sm6_function_emit_blocks(struct sm6_function *function, struct sm6_parser *sm6) diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h index ae4a0ab7b..e95d47480 100644 --- a/libs/vkd3d-shader/vkd3d_shader_private.h +++ b/libs/vkd3d-shader/vkd3d_shader_private.h @@ -1105,6 +1105,7 @@ struct vkd3d_shader_location struct vkd3d_shader_branch { unsigned int true_id; + unsigned int false_id; };
struct vkd3d_shader_instruction