summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2013-08-05 15:15:37 -0700
committerMatt Turner <[email protected]>2013-09-17 16:59:14 -0700
commit5561251b58c976a70125bb07dc1c6cc2bd2541f4 (patch)
tree3677012e424204d7f3a8e3fd68d774bea3a6deba
parentb2ab840130677bbe7b67de4727fcd91ee6506bb8 (diff)
glsl: Allow vectors to be created from ir_constant().
Note the parameter name change in the int version of ir_constant, to avoid the conflict with the loop iterator. v2: Make analogous change to builtin_builder::imm(). Reviewed-by: Paul Berry <[email protected]>
-rw-r--r--src/glsl/builtin_functions.cpp18
-rw-r--r--src/glsl/ir.cpp44
-rw-r--r--src/glsl/ir.h8
3 files changed, 41 insertions, 29 deletions
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index ffabf8a8710..b5be7043fcf 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -348,9 +348,9 @@ private:
*/
ir_variable *in_var(const glsl_type *type, const char *name);
ir_variable *out_var(const glsl_type *type, const char *name);
- ir_constant *imm(float f);
- ir_constant *imm(int i);
- ir_constant *imm(unsigned u);
+ ir_constant *imm(float f, unsigned vector_elements=1);
+ ir_constant *imm(int i, unsigned vector_elements=1);
+ ir_constant *imm(unsigned u, unsigned vector_elements=1);
ir_constant *imm(const glsl_type *type, const ir_constant_data &);
ir_dereference_variable *var_ref(ir_variable *var);
ir_dereference_array *array_ref(ir_variable *var, int i);
@@ -1878,21 +1878,21 @@ builtin_builder::out_var(const glsl_type *type, const char *name)
}
ir_constant *
-builtin_builder::imm(float f)
+builtin_builder::imm(float f, unsigned vector_elements)
{
- return new(mem_ctx) ir_constant(f);
+ return new(mem_ctx) ir_constant(f, vector_elements);
}
ir_constant *
-builtin_builder::imm(int i)
+builtin_builder::imm(int i, unsigned vector_elements)
{
- return new(mem_ctx) ir_constant(i);
+ return new(mem_ctx) ir_constant(i, vector_elements);
}
ir_constant *
-builtin_builder::imm(unsigned u)
+builtin_builder::imm(unsigned u, unsigned vector_elements)
{
- return new(mem_ctx) ir_constant(u);
+ return new(mem_ctx) ir_constant(u, vector_elements);
}
ir_constant *
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index a2dca457a95..b0f92cb3f53 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -619,42 +619,54 @@ ir_constant::ir_constant(const struct glsl_type *type,
memcpy(& this->value, data, sizeof(this->value));
}
-ir_constant::ir_constant(float f)
+ir_constant::ir_constant(float f, unsigned vector_elements)
{
+ assert(vector_elements <= 4);
this->ir_type = ir_type_constant;
- this->type = glsl_type::float_type;
- this->value.f[0] = f;
- for (int i = 1; i < 16; i++) {
+ this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.f[i] = f;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
this->value.f[i] = 0;
}
}
-ir_constant::ir_constant(unsigned int u)
+ir_constant::ir_constant(unsigned int u, unsigned vector_elements)
{
+ assert(vector_elements <= 4);
this->ir_type = ir_type_constant;
- this->type = glsl_type::uint_type;
- this->value.u[0] = u;
- for (int i = 1; i < 16; i++) {
+ this->type = glsl_type::get_instance(GLSL_TYPE_UINT, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.u[i] = u;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
this->value.u[i] = 0;
}
}
-ir_constant::ir_constant(int i)
+ir_constant::ir_constant(int integer, unsigned vector_elements)
{
+ assert(vector_elements <= 4);
this->ir_type = ir_type_constant;
- this->type = glsl_type::int_type;
- this->value.i[0] = i;
- for (int i = 1; i < 16; i++) {
+ this->type = glsl_type::get_instance(GLSL_TYPE_INT, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.i[i] = integer;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
this->value.i[i] = 0;
}
}
-ir_constant::ir_constant(bool b)
+ir_constant::ir_constant(bool b, unsigned vector_elements)
{
+ assert(vector_elements <= 4);
this->ir_type = ir_type_constant;
- this->type = glsl_type::bool_type;
- this->value.b[0] = b;
- for (int i = 1; i < 16; i++) {
+ this->type = glsl_type::get_instance(GLSL_TYPE_BOOL, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.b[i] = b;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
this->value.b[i] = false;
}
}
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index b0e77327711..6c5630b0965 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1922,10 +1922,10 @@ union ir_constant_data {
class ir_constant : public ir_rvalue {
public:
ir_constant(const struct glsl_type *type, const ir_constant_data *data);
- ir_constant(bool b);
- ir_constant(unsigned int u);
- ir_constant(int i);
- ir_constant(float f);
+ ir_constant(bool b, unsigned vector_elements=1);
+ ir_constant(unsigned int u, unsigned vector_elements=1);
+ ir_constant(int i, unsigned vector_elements=1);
+ ir_constant(float f, unsigned vector_elements=1);
/**
* Construct an ir_constant from a list of ir_constant values