vkd3d-shader/hlsl: Add some swizzle manipulation definitions.

This commit is contained in:
Zebediah Figura 2023-01-12 15:52:49 -06:00 committed by Alexandre Julliard
parent 337b4c5db0
commit 8fd30aa87d
Notes: Alexandre Julliard 2023-01-24 22:27:58 +01:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/51
4 changed files with 15 additions and 11 deletions

View File

@ -1641,7 +1641,7 @@ const char *debug_hlsl_swizzle(unsigned int swizzle, unsigned int size)
assert(size <= ARRAY_SIZE(components));
for (i = 0; i < size; ++i)
string[i] = components[(swizzle >> i * 2) & 3];
string[i] = components[hlsl_swizzle_get_component(swizzle, i)];
string[size] = 0;
return vkd3d_dbg_sprintf(".%s", string);
}
@ -2299,8 +2299,8 @@ unsigned int hlsl_combine_swizzles(unsigned int first, unsigned int second, unsi
unsigned int ret = 0, i;
for (i = 0; i < dim; ++i)
{
unsigned int s = (second >> (i * 2)) & 3;
ret |= ((first >> (s * 2)) & 3) << (i * 2);
unsigned int s = hlsl_swizzle_get_component(second, i);
ret |= hlsl_swizzle_get_component(first, s) << HLSL_SWIZZLE_SHIFT(i);
}
return ret;
}

View File

@ -63,6 +63,14 @@
| ((HLSL_SWIZZLE_ ## z) << 4) \
| ((HLSL_SWIZZLE_ ## w) << 6))
#define HLSL_SWIZZLE_MASK (0x3u)
#define HLSL_SWIZZLE_SHIFT(idx) (2u * (idx))
static inline unsigned int hlsl_swizzle_get_component(unsigned int swizzle, unsigned int idx)
{
return (swizzle >> HLSL_SWIZZLE_SHIFT(idx)) & HLSL_SWIZZLE_MASK;
}
enum hlsl_type_class
{
HLSL_CLASS_SCALAR,

View File

@ -752,7 +752,7 @@ static struct hlsl_ir_node *copy_propagation_compute_replacement(struct hlsl_ctx
TRACE("No single source for propagating load from %s[%u-%u].\n", var->name, start, start + count);
return NULL;
}
*swizzle |= value->component << i * 2;
*swizzle |= value->component << HLSL_SWIZZLE_SHIFT(i);
}
TRACE("Load from %s[%u-%u] propagated as instruction %p%s.\n",
@ -1316,7 +1316,7 @@ static bool remove_trivial_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *i
return false;
for (i = 0; i < instr->data_type->dimx; ++i)
if (((swizzle->swizzle >> (2 * i)) & 3) != i)
if (hlsl_swizzle_get_component(swizzle->swizzle, i) != i)
return false;
hlsl_replace_node(instr, swizzle->val.node);

View File

@ -603,7 +603,7 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
{
struct hlsl_ir_constant *value, *res;
struct hlsl_ir_swizzle *swizzle;
unsigned int i, swizzle_bits;
unsigned int i;
if (instr->type != HLSL_IR_SWIZZLE)
return false;
@ -615,12 +615,8 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc)))
return false;
swizzle_bits = swizzle->swizzle;
for (i = 0; i < swizzle->node.data_type->dimx; ++i)
{
res->value[i] = value->value[swizzle_bits & 3];
swizzle_bits >>= 2;
}
res->value[i] = value->value[hlsl_swizzle_get_component(swizzle->swizzle, i)];
list_add_before(&swizzle->node.entry, &res->node.entry);
hlsl_replace_node(&swizzle->node, &res->node);