From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 50 ++++++++++++++++++++++++++++++++ libs/vkd3d-shader/hlsl.h | 18 ++++++++++++ libs/vkd3d-shader/hlsl.y | 13 ++++----- libs/vkd3d-shader/hlsl_codegen.c | 6 ++++ 4 files changed, 80 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index b45b3b9a8..ebeeedafd 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1591,6 +1591,27 @@ struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned return &swizzle->node; }
+struct hlsl_ir_node *hlsl_new_undeclared_load(struct hlsl_ctx *ctx, const char *name, + struct vkd3d_shader_location *loc) +{ + struct hlsl_ir_undeclared_load *load; + struct hlsl_type *type = hlsl_get_scalar_type(ctx, HLSL_TYPE_INT); + + if (!(load = hlsl_alloc(ctx, sizeof(*load)))) + return NULL; + + init_node(&load->node, HLSL_IR_UNDECLARED_LOAD, type, loc); + + if (!(load->name = hlsl_alloc(ctx, strlen(name) + 1))) + { + vkd3d_free(load); + return NULL; + } + strcpy(load->name, name); + + return &load->node; +} + bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index) { struct hlsl_type *type = index->val.node->data_type; @@ -1911,6 +1932,12 @@ static struct hlsl_ir_node *clone_index(struct hlsl_ctx *ctx, struct clone_instr return dst; }
+static struct hlsl_ir_node *clone_undeclared_load(struct hlsl_ctx *ctx, + struct clone_instr_map *map, struct hlsl_ir_undeclared_load *load) +{ + return hlsl_new_undeclared_load(ctx, load->name, &load->node.loc); +} + void hlsl_free_ir_switch_case(struct hlsl_ir_switch_case *c) { hlsl_block_cleanup(&c->body); @@ -2006,6 +2033,9 @@ static struct hlsl_ir_node *clone_instr(struct hlsl_ctx *ctx,
case HLSL_IR_SWIZZLE: return clone_swizzle(ctx, map, hlsl_ir_swizzle(instr)); + + case HLSL_IR_UNDECLARED_LOAD: + return clone_undeclared_load(ctx, map, hlsl_ir_undeclared_load(instr)); }
vkd3d_unreachable(); @@ -2836,6 +2866,12 @@ static void dump_ir_index(struct vkd3d_string_buffer *buffer, const struct hlsl_ vkd3d_string_buffer_printf(buffer, "]"); }
+static void dump_ir_undeclared_load(struct vkd3d_string_buffer *buffer, + const struct hlsl_ir_undeclared_load *load) +{ + vkd3d_string_buffer_printf(buffer, "%s", load->name); +} + static void dump_ir_switch(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_switch *s) { struct hlsl_ir_switch_case *c; @@ -2924,6 +2960,10 @@ static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, case HLSL_IR_SWIZZLE: dump_ir_swizzle(buffer, hlsl_ir_swizzle(instr)); break; + + case HLSL_IR_UNDECLARED_LOAD: + dump_ir_undeclared_load(buffer, hlsl_ir_undeclared_load(instr)); + break; } }
@@ -3096,6 +3136,12 @@ static void free_ir_index(struct hlsl_ir_index *index) vkd3d_free(index); }
+static void free_ir_undeclared_load(struct hlsl_ir_undeclared_load *load) +{ + vkd3d_free(load->name); + vkd3d_free(load); +} + void hlsl_free_instr(struct hlsl_ir_node *node) { assert(list_empty(&node->uses)); @@ -3153,6 +3199,10 @@ void hlsl_free_instr(struct hlsl_ir_node *node) case HLSL_IR_SWITCH: free_ir_switch(hlsl_ir_switch(node)); break; + + case HLSL_IR_UNDECLARED_LOAD: + free_ir_undeclared_load(hlsl_ir_undeclared_load(node)); + break; } }
diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 8b47453b4..97deb7440 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -299,6 +299,7 @@ enum hlsl_ir_node_type HLSL_IR_STORE, HLSL_IR_SWIZZLE, HLSL_IR_SWITCH, + HLSL_IR_UNDECLARED_LOAD, };
/* Common data for every type of IR instruction node. */ @@ -800,6 +801,15 @@ struct hlsl_ir_constant struct hlsl_reg reg; };
+/* Undeclared loads are load to values found on state blocks or technique passes descriptions, that + * only have a specific value for them and do not concern regular pixel, vertex, or compute + * shaders, except for parsing. */ +struct hlsl_ir_undeclared_load +{ + struct hlsl_ir_node node; + char *name; +}; + struct hlsl_scope { /* Item entry for hlsl_ctx.scopes. */ @@ -1061,6 +1071,12 @@ static inline struct hlsl_ir_switch *hlsl_ir_switch(const struct hlsl_ir_node *n return CONTAINING_RECORD(node, struct hlsl_ir_switch, node); }
+static inline struct hlsl_ir_undeclared_load *hlsl_ir_undeclared_load(const struct hlsl_ir_node *node) +{ + assert(node->type == HLSL_IR_UNDECLARED_LOAD); + return CONTAINING_RECORD(node, struct hlsl_ir_undeclared_load, node); +} + static inline void hlsl_block_init(struct hlsl_block *block) { list_init(&block->instrs); @@ -1334,6 +1350,8 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct hlsl_struct_field *fields, size_t field_count); struct hlsl_ir_node *hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned int components, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc); +struct hlsl_ir_node *hlsl_new_undeclared_load(struct hlsl_ctx *ctx, const char *name, + struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template, struct hlsl_type *type, const struct vkd3d_shader_location *loc); struct hlsl_ir_var *hlsl_new_synthetic_var_named(struct hlsl_ctx *ctx, const char *name, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index d4646a365..015974fe1 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -1297,6 +1297,7 @@ static unsigned int evaluate_static_expression_as_uint(struct hlsl_ctx *ctx, str case HLSL_IR_RESOURCE_STORE: case HLSL_IR_STORE: case HLSL_IR_SWITCH: + case HLSL_IR_UNDECLARED_LOAD: hlsl_error(ctx, &node->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_SYNTAX, "Expected literal expression."); } @@ -7386,15 +7387,13 @@ primary_expr: { if (ctx->in_state_block) { - struct hlsl_ir_load *load; - struct hlsl_ir_var *var; + struct hlsl_ir_node *load;
- if (!(var = hlsl_new_synthetic_var(ctx, "state_block_expr", - hlsl_get_scalar_type(ctx, HLSL_TYPE_INT), &@1))) + if (!(load = hlsl_new_undeclared_load(ctx, $1, &@1))) YYABORT; - if (!(load = hlsl_new_var_load(ctx, var, &@1))) - YYABORT; - if (!($$ = make_block(ctx, &load->node))) + vkd3d_free($1); + + if (!($$ = make_block(ctx, load))) YYABORT; } else diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 17421e8ef..34b4f1658 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -3706,6 +3706,9 @@ static bool dce(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context) case HLSL_IR_RESOURCE_STORE: case HLSL_IR_SWITCH: break; + case HLSL_IR_UNDECLARED_LOAD: + /* Unindentified symbol loads should not appear in the shader program. */ + vkd3d_unreachable(); }
return false; @@ -3817,6 +3820,9 @@ static void compute_liveness_recurse(struct hlsl_block *block, unsigned int loop case HLSL_IR_CALL: /* We should have inlined all calls before computing liveness. */ vkd3d_unreachable(); + case HLSL_IR_UNDECLARED_LOAD: + /* Unindentified symbol loads should not appear in the shader program. */ + vkd3d_unreachable();
case HLSL_IR_STORE: {