[PATCH vkd3d 3/5] vkd3d-shader/hlsl: Write SM4 conditionals.

Matteo Bruni matteo.mystral at gmail.com
Fri Nov 5 13:37:50 CDT 2021


On Tue, Nov 2, 2021 at 11:49 AM Giovanni Mascellani
<gmascellani at codeweavers.com> wrote:
>
> Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
> ---
>  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 c022b5dd..3919725d 100644
> --- a/libs/vkd3d-shader/hlsl_sm4.c
> +++ b/libs/vkd3d-shader/hlsl_sm4.c
> @@ -1358,6 +1358,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);

It would probably be nicer not to emit the else at all when there are
no instructions in the block.

> +
> +    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)
>  {



More information about the wine-devel mailing list