glsl: make use of glsl_type::is_float()

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
This commit is contained in:
Samuel Pitoiset
2017-04-21 11:18:50 +02:00
parent cacc823c39
commit a7bc51aef8
10 changed files with 48 additions and 56 deletions

View File

@@ -1504,8 +1504,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
* components with zero. * components with zero.
*/ */
glsl_base_type param_base_type = first_param->type->base_type; glsl_base_type param_base_type = first_param->type->base_type;
assert(param_base_type == GLSL_TYPE_FLOAT || assert(first_param->type->is_float() || first_param->type->is_double());
first_param->type->is_double());
ir_variable *rhs_var = ir_variable *rhs_var =
new(ctx) ir_variable(glsl_type::get_instance(param_base_type, 4, 1), new(ctx) ir_variable(glsl_type::get_instance(param_base_type, 4, 1),
"mat_ctor_vec", "mat_ctor_vec",
@@ -1514,7 +1513,7 @@ emit_inline_matrix_constructor(const glsl_type *type,
ir_constant_data zero; ir_constant_data zero;
for (unsigned i = 0; i < 4; i++) for (unsigned i = 0; i < 4; i++)
if (param_base_type == GLSL_TYPE_FLOAT) if (first_param->type->is_float())
zero.f[i] = 0.0; zero.f[i] = 0.0;
else else
zero.d[i] = 0.0; zero.d[i] = 0.0;

View File

@@ -444,10 +444,8 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* type of both operands must be float. * type of both operands must be float.
*/ */
assert(type_a->is_matrix() || type_b->is_matrix()); assert(type_a->is_matrix() || type_b->is_matrix());
assert(type_a->base_type == GLSL_TYPE_FLOAT || assert(type_a->is_float() || type_a->is_double());
type_a->is_double()); assert(type_b->is_float() || type_b->is_double());
assert(type_b->base_type == GLSL_TYPE_FLOAT ||
type_b->is_double());
/* "* The operator is add (+), subtract (-), or divide (/), and the /* "* The operator is add (+), subtract (-), or divide (/), and the
* operands are matrices with the same number of rows and the same * operands are matrices with the same number of rows and the same

View File

@@ -783,10 +783,9 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
if (value->type->is_scalar() && value->next->is_tail_sentinel()) { if (value->type->is_scalar() && value->next->is_tail_sentinel()) {
if (type->is_matrix()) { if (type->is_matrix()) {
/* Matrix - fill diagonal (rest is already set to 0) */ /* Matrix - fill diagonal (rest is already set to 0) */
assert(type->base_type == GLSL_TYPE_FLOAT || assert(type->is_float() || type->is_double());
type->is_double());
for (unsigned i = 0; i < type->matrix_columns; i++) { for (unsigned i = 0; i < type->matrix_columns; i++) {
if (type->base_type == GLSL_TYPE_FLOAT) if (type->is_float())
this->value.f[i * type->vector_elements + i] = this->value.f[i * type->vector_elements + i] =
value->value.f[0]; value->value.f[0];
else else
@@ -1510,7 +1509,7 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
assert(type->base_type == GLSL_TYPE_INT); assert(type->base_type == GLSL_TYPE_INT);
} else if (this->op == ir_lod) { } else if (this->op == ir_lod) {
assert(type->vector_elements == 2); assert(type->vector_elements == 2);
assert(type->base_type == GLSL_TYPE_FLOAT); assert(type->is_float());
} else if (this->op == ir_samples_identical) { } else if (this->op == ir_samples_identical) {
assert(type == glsl_type::bool_type); assert(type == glsl_type::bool_type);
assert(sampler->type->is_sampler()); assert(sampler->type->is_sampler());

View File

@@ -276,12 +276,9 @@ constant_template_vector = mako.template.Template("""\
# This template is for ir_triop_lrp. # This template is for ir_triop_lrp.
constant_template_lrp = mako.template.Template("""\ constant_template_lrp = mako.template.Template("""\
case ${op.get_enum_name()}: { case ${op.get_enum_name()}: {
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT || assert(op[0]->type->is_float() || op[0]->type->is_double());
op[0]->type->is_double()); assert(op[1]->type->is_float() || op[1]->type->is_double());
assert(op[1]->type->base_type == GLSL_TYPE_FLOAT || assert(op[2]->type->is_float() || op[2]->type->is_double());
op[1]->type->is_double());
assert(op[2]->type->base_type == GLSL_TYPE_FLOAT ||
op[2]->type->is_double());
unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) {

View File

@@ -150,12 +150,12 @@ get_parameter_match_type(const ir_variable *param,
return PARAMETER_EXACT_MATCH; return PARAMETER_EXACT_MATCH;
if (to_type->is_double()) { if (to_type->is_double()) {
if (from_type->base_type == GLSL_TYPE_FLOAT) if (from_type->is_float())
return PARAMETER_FLOAT_TO_DOUBLE; return PARAMETER_FLOAT_TO_DOUBLE;
return PARAMETER_INT_TO_DOUBLE; return PARAMETER_INT_TO_DOUBLE;
} }
if (to_type->base_type == GLSL_TYPE_FLOAT) if (to_type->is_float())
return PARAMETER_INT_TO_FLOAT; return PARAMETER_INT_TO_FLOAT;
/* int -> uint and any other oddball conversions */ /* int -> uint and any other oddball conversions */

View File

@@ -833,7 +833,7 @@ ir_reader::read_constant(s_expression *expr)
return NULL; return NULL;
} }
if (type->base_type == GLSL_TYPE_FLOAT) { if (type->is_float()) {
s_number *value = SX_AS_NUMBER(expr); s_number *value = SX_AS_NUMBER(expr);
if (value == NULL) { if (value == NULL) {
ir_read_error(values, "expected numbers"); ir_read_error(values, "expected numbers");

View File

@@ -252,7 +252,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_abs: case ir_unop_abs:
case ir_unop_sign: case ir_unop_sign:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT || assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT ||
ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double() || ir->operands[0]->type->is_double() ||
ir->operands[0]->type->base_type == GLSL_TYPE_INT64); ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
assert(ir->type == ir->operands[0]->type); assert(ir->type == ir->operands[0]->type);
@@ -261,7 +261,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_rcp: case ir_unop_rcp:
case ir_unop_rsq: case ir_unop_rsq:
case ir_unop_sqrt: case ir_unop_sqrt:
assert(ir->type->base_type == GLSL_TYPE_FLOAT || assert(ir->type->is_float() ||
ir->type->is_double()); ir->type->is_double());
assert(ir->type == ir->operands[0]->type); assert(ir->type == ir->operands[0]->type);
break; break;
@@ -271,29 +271,29 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_exp2: case ir_unop_exp2:
case ir_unop_log2: case ir_unop_log2:
case ir_unop_saturate: case ir_unop_saturate:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type == ir->operands[0]->type); assert(ir->type == ir->operands[0]->type);
break; break;
case ir_unop_f2i: case ir_unop_f2i:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_INT); assert(ir->type->base_type == GLSL_TYPE_INT);
break; break;
case ir_unop_f2u: case ir_unop_f2u:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_UINT); assert(ir->type->base_type == GLSL_TYPE_UINT);
break; break;
case ir_unop_i2f: case ir_unop_i2f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_f2b: case ir_unop_f2b:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->is_boolean()); assert(ir->type->is_boolean());
break; break;
case ir_unop_b2f: case ir_unop_b2f:
assert(ir->operands[0]->type->is_boolean()); assert(ir->operands[0]->type->is_boolean());
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_i2b: case ir_unop_i2b:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
@@ -305,7 +305,7 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_unop_u2f: case ir_unop_u2f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_i2u: case ir_unop_i2u:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
@@ -317,18 +317,18 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_unop_bitcast_i2f: case ir_unop_bitcast_i2f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_bitcast_f2i: case ir_unop_bitcast_f2i:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_INT); assert(ir->type->base_type == GLSL_TYPE_INT);
break; break;
case ir_unop_bitcast_u2f: case ir_unop_bitcast_u2f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_bitcast_f2u: case ir_unop_bitcast_f2u:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_UINT); assert(ir->type->base_type == GLSL_TYPE_UINT);
break; break;
@@ -370,11 +370,11 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_unop_i642f: case ir_unop_i642f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_u642f: case ir_unop_u642f:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64); assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_i642d: case ir_unop_i642d:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64); assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
@@ -397,7 +397,7 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->type->base_type == GLSL_TYPE_INT64); assert(ir->type->base_type == GLSL_TYPE_INT64);
break; break;
case ir_unop_f2i64: case ir_unop_f2i64:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_INT64); assert(ir->type->base_type == GLSL_TYPE_INT64);
break; break;
case ir_unop_d2i64: case ir_unop_d2i64:
@@ -413,7 +413,7 @@ ir_validate::visit_leave(ir_expression *ir)
assert(ir->type->base_type == GLSL_TYPE_UINT64); assert(ir->type->base_type == GLSL_TYPE_UINT64);
break; break;
case ir_unop_f2u64: case ir_unop_f2u64:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->base_type == GLSL_TYPE_UINT64); assert(ir->type->base_type == GLSL_TYPE_UINT64);
break; break;
case ir_unop_d2u64: case ir_unop_d2u64:
@@ -433,7 +433,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_ceil: case ir_unop_ceil:
case ir_unop_floor: case ir_unop_floor:
case ir_unop_fract: case ir_unop_fract:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || assert(ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double()); ir->operands[0]->type->is_double());
assert(ir->operands[0]->type == ir->type); assert(ir->operands[0]->type == ir->type);
break; break;
@@ -445,7 +445,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_dFdy: case ir_unop_dFdy:
case ir_unop_dFdy_coarse: case ir_unop_dFdy_coarse:
case ir_unop_dFdy_fine: case ir_unop_dFdy_fine:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->operands[0]->type == ir->type); assert(ir->operands[0]->type == ir->type);
break; break;
@@ -540,10 +540,10 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_d2f: case ir_unop_d2f:
assert(ir->operands[0]->type->is_double()); assert(ir->operands[0]->type->is_double());
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
break; break;
case ir_unop_f2d: case ir_unop_f2d:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT); assert(ir->operands[0]->type->is_float());
assert(ir->type->is_double()); assert(ir->type->is_double());
break; break;
case ir_unop_d2i: case ir_unop_d2i:
@@ -568,12 +568,12 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_unop_frexp_sig: case ir_unop_frexp_sig:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || assert(ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double()); ir->operands[0]->type->is_double());
assert(ir->type->is_double()); assert(ir->type->is_double());
break; break;
case ir_unop_frexp_exp: case ir_unop_frexp_exp:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || assert(ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double()); ir->operands[0]->type->is_double());
assert(ir->type->base_type == GLSL_TYPE_INT); assert(ir->type->base_type == GLSL_TYPE_INT);
break; break;
@@ -593,7 +593,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_unop_read_first_invocation: case ir_unop_read_first_invocation:
assert(ir->type == ir->operands[0]->type); assert(ir->type == ir->operands[0]->type);
assert(ir->type->is_scalar() || ir->type->is_vector()); assert(ir->type->is_scalar() || ir->type->is_vector());
assert(ir->type->base_type == GLSL_TYPE_FLOAT || assert(ir->type->is_float() ||
ir->type->base_type == GLSL_TYPE_INT || ir->type->base_type == GLSL_TYPE_INT ||
ir->type->base_type == GLSL_TYPE_UINT); ir->type->base_type == GLSL_TYPE_UINT);
break; break;
@@ -707,7 +707,7 @@ ir_validate::visit_leave(ir_expression *ir)
case ir_binop_dot: case ir_binop_dot:
assert(ir->type == glsl_type::float_type || assert(ir->type == glsl_type::float_type ||
ir->type == glsl_type::double_type); ir->type == glsl_type::double_type);
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || assert(ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double()); ir->operands[0]->type->is_double());
assert(ir->operands[0]->type->is_vector()); assert(ir->operands[0]->type->is_vector());
assert(ir->operands[0]->type == ir->operands[1]->type); assert(ir->operands[0]->type == ir->operands[1]->type);
@@ -748,7 +748,7 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_triop_fma: case ir_triop_fma:
assert(ir->type->base_type == GLSL_TYPE_FLOAT || assert(ir->type->is_float() ||
ir->type->is_double()); ir->type->is_double());
assert(ir->type == ir->operands[0]->type); assert(ir->type == ir->operands[0]->type);
assert(ir->type == ir->operands[1]->type); assert(ir->type == ir->operands[1]->type);
@@ -756,7 +756,7 @@ ir_validate::visit_leave(ir_expression *ir)
break; break;
case ir_triop_lrp: case ir_triop_lrp:
assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT || assert(ir->operands[0]->type->is_float() ||
ir->operands[0]->type->is_double()); ir->operands[0]->type->is_double());
assert(ir->operands[0]->type == ir->operands[1]->type); assert(ir->operands[0]->type == ir->operands[1]->type);
assert(ir->operands[2]->type == ir->operands[0]->type || assert(ir->operands[2]->type == ir->operands[0]->type ||

View File

@@ -164,8 +164,8 @@ lower_buffer_access::emit_access(void *mem_ctx,
/* We're dereffing a column out of a row-major matrix, so we /* We're dereffing a column out of a row-major matrix, so we
* gather the vector from each stored row. * gather the vector from each stored row.
*/ */
assert(deref->type->base_type == GLSL_TYPE_FLOAT || assert(deref->type->is_float() || deref->type->is_double());
deref->type->is_double());
/* Matrices, row_major or not, are stored as if they were /* Matrices, row_major or not, are stored as if they were
* arrays of vectors of the appropriate size in std140. * arrays of vectors of the appropriate size in std140.
* Arrays have their strides rounded up to a vec4, so the * Arrays have their strides rounded up to a vec4, so the
@@ -199,7 +199,7 @@ lower_buffer_access::emit_access(void *mem_ctx,
else else
matrix_stride = glsl_align(matrix_columns * N, 16); matrix_stride = glsl_align(matrix_columns * N, 16);
const glsl_type *deref_type = deref->type->base_type == GLSL_TYPE_FLOAT ? const glsl_type *deref_type = deref->type->is_float() ?
glsl_type::float_type : glsl_type::double_type; glsl_type::float_type : glsl_type::double_type;
for (unsigned i = 0; i < deref->type->vector_elements; i++) { for (unsigned i = 0; i < deref->type->vector_elements; i++) {

View File

@@ -144,7 +144,7 @@ is_valid_vec_const(ir_constant *ir)
static inline bool static inline bool
is_less_than_one(ir_constant *ir) is_less_than_one(ir_constant *ir)
{ {
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
if (!is_valid_vec_const(ir)) if (!is_valid_vec_const(ir))
return false; return false;
@@ -161,7 +161,7 @@ is_less_than_one(ir_constant *ir)
static inline bool static inline bool
is_greater_than_zero(ir_constant *ir) is_greater_than_zero(ir_constant *ir)
{ {
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
if (!is_valid_vec_const(ir)) if (!is_valid_vec_const(ir))
return false; return false;
@@ -649,8 +649,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
case ir_binop_div: case ir_binop_div:
if (is_vec_one(op_const[0]) && ( if (is_vec_one(op_const[0]) && (
ir->type->base_type == GLSL_TYPE_FLOAT || ir->type->is_float() || ir->type->is_double())) {
ir->type->is_double())) {
return new(mem_ctx) ir_expression(ir_unop_rcp, return new(mem_ctx) ir_expression(ir_unop_rcp,
ir->operands[1]->type, ir->operands[1]->type,
ir->operands[1], ir->operands[1],
@@ -845,7 +844,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
case ir_binop_min: case ir_binop_min:
case ir_binop_max: case ir_binop_max:
if (ir->type->base_type != GLSL_TYPE_FLOAT || options->EmitNoSat) if (!ir->type->is_float() || options->EmitNoSat)
break; break;
/* Replace min(max) operations and its commutative combinations with /* Replace min(max) operations and its commutative combinations with

View File

@@ -1952,7 +1952,7 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
dst_reg mat_column = dst_reg(mat); dst_reg mat_column = dst_reg(mat);
for (i = 0; i < ir->type->matrix_columns; i++) { for (i = 0; i < ir->type->matrix_columns; i++) {
assert(ir->type->base_type == GLSL_TYPE_FLOAT); assert(ir->type->is_float());
values = &ir->value.f[i * ir->type->vector_elements]; values = &ir->value.f[i * ir->type->vector_elements];
src = src_reg(PROGRAM_CONSTANT, -1, NULL); src = src_reg(PROGRAM_CONSTANT, -1, NULL);