mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Lower narrowing casts to swizzles.
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com> Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com> Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
0a4e948453
commit
a33439f1a0
@@ -290,7 +290,6 @@ XFAIL_TESTS = \
|
|||||||
tests/conditional.shader_test \
|
tests/conditional.shader_test \
|
||||||
tests/hlsl-array-dimension.shader_test \
|
tests/hlsl-array-dimension.shader_test \
|
||||||
tests/hlsl-bool-cast.shader_test \
|
tests/hlsl-bool-cast.shader_test \
|
||||||
tests/hlsl-cross.shader_test \
|
|
||||||
tests/hlsl-duplicate-modifiers.shader_test \
|
tests/hlsl-duplicate-modifiers.shader_test \
|
||||||
tests/hlsl-for.shader_test \
|
tests/hlsl-for.shader_test \
|
||||||
tests/hlsl-function-overload.shader_test \
|
tests/hlsl-function-overload.shader_test \
|
||||||
|
@@ -616,6 +616,42 @@ static bool split_struct_copies(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool lower_narrowing_casts(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
|
{
|
||||||
|
const struct hlsl_type *src_type, *dst_type;
|
||||||
|
struct hlsl_type *dst_vector_type;
|
||||||
|
struct hlsl_ir_expr *cast;
|
||||||
|
|
||||||
|
if (instr->type != HLSL_IR_EXPR)
|
||||||
|
return false;
|
||||||
|
cast = hlsl_ir_expr(instr);
|
||||||
|
src_type = cast->operands[0].node->data_type;
|
||||||
|
dst_type = cast->node.data_type;
|
||||||
|
|
||||||
|
if (cast->op == HLSL_OP1_CAST
|
||||||
|
&& src_type->type <= HLSL_CLASS_VECTOR && dst_type->type <= HLSL_CLASS_VECTOR
|
||||||
|
&& dst_type->dimx < src_type->dimx)
|
||||||
|
{
|
||||||
|
struct hlsl_ir_swizzle *swizzle;
|
||||||
|
struct hlsl_ir_expr *new_cast;
|
||||||
|
|
||||||
|
dst_vector_type = hlsl_get_vector_type(ctx, dst_type->base_type, src_type->dimx);
|
||||||
|
/* We need to preserve the cast since it might be doing more than just
|
||||||
|
* narrowing the vector. */
|
||||||
|
if (!(new_cast = hlsl_new_cast(ctx, cast->operands[0].node, dst_vector_type, &cast->node.loc)))
|
||||||
|
return false;
|
||||||
|
list_add_after(&cast->node.entry, &new_cast->node.entry);
|
||||||
|
if (!(swizzle = hlsl_new_swizzle(ctx, HLSL_SWIZZLE(X, Y, Z, W), dst_type->dimx, &new_cast->node, &cast->node.loc)))
|
||||||
|
return false;
|
||||||
|
list_add_after(&new_cast->node.entry, &swizzle->node.entry);
|
||||||
|
|
||||||
|
replace_node(&cast->node, &swizzle->node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
static bool fold_constants(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr, void *context)
|
||||||
{
|
{
|
||||||
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
|
struct hlsl_ir_constant *arg1, *arg2 = NULL, *res;
|
||||||
@@ -1669,6 +1705,7 @@ int hlsl_emit_dxbc(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_fun
|
|||||||
progress |= transform_ir(ctx, split_struct_copies, body, NULL);
|
progress |= transform_ir(ctx, split_struct_copies, body, NULL);
|
||||||
}
|
}
|
||||||
while (progress);
|
while (progress);
|
||||||
|
transform_ir(ctx, lower_narrowing_casts, body, NULL);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
progress = transform_ir(ctx, fold_constants, body, NULL);
|
progress = transform_ir(ctx, fold_constants, body, NULL);
|
||||||
|
@@ -1298,9 +1298,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
const struct hlsl_type *src_type = arg1->data_type;
|
const struct hlsl_type *src_type = arg1->data_type;
|
||||||
|
|
||||||
/* Narrowing casts need to be lowered. */
|
/* Narrowing casts were already lowered. */
|
||||||
if (src_type->dimx != expr->node.data_type->dimx)
|
assert(src_type->dimx == expr->node.data_type->dimx);
|
||||||
hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.\n");
|
|
||||||
|
|
||||||
switch (src_type->base_type)
|
switch (src_type->base_type)
|
||||||
{
|
{
|
||||||
@@ -1388,9 +1387,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
const struct hlsl_type *src_type = arg1->data_type;
|
const struct hlsl_type *src_type = arg1->data_type;
|
||||||
|
|
||||||
/* Narrowing casts need to be lowered. */
|
/* Narrowing casts were already lowered. */
|
||||||
if (src_type->dimx != expr->node.data_type->dimx)
|
assert(src_type->dimx == expr->node.data_type->dimx);
|
||||||
hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.");
|
|
||||||
|
|
||||||
switch (src_type->base_type)
|
switch (src_type->base_type)
|
||||||
{
|
{
|
||||||
@@ -1433,9 +1431,8 @@ static void write_sm4_expr(struct hlsl_ctx *ctx,
|
|||||||
{
|
{
|
||||||
const struct hlsl_type *src_type = arg1->data_type;
|
const struct hlsl_type *src_type = arg1->data_type;
|
||||||
|
|
||||||
/* Narrowing casts need to be lowered. */
|
/* Narrowing casts were already lowered. */
|
||||||
if (src_type->dimx != expr->node.data_type->dimx)
|
assert(src_type->dimx == expr->node.data_type->dimx);
|
||||||
hlsl_fixme(ctx, expr->node.loc, "SM4 narrowing cast.\n");
|
|
||||||
|
|
||||||
switch (src_type->base_type)
|
switch (src_type->base_type)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user