vkd3d-shader/hlsl: Write SM4 addition instructions.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2021-08-24 01:18:12 -05:00 committed by Alexandre Julliard
parent ebfb8be1c6
commit fbcdc7a9d4
2 changed files with 62 additions and 1 deletions

View File

@ -273,7 +273,6 @@ XFAIL_TESTS = \
tests/hlsl-return-void.shader_test \ tests/hlsl-return-void.shader_test \
tests/hlsl-static-initializer.shader_test \ tests/hlsl-static-initializer.shader_test \
tests/hlsl-storage-qualifiers.shader_test \ tests/hlsl-storage-qualifiers.shader_test \
tests/hlsl-struct-assignment.shader_test \
tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing.shader_test \
tests/hlsl-vector-indexing-uniform.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \
tests/math.shader_test \ tests/math.shader_test \

View File

@ -894,6 +894,27 @@ static void write_sm4_ret(struct vkd3d_bytecode_buffer *buffer)
write_sm4_instruction(buffer, &instr); write_sm4_instruction(buffer, &instr);
} }
static void write_sm4_binary_op(struct vkd3d_bytecode_buffer *buffer, enum vkd3d_sm4_opcode opcode,
const struct hlsl_ir_node *dst, const struct hlsl_ir_node *src1, const struct hlsl_ir_node *src2)
{
struct sm4_instruction instr;
unsigned int writemask;
memset(&instr, 0, sizeof(instr));
instr.opcode = opcode;
sm4_register_from_node(&instr.dst.reg, &instr.dst.writemask, dst);
instr.has_dst = 1;
sm4_register_from_node(&instr.srcs[0].reg, &writemask, src1);
instr.srcs[0].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask);
sm4_register_from_node(&instr.srcs[1].reg, &writemask, src2);
instr.srcs[1].swizzle = hlsl_map_swizzle(hlsl_swizzle_from_writemask(writemask), instr.dst.writemask);
instr.src_count = 2;
write_sm4_instruction(buffer, &instr);
}
static void write_sm4_constant(struct hlsl_ctx *ctx, static void write_sm4_constant(struct hlsl_ctx *ctx,
struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_constant *constant) struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_constant *constant)
{ {
@ -918,6 +939,43 @@ static void write_sm4_constant(struct hlsl_ctx *ctx,
write_sm4_instruction(buffer, &instr); write_sm4_instruction(buffer, &instr);
} }
static void write_sm4_expr(struct hlsl_ctx *ctx,
struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_expr *expr)
{
const struct hlsl_ir_node *arg1 = expr->operands[0].node;
const struct hlsl_ir_node *arg2 = expr->operands[1].node;
assert(expr->node.reg.allocated);
switch (expr->node.data_type->base_type)
{
case HLSL_TYPE_FLOAT:
{
switch (expr->op)
{
case HLSL_OP2_ADD:
write_sm4_binary_op(buffer, VKD3D_SM4_OP_ADD, &expr->node, arg1, arg2);
break;
default:
hlsl_fixme(ctx, expr->node.loc, "SM4 float \"%s\" expression.", debug_hlsl_expr_op(expr->op));
break;
}
break;
}
default:
{
struct vkd3d_string_buffer *string;
if ((string = hlsl_type_to_string(ctx, expr->node.data_type)))
hlsl_fixme(ctx, expr->node.loc, "SM4 %s expression.", string->buffer);
hlsl_release_string_buffer(ctx, string);
break;
}
}
}
static void write_sm4_load(struct hlsl_ctx *ctx, static void write_sm4_load(struct hlsl_ctx *ctx,
struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_load *load) struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_load *load)
{ {
@ -1044,6 +1102,10 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx,
write_sm4_constant(ctx, &buffer, hlsl_ir_constant(instr)); write_sm4_constant(ctx, &buffer, hlsl_ir_constant(instr));
break; break;
case HLSL_IR_EXPR:
write_sm4_expr(ctx, &buffer, hlsl_ir_expr(instr));
break;
case HLSL_IR_LOAD: case HLSL_IR_LOAD:
write_sm4_load(ctx, &buffer, hlsl_ir_load(instr)); write_sm4_load(ctx, &buffer, hlsl_ir_load(instr));
break; break;