mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-01 01:38:06 +02:00
Add methods to ir_constant to get scalar components in a particular type
This commit is contained in:
parent
c9cb1032be
commit
31881908eb
2 changed files with 82 additions and 0 deletions
68
ir.cpp
68
ir.cpp
|
|
@ -240,6 +240,74 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ir_constant::get_bool_component(unsigned i) const
|
||||
{
|
||||
switch (this->type->base_type) {
|
||||
case GLSL_TYPE_UINT: return this->value.u[i] != 0;
|
||||
case GLSL_TYPE_INT: return this->value.i[i] != 0;
|
||||
case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
|
||||
case GLSL_TYPE_BOOL: return this->value.b[i];
|
||||
default: assert(!"Should not get here."); break;
|
||||
}
|
||||
|
||||
/* Must return something to make the compiler happy. This is clearly an
|
||||
* error case.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
float
|
||||
ir_constant::get_float_component(unsigned i) const
|
||||
{
|
||||
switch (this->type->base_type) {
|
||||
case GLSL_TYPE_UINT: return (float) this->value.u[i];
|
||||
case GLSL_TYPE_INT: return (float) this->value.i[i];
|
||||
case GLSL_TYPE_FLOAT: return this->value.f[i];
|
||||
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
|
||||
default: assert(!"Should not get here."); break;
|
||||
}
|
||||
|
||||
/* Must return something to make the compiler happy. This is clearly an
|
||||
* error case.
|
||||
*/
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
int
|
||||
ir_constant::get_int_component(unsigned i) const
|
||||
{
|
||||
switch (this->type->base_type) {
|
||||
case GLSL_TYPE_UINT: return this->value.u[i];
|
||||
case GLSL_TYPE_INT: return this->value.i[i];
|
||||
case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
|
||||
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
|
||||
default: assert(!"Should not get here."); break;
|
||||
}
|
||||
|
||||
/* Must return something to make the compiler happy. This is clearly an
|
||||
* error case.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
ir_constant::get_uint_component(unsigned i) const
|
||||
{
|
||||
switch (this->type->base_type) {
|
||||
case GLSL_TYPE_UINT: return this->value.u[i];
|
||||
case GLSL_TYPE_INT: return this->value.i[i];
|
||||
case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
|
||||
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
|
||||
default: assert(!"Should not get here."); break;
|
||||
}
|
||||
|
||||
/* Must return something to make the compiler happy. This is clearly an
|
||||
* error case.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ir_dereference_variable::ir_dereference_variable(ir_variable *var)
|
||||
{
|
||||
|
|
|
|||
14
ir.h
14
ir.h
|
|
@ -1055,6 +1055,20 @@ public:
|
|||
return new ir_constant(this->type, &this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a particular component of a constant as a specific type
|
||||
*
|
||||
* This is useful, for example, to get a value from an integer constant
|
||||
* as a float or bool. This appears frequently when constructors are
|
||||
* called with all constant parameters.
|
||||
*/
|
||||
/*@{*/
|
||||
bool get_bool_component(unsigned i) const;
|
||||
float get_float_component(unsigned i) const;
|
||||
int get_int_component(unsigned i) const;
|
||||
unsigned get_uint_component(unsigned i) const;
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Value of the constant.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue