Spotted by Giovanni Mascellani.
Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 8ae31306..a2879740 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -265,7 +265,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_ { struct hlsl_type *type;
- if (!(type = vkd3d_calloc(1, sizeof(*type)))) + if (!(type = hlsl_alloc(ctx, sizeof(*type)))) return NULL; type->type = HLSL_CLASS_OBJECT; type->base_type = HLSL_TYPE_TEXTURE;
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl.c | 3 ++ libs/vkd3d-shader/hlsl_codegen.c | 49 +++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index a2879740..d8913850 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -196,6 +196,8 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type }
case HLSL_CLASS_OBJECT: + /* For convenience when performing copy propagation. */ + type->reg_size = 1; break; } } @@ -273,6 +275,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_ type->dimy = 1; type->sampler_dim = dim; type->e.resource_format = format; + hlsl_type_calculate_reg_size(ctx, type); list_add_tail(&ctx->types, &type->entry); return type; } diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e43e6378..e426101f 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -394,9 +394,26 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l struct hlsl_deref *src = &load->src; struct hlsl_ir_var *var = src->var; unsigned int offset, swizzle; + unsigned int dimx = 0;
- if (type->type != HLSL_CLASS_SCALAR && type->type != HLSL_CLASS_VECTOR) - return false; + switch (type->type) + { + case HLSL_CLASS_SCALAR: + case HLSL_CLASS_VECTOR: + dimx = type->dimx; + break; + + case HLSL_CLASS_OBJECT: + dimx = 1; + break; + + case HLSL_CLASS_MATRIX: + case HLSL_CLASS_ARRAY: + case HLSL_CLASS_STRUCT: + /* FIXME: Actually we shouldn't even get here, but we don't split + * matrices yet. */ + return false; + }
if (!hlsl_offset_from_deref(src, &offset)) return false; @@ -404,18 +421,22 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l if (!(var_def = copy_propagation_get_var_def(state, var))) return false;
- if (!(new_node = copy_propagation_compute_replacement(var_def, offset, type->dimx, &swizzle))) + if (!(new_node = copy_propagation_compute_replacement(var_def, offset, dimx, &swizzle))) { - TRACE("No single source for propagating load from %s[%u-%u].\n", var->name, offset, offset + type->dimx); + TRACE("No single source for propagating load from %s[%u-%u].\n", var->name, offset, offset + dimx); return false; }
TRACE("Load from %s[%u-%u] propagated as instruction %p%s.\n", - var->name, offset, offset + type->dimx, new_node, debug_hlsl_swizzle(swizzle, 4)); - if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, type->dimx, new_node, &node->loc))) - return false; - list_add_before(&node->entry, &swizzle_node->node.entry); - replace_node(node, &swizzle_node->node); + var->name, offset, offset + dimx, new_node, debug_hlsl_swizzle(swizzle, 4)); + if (type->type != HLSL_CLASS_OBJECT) + { + if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, dimx, new_node, &node->loc))) + return false; + list_add_before(&node->entry, &swizzle_node->node.entry); + new_node = &swizzle_node->node; + } + replace_node(node, new_node); return true; }
@@ -431,9 +452,17 @@ static void copy_propagation_record_store(struct hlsl_ctx *ctx, struct hlsl_ir_s return;
if (hlsl_offset_from_deref(lhs, &offset)) - copy_propagation_set_value(var_def, offset, store->writemask, store->rhs.node); + { + unsigned int writemask = store->writemask; + + if (store->rhs.node->data_type->type == HLSL_CLASS_OBJECT) + writemask = VKD3DSP_WRITEMASK_0; + copy_propagation_set_value(var_def, offset, writemask, store->rhs.node); + } else + { copy_propagation_invalidate_whole_variable(var_def); + } }
static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_block *block,
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- v2: Added braces to the "then" branch.
libs/vkd3d-shader/hlsl_codegen.c | 43 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e426101f..17d58001 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -307,8 +307,8 @@ static void copy_propagation_var_def_destroy(struct rb_entry *entry, void *conte vkd3d_free(var_def); }
-static struct copy_propagation_var_def *copy_propagation_get_var_def(struct copy_propagation_state *state, - struct hlsl_ir_var *var) +static struct copy_propagation_var_def *copy_propagation_get_var_def(const struct copy_propagation_state *state, + const struct hlsl_ir_var *var) { struct rb_entry *entry = rb_get(&state->var_defs, var);
@@ -362,11 +362,19 @@ static void copy_propagation_set_value(struct copy_propagation_var_def *var_def, } }
-static struct hlsl_ir_node *copy_propagation_compute_replacement(struct copy_propagation_var_def *var_def, - unsigned int offset, unsigned int count, unsigned int *swizzle) +static struct hlsl_ir_node *copy_propagation_compute_replacement(const struct copy_propagation_state *state, + const struct hlsl_deref *deref, unsigned int count, unsigned int *swizzle) { + const struct hlsl_ir_var *var = deref->var; + struct copy_propagation_var_def *var_def; struct hlsl_ir_node *node = NULL; - unsigned int i; + unsigned int offset, i; + + if (!hlsl_offset_from_deref(deref, &offset)) + return NULL; + + if (!(var_def = copy_propagation_get_var_def(state, var))) + return NULL;
assert(offset + count <= var_def->var->data_type->reg_size);
@@ -375,12 +383,19 @@ static struct hlsl_ir_node *copy_propagation_compute_replacement(struct copy_pro for (i = 0; i < count; ++i) { if (!node) + { node = var_def->values[offset + i].node; + } else if (node != var_def->values[offset + i].node) + { + TRACE("No single source for propagating load from %s[%u-%u].\n", var->name, offset, offset + count); return NULL; + } *swizzle |= var_def->values[offset + i].component << i * 2; }
+ TRACE("Load from %s[%u-%u] propagated as instruction %p%s.\n", + var->name, offset, offset + count, node, debug_hlsl_swizzle(*swizzle, count)); return node; }
@@ -388,13 +403,10 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l struct copy_propagation_state *state) { struct hlsl_ir_node *node = &load->node, *new_node; - struct copy_propagation_var_def *var_def; struct hlsl_type *type = node->data_type; struct hlsl_ir_swizzle *swizzle_node; - struct hlsl_deref *src = &load->src; - struct hlsl_ir_var *var = src->var; - unsigned int offset, swizzle; unsigned int dimx = 0; + unsigned int swizzle;
switch (type->type) { @@ -415,20 +427,9 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l return false; }
- if (!hlsl_offset_from_deref(src, &offset)) - return false; - - if (!(var_def = copy_propagation_get_var_def(state, var))) + if (!(new_node = copy_propagation_compute_replacement(state, &load->src, dimx, &swizzle))) return false;
- if (!(new_node = copy_propagation_compute_replacement(var_def, offset, dimx, &swizzle))) - { - TRACE("No single source for propagating load from %s[%u-%u].\n", var->name, offset, offset + dimx); - return false; - } - - TRACE("Load from %s[%u-%u] propagated as instruction %p%s.\n", - var->name, offset, offset + dimx, new_node, debug_hlsl_swizzle(swizzle, 4)); if (type->type != HLSL_CLASS_OBJECT) { if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, dimx, new_node, &node->loc)))
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- libs/vkd3d-shader/hlsl_codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 17d58001..e19b204c 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -1506,7 +1506,7 @@ static void allocate_buffers(struct hlsl_ctx *ctx)
LIST_FOR_EACH_ENTRY(var, &ctx->extern_vars, struct hlsl_ir_var, extern_entry) { - if (var->is_uniform) + if (var->is_uniform && var->data_type->type != HLSL_CLASS_OBJECT) { if (var->is_param) var->buffer = ctx->params_buffer;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- Makefile.am | 3 --- libs/vkd3d-shader/hlsl_codegen.c | 39 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/Makefile.am b/Makefile.am index a3ec6850..1c14f958 100644 --- a/Makefile.am +++ b/Makefile.am @@ -306,9 +306,6 @@ XFAIL_TESTS = \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/max.shader_test \ - tests/sampler.shader_test \ - tests/texture-load.shader_test \ - tests/texture-load-typed.shader_test \ tests/trigonometry.shader_test endif
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index e19b204c..98afd0e0 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -399,8 +399,8 @@ static struct hlsl_ir_node *copy_propagation_compute_replacement(const struct co return node; }
-static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_load *load, - struct copy_propagation_state *state) +static bool copy_propagation_transform_load(struct hlsl_ctx *ctx, + struct hlsl_ir_load *load, struct copy_propagation_state *state) { struct hlsl_ir_node *node = &load->node, *new_node; struct hlsl_type *type = node->data_type; @@ -441,6 +441,35 @@ static bool copy_propagation_analyze_load(struct hlsl_ctx *ctx, struct hlsl_ir_l return true; }
+static bool copy_propagation_transform_object_load(struct hlsl_ctx *ctx, + struct hlsl_deref *deref, struct copy_propagation_state *state) +{ + struct hlsl_ir_load *load; + struct hlsl_ir_node *node; + unsigned int swizzle; + + if (!(node = copy_propagation_compute_replacement(state, deref, 1, &swizzle))) + return false; + + /* Only HLSL_IR_LOAD can produce an object. */ + load = hlsl_ir_load(node); + deref->var = load->src.var; + hlsl_src_remove(&deref->offset); + hlsl_src_from_node(&deref->offset, load->src.offset.node); + return true; +} + +static bool copy_propagation_transform_resource_load(struct hlsl_ctx *ctx, + struct hlsl_ir_resource_load *load, struct copy_propagation_state *state) +{ + bool progress = false; + + progress |= copy_propagation_transform_object_load(ctx, &load->resource, state); + if (load->sampler.var) + progress |= copy_propagation_transform_object_load(ctx, &load->sampler, state); + return progress; +} + static void copy_propagation_record_store(struct hlsl_ctx *ctx, struct hlsl_ir_store *store, struct copy_propagation_state *state) { @@ -477,7 +506,11 @@ static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_b switch (instr->type) { case HLSL_IR_LOAD: - progress |= copy_propagation_analyze_load(ctx, hlsl_ir_load(instr), state); + progress |= copy_propagation_transform_load(ctx, hlsl_ir_load(instr), state); + break; + + case HLSL_IR_RESOURCE_LOAD: + progress |= copy_propagation_transform_resource_load(ctx, hlsl_ir_resource_load(instr), state); break;
case HLSL_IR_STORE:
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com