diff options
author | Ian Romanick <ian.d.romanick@intel.com> | 2013-03-06 11:05:14 -0800 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2013-05-13 12:05:18 -0700 |
commit | f274a2ca8733059bdd4f1c456ed4f6df7d7ec008 (patch) | |
tree | 002b5b4e0268463d283b4ab2cbcb757c97312533 /src/glsl/ir_constant_expression.cpp | |
parent | b0bb6103d23c16d23b0ec617746b4b0d1c22075d (diff) | |
download | external_mesa3d-f274a2ca8733059bdd4f1c456ed4f6df7d7ec008.zip external_mesa3d-f274a2ca8733059bdd4f1c456ed4f6df7d7ec008.tar.gz external_mesa3d-f274a2ca8733059bdd4f1c456ed4f6df7d7ec008.tar.bz2 |
glsl: Add ir_binop_vector_extract
The new opcode is used to get a single field from a vector. The field
index may not be constant. This will eventually replace
ir_dereference_array of vectors. This is similar to the extractelement
instruction in LLVM IR.
http://llvm.org/docs/LangRef.html#extractelement-instruction
v2: Convert tabs to spaces. Suggested by Eric.
v3: Add array index range checking to ir_binop_vector_extract constant
expression handling. Suggested by Ken.
v4: Use CLAMP instead of MIN2(MAX2()). Suggested by Ken.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r-- | src/glsl/ir_constant_expression.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index a4a117e..990f983 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -391,10 +391,17 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) } if (op[1] != NULL) - assert(op[0]->type->base_type == op[1]->type->base_type || - this->operation == ir_binop_lshift || - this->operation == ir_binop_rshift || - this->operation == ir_triop_bitfield_extract); + switch (this->operation) { + case ir_binop_lshift: + case ir_binop_rshift: + case ir_binop_vector_extract: + case ir_triop_bitfield_extract: + break; + + default: + assert(op[0]->type->base_type == op[1]->type->base_type); + break; + } bool op0_scalar = op[0]->type->is_scalar(); bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar(); @@ -1231,6 +1238,29 @@ ir_expression::constant_expression_value(struct hash_table *variable_context) } break; + case ir_binop_vector_extract: { + const int c = CLAMP(op[1]->value.i[0], 0, + (int) op[0]->type->vector_elements - 1); + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[0] = op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[0] = op[0]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[0] = op[0]->value.f[c]; + break; + case GLSL_TYPE_BOOL: + data.b[0] = op[0]->value.b[c]; + break; + default: + assert(0); + } + break; + } + case ir_binop_bit_xor: for (unsigned c = 0, c0 = 0, c1 = 0; c < components; |