vkd3d-shader/hlsl: Handle objects in copy propagation.

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:
Zebediah Figura 2022-01-21 22:22:26 +01:00 committed by Alexandre Julliard
parent 5e14b843ea
commit 62bcdcda76
2 changed files with 42 additions and 10 deletions

View File

@ -196,6 +196,8 @@ static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type
} }
case HLSL_CLASS_OBJECT: case HLSL_CLASS_OBJECT:
/* For convenience when performing copy propagation. */
type->reg_size = 1;
break; break;
} }
} }
@ -273,6 +275,7 @@ struct hlsl_type *hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_
type->dimy = 1; type->dimy = 1;
type->sampler_dim = dim; type->sampler_dim = dim;
type->e.resource_format = format; type->e.resource_format = format;
hlsl_type_calculate_reg_size(ctx, type);
list_add_tail(&ctx->types, &type->entry); list_add_tail(&ctx->types, &type->entry);
return type; return type;
} }

View File

@ -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_deref *src = &load->src;
struct hlsl_ir_var *var = src->var; struct hlsl_ir_var *var = src->var;
unsigned int offset, swizzle; unsigned int offset, swizzle;
unsigned int dimx = 0;
if (type->type != HLSL_CLASS_SCALAR && type->type != HLSL_CLASS_VECTOR) switch (type->type)
return false; {
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)) if (!hlsl_offset_from_deref(src, &offset))
return false; 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))) if (!(var_def = copy_propagation_get_var_def(state, var)))
return false; 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; return false;
} }
TRACE("Load from %s[%u-%u] propagated as instruction %p%s.\n", 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)); var->name, offset, offset + dimx, new_node, debug_hlsl_swizzle(swizzle, 4));
if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, type->dimx, new_node, &node->loc))) if (type->type != HLSL_CLASS_OBJECT)
return false; {
list_add_before(&node->entry, &swizzle_node->node.entry); if (!(swizzle_node = hlsl_new_swizzle(ctx, swizzle, dimx, new_node, &node->loc)))
replace_node(node, &swizzle_node->node); return false;
list_add_before(&node->entry, &swizzle_node->node.entry);
new_node = &swizzle_node->node;
}
replace_node(node, new_node);
return true; return true;
} }
@ -431,9 +452,17 @@ static void copy_propagation_record_store(struct hlsl_ctx *ctx, struct hlsl_ir_s
return; return;
if (hlsl_offset_from_deref(lhs, &offset)) 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 else
{
copy_propagation_invalidate_whole_variable(var_def); copy_propagation_invalidate_whole_variable(var_def);
}
} }
static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_block *block, static bool copy_propagation_transform_block(struct hlsl_ctx *ctx, struct hlsl_block *block,