Make glsl_*_type glsl_type class static data

This commit is contained in:
Ian Romanick 2010-03-26 14:33:41 -07:00
parent a43817a483
commit 0471e8b089
5 changed files with 66 additions and 60 deletions

View File

@ -85,7 +85,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
* floating-point scalars, vectors, and matrices."
*/
if (!type_a->is_numeric() || !type_b->is_numeric()) {
return glsl_error_type;
return glsl_type::error_type;
}
@ -114,7 +114,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
* equality.
*/
if (type_a->base_type != type_b->base_type) {
return glsl_error_type;
return glsl_type::error_type;
}
/* "All arithmetic binary operators result in the same fundamental type
@ -152,7 +152,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
* vector."
*/
if (type_a->is_vector() && type_b->is_vector()) {
return (type_a == type_b) ? type_a : glsl_error_type;
return (type_a == type_b) ? type_a : glsl_type::error_type;
}
/* All of the combinations of <scalar, scalar>, <vector, scalar>,
@ -181,7 +181,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
* more detail how vectors and matrices are operated on."
*/
if (! multiply) {
return (type_a == type_b) ? type_a : glsl_error_type;
return (type_a == type_b) ? type_a : glsl_type::error_type;
} else {
if (type_a->is_matrix() && type_b->is_matrix()) {
/* Matrix multiply. The columns of A must match the rows of B. Given
@ -224,7 +224,7 @@ arithmetic_result_type(const struct glsl_type *type_a,
/* "All other cases are illegal."
*/
return glsl_error_type;
return glsl_type::error_type;
}
@ -240,7 +240,7 @@ unary_arithmetic_result_type(const struct glsl_type *type)
* they operated on."
*/
if (!is_numeric_base_type(type->base_type))
return glsl_error_type;
return glsl_type::error_type;
return type;
}
@ -258,7 +258,7 @@ modulus_result_type(const struct glsl_type *type_a,
if (! is_integer_base_type(type_a->base_type)
|| ! is_integer_base_type(type_b->base_type)
|| (type_a->base_type != type_b->base_type)) {
return glsl_error_type;
return glsl_type::error_type;
}
/* "The operands cannot be vectors of differing size. If one operand is
@ -276,7 +276,7 @@ modulus_result_type(const struct glsl_type *type_a,
/* "The operator modulus (%) is not defined for any other data types
* (non-integer types)."
*/
return glsl_error_type;
return glsl_type::error_type;
}
@ -294,7 +294,7 @@ relational_result_type(const struct glsl_type *type_a,
|| ! is_numeric_base_type(type_b->base_type)
|| !type_a->is_scalar()
|| !type_b->is_scalar())
return glsl_error_type;
return glsl_type::error_type;
/* "Either the operands' types must match, or the conversions from
* Section 4.1.10 "Implicit Conversions" will be applied to the integer
@ -314,11 +314,11 @@ relational_result_type(const struct glsl_type *type_a,
}
if (type_a->base_type != type_b->base_type)
return glsl_error_type;
return glsl_type::error_type;
/* "The result is scalar Boolean."
*/
return glsl_bool_type;
return glsl_type::bool_type;
}
@ -434,7 +434,7 @@ ast_expression::hir(exec_list *instructions,
ir_rvalue *result = NULL;
ir_rvalue *op[2];
struct simple_node op_list;
const struct glsl_type *type = glsl_error_type;
const struct glsl_type *type = glsl_type::error_type;
bool error_emitted = false;
YYLTYPE loc;
@ -456,13 +456,13 @@ ast_expression::hir(exec_list *instructions,
if (!op[0]->is_lvalue()) {
_mesa_glsl_error(& loc, state, "non-lvalue in assignment");
error_emitted = true;
type = glsl_error_type;
type = glsl_type::error_type;
}
}
ir_instruction *rhs = validate_assignment(op[0]->type, op[1]);
if (rhs == NULL) {
type = glsl_error_type;
type = glsl_type::error_type;
rhs = op[1];
}
@ -597,13 +597,13 @@ ast_expression::hir(exec_list *instructions,
if (!op[0]->is_lvalue()) {
_mesa_glsl_error(& loc, state, "non-lvalue in assignment");
error_emitted = true;
type = glsl_error_type;
type = glsl_type::error_type;
}
}
ir_rvalue *rhs = validate_assignment(op[0]->type, temp_rhs);
if (rhs == NULL) {
type = glsl_error_type;
type = glsl_type::error_type;
rhs = temp_rhs;
}
@ -674,22 +674,22 @@ ast_expression::hir(exec_list *instructions,
}
case ast_int_constant:
type = glsl_int_type;
type = glsl_type::int_type;
result = new ir_constant(type, & this->primary_expression);
break;
case ast_uint_constant:
type = glsl_uint_type;
type = glsl_type::uint_type;
result = new ir_constant(type, & this->primary_expression);
break;
case ast_float_constant:
type = glsl_float_type;
type = glsl_type::float_type;
result = new ir_constant(type, & this->primary_expression);
break;
case ast_bool_constant:
type = glsl_bool_type;
type = glsl_type::bool_type;
result = new ir_constant(type, & this->primary_expression);
break;
@ -939,7 +939,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
this->identifier);
}
type = glsl_error_type;
type = glsl_type::error_type;
}
ir_variable *var = new ir_variable(type, this->identifier);

