diff options
author | Kenneth Graunke <[email protected]> | 2012-07-09 20:59:29 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2012-07-12 10:20:20 -0700 |
commit | d9da350a8334201400a43d105b92fce2bd6a5f32 (patch) | |
tree | 60e76ef1eae2e71532b1a03b503fab8a72493a1f /src/glsl | |
parent | 0bb3d4ba54f98f4d45abe598dabc905f08055cd5 (diff) |
glsl/ir_builder: Add a new swizzle_for_size() function.
This swizzles away unwanted components, while preserving the order of
the ones that remain.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/ir_builder.cpp | 15 | ||||
-rw-r--r-- | src/glsl/ir_builder.h | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp index fc6ee96a331..d96e25c189f 100644 --- a/src/glsl/ir_builder.cpp +++ b/src/glsl/ir_builder.cpp @@ -77,6 +77,21 @@ swizzle(operand a, int swizzle, int 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) { return swizzle(a, SWIZZLE_XXXX, 4); diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h index 410b08cd052..7a0a196ee67 100644 --- a/src/glsl/ir_builder.h +++ b/src/glsl/ir_builder.h @@ -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); |