X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fglsl%2Fir.cpp;h=dad58deeb97aa8a874ee3621178bb054a7df9919;hb=ce2464a8a70e8449cb8b927fe4ae485dc93cfda3;hp=970d8f3bac094080a346b226f33d4a572ba32c07;hpb=bb4c5d72d7c7cb1d9e7016e2c07c36875f30011a;p=mesa.git diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 970d8f3bac0..dad58deeb97 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -46,6 +46,11 @@ bool ir_rvalue::is_negative_one() const return false; } +bool ir_rvalue::is_basis() const +{ + return false; +} + /** * Modify the swizzle make to move one component to another * @@ -190,34 +195,6 @@ ir_assignment::ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, this->set_lhs(lhs); } - -ir_expression::ir_expression(int op, const struct glsl_type *type, - ir_rvalue *op0) -{ - assert(get_num_operands(ir_expression_operation(op)) == 1); - this->ir_type = ir_type_expression; - this->type = type; - this->operation = ir_expression_operation(op); - this->operands[0] = op0; - this->operands[1] = NULL; - this->operands[2] = NULL; - this->operands[3] = NULL; -} - -ir_expression::ir_expression(int op, const struct glsl_type *type, - ir_rvalue *op0, ir_rvalue *op1) -{ - assert(((op1 == NULL) && (get_num_operands(ir_expression_operation(op)) == 1)) - || (get_num_operands(ir_expression_operation(op)) == 2)); - this->ir_type = ir_type_expression; - this->type = type; - this->operation = ir_expression_operation(op); - this->operands[0] = op0; - this->operands[1] = op1; - this->operands[2] = NULL; - this->operands[3] = NULL; -} - ir_expression::ir_expression(int op, const struct glsl_type *type, ir_rvalue *op0, ir_rvalue *op1, ir_rvalue *op2, ir_rvalue *op3) @@ -229,6 +206,12 @@ ir_expression::ir_expression(int op, const struct glsl_type *type, this->operands[1] = op1; this->operands[2] = op2; this->operands[3] = op3; +#ifndef NDEBUG + int num_operands = get_num_operands(this->operation); + for (int i = num_operands; i < 4; i++) { + assert(this->operands[i] == NULL); + } +#endif } ir_expression::ir_expression(int op, ir_rvalue *op0) @@ -273,6 +256,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_f2i: case ir_unop_b2i: case ir_unop_u2i: + case ir_unop_bitcast_f2i: this->type = glsl_type::get_instance(GLSL_TYPE_INT, op0->type->vector_elements, 1); break; @@ -280,6 +264,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_b2f: case ir_unop_i2f: case ir_unop_u2f: + case ir_unop_bitcast_i2f: + case ir_unop_bitcast_u2f: this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT, op0->type->vector_elements, 1); break; @@ -291,11 +277,15 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) break; case ir_unop_i2u: + case ir_unop_f2u: + case ir_unop_bitcast_f2u: this->type = glsl_type::get_instance(GLSL_TYPE_UINT, op0->type->vector_elements, 1); break; case ir_unop_noise: + case ir_unop_unpack_half_2x16_split_x: + case ir_unop_unpack_half_2x16_split_y: this->type = glsl_type::float_type; break; @@ -303,6 +293,25 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) this->type = glsl_type::bool_type; break; + case ir_unop_pack_snorm_2x16: + case ir_unop_pack_snorm_4x8: + case ir_unop_pack_unorm_2x16: + case ir_unop_pack_unorm_4x8: + case ir_unop_pack_half_2x16: + this->type = glsl_type::uint_type; + break; + + case ir_unop_unpack_snorm_2x16: + case ir_unop_unpack_unorm_2x16: + case ir_unop_unpack_half_2x16: + this->type = glsl_type::vec2_type; + break; + + case ir_unop_unpack_snorm_4x8: + case ir_unop_unpack_unorm_4x8: + this->type = glsl_type::vec4_type; + break; + default: assert(!"not reached: missing automatic type setup for ir_expression"); this->type = op0->type; @@ -354,10 +363,15 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) case ir_binop_bit_and: case ir_binop_bit_xor: case ir_binop_bit_or: + assert(!op0->type->is_matrix()); + assert(!op1->type->is_matrix()); if (op0->type->is_scalar()) { - this->type = op1->type; + this->type = op1->type; } else if (op1->type->is_scalar()) { - this->type = op0->type; + this->type = op0->type; + } else { + assert(op0->type->vector_elements == op1->type->vector_elements); + this->type = op0->type; } break; @@ -376,11 +390,19 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) this->type = glsl_type::float_type; break; + case ir_binop_pack_half_2x16_split: + this->type = glsl_type::uint_type; + break; + case ir_binop_lshift: case ir_binop_rshift: this->type = op0->type; break; + case ir_binop_vector_extract: + this->type = op0->type->get_scalar_type(); + break; + default: assert(!"not reached: missing automatic type setup for ir_expression"); this->type = glsl_type::float_type; @@ -398,7 +420,10 @@ ir_expression::get_num_operands(ir_expression_operation op) if (op <= ir_last_binop) return 2; - if (op == ir_quadop_vector) + if (op <= ir_last_triop) + return 3; + + if (op <= ir_last_quadop) return 4; assert(false); @@ -419,6 +444,7 @@ static const char *const operator_strs[] = { "exp2", "log2", "f2i", + "f2u", "i2f", "f2b", "b2f", @@ -427,6 +453,10 @@ static const char *const operator_strs[] = { "u2f", "i2u", "u2i", + "bitcast_i2f", + "bitcast_f2i", + "bitcast_u2f", + "bitcast_f2u", "any", "trunc", "ceil", @@ -439,6 +469,22 @@ static const char *const operator_strs[] = { "cos_reduced", "dFdx", "dFdy", + "packSnorm2x16", + "packSnorm4x8", + "packUnorm2x16", + "packUnorm4x8", + "packHalf2x16", + "unpackSnorm2x16", + "unpackSnorm4x8", + "unpackUnorm2x16", + "unpackUnorm4x8", + "unpackHalf2x16", + "unpackHalf2x16_split_x", + "unpackHalf2x16_split_y", + "bitfield_reverse", + "bit_count", + "find_msb", + "find_lsb", "noise", "+", "-", @@ -465,6 +511,15 @@ static const char *const operator_strs[] = { "min", "max", "pow", + "packHalf2x16_split", + "bfm", + "ubo_load", + "vector_extract", + "lrp", + "bfi", + "bitfield_extract", + "vector_insert", + "bitfield_insert", "vector", }; @@ -764,7 +819,7 @@ ir_constant::get_float_component(unsigned i) const 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; + case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0f : 0.0f; default: assert(!"Should not get here."); break; } @@ -1117,6 +1172,49 @@ ir_constant::is_negative_one() const return true; } +bool +ir_constant::is_basis() const +{ + if (!this->type->is_scalar() && !this->type->is_vector()) + return false; + + if (this->type->is_boolean()) + return false; + + unsigned ones = 0; + for (unsigned c = 0; c < this->type->vector_elements; c++) { + switch (this->type->base_type) { + case GLSL_TYPE_FLOAT: + if (this->value.f[c] == 1.0) + ones++; + else if (this->value.f[c] != 0.0) + return false; + break; + case GLSL_TYPE_INT: + if (this->value.i[c] == 1) + ones++; + else if (this->value.i[c] != 0) + return false; + break; + case GLSL_TYPE_UINT: + if (int(this->value.u[c]) == 1) + ones++; + else if (int(this->value.u[c]) != 0) + return false; + break; + default: + /* The only other base types are structures, arrays, samplers, and + * booleans. Samplers cannot be constants, and the others should + * have been filtered out above. + */ + assert(!"Should not get here."); + return false; + } + } + + return ones == 1; +} + ir_loop::ir_loop() { this->ir_type = ir_type_loop; @@ -1223,7 +1321,7 @@ ir_dereference::is_lvalue() const } -const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txs" }; +static const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf", "txf_ms", "txs", "lod" }; const char *ir_texture::opcode_string() { @@ -1254,6 +1352,9 @@ ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type) if (this->op == ir_txs) { assert(type->base_type == GLSL_TYPE_INT); + } else if (this->op == ir_lod) { + assert(type->vector_elements == 2); + assert(type->base_type == GLSL_TYPE_FLOAT); } else { assert(sampler->type->sampler_type == (int) type->base_type); if (sampler->type->sampler_shadow) @@ -1433,6 +1534,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name, this->explicit_location = false; this->has_initializer = false; this->location = -1; + this->location_frac = 0; this->warn_extension = NULL; this->constant_value = NULL; this->constant_initializer = NULL; @@ -1468,7 +1570,7 @@ ir_variable::determine_interpolation_mode(bool flat_shade) return (glsl_interp_qualifier) this->interpolation; int location = this->location; bool is_gl_Color = - location == FRAG_ATTRIB_COL0 || location == FRAG_ATTRIB_COL1; + location == VARYING_SLOT_COL0 || location == VARYING_SLOT_COL1; if (flat_shade && is_gl_Color) return INTERP_QUALIFIER_FLAT; else @@ -1492,8 +1594,8 @@ modes_match(unsigned a, unsigned b) return true; /* Accept "in" vs. "const in" */ - if ((a == ir_var_const_in && b == ir_var_in) || - (b == ir_var_const_in && a == ir_var_in)) + if ((a == ir_var_const_in && b == ir_var_function_in) || + (b == ir_var_const_in && a == ir_var_function_in)) return true; return false;