View File

@ -119,13 +119,13 @@ cat <<EOF
#define Elements(x) (sizeof(x)/sizeof(*(x)))
#endif
static const struct glsl_type error_type =
static const struct glsl_type _error_type =
glsl_type(GLSL_TYPE_ERROR, 0, 0, "");
static const struct glsl_type void_type =
glsl_type(GLSL_TYPE_VOID, 0, 0, "void");
const struct glsl_type *const glsl_error_type = & error_type;
const glsl_type *const glsl_type::error_type = & _error_type;
EOF
@ -173,9 +173,9 @@ gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 1 0 "GLSL_TYPE_FLOAT"
gen_footer
echo
echo 'const struct glsl_type *const glsl_bool_type = & builtin_core_types['$bool_index'];'
echo 'const struct glsl_type *const glsl_int_type = & builtin_core_types['$int_index'];'
echo 'const struct glsl_type *const glsl_float_type = & builtin_core_types['$float_index'];'
echo 'const glsl_type *const glsl_type::bool_type = & builtin_core_types['$bool_index'];'
echo 'const glsl_type *const glsl_type::int_type = & builtin_core_types['$int_index'];'
echo 'const glsl_type *const glsl_type::float_type = & builtin_core_types['$float_index'];'
echo 'const glsl_type *const glsl_type::mat2_type = & builtin_core_types['$(($matX_index + 0))'];'
echo 'const glsl_type *const glsl_type::mat3_type = & builtin_core_types['$(($matX_index + 1))'];'
echo 'const glsl_type *const glsl_type::mat4_type = & builtin_core_types['$(($matX_index + 2))'];'
@ -325,7 +325,7 @@ gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_UINT"
gen_footer
echo ''
echo 'const struct glsl_type *const glsl_uint_type = & builtin_130_types['$uint_index'];'
echo 'const glsl_type *const glsl_type::uint_type = & builtin_130_types['$uint_index'];'
echo '/*@}*/'
echo

View File

@ -98,15 +98,15 @@ const glsl_type *glsl_type::get_base_type() const
{
switch (base_type) {
case GLSL_TYPE_UINT:
return glsl_uint_type;
return uint_type;
case GLSL_TYPE_INT:
return glsl_int_type;
return int_type;
case GLSL_TYPE_FLOAT:
return glsl_float_type;
return float_type;
case GLSL_TYPE_BOOL:
return glsl_bool_type;
return bool_type;
default:
return glsl_error_type;
return error_type;
}
}
@ -271,7 +271,7 @@ generate_mat_body_from_scalar(exec_list *instructions,
instructions->push_tail(inst);
const float z = 0.0f;
ir_constant *const zero = new ir_constant(glsl_float_type, &z);
ir_constant *const zero = new ir_constant(glsl_type::float_type, &z);
for (unsigned i = 1; i < column_type->vector_elements; i++) {
ir_dereference *const lhs_ref = new ir_dereference(column);
@ -293,7 +293,7 @@ generate_mat_body_from_scalar(exec_list *instructions,
swiz[5 - i], swiz[6 - i],
column_type->vector_elements);
ir_constant *const idx = new ir_constant(glsl_int_type, &i);
ir_constant *const idx = new ir_constant(glsl_type::int_type, &i);
ir_dereference *const lhs = new ir_dereference(declarations[16], idx);
inst = new ir_assignment(lhs, rhs, NULL);
@ -323,7 +323,7 @@ generate_mat_body_from_N_scalars(exec_list *instructions,
*/
for (unsigned i = 0; i < column_type->vector_elements; i++) {
for (unsigned j = 0; j < row_type->vector_elements; j++) {
ir_constant *row_index = new ir_constant(glsl_int_type, &i);
ir_constant *row_index = new ir_constant(glsl_type::int_type, &i);
ir_dereference *const row_access =
new ir_dereference(declarations[16], row_index);
@ -486,7 +486,7 @@ const glsl_type *
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
{
if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
return glsl_error_type;
return error_type;
/* Treat GLSL vectors as Nx1 matrices.
@ -494,19 +494,19 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
if (columns == 1) {
switch (base_type) {
case GLSL_TYPE_UINT:
return glsl_uint_type + (rows - 1);
return uint_type + (rows - 1);
case GLSL_TYPE_INT:
return glsl_int_type + (rows - 1);
return int_type + (rows - 1);
case GLSL_TYPE_FLOAT:
return glsl_float_type + (rows - 1);
return float_type + (rows - 1);
case GLSL_TYPE_BOOL:
return glsl_bool_type + (rows - 1);
return bool_type + (rows - 1);
default:
return glsl_error_type;
return error_type;
}
} else {
if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
return glsl_error_type;
return error_type;
/* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
* combinations are valid:
@ -529,10 +529,10 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
case IDX(4,2): return mat4x2_type;
case IDX(4,3): return mat4x3_type;
case IDX(4,4): return mat4_type;
default: return glsl_error_type;
default: return error_type;
}
}
assert(!"Should not get here.");
return glsl_error_type;
return error_type;
}

View File

@ -39,12 +39,6 @@
#define GLSL_TYPE_VOID 8
#define GLSL_TYPE_ERROR 9
extern const struct glsl_type *const glsl_error_type;
extern const struct glsl_type *const glsl_int_type;
extern const struct glsl_type *const glsl_uint_type;
extern const struct glsl_type *const glsl_float_type;
extern const struct glsl_type *const glsl_bool_type;
#define is_numeric_base_type(b) \
(((b) >= GLSL_TYPE_UINT) && ((b) <= GLSL_TYPE_FLOAT))
@ -107,6 +101,18 @@ struct glsl_type {
} fields;
/**
* \name Pointers to various public type singletons
*/
/*@{*/
static const glsl_type *const error_type;
static const glsl_type *const int_type;
static const glsl_type *const uint_type;
static const glsl_type *const float_type;
static const glsl_type *const bool_type;
/*@}*/
glsl_type(unsigned base_type, unsigned vector_elements,
unsigned matrix_columns, const char *name) :
base_type(base_type),
@ -233,33 +239,33 @@ struct glsl_type {
* Query the full type of a matrix row
*
* \return
* If the type is not a matrix, \c glsl_error_type is returned. Otherwise
* a type matching the rows of the matrix is returned.
* If the type is not a matrix, \c glsl_type::error_type is returned.
* Otherwise a type matching the rows of the matrix is returned.
*/
const glsl_type *row_type() const
{
return is_matrix()
? get_instance(base_type, matrix_columns, 1)
: glsl_error_type;
: error_type;
}
/**
* Query the full type of a matrix column
*
* \return
* If the type is not a matrix, \c glsl_error_type is returned. Otherwise
* a type matching the columns of the matrix is returned.
* If the type is not a matrix, \c glsl_type::error_type is returned.
* Otherwise a type matching the columns of the matrix is returned.
*/
const glsl_type *column_type() const
{
return is_matrix()
? get_instance(base_type, vector_elements, 1)
: glsl_error_type;
: error_type;
}
private:
/**
* \name Pointers to various type singletons
* \name Pointers to various private type singletons
*/
/*@{*/
static const glsl_type *const mat2_type;

6
ir.cpp
View File

@ -83,7 +83,7 @@ ir_dereference::ir_dereference(ir_instruction *var)
{
this->mode = ir_reference_variable;
this->var = var;
this->type = (var != NULL) ? var->type : glsl_error_type;
this->type = (var != NULL) ? var->type : glsl_type::error_type;
}
@ -92,7 +92,7 @@ ir_dereference::ir_dereference(ir_instruction *var,
: ir_rvalue(), mode(ir_reference_array),
var(var)
{
this->type = (var != NULL) ? var->type : glsl_error_type;
this->type = (var != NULL) ? var->type : glsl_type::error_type;
this->selector.array_index = array_index;
}
@ -237,6 +237,6 @@ ir_call::get_error_instruction()
{
ir_call *call = new ir_call;
call->type = glsl_error_type;
call->type = glsl_type::error_type;
return call;
}