summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/nir/nir_builder.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index c6e80e729a8..253ca5941cb 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -497,8 +497,16 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, const unsigned *swiz,
assert(num_components <= NIR_MAX_VEC_COMPONENTS);
nir_alu_src alu_src = { NIR_SRC_INIT };
alu_src.src = nir_src_for_ssa(src);
- for (unsigned i = 0; i < num_components && i < NIR_MAX_VEC_COMPONENTS; i++)
+
+ bool is_identity_swizzle = true;
+ for (unsigned i = 0; i < num_components && i < NIR_MAX_VEC_COMPONENTS; i++) {
+ if (swiz[i] != i)
+ is_identity_swizzle = false;
alu_src.swizzle[i] = swiz[i];
+ }
+
+ if (num_components == src->num_components && is_identity_swizzle)
+ return src;
return use_fmov ? nir_fmov_alu(build, alu_src, num_components) :
nir_imov_alu(build, alu_src, num_components);