mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d-shader: Introduce HLSL allocation helpers.
To automatically put the compilation context in a failed state. Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
3a9f547be3
commit
49726b0e64
@ -103,7 +103,7 @@ struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hls
|
|||||||
{
|
{
|
||||||
struct hlsl_type *type;
|
struct hlsl_type *type;
|
||||||
|
|
||||||
if (!(type = vkd3d_calloc(1, sizeof(*type))))
|
if (!(type = hlsl_alloc(ctx, sizeof(*type))))
|
||||||
return NULL;
|
return NULL;
|
||||||
type->name = name;
|
type->name = name;
|
||||||
type->type = type_class;
|
type->type = type_class;
|
||||||
@ -149,7 +149,7 @@ struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, s
|
|||||||
unsigned int reg_size = 0;
|
unsigned int reg_size = 0;
|
||||||
struct hlsl_type *type;
|
struct hlsl_type *type;
|
||||||
|
|
||||||
if (!(type = vkd3d_calloc(1, sizeof(*type))))
|
if (!(type = hlsl_alloc(ctx, sizeof(*type))))
|
||||||
return NULL;
|
return NULL;
|
||||||
type->type = HLSL_CLASS_STRUCT;
|
type->type = HLSL_CLASS_STRUCT;
|
||||||
type->base_type = HLSL_TYPE_VOID;
|
type->base_type = HLSL_TYPE_VOID;
|
||||||
@ -281,12 +281,12 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, u
|
|||||||
struct hlsl_struct_field *old_field, *field;
|
struct hlsl_struct_field *old_field, *field;
|
||||||
struct hlsl_type *type;
|
struct hlsl_type *type;
|
||||||
|
|
||||||
if (!(type = vkd3d_calloc(1, sizeof(*type))))
|
if (!(type = hlsl_alloc(ctx, sizeof(*type))))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (old->name)
|
if (old->name)
|
||||||
{
|
{
|
||||||
type->name = vkd3d_strdup(old->name);
|
type->name = hlsl_strdup(ctx, old->name);
|
||||||
if (!type->name)
|
if (!type->name)
|
||||||
{
|
{
|
||||||
vkd3d_free(type);
|
vkd3d_free(type);
|
||||||
@ -313,7 +313,7 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, u
|
|||||||
{
|
{
|
||||||
unsigned int reg_size = 0;
|
unsigned int reg_size = 0;
|
||||||
|
|
||||||
if (!(type->e.elements = vkd3d_malloc(sizeof(*type->e.elements))))
|
if (!(type->e.elements = hlsl_alloc(ctx, sizeof(*type->e.elements))))
|
||||||
{
|
{
|
||||||
vkd3d_free((void *)type->name);
|
vkd3d_free((void *)type->name);
|
||||||
vkd3d_free(type);
|
vkd3d_free(type);
|
||||||
@ -322,7 +322,7 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, u
|
|||||||
list_init(type->e.elements);
|
list_init(type->e.elements);
|
||||||
LIST_FOR_EACH_ENTRY(old_field, old->e.elements, struct hlsl_struct_field, entry)
|
LIST_FOR_EACH_ENTRY(old_field, old->e.elements, struct hlsl_struct_field, entry)
|
||||||
{
|
{
|
||||||
if (!(field = vkd3d_calloc(1, sizeof(*field))))
|
if (!(field = hlsl_alloc(ctx, sizeof(*field))))
|
||||||
{
|
{
|
||||||
LIST_FOR_EACH_ENTRY_SAFE(field, old_field, type->e.elements, struct hlsl_struct_field, entry)
|
LIST_FOR_EACH_ENTRY_SAFE(field, old_field, type->e.elements, struct hlsl_struct_field, entry)
|
||||||
{
|
{
|
||||||
@ -337,10 +337,10 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, u
|
|||||||
}
|
}
|
||||||
field->loc = old_field->loc;
|
field->loc = old_field->loc;
|
||||||
field->type = hlsl_type_clone(ctx, old_field->type, default_majority);
|
field->type = hlsl_type_clone(ctx, old_field->type, default_majority);
|
||||||
field->name = vkd3d_strdup(old_field->name);
|
field->name = hlsl_strdup(ctx, old_field->name);
|
||||||
if (old_field->semantic.name)
|
if (old_field->semantic.name)
|
||||||
{
|
{
|
||||||
field->semantic.name = vkd3d_strdup(old_field->semantic.name);
|
field->semantic.name = hlsl_strdup(ctx, old_field->semantic.name);
|
||||||
field->semantic.index = old_field->semantic.index;
|
field->semantic.index = old_field->semantic.index;
|
||||||
}
|
}
|
||||||
field->reg_offset = reg_size;
|
field->reg_offset = reg_size;
|
||||||
@ -373,30 +373,30 @@ bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
|
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
|
||||||
struct vkd3d_shader_location *loc)
|
struct vkd3d_shader_location *loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *cast;
|
struct hlsl_ir_node *cast;
|
||||||
|
|
||||||
cast = hlsl_new_unary_expr(HLSL_IR_UNOP_CAST, node, *loc);
|
cast = hlsl_new_unary_expr(ctx, HLSL_IR_UNOP_CAST, node, *loc);
|
||||||
if (cast)
|
if (cast)
|
||||||
cast->data_type = type;
|
cast->data_type = type;
|
||||||
return hlsl_ir_expr(cast);
|
return hlsl_ir_expr(cast);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ir_node *node)
|
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node)
|
||||||
{
|
{
|
||||||
/* Use a cast to the same type as a makeshift identity expression. */
|
/* Use a cast to the same type as a makeshift identity expression. */
|
||||||
return hlsl_new_cast(node, node->data_type, &node->loc);
|
return hlsl_new_cast(ctx, node, node->data_type, &node->loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_var *hlsl_new_var(const char *name, struct hlsl_type *type,
|
struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
|
||||||
const struct vkd3d_shader_location loc, const struct hlsl_semantic *semantic, unsigned int modifiers,
|
const struct vkd3d_shader_location loc, const struct hlsl_semantic *semantic, unsigned int modifiers,
|
||||||
const struct hlsl_reg_reservation *reg_reservation)
|
const struct hlsl_reg_reservation *reg_reservation)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_var *var;
|
struct hlsl_ir_var *var;
|
||||||
|
|
||||||
if (!(var = vkd3d_calloc(1, sizeof(*var))))
|
if (!(var = hlsl_alloc(ctx, sizeof(*var))))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
var->name = name;
|
var->name = name;
|
||||||
@ -412,7 +412,7 @@ struct hlsl_ir_var *hlsl_new_var(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,
|
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, 0, NULL);
|
struct hlsl_ir_var *var = hlsl_new_var(ctx, hlsl_strdup(ctx, 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);
|
||||||
@ -424,7 +424,7 @@ static bool type_is_single_reg(const struct hlsl_type *type)
|
|||||||
return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
|
return type->type == HLSL_CLASS_SCALAR || type->type == HLSL_CLASS_VECTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
||||||
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc)
|
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_store *store;
|
struct hlsl_ir_store *store;
|
||||||
@ -432,7 +432,7 @@ struct hlsl_ir_store *hlsl_new_store(struct hlsl_ir_var *var, struct hlsl_ir_nod
|
|||||||
if (!writemask && type_is_single_reg(rhs->data_type))
|
if (!writemask && type_is_single_reg(rhs->data_type))
|
||||||
writemask = (1 << rhs->data_type->dimx) - 1;
|
writemask = (1 << rhs->data_type->dimx) - 1;
|
||||||
|
|
||||||
if (!(store = vkd3d_malloc(sizeof(*store))))
|
if (!(store = hlsl_alloc(ctx, sizeof(*store))))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
init_node(&store->node, HLSL_IR_STORE, NULL, loc);
|
init_node(&store->node, HLSL_IR_STORE, NULL, loc);
|
||||||
@ -443,9 +443,9 @@ struct hlsl_ir_store *hlsl_new_store(struct hlsl_ir_var *var, struct hlsl_ir_nod
|
|||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
|
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
|
||||||
{
|
{
|
||||||
return hlsl_new_store(lhs, NULL, rhs, 0, rhs->loc);
|
return hlsl_new_store(ctx, lhs, NULL, rhs, 0, rhs->loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
|
struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
|
||||||
@ -453,19 +453,19 @@ struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned i
|
|||||||
{
|
{
|
||||||
struct hlsl_ir_constant *c;
|
struct hlsl_ir_constant *c;
|
||||||
|
|
||||||
if (!(c = vkd3d_malloc(sizeof(*c))))
|
if (!(c = hlsl_alloc(ctx, sizeof(*c))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_UINT], loc);
|
init_node(&c->node, HLSL_IR_CONSTANT, ctx->builtin_types.scalar[HLSL_TYPE_UINT], loc);
|
||||||
c->value.u[0] = n;
|
c->value.u[0] = n;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op,
|
struct hlsl_ir_node *hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
|
||||||
struct hlsl_ir_node *arg, struct vkd3d_shader_location loc)
|
struct hlsl_ir_node *arg, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
|
|
||||||
if (!(expr = vkd3d_calloc(1, sizeof(*expr))))
|
if (!(expr = hlsl_alloc(ctx, sizeof(*expr))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&expr->node, HLSL_IR_EXPR, arg->data_type, loc);
|
init_node(&expr->node, HLSL_IR_EXPR, arg->data_type, loc);
|
||||||
expr->op = op;
|
expr->op = op;
|
||||||
@ -473,13 +473,14 @@ struct hlsl_ir_node *hlsl_new_unary_expr(enum hlsl_ir_expr_op op,
|
|||||||
return &expr->node;
|
return &expr->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
|
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op,
|
||||||
|
struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_expr *expr;
|
struct hlsl_ir_expr *expr;
|
||||||
|
|
||||||
assert(hlsl_types_are_equal(arg1->data_type, arg2->data_type));
|
assert(hlsl_types_are_equal(arg1->data_type, arg2->data_type));
|
||||||
|
|
||||||
if (!(expr = vkd3d_calloc(1, sizeof(*expr))))
|
if (!(expr = hlsl_alloc(ctx, sizeof(*expr))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&expr->node, HLSL_IR_EXPR, arg1->data_type, arg1->loc);
|
init_node(&expr->node, HLSL_IR_EXPR, arg1->data_type, arg1->loc);
|
||||||
expr->op = op;
|
expr->op = op;
|
||||||
@ -488,11 +489,11 @@ struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_i
|
|||||||
return &expr->node;
|
return &expr->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct vkd3d_shader_location loc)
|
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_if *iff;
|
struct hlsl_ir_if *iff;
|
||||||
|
|
||||||
if (!(iff = vkd3d_malloc(sizeof(*iff))))
|
if (!(iff = hlsl_alloc(ctx, sizeof(*iff))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&iff->node, HLSL_IR_IF, NULL, loc);
|
init_node(&iff->node, HLSL_IR_IF, NULL, loc);
|
||||||
hlsl_src_from_node(&iff->condition, condition);
|
hlsl_src_from_node(&iff->condition, condition);
|
||||||
@ -501,12 +502,12 @@ struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct vkd3d_shad
|
|||||||
return iff;
|
return iff;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_load *hlsl_new_load(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
||||||
struct hlsl_type *type, const struct vkd3d_shader_location loc)
|
struct hlsl_type *type, const struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_load *load;
|
struct hlsl_ir_load *load;
|
||||||
|
|
||||||
if (!(load = vkd3d_calloc(1, sizeof(*load))))
|
if (!(load = hlsl_alloc(ctx, sizeof(*load))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&load->node, HLSL_IR_LOAD, type, loc);
|
init_node(&load->node, HLSL_IR_LOAD, type, loc);
|
||||||
load->src.var = var;
|
load->src.var = var;
|
||||||
@ -514,9 +515,10 @@ struct hlsl_ir_load *hlsl_new_load(struct hlsl_ir_var *var, struct hlsl_ir_node
|
|||||||
return load;
|
return load;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ir_var *var, const struct vkd3d_shader_location loc)
|
struct hlsl_ir_load *hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var,
|
||||||
|
const struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
return hlsl_new_load(var, NULL, var->data_type, loc);
|
return hlsl_new_load(ctx, var, NULL, var->data_type, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
||||||
@ -524,7 +526,7 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned
|
|||||||
{
|
{
|
||||||
struct hlsl_ir_swizzle *swizzle;
|
struct hlsl_ir_swizzle *swizzle;
|
||||||
|
|
||||||
if (!(swizzle = vkd3d_malloc(sizeof(*swizzle))))
|
if (!(swizzle = hlsl_alloc(ctx, sizeof(*swizzle))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&swizzle->node, HLSL_IR_SWIZZLE,
|
init_node(&swizzle->node, HLSL_IR_SWIZZLE,
|
||||||
hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc);
|
hlsl_new_type(ctx, NULL, HLSL_CLASS_VECTOR, val->data_type->base_type, components, 1), *loc);
|
||||||
@ -533,22 +535,22 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned
|
|||||||
return swizzle;
|
return swizzle;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc)
|
struct hlsl_ir_jump *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_jump *jump;
|
struct hlsl_ir_jump *jump;
|
||||||
|
|
||||||
if (!(jump = vkd3d_malloc(sizeof(*jump))))
|
if (!(jump = hlsl_alloc(ctx, sizeof(*jump))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&jump->node, HLSL_IR_JUMP, NULL, loc);
|
init_node(&jump->node, HLSL_IR_JUMP, NULL, loc);
|
||||||
jump->type = type;
|
jump->type = type;
|
||||||
return jump;
|
return jump;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hlsl_ir_loop *hlsl_new_loop(struct vkd3d_shader_location loc)
|
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_loop *loop;
|
struct hlsl_ir_loop *loop;
|
||||||
|
|
||||||
if (!(loop = vkd3d_calloc(1, sizeof(*loop))))
|
if (!(loop = hlsl_alloc(ctx, sizeof(*loop))))
|
||||||
return NULL;
|
return NULL;
|
||||||
init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
|
init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
|
||||||
list_init(&loop->body);
|
list_init(&loop->body);
|
||||||
@ -565,7 +567,7 @@ struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hl
|
|||||||
{
|
{
|
||||||
struct hlsl_ir_function_decl *decl;
|
struct hlsl_ir_function_decl *decl;
|
||||||
|
|
||||||
if (!(decl = vkd3d_calloc(1, sizeof(*decl))))
|
if (!(decl = hlsl_alloc(ctx, sizeof(*decl))))
|
||||||
return NULL;
|
return NULL;
|
||||||
decl->return_type = return_type;
|
decl->return_type = return_type;
|
||||||
decl->parameters = parameters;
|
decl->parameters = parameters;
|
||||||
@ -577,7 +579,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, 0, NULL)))
|
if (!(return_var = hlsl_new_var(ctx, hlsl_strdup(ctx, name), return_type, loc, semantic, 0, NULL)))
|
||||||
{
|
{
|
||||||
vkd3d_free(decl);
|
vkd3d_free(decl);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -609,7 +611,7 @@ void hlsl_push_scope(struct hlsl_ctx *ctx)
|
|||||||
{
|
{
|
||||||
struct hlsl_scope *new_scope;
|
struct hlsl_scope *new_scope;
|
||||||
|
|
||||||
if (!(new_scope = vkd3d_malloc(sizeof(*new_scope))))
|
if (!(new_scope = hlsl_alloc(ctx, sizeof(*new_scope))))
|
||||||
return;
|
return;
|
||||||
TRACE("Pushing a new scope.\n");
|
TRACE("Pushing a new scope.\n");
|
||||||
list_init(&new_scope->vars);
|
list_init(&new_scope->vars);
|
||||||
@ -1333,12 +1335,12 @@ static void free_function_rb(struct rb_entry *entry, void *context)
|
|||||||
free_function(RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry));
|
free_function(RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl, bool intrinsic)
|
void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl, bool intrinsic)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_function *func;
|
struct hlsl_ir_function *func;
|
||||||
struct rb_entry *func_entry, *old_entry;
|
struct rb_entry *func_entry, *old_entry;
|
||||||
|
|
||||||
func_entry = rb_get(funcs, name);
|
func_entry = rb_get(&ctx->functions, name);
|
||||||
if (func_entry)
|
if (func_entry)
|
||||||
{
|
{
|
||||||
func = RB_ENTRY_VALUE(func_entry, struct hlsl_ir_function, entry);
|
func = RB_ENTRY_VALUE(func_entry, struct hlsl_ir_function, entry);
|
||||||
@ -1372,13 +1374,13 @@ void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_functio
|
|||||||
vkd3d_free(name);
|
vkd3d_free(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
func = vkd3d_malloc(sizeof(*func));
|
func = hlsl_alloc(ctx, sizeof(*func));
|
||||||
func->name = name;
|
func->name = name;
|
||||||
rb_init(&func->overloads, compare_function_decl_rb);
|
rb_init(&func->overloads, compare_function_decl_rb);
|
||||||
decl->func = func;
|
decl->func = func;
|
||||||
rb_put(&func->overloads, decl->parameters, &decl->entry);
|
rb_put(&func->overloads, decl->parameters, &decl->entry);
|
||||||
func->intrinsic = intrinsic;
|
func->intrinsic = intrinsic;
|
||||||
rb_put(funcs, func->name, &func->entry);
|
rb_put(&ctx->functions, func->name, &func->entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct hlsl_profile_info *get_target_info(const char *target)
|
static const struct hlsl_profile_info *get_target_info(const char *target)
|
||||||
@ -1517,20 +1519,20 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
|
|||||||
for (x = 1; x <= 4; ++x)
|
for (x = 1; x <= 4; ++x)
|
||||||
{
|
{
|
||||||
sprintf(name, "%s%ux%u", names[bt], y, x);
|
sprintf(name, "%s%ux%u", names[bt], y, x);
|
||||||
type = hlsl_new_type(ctx, vkd3d_strdup(name), HLSL_CLASS_MATRIX, bt, x, y);
|
type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_MATRIX, bt, x, y);
|
||||||
hlsl_scope_add_type(ctx->globals, type);
|
hlsl_scope_add_type(ctx->globals, type);
|
||||||
|
|
||||||
if (y == 1)
|
if (y == 1)
|
||||||
{
|
{
|
||||||
sprintf(name, "%s%u", names[bt], x);
|
sprintf(name, "%s%u", names[bt], x);
|
||||||
type = hlsl_new_type(ctx, vkd3d_strdup(name), HLSL_CLASS_VECTOR, bt, x, y);
|
type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_VECTOR, bt, x, y);
|
||||||
hlsl_scope_add_type(ctx->globals, type);
|
hlsl_scope_add_type(ctx->globals, type);
|
||||||
ctx->builtin_types.vector[bt][x - 1] = type;
|
ctx->builtin_types.vector[bt][x - 1] = type;
|
||||||
|
|
||||||
if (x == 1)
|
if (x == 1)
|
||||||
{
|
{
|
||||||
sprintf(name, "%s", names[bt]);
|
sprintf(name, "%s", names[bt]);
|
||||||
type = hlsl_new_type(ctx, vkd3d_strdup(name), HLSL_CLASS_SCALAR, bt, x, y);
|
type = hlsl_new_type(ctx, hlsl_strdup(ctx, name), HLSL_CLASS_SCALAR, bt, x, y);
|
||||||
hlsl_scope_add_type(ctx->globals, type);
|
hlsl_scope_add_type(ctx->globals, type);
|
||||||
ctx->builtin_types.scalar[bt] = type;
|
ctx->builtin_types.scalar[bt] = type;
|
||||||
}
|
}
|
||||||
@ -1541,16 +1543,16 @@ static void declare_predefined_types(struct hlsl_ctx *ctx)
|
|||||||
|
|
||||||
for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt)
|
for (bt = 0; bt <= HLSL_SAMPLER_DIM_MAX; ++bt)
|
||||||
{
|
{
|
||||||
type = hlsl_new_type(ctx, vkd3d_strdup(sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
|
type = hlsl_new_type(ctx, hlsl_strdup(ctx, sampler_names[bt]), HLSL_CLASS_OBJECT, HLSL_TYPE_SAMPLER, 1, 1);
|
||||||
type->sampler_dim = bt;
|
type->sampler_dim = bt;
|
||||||
ctx->builtin_types.sampler[bt] = type;
|
ctx->builtin_types.sampler[bt] = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->builtin_types.Void = hlsl_new_type(ctx, vkd3d_strdup("void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
|
ctx->builtin_types.Void = hlsl_new_type(ctx, hlsl_strdup(ctx, "void"), HLSL_CLASS_OBJECT, HLSL_TYPE_VOID, 1, 1);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(effect_types); ++i)
|
for (i = 0; i < ARRAY_SIZE(effect_types); ++i)
|
||||||
{
|
{
|
||||||
type = hlsl_new_type(ctx, vkd3d_strdup(effect_types[i].name), effect_types[i].class,
|
type = hlsl_new_type(ctx, hlsl_strdup(ctx, effect_types[i].name), effect_types[i].class,
|
||||||
effect_types[i].base_type, effect_types[i].dimx, effect_types[i].dimy);
|
effect_types[i].base_type, effect_types[i].dimx, effect_types[i].dimy);
|
||||||
hlsl_scope_add_type(ctx->globals, type);
|
hlsl_scope_add_type(ctx->globals, type);
|
||||||
}
|
}
|
||||||
@ -1565,9 +1567,9 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct hlsl_profile_info *
|
|||||||
|
|
||||||
ctx->message_context = message_context;
|
ctx->message_context = message_context;
|
||||||
|
|
||||||
if (!(ctx->source_files = vkd3d_malloc(sizeof(*ctx->source_files))))
|
if (!(ctx->source_files = hlsl_alloc(ctx, sizeof(*ctx->source_files))))
|
||||||
return false;
|
return false;
|
||||||
if (!(ctx->source_files[0] = vkd3d_strdup("")))
|
if (!(ctx->source_files[0] = hlsl_strdup(ctx, "")))
|
||||||
{
|
{
|
||||||
vkd3d_free(ctx->source_files);
|
vkd3d_free(ctx->source_files);
|
||||||
return false;
|
return false;
|
||||||
|
@ -539,6 +539,34 @@ static inline void hlsl_src_remove(struct hlsl_src *src)
|
|||||||
src->node = NULL;
|
src->node = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void *hlsl_alloc(struct hlsl_ctx *ctx, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr = vkd3d_calloc(1, size);
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
ctx->failed = true;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char *hlsl_strdup(struct hlsl_ctx *ctx, const char *string)
|
||||||
|
{
|
||||||
|
char *ptr = vkd3d_strdup(string);
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
ctx->failed = true;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool hlsl_array_reserve(struct hlsl_ctx *ctx, void **elements,
|
||||||
|
size_t *capacity, size_t element_count, size_t element_size)
|
||||||
|
{
|
||||||
|
bool ret = vkd3d_array_reserve(elements, capacity, element_count, element_size);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
ctx->failed = true;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
const char *debug_hlsl_type(const struct hlsl_type *type) DECLSPEC_HIDDEN;
|
||||||
const char *debug_hlsl_writemask(unsigned int writemask) DECLSPEC_HIDDEN;
|
const char *debug_hlsl_writemask(unsigned int writemask) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
@ -548,7 +576,7 @@ struct vkd3d_string_buffer *hlsl_modifiers_to_string(struct vkd3d_string_buffer_
|
|||||||
unsigned int modifiers) DECLSPEC_HIDDEN;
|
unsigned int modifiers) DECLSPEC_HIDDEN;
|
||||||
const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
|
const char *hlsl_node_type_to_string(enum hlsl_ir_node_type type) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
void hlsl_add_function(struct rb_tree *funcs, char *name, struct hlsl_ir_function_decl *decl,
|
void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl,
|
||||||
bool intrinsic) DECLSPEC_HIDDEN;
|
bool intrinsic) DECLSPEC_HIDDEN;
|
||||||
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var) DECLSPEC_HIDDEN;
|
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
@ -569,22 +597,24 @@ struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name) DEC
|
|||||||
|
|
||||||
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type,
|
struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type,
|
||||||
unsigned int array_size) DECLSPEC_HIDDEN;
|
unsigned int array_size) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_node *hlsl_new_binary_expr(enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
|
struct hlsl_ir_node *hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1,
|
||||||
struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN;
|
struct hlsl_ir_node *arg2) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ir_node *node, struct hlsl_type *type,
|
struct hlsl_ir_expr *hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type,
|
||||||
struct vkd3d_shader_location *loc) DECLSPEC_HIDDEN;
|
struct vkd3d_shader_location *loc) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
|
struct hlsl_ir_expr *hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type,
|
struct hlsl_ir_function_decl *hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type,
|
||||||
struct list *parameters, const struct hlsl_semantic *semantic,
|
struct list *parameters, const struct hlsl_semantic *semantic,
|
||||||
struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ir_node *condition, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
struct hlsl_ir_if *hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition,
|
||||||
struct hlsl_ir_jump *hlsl_new_jump(enum hlsl_ir_jump_type type, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
|
||||||
struct hlsl_ir_load *hlsl_new_load(struct hlsl_ir_var *var, struct hlsl_ir_node *offset, struct hlsl_type *type,
|
|
||||||
struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_loop *hlsl_new_loop(struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
struct hlsl_ir_jump *hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type,
|
||||||
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ir_var *lhs,
|
struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
|
struct hlsl_ir_load *hlsl_new_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
||||||
|
struct hlsl_type *type, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
|
struct hlsl_ir_loop *hlsl_new_loop(struct hlsl_ctx *ctx, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
|
struct hlsl_ir_store *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs,
|
||||||
struct hlsl_ir_node *rhs) DECLSPEC_HIDDEN;
|
struct hlsl_ir_node *rhs) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
struct hlsl_ir_store *hlsl_new_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct hlsl_ir_node *offset,
|
||||||
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
struct hlsl_ir_node *rhs, unsigned int writemask, struct vkd3d_shader_location loc) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct list *fields) DECLSPEC_HIDDEN;
|
struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct list *fields) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned int components,
|
||||||
@ -595,12 +625,13 @@ struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hls
|
|||||||
enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
|
enum hlsl_base_type base_type, unsigned dimx, unsigned dimy) DECLSPEC_HIDDEN;
|
||||||
struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
|
struct hlsl_ir_constant *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
|
||||||
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(struct hlsl_ctx *ctx, 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,
|
struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
|
||||||
const struct vkd3d_shader_location loc, const struct hlsl_semantic *semantic, unsigned int modifiers,
|
const struct vkd3d_shader_location loc, const struct hlsl_semantic *semantic, unsigned int modifiers,
|
||||||
const struct hlsl_reg_reservation *reg_reservation) DECLSPEC_HIDDEN;
|
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_ctx *ctx, 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,
|
||||||
const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN;
|
const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5) DECLSPEC_HIDDEN;
|
||||||
|
@ -170,7 +170,7 @@ row_major {return KW_ROW_MAJOR; }
|
|||||||
{IDENTIFIER} {
|
{IDENTIFIER} {
|
||||||
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
||||||
|
|
||||||
yylval->name = vkd3d_strdup(yytext);
|
yylval->name = hlsl_strdup(ctx, yytext);
|
||||||
if (hlsl_get_var(ctx->cur_scope, yytext) || hlsl_get_function(ctx, yytext))
|
if (hlsl_get_var(ctx->cur_scope, yytext) || hlsl_get_function(ctx, yytext))
|
||||||
return VAR_IDENTIFIER;
|
return VAR_IDENTIFIER;
|
||||||
else if (hlsl_get_type(ctx->cur_scope, yytext, true))
|
else if (hlsl_get_type(ctx->cur_scope, yytext, true))
|
||||||
@ -248,7 +248,8 @@ row_major {return KW_ROW_MAJOR; }
|
|||||||
return PRE_LINE;
|
return PRE_LINE;
|
||||||
}
|
}
|
||||||
<pp_line>{STRING} {
|
<pp_line>{STRING} {
|
||||||
char *string = vkd3d_strdup(yytext + 1);
|
struct hlsl_ctx *ctx = yyget_extra(yyscanner);
|
||||||
|
char *string = hlsl_strdup(ctx, yytext + 1);
|
||||||
|
|
||||||
BEGIN(pp_ignore);
|
BEGIN(pp_ignore);
|
||||||
string[strlen(string) - 1] = 0;
|
string[strlen(string) - 1] = 0;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -35,11 +35,8 @@ 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, 0, temp->reg_reservation)))
|
if (!(uniform = hlsl_new_var(ctx, temp->name, temp->data_type, temp->loc, NULL, 0, temp->reg_reservation)))
|
||||||
{
|
|
||||||
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);
|
||||||
uniform->is_uniform = 1;
|
uniform->is_uniform = 1;
|
||||||
@ -51,21 +48,15 @@ static void prepend_uniform_copy(struct hlsl_ctx *ctx, struct list *instrs, stru
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "<temp-%s>", temp->name);
|
vkd3d_string_buffer_printf(name, "<temp-%s>", temp->name);
|
||||||
temp->name = vkd3d_strdup(name->buffer);
|
temp->name = hlsl_strdup(ctx, name->buffer);
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
|
|
||||||
if (!(load = hlsl_new_var_load(uniform, temp->loc)))
|
if (!(load = hlsl_new_var_load(ctx, uniform, temp->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_head(instrs, &load->node.entry);
|
list_add_head(instrs, &load->node.entry);
|
||||||
|
|
||||||
if (!(store = hlsl_new_simple_store(temp, &load->node)))
|
if (!(store = hlsl_new_simple_store(ctx, temp, &load->node)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_after(&load->node.entry, &store->node.entry);
|
list_add_after(&load->node.entry, &store->node.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,18 +76,16 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index);
|
vkd3d_string_buffer_printf(name, "<input-%s%u>", semantic->name, semantic->index);
|
||||||
if (!(new_semantic.name = vkd3d_strdup(semantic->name)))
|
if (!(new_semantic.name = hlsl_strdup(ctx, semantic->name)))
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new_semantic.index = semantic->index;
|
new_semantic.index = semantic->index;
|
||||||
if (!(input = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, &new_semantic, 0, NULL)))
|
if (!(input = hlsl_new_var(ctx, hlsl_strdup(ctx, name->buffer), type, var->loc, &new_semantic, 0, NULL)))
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
vkd3d_free((void *)new_semantic.name);
|
vkd3d_free((void *)new_semantic.name);
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
@ -105,25 +94,16 @@ static void prepend_input_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
|
|||||||
list_add_before(&var->scope_entry, &input->scope_entry);
|
list_add_before(&var->scope_entry, &input->scope_entry);
|
||||||
list_add_tail(&ctx->extern_vars, &input->extern_entry);
|
list_add_tail(&ctx->extern_vars, &input->extern_entry);
|
||||||
|
|
||||||
if (!(load = hlsl_new_var_load(input, var->loc)))
|
if (!(load = hlsl_new_var_load(ctx, input, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_head(instrs, &load->node.entry);
|
list_add_head(instrs, &load->node.entry);
|
||||||
|
|
||||||
if (!(offset = hlsl_new_uint_constant(ctx, field_offset * 4, var->loc)))
|
if (!(offset = hlsl_new_uint_constant(ctx, field_offset * 4, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_after(&load->node.entry, &offset->node.entry);
|
list_add_after(&load->node.entry, &offset->node.entry);
|
||||||
|
|
||||||
if (!(store = hlsl_new_store(var, &offset->node, &load->node, 0, var->loc)))
|
if (!(store = hlsl_new_store(ctx, var, &offset->node, &load->node, 0, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_after(&offset->node.entry, &store->node.entry);
|
list_add_after(&offset->node.entry, &store->node.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,18 +150,16 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index);
|
vkd3d_string_buffer_printf(name, "<output-%s%u>", semantic->name, semantic->index);
|
||||||
if (!(new_semantic.name = vkd3d_strdup(semantic->name)))
|
if (!(new_semantic.name = hlsl_strdup(ctx, semantic->name)))
|
||||||
{
|
{
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new_semantic.index = semantic->index;
|
new_semantic.index = semantic->index;
|
||||||
if (!(output = hlsl_new_var(vkd3d_strdup(name->buffer), type, var->loc, &new_semantic, 0, NULL)))
|
if (!(output = hlsl_new_var(ctx, hlsl_strdup(ctx, name->buffer), type, var->loc, &new_semantic, 0, NULL)))
|
||||||
{
|
{
|
||||||
vkd3d_free((void *)new_semantic.name);
|
vkd3d_free((void *)new_semantic.name);
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
@ -191,24 +169,15 @@ static void append_output_copy(struct hlsl_ctx *ctx, struct list *instrs, struct
|
|||||||
list_add_tail(&ctx->extern_vars, &output->extern_entry);
|
list_add_tail(&ctx->extern_vars, &output->extern_entry);
|
||||||
|
|
||||||
if (!(offset = hlsl_new_uint_constant(ctx, field_offset * 4, var->loc)))
|
if (!(offset = hlsl_new_uint_constant(ctx, field_offset * 4, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_tail(instrs, &offset->node.entry);
|
list_add_tail(instrs, &offset->node.entry);
|
||||||
|
|
||||||
if (!(load = hlsl_new_load(var, &offset->node, type, var->loc)))
|
if (!(load = hlsl_new_load(ctx, var, &offset->node, type, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_after(&offset->node.entry, &load->node.entry);
|
list_add_after(&offset->node.entry, &load->node.entry);
|
||||||
|
|
||||||
if (!(store = hlsl_new_store(output, NULL, &load->node, 0, var->loc)))
|
if (!(store = hlsl_new_store(ctx, output, NULL, &load->node, 0, var->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
list_add_after(&load->node.entry, &store->node.entry);
|
list_add_after(&load->node.entry, &store->node.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,47 +300,32 @@ static bool split_struct_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
|
|||||||
struct hlsl_ir_constant *c;
|
struct hlsl_ir_constant *c;
|
||||||
|
|
||||||
if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset * 4, instr->loc)))
|
if (!(c = hlsl_new_uint_constant(ctx, field->reg_offset * 4, instr->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
list_add_before(&instr->entry, &c->node.entry);
|
list_add_before(&instr->entry, &c->node.entry);
|
||||||
|
|
||||||
offset = &c->node;
|
offset = &c->node;
|
||||||
if (rhs_load->src.offset.node)
|
if (rhs_load->src.offset.node)
|
||||||
{
|
{
|
||||||
if (!(add = hlsl_new_binary_expr(HLSL_IR_BINOP_ADD, rhs_load->src.offset.node, &c->node)))
|
if (!(add = hlsl_new_binary_expr(ctx, HLSL_IR_BINOP_ADD, rhs_load->src.offset.node, &c->node)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
list_add_before(&instr->entry, &add->entry);
|
list_add_before(&instr->entry, &add->entry);
|
||||||
offset = add;
|
offset = add;
|
||||||
}
|
}
|
||||||
if (!(field_load = hlsl_new_load(rhs_load->src.var, offset, field->type, instr->loc)))
|
if (!(field_load = hlsl_new_load(ctx, rhs_load->src.var, offset, field->type, instr->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
list_add_before(&instr->entry, &field_load->node.entry);
|
list_add_before(&instr->entry, &field_load->node.entry);
|
||||||
|
|
||||||
offset = &c->node;
|
offset = &c->node;
|
||||||
if (store->lhs.offset.node)
|
if (store->lhs.offset.node)
|
||||||
{
|
{
|
||||||
if (!(add = hlsl_new_binary_expr(HLSL_IR_BINOP_ADD, store->lhs.offset.node, &c->node)))
|
if (!(add = hlsl_new_binary_expr(ctx, HLSL_IR_BINOP_ADD, store->lhs.offset.node, &c->node)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
list_add_before(&instr->entry, &add->entry);
|
list_add_before(&instr->entry, &add->entry);
|
||||||
offset = add;
|
offset = add;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(field_store = hlsl_new_store(store->lhs.var, offset, &field_load->node, 0, instr->loc)))
|
if (!(field_store = hlsl_new_store(ctx, store->lhs.var, offset, &field_load->node, 0, instr->loc)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
list_add_before(&instr->entry, &field_store->node.entry);
|
list_add_before(&instr->entry, &field_store->node.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,11 +356,8 @@ static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, voi
|
|||||||
if (expr->operands[1].node)
|
if (expr->operands[1].node)
|
||||||
arg2 = hlsl_ir_constant(expr->operands[1].node);
|
arg2 = hlsl_ir_constant(expr->operands[1].node);
|
||||||
|
|
||||||
if (!(res = vkd3d_calloc(1, sizeof(*res))))
|
if (!(res = hlsl_alloc(ctx, sizeof(*res))))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
init_node(&res->node, HLSL_IR_CONSTANT, instr->data_type, instr->loc);
|
init_node(&res->node, HLSL_IR_CONSTANT, instr->data_type, instr->loc);
|
||||||
|
|
||||||
switch (instr->data_type->base_type)
|
switch (instr->data_type->base_type)
|
||||||
@ -657,11 +608,11 @@ static unsigned int get_available_writemask(struct liveness *liveness,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool resize_liveness(struct liveness *liveness, size_t new_count)
|
static bool resize_liveness(struct hlsl_ctx *ctx, struct liveness *liveness, size_t new_count)
|
||||||
{
|
{
|
||||||
size_t old_capacity = liveness->size;
|
size_t old_capacity = liveness->size;
|
||||||
|
|
||||||
if (!vkd3d_array_reserve((void **)&liveness->regs, &liveness->size, new_count, sizeof(*liveness->regs)))
|
if (!hlsl_array_reserve(ctx, (void **)&liveness->regs, &liveness->size, new_count, sizeof(*liveness->regs)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (liveness->size > old_capacity)
|
if (liveness->size > old_capacity)
|
||||||
@ -669,7 +620,7 @@ static bool resize_liveness(struct liveness *liveness, size_t new_count)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_reg allocate_register(struct liveness *liveness,
|
static struct hlsl_reg allocate_register(struct hlsl_ctx *ctx, struct liveness *liveness,
|
||||||
unsigned int first_write, unsigned int last_read, unsigned int component_count)
|
unsigned int first_write, unsigned int last_read, unsigned int component_count)
|
||||||
{
|
{
|
||||||
unsigned int component_idx, writemask, i;
|
unsigned int component_idx, writemask, i;
|
||||||
@ -682,7 +633,7 @@ static struct hlsl_reg allocate_register(struct liveness *liveness,
|
|||||||
}
|
}
|
||||||
if (component_idx == liveness->size)
|
if (component_idx == liveness->size)
|
||||||
{
|
{
|
||||||
if (!resize_liveness(liveness, component_idx + 4))
|
if (!resize_liveness(ctx, liveness, component_idx + 4))
|
||||||
return ret;
|
return ret;
|
||||||
writemask = (1u << component_count) - 1;
|
writemask = (1u << component_count) - 1;
|
||||||
}
|
}
|
||||||
@ -710,7 +661,7 @@ static bool is_range_available(struct liveness *liveness, unsigned int first_wri
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct hlsl_reg allocate_range(struct liveness *liveness,
|
static struct hlsl_reg allocate_range(struct hlsl_ctx *ctx, struct liveness *liveness,
|
||||||
unsigned int first_write, unsigned int last_read, unsigned int reg_count)
|
unsigned int first_write, unsigned int last_read, unsigned int reg_count)
|
||||||
{
|
{
|
||||||
const unsigned int component_count = reg_count * 4;
|
const unsigned int component_count = reg_count * 4;
|
||||||
@ -723,7 +674,7 @@ static struct hlsl_reg allocate_range(struct liveness *liveness,
|
|||||||
min(component_count, liveness->size - component_idx)))
|
min(component_count, liveness->size - component_idx)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!resize_liveness(liveness, component_idx + component_count))
|
if (!resize_liveness(ctx, liveness, component_idx + component_count))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < component_count; ++i)
|
for (i = 0; i < component_count; ++i)
|
||||||
@ -741,7 +692,7 @@ static const char *debug_register(char class, struct hlsl_reg reg, const struct
|
|||||||
return vkd3d_dbg_sprintf("%c%u%s", class, reg.id, debug_hlsl_writemask(reg.writemask));
|
return vkd3d_dbg_sprintf("%c%u%s", class, reg.id, debug_hlsl_writemask(reg.writemask));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_variable_temp_register(struct hlsl_ir_var *var, struct liveness *liveness)
|
static void allocate_variable_temp_register(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, struct liveness *liveness)
|
||||||
{
|
{
|
||||||
if (var->is_input_semantic || var->is_output_semantic || var->is_uniform)
|
if (var->is_input_semantic || var->is_output_semantic || var->is_uniform)
|
||||||
return;
|
return;
|
||||||
@ -749,17 +700,17 @@ static void allocate_variable_temp_register(struct hlsl_ir_var *var, struct live
|
|||||||
if (!var->reg.allocated && var->last_read)
|
if (!var->reg.allocated && var->last_read)
|
||||||
{
|
{
|
||||||
if (var->data_type->reg_size > 1)
|
if (var->data_type->reg_size > 1)
|
||||||
var->reg = allocate_range(liveness, var->first_write,
|
var->reg = allocate_range(ctx, liveness, var->first_write,
|
||||||
var->last_read, var->data_type->reg_size);
|
var->last_read, var->data_type->reg_size);
|
||||||
else
|
else
|
||||||
var->reg = allocate_register(liveness, var->first_write,
|
var->reg = allocate_register(ctx, liveness, var->first_write,
|
||||||
var->last_read, var->data_type->dimx);
|
var->last_read, var->data_type->dimx);
|
||||||
TRACE("Allocated %s to %s (liveness %u-%u).\n", var->name,
|
TRACE("Allocated %s to %s (liveness %u-%u).\n", var->name,
|
||||||
debug_register('r', var->reg, var->data_type), var->first_write, var->last_read);
|
debug_register('r', var->reg, var->data_type), var->first_write, var->last_read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void allocate_temp_registers_recurse(struct list *instrs, struct liveness *liveness)
|
static void allocate_temp_registers_recurse(struct hlsl_ctx *ctx, struct list *instrs, struct liveness *liveness)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_node *instr;
|
struct hlsl_ir_node *instr;
|
||||||
|
|
||||||
@ -768,10 +719,10 @@ static void allocate_temp_registers_recurse(struct list *instrs, struct liveness
|
|||||||
if (!instr->reg.allocated && instr->last_read)
|
if (!instr->reg.allocated && instr->last_read)
|
||||||
{
|
{
|
||||||
if (instr->data_type->reg_size > 1)
|
if (instr->data_type->reg_size > 1)
|
||||||
instr->reg = allocate_range(liveness, instr->index,
|
instr->reg = allocate_range(ctx, liveness, instr->index,
|
||||||
instr->last_read, instr->data_type->reg_size);
|
instr->last_read, instr->data_type->reg_size);
|
||||||
else
|
else
|
||||||
instr->reg = allocate_register(liveness, instr->index,
|
instr->reg = allocate_register(ctx, liveness, instr->index,
|
||||||
instr->last_read, instr->data_type->dimx);
|
instr->last_read, instr->data_type->dimx);
|
||||||
TRACE("Allocated anonymous expression @%u to %s (liveness %u-%u).\n", instr->index,
|
TRACE("Allocated anonymous expression @%u to %s (liveness %u-%u).\n", instr->index,
|
||||||
debug_register('r', instr->reg, instr->data_type), instr->index, instr->last_read);
|
debug_register('r', instr->reg, instr->data_type), instr->index, instr->last_read);
|
||||||
@ -782,8 +733,8 @@ static void allocate_temp_registers_recurse(struct list *instrs, struct liveness
|
|||||||
case HLSL_IR_IF:
|
case HLSL_IR_IF:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
|
struct hlsl_ir_if *iff = hlsl_ir_if(instr);
|
||||||
allocate_temp_registers_recurse(&iff->then_instrs, liveness);
|
allocate_temp_registers_recurse(ctx, &iff->then_instrs, liveness);
|
||||||
allocate_temp_registers_recurse(&iff->else_instrs, liveness);
|
allocate_temp_registers_recurse(ctx, &iff->else_instrs, liveness);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,21 +743,21 @@ static void allocate_temp_registers_recurse(struct list *instrs, struct liveness
|
|||||||
struct hlsl_ir_load *load = hlsl_ir_load(instr);
|
struct hlsl_ir_load *load = hlsl_ir_load(instr);
|
||||||
/* We need to at least allocate a variable for undefs.
|
/* We need to at least allocate a variable for undefs.
|
||||||
* FIXME: We should probably find a way to remove them instead. */
|
* FIXME: We should probably find a way to remove them instead. */
|
||||||
allocate_variable_temp_register(load->src.var, liveness);
|
allocate_variable_temp_register(ctx, load->src.var, liveness);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_IR_LOOP:
|
case HLSL_IR_LOOP:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
|
struct hlsl_ir_loop *loop = hlsl_ir_loop(instr);
|
||||||
allocate_temp_registers_recurse(&loop->body, liveness);
|
allocate_temp_registers_recurse(ctx, &loop->body, liveness);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case HLSL_IR_STORE:
|
case HLSL_IR_STORE:
|
||||||
{
|
{
|
||||||
struct hlsl_ir_store *store = hlsl_ir_store(instr);
|
struct hlsl_ir_store *store = hlsl_ir_store(instr);
|
||||||
allocate_variable_temp_register(store->lhs.var, liveness);
|
allocate_variable_temp_register(ctx, store->lhs.var, liveness);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -833,17 +784,14 @@ static void allocate_const_registers_recurse(struct hlsl_ctx *ctx, struct list *
|
|||||||
unsigned int x, y, i, writemask;
|
unsigned int x, y, i, writemask;
|
||||||
|
|
||||||
if (reg_size > 1)
|
if (reg_size > 1)
|
||||||
constant->reg = allocate_range(liveness, 1, UINT_MAX, reg_size);
|
constant->reg = allocate_range(ctx, liveness, 1, UINT_MAX, reg_size);
|
||||||
else
|
else
|
||||||
constant->reg = allocate_register(liveness, 1, UINT_MAX, type->dimx);
|
constant->reg = allocate_register(ctx, liveness, 1, UINT_MAX, type->dimx);
|
||||||
TRACE("Allocated constant @%u to %s.\n", instr->index, debug_register('c', constant->reg, type));
|
TRACE("Allocated constant @%u to %s.\n", instr->index, debug_register('c', constant->reg, type));
|
||||||
|
|
||||||
if (!vkd3d_array_reserve((void **)&defs->values, &defs->size,
|
if (!hlsl_array_reserve(ctx, (void **)&defs->values, &defs->size,
|
||||||
constant->reg.id + reg_size, sizeof(*defs->values)))
|
constant->reg.id + reg_size, sizeof(*defs->values)))
|
||||||
{
|
|
||||||
ctx->failed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
defs->count = max(defs->count, constant->reg.id + reg_size);
|
defs->count = max(defs->count, constant->reg.id + reg_size);
|
||||||
|
|
||||||
assert(type->type <= HLSL_CLASS_LAST_NUMERIC);
|
assert(type->type <= HLSL_CLASS_LAST_NUMERIC);
|
||||||
@ -927,10 +875,10 @@ static void allocate_const_registers(struct hlsl_ctx *ctx, struct hlsl_ir_functi
|
|||||||
if (var->is_uniform && var->last_read)
|
if (var->is_uniform && var->last_read)
|
||||||
{
|
{
|
||||||
if (var->data_type->reg_size > 1)
|
if (var->data_type->reg_size > 1)
|
||||||
var->reg = allocate_range(&liveness, 1, UINT_MAX, var->data_type->reg_size);
|
var->reg = allocate_range(ctx, &liveness, 1, UINT_MAX, var->data_type->reg_size);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var->reg = allocate_register(&liveness, 1, UINT_MAX, 4);
|
var->reg = allocate_register(ctx, &liveness, 1, UINT_MAX, 4);
|
||||||
var->reg.writemask = (1u << var->data_type->dimx) - 1;
|
var->reg.writemask = (1u << var->data_type->dimx) - 1;
|
||||||
}
|
}
|
||||||
TRACE("Allocated %s to %s.\n", var->name, debug_register('c', var->reg, var->data_type));
|
TRACE("Allocated %s to %s.\n", var->name, debug_register('c', var->reg, var->data_type));
|
||||||
@ -942,10 +890,10 @@ static void allocate_const_registers(struct hlsl_ctx *ctx, struct hlsl_ir_functi
|
|||||||
* index to all (simultaneously live) variables or intermediate values. Agnostic
|
* index to all (simultaneously live) variables or intermediate values. Agnostic
|
||||||
* as to how many registers are actually available for the current backend, and
|
* as to how many registers are actually available for the current backend, and
|
||||||
* does not handle constants. */
|
* does not handle constants. */
|
||||||
static void allocate_temp_registers(struct hlsl_ir_function_decl *entry_func)
|
static void allocate_temp_registers(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func)
|
||||||
{
|
{
|
||||||
struct liveness liveness = {0};
|
struct liveness liveness = {0};
|
||||||
allocate_temp_registers_recurse(entry_func->body, &liveness);
|
allocate_temp_registers_recurse(ctx, entry_func->body, &liveness);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic, bool output,
|
static bool sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semantic *semantic, bool output,
|
||||||
@ -1216,6 +1164,7 @@ static struct hlsl_reg hlsl_reg_from_deref(const struct hlsl_deref *deref, const
|
|||||||
|
|
||||||
struct bytecode_buffer
|
struct bytecode_buffer
|
||||||
{
|
{
|
||||||
|
struct hlsl_ctx *ctx;
|
||||||
uint32_t *data;
|
uint32_t *data;
|
||||||
size_t count, size;
|
size_t count, size;
|
||||||
int status;
|
int status;
|
||||||
@ -1229,7 +1178,8 @@ static unsigned int put_dword(struct bytecode_buffer *buffer, uint32_t value)
|
|||||||
if (buffer->status)
|
if (buffer->status)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->size, buffer->count + 1, sizeof(*buffer->data)))
|
if (!hlsl_array_reserve(buffer->ctx, (void **)&buffer->data, &buffer->size,
|
||||||
|
buffer->count + 1, sizeof(*buffer->data)))
|
||||||
{
|
{
|
||||||
buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
|
buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
return index;
|
return index;
|
||||||
@ -1270,7 +1220,8 @@ static unsigned int put_string(struct bytecode_buffer *buffer, const char *str)
|
|||||||
if (buffer->status)
|
if (buffer->status)
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->size, buffer->count + token_count, sizeof(*buffer->data)))
|
if (!hlsl_array_reserve(buffer->ctx, (void **)&buffer->data, &buffer->size,
|
||||||
|
buffer->count + token_count, sizeof(*buffer->data)))
|
||||||
{
|
{
|
||||||
buffer->status = E_OUTOFMEMORY;
|
buffer->status = E_OUTOFMEMORY;
|
||||||
return index;
|
return index;
|
||||||
@ -1478,7 +1429,7 @@ static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct bytecode_buffer *buf
|
|||||||
}
|
}
|
||||||
vkd3d_string_buffer_printf(name, "$%s", var->name);
|
vkd3d_string_buffer_printf(name, "$%s", var->name);
|
||||||
vkd3d_free((char *)var->name);
|
vkd3d_free((char *)var->name);
|
||||||
var->name = vkd3d_strdup(name->buffer);
|
var->name = hlsl_strdup(ctx, name->buffer);
|
||||||
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
vkd3d_string_buffer_release(&ctx->string_buffers, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1936,7 +1887,7 @@ static void write_sm1_instructions(struct hlsl_ctx *ctx, struct bytecode_buffer
|
|||||||
static int write_sm1_shader(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
|
static int write_sm1_shader(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func,
|
||||||
struct vkd3d_shader_code *out)
|
struct vkd3d_shader_code *out)
|
||||||
{
|
{
|
||||||
struct bytecode_buffer buffer = {0};
|
struct bytecode_buffer buffer = {.ctx = ctx};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
put_dword(&buffer, sm1_version(ctx->profile->type, ctx->profile->major_version, ctx->profile->minor_version));
|
put_dword(&buffer, sm1_version(ctx->profile->type, ctx->profile->major_version, ctx->profile->minor_version));
|
||||||
@ -2018,7 +1969,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
|
|||||||
if (TRACE_ON())
|
if (TRACE_ON())
|
||||||
rb_for_each_entry(&ctx->functions, dump_function, NULL);
|
rb_for_each_entry(&ctx->functions, dump_function, NULL);
|
||||||
|
|
||||||
allocate_temp_registers(entry_func);
|
allocate_temp_registers(ctx, entry_func);
|
||||||
if (ctx->profile->major_version < 4)
|
if (ctx->profile->major_version < 4)
|
||||||
allocate_const_registers(ctx, entry_func);
|
allocate_const_registers(ctx, entry_func);
|
||||||
allocate_semantic_registers(ctx);
|
allocate_semantic_registers(ctx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user