Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 97 +++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 45 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 9d45e163..0a9aac2a 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1422,13 +1422,63 @@ static void write_sm4_swizzle(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, + const struct hlsl_block *block) +{ + const struct hlsl_ir_node *instr; + + LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry) + { + if (instr->data_type) + { + if (instr->data_type->type == HLSL_CLASS_MATRIX) + { + FIXME("Matrix operations need to be lowered.\n"); + break; + } + else if (instr->data_type->type == HLSL_CLASS_OBJECT) + { + hlsl_fixme(ctx, instr->loc, "Object copy.\n"); + break; + } + + assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); + } + + switch (instr->type) + { + case HLSL_IR_CONSTANT: + write_sm4_constant(ctx, buffer, hlsl_ir_constant(instr)); + break; + + case HLSL_IR_EXPR: + write_sm4_expr(ctx, buffer, hlsl_ir_expr(instr)); + break; + + case HLSL_IR_LOAD: + write_sm4_load(ctx, buffer, hlsl_ir_load(instr)); + break; + + case HLSL_IR_STORE: + write_sm4_store(ctx, buffer, hlsl_ir_store(instr)); + break; + + case HLSL_IR_SWIZZLE: + write_sm4_swizzle(ctx, buffer, hlsl_ir_swizzle(instr)); + break; + + default: + FIXME("Unhandled instruction type %s.\n", hlsl_node_type_to_string(instr->type)); + } + } +} + static void write_sm4_shdr(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *entry_func, struct dxbc_writer *dxbc) { const struct hlsl_profile_info *profile = ctx->profile; struct vkd3d_bytecode_buffer buffer = {0}; const struct hlsl_buffer *cbuffer; - const struct hlsl_ir_node *instr; const struct hlsl_ir_var *var; size_t token_count_position;
@@ -1472,50 +1522,7 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, if (ctx->temp_count) write_sm4_dcl_temps(&buffer, ctx->temp_count);
- LIST_FOR_EACH_ENTRY(instr, &entry_func->body.instrs, struct hlsl_ir_node, entry) - { - if (instr->data_type) - { - if (instr->data_type->type == HLSL_CLASS_MATRIX) - { - FIXME("Matrix operations need to be lowered.\n"); - break; - } - else if (instr->data_type->type == HLSL_CLASS_OBJECT) - { - hlsl_fixme(ctx, instr->loc, "Object copy.\n"); - break; - } - - assert(instr->data_type->type == HLSL_CLASS_SCALAR || instr->data_type->type == HLSL_CLASS_VECTOR); - } - - switch (instr->type) - { - case HLSL_IR_CONSTANT: - write_sm4_constant(ctx, &buffer, hlsl_ir_constant(instr)); - break; - - case HLSL_IR_EXPR: - write_sm4_expr(ctx, &buffer, hlsl_ir_expr(instr)); - break; - - case HLSL_IR_LOAD: - write_sm4_load(ctx, &buffer, hlsl_ir_load(instr)); - break; - - case HLSL_IR_STORE: - write_sm4_store(ctx, &buffer, hlsl_ir_store(instr)); - break; - - case HLSL_IR_SWIZZLE: - write_sm4_swizzle(ctx, &buffer, hlsl_ir_swizzle(instr)); - break; - - default: - FIXME("Unhandled instruction type %s.\n", hlsl_node_type_to_string(instr->type)); - } - } + write_sm4_block(ctx, &buffer, &entry_func->body);
write_sm4_ret(&buffer);
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 0a9aac2a..c022b5dd 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -23,6 +23,8 @@ #include "vkd3d_d3dcommon.h" #include "sm4.h"
+static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_block *block); + bool hlsl_sm4_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic, bool output, enum vkd3d_sm4_register_type *type, bool *has_idx) { @@ -1375,6 +1377,22 @@ static void write_sm4_load(struct hlsl_ctx *ctx, write_sm4_instruction(buffer, &instr); }
+static void write_sm4_loop(struct hlsl_ctx *ctx, + struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_loop *loop) +{ + struct sm4_instruction instr = + { + .opcode = VKD3D_SM4_OP_LOOP, + }; + + write_sm4_instruction(buffer, &instr); + + write_sm4_block(ctx, buffer, &loop->body); + + instr.opcode = VKD3D_SM4_OP_ENDLOOP; + write_sm4_instruction(buffer, &instr); +} + static void write_sm4_store(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_store *store) { @@ -1459,6 +1477,10 @@ static void write_sm4_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer * write_sm4_load(ctx, buffer, hlsl_ir_load(instr)); break;
+ case HLSL_IR_LOOP: + write_sm4_loop(ctx, buffer, hlsl_ir_loop(instr)); + break; + case HLSL_IR_STORE: write_sm4_store(ctx, buffer, hlsl_ir_store(instr)); break;
Signed-off-by: Giovanni Mascellani gmascellani@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); + + 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) { @@ -1473,6 +1500,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;
On Tue, Nov 2, 2021 at 11:49 AM Giovanni Mascellani gmascellani@codeweavers.com wrote:
Signed-off-by: Giovanni Mascellani gmascellani@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) {
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a72e0a18..6e5fad8c 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1198,11 +1198,11 @@ static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, { vkd3d_string_buffer_printf(buffer, "if ("); dump_src(buffer, &if_node->condition); - vkd3d_string_buffer_printf(buffer, ")\n{\n"); + vkd3d_string_buffer_printf(buffer, ") {\n"); dump_instr_list(ctx, buffer, &if_node->then_instrs.instrs); - vkd3d_string_buffer_printf(buffer, "}\nelse\n{\n"); + vkd3d_string_buffer_printf(buffer, " %10s } else {\n", ""); dump_instr_list(ctx, buffer, &if_node->else_instrs.instrs); - vkd3d_string_buffer_printf(buffer, "}\n"); + vkd3d_string_buffer_printf(buffer, " %10s }", ""); }
static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_jump *jump) @@ -1229,9 +1229,9 @@ static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_i
static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop) { - vkd3d_string_buffer_printf(buffer, "for (;;)\n{\n"); + vkd3d_string_buffer_printf(buffer, "for (;;) {\n"); dump_instr_list(ctx, buffer, &loop->body.instrs); - vkd3d_string_buffer_printf(buffer, "}\n"); + vkd3d_string_buffer_printf(buffer, " %10s }", ""); }
static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_resource_load *load)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- libs/vkd3d-shader/hlsl.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index aae0ebce..7c1ae447 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -2146,7 +2146,7 @@ struct_declaration: "Anonymous struct type must declare a variable."); if (modifiers) hlsl_error(ctx, @1, VKD3D_SHADER_ERROR_HLSL_INVALID_MODIFIER, - "Modifiers are not allowed on struct type declataions."); + "Modifiers are not allowed on struct type declarations."); }
if (!(type = apply_type_modifiers(ctx, $2, &modifiers, @1)))
Signed-off-by: Zebediah Figura zfigura@codeweavers.com