Add two overloaded variants of ir_if *if_tree() The new functions allow one to chain together if-trees within a single C++ expression that resembles a real if-statement.
Signed-off-by: Chad Versace <chad.vers...@linux.intel.com> --- src/glsl/ir_builder.cpp | 29 +++++++++++++++++++++++++++++ src/glsl/ir_builder.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp index b7a116e..8fb30a0 100644 --- a/src/glsl/ir_builder.cpp +++ b/src/glsl/ir_builder.cpp @@ -333,4 +333,33 @@ u2f(operand a) return expr(ir_unop_u2f, a); } +ir_if* +if_tree(operand condition, + ir_instruction *then_branch) +{ + assert(then_branch != NULL); + + void *mem_ctx = ralloc_parent(condition.val); + + ir_if *result = new(mem_ctx) ir_if(condition.val); + result->then_instructions.push_tail(then_branch); + return result; +} + +ir_if* +if_tree(operand condition, + ir_instruction *then_branch, + ir_instruction *else_branch) +{ + assert(then_branch != NULL); + assert(else_branch != NULL); + + void *mem_ctx = ralloc_parent(condition.val); + + ir_if *result = new(mem_ctx) ir_if(condition.val); + result->then_instructions.push_tail(then_branch); + result->else_instructions.push_tail(else_branch); + return result; +} + } /* namespace ir_builder */ diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h index 82e3762..690ac74 100644 --- a/src/glsl/ir_builder.h +++ b/src/glsl/ir_builder.h @@ -174,4 +174,10 @@ ir_swizzle *swizzle_xy(operand a); ir_swizzle *swizzle_xyz(operand a); ir_swizzle *swizzle_xyzw(operand a); +ir_if *if_tree(operand condition, + ir_instruction *then_branch); +ir_if *if_tree(operand condition, + ir_instruction *then_branch, + ir_instruction *else_branch); + } /* namespace ir_builder */ -- 1.8.1.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev