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 <stereotype441@gmail.com>
This commit is contained in:
Matt Turner
2013-08-05 15:15:37 -07:00
parent b2ab840130
commit 5561251b58
3 changed files with 41 additions and 29 deletions

View File

@@ -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;
}
}