In fact, don't even mark them directly; only mark the synthetic variables.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v2: New patch.
libs/vkd3d-shader/hlsl.c | 38 +++++++++++---------------- libs/vkd3d-shader/hlsl.h | 6 +++-- libs/vkd3d-shader/hlsl.y | 22 ++-------------- libs/vkd3d-shader/hlsl_codegen.c | 45 +++++++++++++++++++++----------- 4 files changed, 51 insertions(+), 60 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 50b40d65..5804c8e5 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -388,7 +388,7 @@ struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ir_node *node) }
struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc, - const char *semantic, const struct hlsl_reg_reservation *reg_reservation) + const char *semantic, unsigned int modifiers, const struct hlsl_reg_reservation *reg_reservation) { struct hlsl_ir_var *var;
@@ -399,6 +399,7 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const var->data_type = type; var->loc = loc; var->semantic = semantic; + var->modifiers = modifiers; var->reg_reservation = reg_reservation; return var; } @@ -406,7 +407,7 @@ struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc) { - struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, NULL); + struct hlsl_ir_var *var = hlsl_new_var(vkd3d_strdup(name), type, loc, NULL, 0, NULL);
if (var) list_add_tail(&ctx->globals->vars, &var->scope_entry); @@ -571,7 +572,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl char name[28];
sprintf(name, "<retval-%p>", decl); - if (!(return_var = hlsl_new_var(vkd3d_strdup(name), return_type, loc, semantic, NULL))) + if (!(return_var = hlsl_new_var(vkd3d_strdup(name), return_type, loc, semantic, 0, NULL))) { vkd3d_free(decl); return NULL; @@ -868,12 +869,17 @@ static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *
static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var) { - if (var->is_input_varying) - vkd3d_string_buffer_printf(buffer, "in "); - if (var->is_output_varying) - vkd3d_string_buffer_printf(buffer, "out "); - if (var->is_uniform) - vkd3d_string_buffer_printf(buffer, "uniform "); + if (var->modifiers) + { + struct vkd3d_string_buffer_cache string_buffers; + struct vkd3d_string_buffer *string; + + vkd3d_string_buffer_cache_init(&string_buffers); + if ((string = hlsl_modifiers_to_string(&string_buffers, var->modifiers))) + vkd3d_string_buffer_printf(buffer, "%s ", string->buffer); + vkd3d_string_buffer_release(&string_buffers, string); + vkd3d_string_buffer_cache_cleanup(&string_buffers); + } vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name); if (var->semantic) vkd3d_string_buffer_printf(buffer, " : %s", var->semantic); @@ -1616,7 +1622,6 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d struct hlsl_ir_function_decl *entry_func; const struct hlsl_profile_info *profile; const char *entry_point; - struct hlsl_ir_var *var; struct hlsl_ctx ctx; int ret;
@@ -1659,19 +1664,6 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d return VKD3D_ERROR_INVALID_SHADER; }
- LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry) - { - if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic - && (var->is_input_varying || var->is_output_varying)) - hlsl_error(&ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, - "Parameter "%s" is missing a semantic.", var->name); - } - - if (!hlsl_type_is_void(entry_func->return_type) - && entry_func->return_type->type != HLSL_CLASS_STRUCT && !entry_func->return_var->semantic) - hlsl_error(&ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, - "Entry point "%s" is missing a return value semantic.", entry_point); - ret = hlsl_emit_dxbc(&ctx, entry_func, dxbc);
hlsl_ctx_cleanup(&ctx); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index d65c25e2..1c5f63aa 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -216,6 +216,7 @@ struct hlsl_ir_var struct vkd3d_shader_location loc; const char *name; const char *semantic; + unsigned int modifiers; const struct hlsl_reg_reservation *reg_reservation; struct list scope_entry, param_entry, extern_entry;
@@ -589,8 +590,9 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN; -struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, const struct vkd3d_shader_location loc, - const char *semantic, const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN; +struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type, + const struct vkd3d_shader_location loc, const char *semantic, unsigned int modifiers, + const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN; struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, enum vkd3d_shader_error error, diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y index 8cd80533..bc4e1b8d 100644 --- a/libs/vkd3d-shader/hlsl.y +++ b/libs/vkd3d-shader/hlsl.y @@ -763,25 +763,10 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list, if (param->type->type == HLSL_CLASS_MATRIX) assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
- if (!(var = hlsl_new_var(param->name, param->type, loc, param->semantic, param->reg_reservation))) + if (!(var = hlsl_new_var(param->name, param->type, loc, param->semantic, param->modifiers, param->reg_reservation))) return false; var->is_param = 1;
- if (param->type->type != HLSL_CLASS_OBJECT) - { - if (param->modifiers & HLSL_STORAGE_UNIFORM) - { - var->is_uniform = 1; - } - else - { - if (param->modifiers & HLSL_STORAGE_IN) - var->is_input_varying = 1; - if (param->modifiers & HLSL_STORAGE_OUT) - var->is_output_varying = 1; - } - } - if (!hlsl_add_var(ctx, var, false)) { hlsl_free_var(var); @@ -1424,7 +1409,7 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t if (type->type != HLSL_CLASS_MATRIX) check_invalid_matrix_modifiers(ctx, modifiers, v->loc);
- if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, v->reg_reservation))) + if (!(var = hlsl_new_var(v->name, type, v->loc, v->semantic, modifiers, v->reg_reservation))) { free_parse_variable_def(v); continue; @@ -1432,9 +1417,6 @@ static struct list *declare_vars(struct hlsl_ctx *ctx, struct hlsl_type *basic_t
if (ctx->cur_scope == ctx->globals) { - if (type->type != HLSL_CLASS_OBJECT && !(modifiers & HLSL_STORAGE_STATIC)) - var->is_uniform = 1; - local = false;
if ((func = hlsl_get_func_decl(ctx, var->name))) diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index b3e59bc7..3fadc288 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -35,14 +35,13 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru /* Use the synthetic name for the temp, rather than the uniform, so that we * can write the uniform name into the shader reflection data. */
- if (!(uniform = hlsl_new_var(temp->name, temp->data_type, temp->loc, NULL, temp->reg_reservation))) + if (!(uniform = hlsl_new_var(temp->name, temp->data_type, temp->loc, NULL, 0, temp->reg_reservation))) { ctx->failed = true; return; } list_add_before(&temp->scope_entry, &uniform->scope_entry); list_add_tail(&ctx->extern_vars, &uniform->extern_entry); - temp->is_uniform = 0; uniform->is_uniform = 1; uniform->is_param = temp->is_param;
@@ -85,7 +84,7 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct return; } vkd3d_string_buffer_printf(name, "<input-%s>", semantic); - if (!(varying = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, vkd3d_strdup(semantic), NULL))) + if (!(varying = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, vkd3d_strdup(semantic), 0, NULL))) { vkd3d_string_buffer_release(&ctx->string_buffers, name); ctx->failed = true; @@ -145,8 +144,6 @@ static void prepend_input_var_copy(struct hlsl_ctx *ctx, struct list *instrs, st prepend_input_struct_copy(ctx, instrs, var, var->data_type, 0); else if (var->semantic) prepend_input_copy(ctx, instrs, var, var->data_type, 0, var->semantic); - - var->is_input_varying = 0; }
static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_var *var, @@ -164,7 +161,7 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct return; } vkd3d_string_buffer_printf(name, "<output-%s>", semantic); - if (!(varying = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, vkd3d_strdup(semantic), NULL))) + if (!(varying = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, vkd3d_strdup(semantic), 0, NULL))) { vkd3d_string_buffer_release(&ctx->string_buffers, name); ctx->failed = true; @@ -224,8 +221,6 @@ static void append_output_var_copy(struct hlsl_ctx *ctx, struct list *instrs, st append_output_struct_copy(ctx, instrs, var, var->data_type, 0); else if (var->semantic) append_output_copy(ctx, instrs, var, var->data_type, 0, var->semantic); - - var->is_output_varying = 0; }
static bool transform_ir(struct hlsl_ctx *ctx, bool (*func)(struct hlsl_ctx *ctx, struct hlsl_ir_node *, void *), @@ -1315,23 +1310,43 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun { if (var->data_type->type == HLSL_CLASS_OBJECT) list_add_tail(&ctx->extern_vars, &var->extern_entry); - if (var->is_uniform) + else if (!(var->modifiers & HLSL_STORAGE_STATIC)) prepend_uniform_copy(ctx, entry_func->body, var); }
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry) { if (var->data_type->type == HLSL_CLASS_OBJECT) + { list_add_tail(&ctx->extern_vars, &var->extern_entry); - if (var->is_uniform) - prepend_uniform_copy(ctx, entry_func->body, var); - if (var->is_input_varying) - prepend_input_var_copy(ctx, entry_func->body, var); - if (var->is_output_varying) - append_output_var_copy(ctx, entry_func->body, var); + } + else + { + if (var->modifiers & HLSL_STORAGE_UNIFORM) + { + prepend_uniform_copy(ctx, entry_func->body, var); + } + else + { + if (var->data_type->type != HLSL_CLASS_STRUCT && !var->semantic) + hlsl_error(ctx, var->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, + "Parameter "%s" is missing a semantic.", var->name); + + if (var->modifiers & HLSL_STORAGE_IN) + prepend_input_var_copy(ctx, entry_func->body, var); + if (var->modifiers & HLSL_STORAGE_OUT) + append_output_var_copy(ctx, entry_func->body, var); + } + } } if (entry_func->return_var) + { + if (entry_func->return_var->data_type->type != HLSL_CLASS_STRUCT && !entry_func->return_var->semantic) + hlsl_error(ctx, entry_func->loc, VKD3D_SHADER_ERROR_HLSL_MISSING_SEMANTIC, + "Entry point "%s" is missing a return value semantic.", entry_func->func->name); + append_output_var_copy(ctx, entry_func->body, entry_func->return_var); + }
while (transform_ir(ctx, fold_redundant_casts, entry_func->body, NULL)); while (transform_ir(ctx, split_struct_copies, entry_func->body, NULL));