glsl/ir_builder: Add a new swizzle_for_size() function.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 10 Jul 2012 03:59:29 +0000 (20:59 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 12 Jul 2012 17:20:20 +0000 (10:20 -0700)
This swizzles away unwanted components, while preserving the order of
the ones that remain.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/ir_builder.cpp
src/glsl/ir_builder.h

index fc6ee96a3318225650a8b70c029a574e5bc3c10f..d96e25c189fb39d8a9e3415bcd58c8c73f544a77 100644 (file)
@@ -76,6 +76,21 @@ swizzle(operand a, int swizzle, int components)
                                  components);
 }
 
+ir_swizzle *
+swizzle_for_size(operand a, int components)
+{
+   void *mem_ctx = ralloc_parent(a.val);
+
+   if (a.val->type->vector_elements < components)
+      components = a.val->type->vector_elements;
+
+   unsigned s[4] = { 0, 1, 2, 3 };
+   for (int i = components; i < 4; i++)
+      s[i] = components - 1;
+
+   return new(mem_ctx) ir_swizzle(a.val, s, components);
+}
+
 ir_swizzle *
 swizzle_xxxx(operand a)
 {
index 410b08cd0528fff647e186c4921154794806650a..7a0a196ee67c40b85aabe962f8c0630721d08afd 100644 (file)
@@ -91,6 +91,11 @@ ir_expression *mul(operand a, operand b);
 ir_expression *dot(operand a, operand b);
 ir_expression *saturate(operand a);
 
+/**
+ * Swizzle away later components, but preserve the ordering.
+ */
+ir_swizzle *swizzle_for_size(operand a, int components);
+
 ir_swizzle *swizzle_xxxx(operand a);
 ir_swizzle *swizzle_yyyy(operand a);
 ir_swizzle *swizzle_zzzz(operand a);