mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader: Only mark entry point parameters as uniform, input, or output.
In fact, don't even mark them directly; only mark the synthetic variables. 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:
parent
16e549e579
commit
549be35c0a
@ -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,
|
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;
|
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->data_type = type;
|
||||||
var->loc = loc;
|
var->loc = loc;
|
||||||
var->semantic = semantic;
|
var->semantic = semantic;
|
||||||
|
var->modifiers = modifiers;
|
||||||
var->reg_reservation = reg_reservation;
|
var->reg_reservation = reg_reservation;
|
||||||
return var;
|
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,
|
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)
|
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)
|
if (var)
|
||||||
list_add_tail(&ctx->globals->vars, &var->scope_entry);
|
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];
|
char name[28];
|
||||||
|
|
||||||
sprintf(name, "<retval-%p>", decl);
|
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);
|
vkd3d_free(decl);
|
||||||
return NULL;
|
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)
|
static void dump_ir_var(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
|
||||||
{
|
{
|
||||||
if (var->is_input_varying)
|
if (var->modifiers)
|
||||||
vkd3d_string_buffer_printf(buffer, "in ");
|
{
|
||||||
if (var->is_output_varying)
|
struct vkd3d_string_buffer_cache string_buffers;
|
||||||
vkd3d_string_buffer_printf(buffer, "out ");
|
struct vkd3d_string_buffer *string;
|
||||||
if (var->is_uniform)
|
|
||||||
vkd3d_string_buffer_printf(buffer, "uniform ");
|
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);
|
vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(var->data_type), var->name);
|
||||||
if (var->semantic)
|
if (var->semantic)
|
||||||
vkd3d_string_buffer_printf(buffer, " : %s", 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;
|
struct hlsl_ir_function_decl *entry_func;
|
||||||
const struct hlsl_profile_info *profile;
|
const struct hlsl_profile_info *profile;
|
||||||
const char *entry_point;
|
const char *entry_point;
|
||||||
struct hlsl_ir_var *var;
|
|
||||||
struct hlsl_ctx ctx;
|
struct hlsl_ctx ctx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -1659,19 +1664,6 @@ int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d
|
|||||||
return VKD3D_ERROR_INVALID_SHADER;
|
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);
|
ret = hlsl_emit_dxbc(&ctx, entry_func, dxbc);
|
||||||
|
|
||||||
hlsl_ctx_cleanup(&ctx);
|
hlsl_ctx_cleanup(&ctx);
|
||||||
|
@ -216,6 +216,7 @@ struct hlsl_ir_var
|
|||||||
struct vkd3d_shader_location loc;
|
struct vkd3d_shader_location loc;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *semantic;
|
const char *semantic;
|
||||||
|
unsigned int modifiers;
|
||||||
const struct hlsl_reg_reservation *reg_reservation;
|
const struct hlsl_reg_reservation *reg_reservation;
|
||||||
struct list scope_entry, param_entry, extern_entry;
|
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;
|
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 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 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,
|
struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type,
|
||||||
const char *semantic, const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
|
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;
|
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,
|
void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location loc, enum vkd3d_shader_error error,
|
||||||
|
@ -763,25 +763,10 @@ static bool add_func_parameter(struct hlsl_ctx *ctx, struct list *list,
|
|||||||
if (param->type->type == HLSL_CLASS_MATRIX)
|
if (param->type->type == HLSL_CLASS_MATRIX)
|
||||||
assert(param->type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK);
|
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;
|
return false;
|
||||||
var->is_param = 1;
|
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))
|
if (!hlsl_add_var(ctx, var, false))
|
||||||
{
|
{
|
||||||
hlsl_free_var(var);
|
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)
|
if (type->type != HLSL_CLASS_MATRIX)
|
||||||
check_invalid_matrix_modifiers(ctx, modifiers, v->loc);
|
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);
|
free_parse_variable_def(v);
|
||||||
continue;
|
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 (ctx->cur_scope == ctx->globals)
|
||||||
{
|
{
|
||||||
if (type->type != HLSL_CLASS_OBJECT && !(modifiers & HLSL_STORAGE_STATIC))
|
|
||||||
var->is_uniform = 1;
|
|
||||||
|
|
||||||
local = false;
|
local = false;
|
||||||
|
|
||||||
if ((func = hlsl_get_func_decl(ctx, var->name)))
|
if ((func = hlsl_get_func_decl(ctx, var->name)))
|
||||||
|
@ -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
|
/* Use the synthetic name for the temp, rather than the uniform, so that we
|
||||||
* can write the uniform name into the shader reflection data. */
|
* 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;
|
ctx->failed = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list_add_before(&temp->scope_entry, &uniform->scope_entry);
|
list_add_before(&temp->scope_entry, &uniform->scope_entry);
|
||||||
list_add_tail(&ctx->extern_vars, &uniform->extern_entry);
|
list_add_tail(&ctx->extern_vars, &uniform->extern_entry);
|
||||||
temp->is_uniform = 0;
|
|
||||||
uniform->is_uniform = 1;
|
uniform->is_uniform = 1;
|
||||||
uniform->is_param = temp->is_param;
|
uniform->is_param = temp->is_param;
|
||||||
|
|
||||||
@ -85,7 +84,7 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "<input-%s>", semantic);
|
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);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
ctx->failed = true;
|
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);
|
prepend_input_struct_copy(ctx, instrs, var, var->data_type, 0);
|
||||||
else if (var->semantic)
|
else if (var->semantic)
|
||||||
prepend_input_copy(ctx, instrs, var, var->data_type, 0, 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,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "<output-%s>", semantic);
|
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);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
ctx->failed = true;
|
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);
|
append_output_struct_copy(ctx, instrs, var, var->data_type, 0);
|
||||||
else if (var->semantic)
|
else if (var->semantic)
|
||||||
append_output_copy(ctx, instrs, var, var->data_type, 0, 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 *),
|
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)
|
if (var->data_type->type == HLSL_CLASS_OBJECT)
|
||||||
list_add_tail(&ctx->extern_vars, &var->extern_entry);
|
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);
|
prepend_uniform_copy(ctx, entry_func->body, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry)
|
LIST_FOR_EACH_ENTRY(var, entry_func->parameters, struct hlsl_ir_var, param_entry)
|
||||||
{
|
{
|
||||||
if (var->data_type->type == HLSL_CLASS_OBJECT)
|
if (var->data_type->type == HLSL_CLASS_OBJECT)
|
||||||
|
{
|
||||||
list_add_tail(&ctx->extern_vars, &var->extern_entry);
|
list_add_tail(&ctx->extern_vars, &var->extern_entry);
|
||||||
if (var->is_uniform)
|
}
|
||||||
prepend_uniform_copy(ctx, entry_func->body, var);
|
else
|
||||||
if (var->is_input_varying)
|
{
|
||||||
prepend_input_var_copy(ctx, entry_func->body, var);
|
if (var->modifiers & HLSL_STORAGE_UNIFORM)
|
||||||
if (var->is_output_varying)
|
{
|
||||||
append_output_var_copy(ctx, entry_func->body, var);
|
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)
|
||||||
|
{
|
||||||
|
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);
|
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, fold_redundant_casts, entry_func->body, NULL));
|
||||||
while (transform_ir(ctx, split_struct_copies, entry_func->body, NULL));
|
while (transform_ir(ctx, split_struct_copies, entry_func->body, NULL));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user