ir_swizzle: Add new constructor, refactor constructors
Adds a new constructor that takes an array of component values. Refactors the meat of the two constructors to an init_mask method.
This commit is contained in:
@@ -573,28 +573,40 @@ ir_texture::set_sampler(ir_dereference *sampler)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
|
void
|
||||||
unsigned w, unsigned count)
|
ir_swizzle::init_mask(const unsigned *comp, unsigned count)
|
||||||
: val(val)
|
|
||||||
{
|
{
|
||||||
assert((count >= 1) && (count <= 4));
|
assert((count >= 1) && (count <= 4));
|
||||||
|
|
||||||
const unsigned dup_mask = 0
|
memset(&this->mask, 0, sizeof(this->mask));
|
||||||
| ((count > 1) ? ((1U << y) & ((1U << x) )) : 0)
|
this->mask.num_components = count;
|
||||||
| ((count > 2) ? ((1U << z) & ((1U << x) | (1U << y) )) : 0)
|
|
||||||
| ((count > 3) ? ((1U << w) & ((1U << x) | (1U << y) | (1U << z))) : 0);
|
|
||||||
|
|
||||||
assert(x <= 3);
|
unsigned dup_mask = 0;
|
||||||
assert(y <= 3);
|
switch (count) {
|
||||||
assert(z <= 3);
|
case 4:
|
||||||
assert(w <= 3);
|
assert(comp[3] <= 3);
|
||||||
|
dup_mask |= (1U << comp[3])
|
||||||
|
& ((1U << comp[0]) | (1U << comp[1]) | (1U << comp[2]));
|
||||||
|
this->mask.w = comp[3];
|
||||||
|
|
||||||
mask.x = x;
|
case 3:
|
||||||
mask.y = y;
|
assert(comp[2] <= 3);
|
||||||
mask.z = z;
|
dup_mask |= (1U << comp[2])
|
||||||
mask.w = w;
|
& ((1U << comp[0]) | (1U << comp[1]));
|
||||||
mask.num_components = count;
|
this->mask.z = comp[2];
|
||||||
mask.has_duplicates = dup_mask != 0;
|
|
||||||
|
case 2:
|
||||||
|
assert(comp[1] <= 3);
|
||||||
|
dup_mask |= (1U << comp[1])
|
||||||
|
& ((1U << comp[0]));
|
||||||
|
this->mask.y = comp[1];
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
assert(comp[0] <= 3);
|
||||||
|
this->mask.x = comp[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
this->mask.has_duplicates = dup_mask != 0;
|
||||||
|
|
||||||
/* Based on the number of elements in the swizzle and the base type
|
/* Based on the number of elements in the swizzle and the base type
|
||||||
* (i.e., float, int, unsigned, or bool) of the vector being swizzled,
|
* (i.e., float, int, unsigned, or bool) of the vector being swizzled,
|
||||||
@@ -603,6 +615,21 @@ ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
|
|||||||
type = glsl_type::get_instance(val->type->base_type, mask.num_components, 1);
|
type = glsl_type::get_instance(val->type->base_type, mask.num_components, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
|
||||||
|
unsigned w, unsigned count)
|
||||||
|
: val(val)
|
||||||
|
{
|
||||||
|
const unsigned components[4] = { x, y, z, w };
|
||||||
|
this->init_mask(components, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
ir_swizzle::ir_swizzle(ir_rvalue *val, const unsigned *comp,
|
||||||
|
unsigned count)
|
||||||
|
: val(val)
|
||||||
|
{
|
||||||
|
this->init_mask(comp, count);
|
||||||
|
}
|
||||||
|
|
||||||
ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
|
ir_swizzle::ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask)
|
||||||
{
|
{
|
||||||
this->val = val;
|
this->val = val;
|
||||||
|
@@ -918,6 +918,9 @@ class ir_swizzle : public ir_rvalue {
|
|||||||
public:
|
public:
|
||||||
ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
|
ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
|
||||||
unsigned count);
|
unsigned count);
|
||||||
|
|
||||||
|
ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count);
|
||||||
|
|
||||||
ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
|
ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
|
||||||
|
|
||||||
virtual ir_instruction *clone(struct hash_table *) const;
|
virtual ir_instruction *clone(struct hash_table *) const;
|
||||||
@@ -951,6 +954,14 @@ public:
|
|||||||
|
|
||||||
ir_rvalue *val;
|
ir_rvalue *val;
|
||||||
ir_swizzle_mask mask;
|
ir_swizzle_mask mask;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Initialize the mask component of a swizzle
|
||||||
|
*
|
||||||
|
* This is used by the \c ir_swizzle constructors.
|
||||||
|
*/
|
||||||
|
void init_mask(const unsigned *components, unsigned count);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user