From 7abf3c3a3735f09b3cd7d6c85878e5f18e8e00d4 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Wed, 22 May 2024 14:10:42 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Introduce hlsl_ir_vsir_instruction_ref. This node type will be deleted once the hlsl->vsir->d3dbc translation is complete. For now it serves the purpose of allowing to keep both real hlsl_ir_nodes and vsir_instructions in the hlsl_block, until all the former can be translated into the latter. --- libs/vkd3d-shader/hlsl.c | 29 +++++++++++++++++++++++++++++ libs/vkd3d-shader/hlsl.h | 21 +++++++++++++++++++++ libs/vkd3d-shader/hlsl.y | 2 ++ libs/vkd3d-shader/hlsl_codegen.c | 6 ++++++ 4 files changed, 58 insertions(+) diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index bd5baacd..0ecaaa8e 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1640,6 +1640,22 @@ struct hlsl_ir_node *hlsl_new_switch(struct hlsl_ctx *ctx, struct hlsl_ir_node * return &s->node; } +struct hlsl_ir_node *hlsl_new_vsir_instruction_ref(struct hlsl_ctx *ctx, unsigned int vsir_instr_idx, + struct hlsl_type *type, const struct hlsl_reg *reg, const struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_vsir_instruction_ref *vsir_instr; + + if (!(vsir_instr = hlsl_alloc(ctx, sizeof(*vsir_instr)))) + return NULL; + init_node(&vsir_instr->node, HLSL_IR_VSIR_INSTRUCTION_REF, type, loc); + vsir_instr->vsir_instr_idx = vsir_instr_idx; + + if (reg) + vsir_instr->node.reg = *reg; + + return &vsir_instr->node; +} + struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc) { @@ -2286,6 +2302,9 @@ static struct hlsl_ir_node *clone_instr(struct hlsl_ctx *ctx, case HLSL_IR_STATEBLOCK_CONSTANT: return clone_stateblock_constant(ctx, map, hlsl_ir_stateblock_constant(instr)); + + case HLSL_IR_VSIR_INSTRUCTION_REF: + vkd3d_unreachable(); } vkd3d_unreachable(); @@ -2699,6 +2718,7 @@ const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) [HLSL_IR_SWITCH ] = "HLSL_IR_SWITCH", [HLSL_IR_SWIZZLE ] = "HLSL_IR_SWIZZLE", [HLSL_IR_STATEBLOCK_CONSTANT] = "HLSL_IR_STATEBLOCK_CONSTANT", + [HLSL_IR_VSIR_INSTRUCTION_REF] = "HLSL_IR_VSIR_INSTRUCTION_REF", }; if (type >= ARRAY_SIZE(names)) @@ -3248,6 +3268,11 @@ static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, case HLSL_IR_STATEBLOCK_CONSTANT: dump_ir_stateblock_constant(buffer, hlsl_ir_stateblock_constant(instr)); break; + + case HLSL_IR_VSIR_INSTRUCTION_REF: + vkd3d_string_buffer_printf(buffer, "vsir_program instruction %u", + hlsl_ir_vsir_instruction_ref(instr)->vsir_instr_idx); + break; } } @@ -3530,6 +3555,10 @@ void hlsl_free_instr(struct hlsl_ir_node *node) case HLSL_IR_STATEBLOCK_CONSTANT: free_ir_stateblock_constant(hlsl_ir_stateblock_constant(node)); break; + + case HLSL_IR_VSIR_INSTRUCTION_REF: + vkd3d_free(hlsl_ir_vsir_instruction_ref(node)); + break; } } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d03a70f5..fbd9f633 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -317,6 +317,8 @@ enum hlsl_ir_node_type HLSL_IR_SWIZZLE, HLSL_IR_SWITCH, HLSL_IR_STATEBLOCK_CONSTANT, + + HLSL_IR_VSIR_INSTRUCTION_REF, }; /* Common data for every type of IR instruction node. */ @@ -862,6 +864,16 @@ struct hlsl_ir_stateblock_constant char *name; }; +/* A vkd3d_shader_instruction that can be inserted in a hlsl_block. + * Only used for the HLSL IR to vsir translation, might be removed once this translation is complete. */ +struct hlsl_ir_vsir_instruction_ref +{ + struct hlsl_ir_node node; + + /* Index to a vkd3d_shader_instruction within a vkd3d_shader_instruction_array in a vsir_program. */ + unsigned int vsir_instr_idx; +}; + struct hlsl_scope { /* Item entry for hlsl_ctx.scopes. */ @@ -1155,6 +1167,12 @@ static inline struct hlsl_ir_stateblock_constant *hlsl_ir_stateblock_constant(co return CONTAINING_RECORD(node, struct hlsl_ir_stateblock_constant, node); } +static inline struct hlsl_ir_vsir_instruction_ref *hlsl_ir_vsir_instruction_ref(const struct hlsl_ir_node *node) +{ + VKD3D_ASSERT(node->type == HLSL_IR_VSIR_INSTRUCTION_REF); + return CONTAINING_RECORD(node, struct hlsl_ir_vsir_instruction_ref, node); +} + static inline void hlsl_block_init(struct hlsl_block *block) { list_init(&block->instrs); @@ -1466,6 +1484,9 @@ struct hlsl_ir_switch_case *hlsl_new_switch_case(struct hlsl_ctx *ctx, unsigned struct hlsl_ir_node *hlsl_new_switch(struct hlsl_ctx *ctx, struct hlsl_ir_node *selector, struct list *cases, const struct vkd3d_shader_location *loc); +struct hlsl_ir_node *hlsl_new_vsir_instruction_ref(struct hlsl_ctx *ctx, unsigned int vsir_instr_idx, + struct hlsl_type *type, const struct hlsl_reg *reg, const struct vkd3d_shader_location *loc); + void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, enum vkd3d_shader_error error, const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5); void hlsl_fixme(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 3f319dea..3bc2f084 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -632,6 +632,8 @@ static struct hlsl_default_value evaluate_static_expression(struct hlsl_ctx *ctx hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Expected literal expression."); break; + case HLSL_IR_VSIR_INSTRUCTION_REF: + vkd3d_unreachable(); } } diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 154328a6..61c60c5c 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -4088,6 +4088,9 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) case HLSL_IR_STATEBLOCK_CONSTANT: /* Stateblock constants should not appear in the shader program. */ vkd3d_unreachable(); + case HLSL_IR_VSIR_INSTRUCTION_REF: + /* HLSL IR nodes are not translated to hlsl_ir_vsir_instruction_ref at this point. */ + vkd3d_unreachable(); } return false; @@ -4213,6 +4216,9 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop case HLSL_IR_STATEBLOCK_CONSTANT: /* Stateblock constants should not appear in the shader program. */ vkd3d_unreachable(); + case HLSL_IR_VSIR_INSTRUCTION_REF: + /* HLSL IR nodes are not translated to hlsl_ir_vsir_instruction_ref at this point. */ + vkd3d_unreachable(); case HLSL_IR_STORE: {