From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 6 +++--- libs/vkd3d-shader/hlsl.h | 8 ++++++++ libs/vkd3d-shader/hlsl_codegen.c | 4 ++-- libs/vkd3d-shader/hlsl_constant_ops.c | 8 ++------ 4 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 13aac3d4..2b41d4d1 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -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; } diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 059abe18..f9526d9f 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -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, diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 9b644d1b..fefb8406 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -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); diff --git a/libs/vkd3d-shader/hlsl_constant_ops.c b/libs/vkd3d-shader/hlsl_constant_ops.c index ea59fb86..3210bbd5 100644 --- a/libs/vkd3d-shader/hlsl_constant_ops.c +++ b/libs/vkd3d-shader/hlsl_constant_ops.c @@ -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);