From d9da350a8334201400a43d105b92fce2bd6a5f32 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 9 Jul 2012 20:59:29 -0700 Subject: 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 Reviewed-by: Eric Anholt --- src/glsl/ir_builder.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/glsl/ir_builder.cpp') 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 @@ -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) { -- cgit v1.2.3