summaryrefslogtreecommitdiff
path: root/src/compiler/glsl/ast_to_hir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/glsl/ast_to_hir.cpp')
-rw-r--r--src/compiler/glsl/ast_to_hir.cpp966
1 files changed, 568 insertions, 398 deletions
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index ad8f381fc49..93e989f31b7 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -54,11 +54,12 @@
#include "ast.h"
#include "compiler/glsl_types.h"
#include "util/hash_table.h"
-#include "main/mtypes.h"
+#include "main/consts_exts.h"
#include "main/macros.h"
#include "main/shaderobj.h"
#include "ir.h"
#include "ir_builder.h"
+#include "linker_util.h"
#include "builtin_functions.h"
using namespace ir_builder;
@@ -242,10 +243,18 @@ get_implicit_conversion_operation(const glsl_type *to, const glsl_type *from,
struct _mesa_glsl_parse_state *state)
{
switch (to->base_type) {
+ case GLSL_TYPE_FLOAT16:
+ switch (from->base_type) {
+ case GLSL_TYPE_INT: return ir_unop_i2f16;
+ case GLSL_TYPE_UINT: return ir_unop_u2f16;
+ default: return (ir_expression_operation)0;
+ }
+
case GLSL_TYPE_FLOAT:
switch (from->base_type) {
case GLSL_TYPE_INT: return ir_unop_i2f;
case GLSL_TYPE_UINT: return ir_unop_u2f;
+ case GLSL_TYPE_FLOAT16: return ir_unop_f162f;
default: return (ir_expression_operation)0;
}
@@ -263,6 +272,7 @@ get_implicit_conversion_operation(const glsl_type *to, const glsl_type *from,
switch (from->base_type) {
case GLSL_TYPE_INT: return ir_unop_i2d;
case GLSL_TYPE_UINT: return ir_unop_u2d;
+ case GLSL_TYPE_FLOAT16: return ir_unop_f162d;
case GLSL_TYPE_FLOAT: return ir_unop_f2d;
case GLSL_TYPE_INT64: return ir_unop_i642d;
case GLSL_TYPE_UINT64: return ir_unop_u642d;
@@ -323,15 +333,15 @@ apply_implicit_conversion(const glsl_type *to, ir_rvalue * &from,
* example, an array of int cannot be implicitly converted to an
* array of float.
*/
- if (!to->is_numeric() || !from->type->is_numeric())
+ if (!glsl_type_is_numeric(to) || !glsl_type_is_numeric(from->type))
return false;
/* We don't actually want the specific type `to`, we want a type
* with the same base type as `to`, but the same vector width as
* `from`.
*/
- to = glsl_type::get_instance(to->base_type, from->type->vector_elements,
- from->type->matrix_columns);
+ to = glsl_simple_type(to->base_type, from->type->vector_elements,
+ from->type->matrix_columns);
ir_expression_operation op = get_implicit_conversion_operation(to, from->type, state);
if (op) {
@@ -357,10 +367,10 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* multiply (*), and divide (/) operate on integer and
* floating-point scalars, vectors, and matrices."
*/
- if (!type_a->is_numeric() || !type_b->is_numeric()) {
+ if (!glsl_type_is_numeric(type_a) || !glsl_type_is_numeric(type_b)) {
_mesa_glsl_error(loc, state,
"operands to arithmetic operators must be numeric");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
@@ -373,7 +383,7 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
_mesa_glsl_error(loc, state,
"could not implicitly convert operands to "
"arithmetic operator");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
type_a = value_a->type;
type_b = value_b->type;
@@ -390,7 +400,7 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
if (type_a->base_type != type_b->base_type) {
_mesa_glsl_error(loc, state,
"base type mismatch for arithmetic operator");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "All arithmetic binary operators result in the same fundamental type
@@ -401,7 +411,7 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* * The two operands are scalars. In this case the operation is
* applied, resulting in a scalar."
*/
- if (type_a->is_scalar() && type_b->is_scalar())
+ if (glsl_type_is_scalar(type_a) && glsl_type_is_scalar(type_b))
return type_a;
/* "* One operand is a scalar, and the other is a vector or matrix.
@@ -409,10 +419,10 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* component of the vector or matrix, resulting in the same size
* vector or matrix."
*/
- if (type_a->is_scalar()) {
- if (!type_b->is_scalar())
+ if (glsl_type_is_scalar(type_a)) {
+ if (!glsl_type_is_scalar(type_b))
return type_b;
- } else if (type_b->is_scalar()) {
+ } else if (glsl_type_is_scalar(type_b)) {
return type_a;
}
@@ -420,20 +430,20 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* <scalar, vector>, <scalar, matrix>, and <matrix, scalar> have been
* handled.
*/
- assert(!type_a->is_scalar());
- assert(!type_b->is_scalar());
+ assert(!glsl_type_is_scalar(type_a));
+ assert(!glsl_type_is_scalar(type_b));
/* "* The two operands are vectors of the same size. In this case, the
* operation is done component-wise resulting in the same size
* vector."
*/
- if (type_a->is_vector() && type_b->is_vector()) {
+ if (glsl_type_is_vector(type_a) && glsl_type_is_vector(type_b)) {
if (type_a == type_b) {
return type_a;
} else {
_mesa_glsl_error(loc, state,
"vector size mismatch for arithmetic operator");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
}
@@ -443,9 +453,9 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* be matrix. Further, since there are no integer matrix types, the base
* type of both operands must be float.
*/
- assert(type_a->is_matrix() || type_b->is_matrix());
- assert(type_a->is_float() || type_a->is_double());
- assert(type_b->is_float() || type_b->is_double());
+ assert(glsl_type_is_matrix(type_a) || glsl_type_is_matrix(type_b));
+ assert(glsl_type_is_float(type_a) || glsl_type_is_double(type_a));
+ assert(glsl_type_is_float(type_b) || glsl_type_is_double(type_b));
/* "* The operator is add (+), subtract (-), or divide (/), and the
* operands are matrices with the same number of rows and the same
@@ -466,9 +476,9 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
if (type_a == type_b)
return type_a;
} else {
- const glsl_type *type = glsl_type::get_mul_type(type_a, type_b);
+ const glsl_type *type = glsl_get_mul_type(type_a, type_b);
- if (type == glsl_type::error_type) {
+ if (type == &glsl_type_builtin_error) {
_mesa_glsl_error(loc, state,
"size mismatch for matrix multiplication");
}
@@ -480,7 +490,7 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
/* "All other cases are illegal."
*/
_mesa_glsl_error(loc, state, "type mismatch");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
@@ -496,10 +506,10 @@ unary_arithmetic_result_type(const struct glsl_type *type,
* component-wise on their operands. These result with the same type
* they operated on."
*/
- if (!type->is_numeric()) {
+ if (!glsl_type_is_numeric(type)) {
_mesa_glsl_error(loc, state,
"operands to arithmetic operators must be numeric");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
return type;
@@ -509,7 +519,7 @@ unary_arithmetic_result_type(const struct glsl_type *type,
* \brief Return the result type of a bit-logic operation.
*
* If the given types to the bit-logic operator are invalid, return
- * glsl_type::error_type.
+ * &glsl_type_builtin_error.
*
* \param value_a LHS of bit-logic op
* \param value_b RHS of bit-logic op
@@ -523,7 +533,7 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
const glsl_type *type_b = value_b->type;
if (!state->check_bitwise_operations_allowed(loc)) {
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* From page 50 (page 56 of PDF) of GLSL 1.30 spec:
@@ -532,15 +542,15 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* (|). The operands must be of type signed or unsigned integers or
* integer vectors."
*/
- if (!type_a->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(type_a)) {
_mesa_glsl_error(loc, state, "LHS of `%s' must be an integer",
ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
- if (!type_b->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(type_b)) {
_mesa_glsl_error(loc, state, "RHS of `%s' must be an integer",
ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* Prior to GLSL 4.0 / GL_ARB_gpu_shader5, implicit conversions didn't
@@ -561,7 +571,7 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
"could not implicitly convert operands to "
"`%s` operator",
ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
} else {
_mesa_glsl_warning(loc, state,
"some implementations may not support implicit "
@@ -579,16 +589,16 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
if (type_a->base_type != type_b->base_type) {
_mesa_glsl_error(loc, state, "operands of `%s' must have the same "
"base type", ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "The operands cannot be vectors of differing size." */
- if (type_a->is_vector() &&
- type_b->is_vector() &&
+ if (glsl_type_is_vector(type_a) &&
+ glsl_type_is_vector(type_b) &&
type_a->vector_elements != type_b->vector_elements) {
_mesa_glsl_error(loc, state, "operands of `%s' cannot be vectors of "
"different sizes", ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "If one operand is a scalar and the other a vector, the scalar is
@@ -596,7 +606,7 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* the vector. The fundamental types of the operands [...] will be the
* resulting fundamental type."
*/
- if (type_a->is_scalar())
+ if (glsl_type_is_scalar(type_a))
return type_b;
else
return type_a;
@@ -611,7 +621,7 @@ modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
if (!state->EXT_gpu_shader4_enable &&
!state->check_version(130, 300, loc, "operator '%%' is reserved")) {
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* Section 5.9 (Expressions) of the GLSL 4.00 specification says:
@@ -619,13 +629,13 @@ modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* "The operator modulus (%) operates on signed or unsigned integers or
* integer vectors."
*/
- if (!type_a->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(type_a)) {
_mesa_glsl_error(loc, state, "LHS of operator %% must be an integer");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
- if (!type_b->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(type_b)) {
_mesa_glsl_error(loc, state, "RHS of operator %% must be an integer");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "If the fundamental types in the operands do not match, then the
@@ -645,7 +655,7 @@ modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
_mesa_glsl_error(loc, state,
"could not implicitly convert operands to "
"modulus (%%) operator");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
type_a = value_a->type;
type_b = value_b->type;
@@ -655,8 +665,8 @@ modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* wise to the vector, resulting in the same type as the vector. If both
* are vectors of the same size, the result is computed component-wise."
*/
- if (type_a->is_vector()) {
- if (!type_b->is_vector()
+ if (glsl_type_is_vector(type_a)) {
+ if (!glsl_type_is_vector(type_b)
|| (type_a->vector_elements == type_b->vector_elements))
return type_a;
} else
@@ -666,7 +676,7 @@ modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* (non-integer types)."
*/
_mesa_glsl_error(loc, state, "type mismatch");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
@@ -682,14 +692,14 @@ relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
* than or equal (>=), and less than or equal (<=) operate only on
* scalar integer and scalar floating-point expressions."
*/
- if (!type_a->is_numeric()
- || !type_b->is_numeric()
- || !type_a->is_scalar()
- || !type_b->is_scalar()) {
+ if (!glsl_type_is_numeric(type_a)
+ || !glsl_type_is_numeric(type_b)
+ || !glsl_type_is_scalar(type_a)
+ || !glsl_type_is_scalar(type_b)) {
_mesa_glsl_error(loc, state,
"operands to relational operators must be scalar and "
"numeric");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "Either the operands' types must match, or the conversions from
@@ -701,26 +711,26 @@ relational_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
_mesa_glsl_error(loc, state,
"could not implicitly convert operands to "
"relational operator");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
type_a = value_a->type;
type_b = value_b->type;
if (type_a->base_type != type_b->base_type) {
_mesa_glsl_error(loc, state, "base type mismatch");
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "The result is scalar Boolean."
*/
- return glsl_type::bool_type;
+ return &glsl_type_builtin_bool;
}
/**
* \brief Return the result type of a bit-shift operation.
*
* If the given types to the bit-shift operator are invalid, return
- * glsl_type::error_type.
+ * &glsl_type_builtin_error.
*
* \param type_a Type of LHS of bit-shift op
* \param type_b Type of RHS of bit-shift op
@@ -732,7 +742,7 @@ shift_result_type(const struct glsl_type *type_a,
struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
{
if (!state->check_bitwise_operations_allowed(loc)) {
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* From page 50 (page 56 of the PDF) of the GLSL 1.30 spec:
@@ -741,38 +751,38 @@ shift_result_type(const struct glsl_type *type_a,
* must be signed or unsigned integers or integer vectors. One operand
* can be signed while the other is unsigned."
*/
- if (!type_a->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(type_a)) {
_mesa_glsl_error(loc, state, "LHS of operator %s must be an integer or "
"integer vector", ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
- if (!type_b->is_integer_32()) {
+ if (!glsl_type_is_integer_32_64(type_b)) {
_mesa_glsl_error(loc, state, "RHS of operator %s must be an integer or "
"integer vector", ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "If the first operand is a scalar, the second operand has to be
* a scalar as well."
*/
- if (type_a->is_scalar() && !type_b->is_scalar()) {
+ if (glsl_type_is_scalar(type_a) && !glsl_type_is_scalar(type_b)) {
_mesa_glsl_error(loc, state, "if the first operand of %s is scalar, the "
"second must be scalar as well",
ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* If both operands are vectors, check that they have same number of
* elements.
*/
- if (type_a->is_vector() &&
- type_b->is_vector() &&
+ if (glsl_type_is_vector(type_a) &&
+ glsl_type_is_vector(type_b) &&
type_a->vector_elements != type_b->vector_elements) {
_mesa_glsl_error(loc, state, "vector operands to operator %s must "
"have same number of elements",
ast_expression::operator_string(op));
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
/* "In all cases, the resulting type will be the same type as the left
@@ -833,7 +843,7 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
/* If there is already some error in the RHS, just return it. Anything
* else will lead to an avalanche of error message back to the user.
*/
- if (rhs->type->is_error())
+ if (glsl_type_is_error(rhs->type))
return rhs;
/* In the Tessellation Control Shader:
@@ -841,7 +851,7 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
* if the expression indicating the vertex number is not the identifier
* `gl_InvocationID`.
*/
- if (state->stage == MESA_SHADER_TESS_CTRL && !lhs->type->is_error()) {
+ if (state->stage == MESA_SHADER_TESS_CTRL && !glsl_type_is_error(lhs->type)) {
ir_variable *var = lhs->variable_referenced();
if (var && var->data.mode == ir_var_shader_out && !var->data.patch) {
ir_rvalue *index = find_innermost_array_index(lhs);
@@ -870,10 +880,10 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
const glsl_type *lhs_t = lhs->type;
const glsl_type *rhs_t = rhs->type;
bool unsized_array = false;
- while(lhs_t->is_array()) {
+ while(glsl_type_is_array(lhs_t)) {
if (rhs_t == lhs_t)
break; /* the rest of the inner arrays match so break out early */
- if (!rhs_t->is_array()) {
+ if (!glsl_type_is_array(rhs_t)) {
unsized_array = false;
break; /* number of dimensions mismatch */
}
@@ -881,7 +891,7 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
lhs_t = lhs_t->fields.array;
rhs_t = rhs_t->fields.array;
continue;
- } else if (lhs_t->is_unsized_array()) {
+ } else if (glsl_type_is_unsized_array(lhs_t)) {
unsized_array = true;
} else {
unsized_array = false;
@@ -892,7 +902,7 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
}
if (unsized_array) {
if (is_initializer) {
- if (rhs->type->get_scalar_type() == lhs->type->get_scalar_type())
+ if (glsl_get_scalar_type(rhs->type) == glsl_get_scalar_type(lhs->type))
return rhs;
} else {
_mesa_glsl_error(&loc, state,
@@ -911,7 +921,7 @@ validate_assignment(struct _mesa_glsl_parse_state *state,
"%s of type %s cannot be assigned to "
"variable of type %s",
is_initializer ? "initializer" : "value",
- rhs->type->name, lhs->type->name);
+ glsl_get_type_name(rhs->type), glsl_get_type_name(lhs->type));
return NULL;
}
@@ -935,7 +945,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
YYLTYPE lhs_loc)
{
void *ctx = state;
- bool error_emitted = (lhs->type->is_error() || rhs->type->is_error());
+ bool error_emitted = (glsl_type_is_error(lhs->type) || glsl_type_is_error(rhs->type));
ir_variable *lhs_var = lhs->variable_referenced();
if (lhs_var)
@@ -967,7 +977,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
lhs_var->name);
error_emitted = true;
}
- } else if (lhs->type->is_array() &&
+ } else if (glsl_type_is_array(lhs->type) &&
!state->check_version(state->allow_glsl_120_subset_in_110 ? 110 : 120,
300, &lhs_loc,
"whole array assignment forbidden")) {
@@ -996,7 +1006,7 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
* dereference of a variable. Any other case would require that the LHS
* is either not an l-value or not a whole array.
*/
- if (lhs->type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(lhs->type)) {
ir_dereference *const d = lhs->as_dereference();
assert(d != NULL);
@@ -1005,18 +1015,18 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
assert(var != NULL);
- if (var->data.max_array_access >= rhs->type->array_size()) {
+ if (var->data.max_array_access >= glsl_array_size(rhs->type)) {
/* FINISHME: This should actually log the location of the RHS. */
_mesa_glsl_error(& lhs_loc, state, "array size must be > %u due to "
"previous access",
var->data.max_array_access);
}
- var->type = glsl_type::get_array_instance(lhs->type->fields.array,
- rhs->type->array_size());
+ var->type = glsl_array_type(lhs->type->fields.array,
+ glsl_array_size(rhs->type), 0);
d->type = var->type;
}
- if (lhs->type->is_array()) {
+ if (glsl_type_is_array(lhs->type)) {
mark_whole_array_access(rhs);
mark_whole_array_access(lhs);
}
@@ -1182,15 +1192,18 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
case GLSL_TYPE_ERROR:
case GLSL_TYPE_VOID:
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_SUBROUTINE:
- case GLSL_TYPE_FUNCTION:
/* I assume a comparison of a struct containing a sampler just
* ignores the sampler present in the type.
*/
break;
+
+ case GLSL_TYPE_COOPERATIVE_MATRIX:
+ unreachable("unsupported base type cooperative matrix");
}
if (cmp == NULL)
@@ -1215,7 +1228,7 @@ get_scalar_boolean_operand(exec_list *instructions,
void *ctx = state;
ir_rvalue *val = expr->hir(instructions, state);
- if (val->type->is_boolean() && val->type->is_scalar())
+ if (glsl_type_is_boolean(val->type) && glsl_type_is_scalar(val->type))
return val;
if (!*error_emitted) {
@@ -1432,7 +1445,7 @@ ast_expression::do_hir(exec_list *instructions,
type = unary_arithmetic_result_type(op[0]->type, state, & loc);
- error_emitted = type->is_error();
+ error_emitted = glsl_type_is_error(type);
result = op[0];
break;
@@ -1442,7 +1455,7 @@ ast_expression::do_hir(exec_list *instructions,
type = unary_arithmetic_result_type(op[0]->type, state, & loc);
- error_emitted = type->is_error();
+ error_emitted = glsl_type_is_error(type);
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], NULL);
@@ -1458,7 +1471,7 @@ ast_expression::do_hir(exec_list *instructions,
type = arithmetic_result_type(op[0], op[1],
(this->oper == ast_mul),
state, & loc);
- error_emitted = type->is_error();
+ error_emitted = glsl_type_is_error(type);
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
@@ -1474,7 +1487,7 @@ ast_expression::do_hir(exec_list *instructions,
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
- error_emitted = type->is_error();
+ error_emitted = glsl_type_is_error(type);
break;
case ast_lshift:
@@ -1489,7 +1502,7 @@ ast_expression::do_hir(exec_list *instructions,
&loc);
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ error_emitted = glsl_type_is_error(op[0]->type) || glsl_type_is_error(op[1]->type);
break;
case ast_less:
@@ -1504,8 +1517,8 @@ ast_expression::do_hir(exec_list *instructions,
/* The relational operators must either generate an error or result
* in a scalar boolean. See page 57 of the GLSL 1.50 spec.
*/
- assert(type->is_error()
- || (type->is_boolean() && type->is_scalar()));
+ assert(glsl_type_is_error(type)
+ || (glsl_type_is_boolean(type) && glsl_type_is_scalar(type)));
/* Like NIR, GLSL IR does not have opcodes for > or <=. Instead, swap
* the arguments and use < or >=.
@@ -1518,7 +1531,7 @@ ast_expression::do_hir(exec_list *instructions,
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
- error_emitted = type->is_error();
+ error_emitted = glsl_type_is_error(type);
break;
case ast_nequal:
@@ -1536,9 +1549,9 @@ ast_expression::do_hir(exec_list *instructions,
* case this conversion is done."
*/
- if (op[0]->type == glsl_type::void_type || op[1]->type == glsl_type::void_type) {
- _mesa_glsl_error(& loc, state, "`%s': wrong operand types: "
- "no operation `%1$s' exists that takes a left-hand "
+ if (op[0]->type == &glsl_type_builtin_void || op[1]->type == &glsl_type_builtin_void) {
+ _mesa_glsl_error(& loc, state, "wrong operand types: "
+ "no operation `%s' exists that takes a left-hand "
"operand of type 'void' or a right operand of type "
"'void'", (this->oper == ast_equal) ? "==" : "!=");
error_emitted = true;
@@ -1548,16 +1561,16 @@ ast_expression::do_hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "operands of `%s' must have the same "
"type", (this->oper == ast_equal) ? "==" : "!=");
error_emitted = true;
- } else if ((op[0]->type->is_array() || op[1]->type->is_array()) &&
+ } else if ((glsl_type_is_array(op[0]->type) || glsl_type_is_array(op[1]->type)) &&
!state->check_version(120, 300, &loc,
"array comparisons forbidden")) {
error_emitted = true;
- } else if ((op[0]->type->contains_subroutine() ||
- op[1]->type->contains_subroutine())) {
+ } else if ((glsl_contains_subroutine(op[0]->type) ||
+ glsl_contains_subroutine(op[1]->type))) {
_mesa_glsl_error(&loc, state, "subroutine comparisons forbidden");
error_emitted = true;
- } else if ((op[0]->type->contains_opaque() ||
- op[1]->type->contains_opaque())) {
+ } else if ((glsl_contains_opaque(op[0]->type) ||
+ glsl_contains_opaque(op[1]->type))) {
_mesa_glsl_error(&loc, state, "opaque type comparisons forbidden");
error_emitted = true;
}
@@ -1566,7 +1579,7 @@ ast_expression::do_hir(exec_list *instructions,
result = new(ctx) ir_constant(false);
} else {
result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
- assert(result->type == glsl_type::bool_type);
+ assert(result->type == &glsl_type_builtin_bool);
}
break;
@@ -1578,7 +1591,7 @@ ast_expression::do_hir(exec_list *instructions,
type = bit_logic_result_type(op[0], op[1], this->oper, state, &loc);
result = new(ctx) ir_expression(operations[this->oper], type,
op[0], op[1]);
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ error_emitted = glsl_type_is_error(op[0]->type) || glsl_type_is_error(op[1]->type);
break;
case ast_bit_not:
@@ -1588,12 +1601,12 @@ ast_expression::do_hir(exec_list *instructions,
error_emitted = true;
}
- if (!op[0]->type->is_integer_32_64()) {
+ if (!glsl_type_is_integer_32_64(op[0]->type)) {
_mesa_glsl_error(&loc, state, "operand of `~' must be an integer");
error_emitted = true;
}
- type = error_emitted ? glsl_type::error_type : op[0]->type;
+ type = error_emitted ? &glsl_type_builtin_error : op[0]->type;
result = new(ctx) ir_expression(ir_unop_bit_not, type, op[0], NULL);
break;
@@ -1607,7 +1620,7 @@ ast_expression::do_hir(exec_list *instructions,
if (rhs_instructions.is_empty()) {
result = new(ctx) ir_expression(ir_binop_logic_and, op[0], op[1]);
} else {
- ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
+ ir_variable *const tmp = new(ctx) ir_variable(&glsl_type_builtin_bool,
"and_tmp",
ir_var_temporary);
instructions->push_tail(tmp);
@@ -1641,7 +1654,7 @@ ast_expression::do_hir(exec_list *instructions,
if (rhs_instructions.is_empty()) {
result = new(ctx) ir_expression(ir_binop_logic_or, op[0], op[1]);
} else {
- ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
+ ir_variable *const tmp = new(ctx) ir_variable(&glsl_type_builtin_bool,
"or_tmp",
ir_var_temporary);
instructions->push_tail(tmp);
@@ -1677,7 +1690,7 @@ ast_expression::do_hir(exec_list *instructions,
op[1] = get_scalar_boolean_operand(instructions, state, this, 1, "RHS",
&error_emitted);
- result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
+ result = new(ctx) ir_expression(operations[this->oper], &glsl_type_builtin_bool,
op[0], op[1]);
break;
@@ -1685,7 +1698,7 @@ ast_expression::do_hir(exec_list *instructions,
op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
"operand", &error_emitted);
- result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
+ result = new(ctx) ir_expression(operations[this->oper], &glsl_type_builtin_bool,
op[0], NULL);
break;
@@ -1700,8 +1713,8 @@ ast_expression::do_hir(exec_list *instructions,
orig_type = op[0]->type;
/* Break out if operand types were not parsed successfully. */
- if ((op[0]->type == glsl_type::error_type ||
- op[1]->type == glsl_type::error_type)) {
+ if ((op[0]->type == &glsl_type_builtin_error ||
+ op[1]->type == &glsl_type_builtin_error)) {
error_emitted = true;
result = ir_rvalue::error_value(ctx);
break;
@@ -1714,8 +1727,8 @@ ast_expression::do_hir(exec_list *instructions,
if (type != orig_type) {
_mesa_glsl_error(& loc, state,
"could not implicitly convert "
- "%s to %s", type->name, orig_type->name);
- type = glsl_type::error_type;
+ "%s to %s", glsl_get_type_name(type), glsl_get_type_name(orig_type));
+ type = &glsl_type_builtin_error;
}
ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper], type,
@@ -1742,8 +1755,8 @@ ast_expression::do_hir(exec_list *instructions,
op[1] = this->subexpressions[1]->hir(instructions, state);
/* Break out if operand types were not parsed successfully. */
- if ((op[0]->type == glsl_type::error_type ||
- op[1]->type == glsl_type::error_type)) {
+ if ((op[0]->type == &glsl_type_builtin_error ||
+ op[1]->type == &glsl_type_builtin_error)) {
error_emitted = true;
result = ir_rvalue::error_value(ctx);
break;
@@ -1755,8 +1768,8 @@ ast_expression::do_hir(exec_list *instructions,
if (type != orig_type) {
_mesa_glsl_error(& loc, state,
"could not implicitly convert "
- "%s to %s", type->name, orig_type->name);
- type = glsl_type::error_type;
+ "%s to %s", glsl_get_type_name(type), glsl_get_type_name(orig_type));
+ type = &glsl_type_builtin_error;
}
assert(operations[this->oper] == ir_binop_mod);
@@ -1781,8 +1794,8 @@ ast_expression::do_hir(exec_list *instructions,
op[1] = this->subexpressions[1]->hir(instructions, state);
/* Break out if operand types were not parsed successfully. */
- if ((op[0]->type == glsl_type::error_type ||
- op[1]->type == glsl_type::error_type)) {
+ if ((op[0]->type == &glsl_type_builtin_error ||
+ op[1]->type == &glsl_type_builtin_error)) {
error_emitted = true;
result = ir_rvalue::error_value(ctx);
break;
@@ -1809,8 +1822,8 @@ ast_expression::do_hir(exec_list *instructions,
op[1] = this->subexpressions[1]->hir(instructions, state);
/* Break out if operand types were not parsed successfully. */
- if ((op[0]->type == glsl_type::error_type ||
- op[1]->type == glsl_type::error_type)) {
+ if ((op[0]->type == &glsl_type_builtin_error ||
+ op[1]->type == &glsl_type_builtin_error)) {
error_emitted = true;
result = ir_rvalue::error_value(ctx);
break;
@@ -1822,8 +1835,8 @@ ast_expression::do_hir(exec_list *instructions,
if (type != orig_type) {
_mesa_glsl_error(& loc, state,
"could not implicitly convert "
- "%s to %s", type->name, orig_type->name);
- type = glsl_type::error_type;
+ "%s to %s", glsl_get_type_name(type), glsl_get_type_name(orig_type));
+ type = &glsl_type_builtin_error;
}
ir_rvalue *temp_rhs = new(ctx) ir_expression(operations[this->oper],
@@ -1875,7 +1888,7 @@ ast_expression::do_hir(exec_list *instructions,
_mesa_glsl_error(& loc, state, "second and third operands of ?: "
"operator must have matching types");
error_emitted = true;
- type = glsl_type::error_type;
+ type = &glsl_type_builtin_error;
} else {
type = op[1]->type;
}
@@ -1885,7 +1898,7 @@ ast_expression::do_hir(exec_list *instructions,
* "The second and third expressions must be the same type, but can
* be of any type other than an array."
*/
- if (type->is_array() &&
+ if (glsl_type_is_array(type) &&
!state->check_version(120, 300, &loc,
"second and third operands of ?: operator "
"cannot be arrays")) {
@@ -1898,10 +1911,10 @@ ast_expression::do_hir(exec_list *instructions,
* parentheses, opaque variables are not allowed to be operands in
* expressions; such use results in a compile-time error."
*/
- if (type->contains_opaque()) {
- if (!(state->has_bindless() && (type->is_image() || type->is_sampler()))) {
+ if (glsl_contains_opaque(type)) {
+ if (!(state->has_bindless() && (glsl_type_is_image(type) || glsl_type_is_sampler(type)))) {
_mesa_glsl_error(&loc, state, "variables of type %s cannot be "
- "operands of the ?: operator", type->name);
+ "operands of the ?: operator", glsl_get_type_name(type));
error_emitted = true;
}
}
@@ -1914,7 +1927,7 @@ ast_expression::do_hir(exec_list *instructions,
result = cond_val->value.b[0] ? op[1] : op[2];
} else {
/* The copy to conditional_tmp reads the whole array. */
- if (type->is_array()) {
+ if (glsl_type_is_array(type)) {
mark_whole_array_access(op[1]);
mark_whole_array_access(op[2]);
}
@@ -1975,7 +1988,7 @@ ast_expression::do_hir(exec_list *instructions,
op[0] = this->subexpressions[0]->hir(instructions, state);
op[1] = constant_one_for_inc_dec(ctx, op[0]->type);
- error_emitted = op[0]->type->is_error() || op[1]->type->is_error();
+ error_emitted = glsl_type_is_error(op[0]->type) || glsl_type_is_error(op[1]->type);
if (error_emitted) {
result = ir_rvalue::error_value(ctx);
@@ -2022,7 +2035,7 @@ ast_expression::do_hir(exec_list *instructions,
result = _mesa_ast_array_index_to_hir(ctx, state, op[0], op[1],
loc, index_loc);
- if (result->type->is_error())
+ if (glsl_type_is_error(result->type))
error_emitted = true;
break;
@@ -2065,17 +2078,30 @@ ast_expression::do_hir(exec_list *instructions,
this->primary_expression.identifier);
}
- /* From the EXT_shader_framebuffer_fetch spec:
- *
- * "Unless the GL_EXT_shader_framebuffer_fetch extension has been
- * enabled in addition, it's an error to use gl_LastFragData if it
- * hasn't been explicitly redeclared with layout(noncoherent)."
- */
- if (var->data.fb_fetch_output && var->data.memory_coherent &&
- !state->EXT_shader_framebuffer_fetch_enable) {
- _mesa_glsl_error(&loc, state,
- "invalid use of framebuffer fetch output not "
- "qualified with layout(noncoherent)");
+ if (var->is_fb_fetch_color_output()) {
+ /* From the EXT_shader_framebuffer_fetch spec:
+ *
+ * "Unless the GL_EXT_shader_framebuffer_fetch extension has been
+ * enabled in addition, it's an error to use gl_LastFragData if it
+ * hasn't been explicitly redeclared with layout(noncoherent)."
+ */
+ if (var->data.memory_coherent && !state->EXT_shader_framebuffer_fetch_enable) {
+ _mesa_glsl_error(&loc, state,
+ "invalid use of framebuffer fetch output not "
+ "qualified with layout(noncoherent)");
+ }
+ } else if (var->data.fb_fetch_output) {
+ /* From the ARM_shader_framebuffer_fetch_depth_stencil spec:
+ *
+ * "It is not legal for a fragment shader to read from gl_LastFragDepthARM
+ * and gl_LastFragStencilARM if the early_fragment_tests layout qualifier
+ * is specified. This will result in a compile-time error."
+ */
+ if (state->fs_early_fragment_tests) {
+ _mesa_glsl_error(&loc, state,
+ "invalid use of depth or stencil fetch "
+ "with early fragment tests enabled");
+ }
}
} else {
@@ -2096,6 +2122,10 @@ ast_expression::do_hir(exec_list *instructions,
result = new(ctx) ir_constant(this->primary_expression.uint_constant);
break;
+ case ast_float16_constant:
+ result = new(ctx) ir_constant(float16_t(this->primary_expression.float16_constant));
+ break;
+
case ast_float_constant:
result = new(ctx) ir_constant(this->primary_expression.float_constant);
break;
@@ -2173,7 +2203,7 @@ ast_expression::do_hir(exec_list *instructions,
type = NULL; /* use result->type, not type. */
assert(error_emitted || (result != NULL || !needs_rvalue));
- if (result && result->type->is_error() && !error_emitted)
+ if (result && glsl_type_is_error(result->type) && !error_emitted)
_mesa_glsl_error(& loc, state, "type mismatch");
return result;
@@ -2239,6 +2269,7 @@ ast_expression::has_sequence_subexpression() const
case ast_identifier:
case ast_int_constant:
case ast_uint_constant:
+ case ast_float16_constant:
case ast_float_constant:
case ast_bool_constant:
case ast_double_constant:
@@ -2329,13 +2360,13 @@ process_array_size(exec_node *node,
return 0;
}
- if (!ir->type->is_integer_32()) {
+ if (!glsl_type_is_integer_32(ir->type)) {
_mesa_glsl_error(& loc, state,
"array size must be integer type");
return 0;
}
- if (!ir->type->is_scalar()) {
+ if (!glsl_type_is_scalar(ir->type)) {
_mesa_glsl_error(& loc, state,
"array size must be scalar type");
return 0;
@@ -2376,21 +2407,21 @@ process_array_type(YYLTYPE *loc, const glsl_type *base,
const glsl_type *array_type = base;
if (array_specifier != NULL) {
- if (base->is_array()) {
+ if (glsl_type_is_array(base)) {
/* From page 19 (page 25) of the GLSL 1.20 spec:
*
* "Only one-dimensional arrays may be declared."
*/
if (!state->check_arrays_of_arrays_allowed(loc)) {
- return glsl_type::error_type;
+ return &glsl_type_builtin_error;
}
}
for (exec_node *node = array_specifier->array_dimensions.get_tail_raw();
!node->is_head_sentinel(); node = node->prev) {
unsigned array_size = process_array_size(node, state);
- array_type = glsl_type::get_array_instance(array_type, array_size);
+ array_type = glsl_array_type(array_type, array_size, 0);
}
}
@@ -2427,10 +2458,10 @@ precision_qualifier_allowed(const glsl_type *type)
* From this, we infer that GLSL 1.30 (and later) should allow precision
* qualifiers on sampler types just like float and integer types.
*/
- const glsl_type *const t = type->without_array();
+ const glsl_type *const t = glsl_without_array(type);
- return (t->is_float() || t->is_integer_32() || t->contains_opaque()) &&
- !t->is_struct();
+ return (glsl_type_is_float(t) || glsl_type_is_integer_32(t) || glsl_contains_opaque(t)) &&
+ !glsl_type_is_struct(t);
}
const glsl_type *
@@ -2489,13 +2520,13 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
case GLSL_TYPE_SAMPLER: {
const unsigned type_idx =
type->sampler_array + 2 * type->sampler_shadow;
- const unsigned offset = type->is_sampler() ? 0 : 4;
+ const unsigned offset = glsl_type_is_sampler(type) ? 0 : 4;
assert(type_idx < 4);
switch (type->sampled_type) {
case GLSL_TYPE_FLOAT:
switch (type->sampler_dimensionality) {
case GLSL_SAMPLER_DIM_1D: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"sampler1D", "sampler1DArray",
"sampler1DShadow", "sampler1DArrayShadow"
@@ -2526,14 +2557,14 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
return names[offset + type_idx];
}
case GLSL_SAMPLER_DIM_MS: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"sampler2DMS", "sampler2DMSArray", NULL, NULL
};
return names[type_idx];
}
case GLSL_SAMPLER_DIM_RECT: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"samplerRect", NULL, "samplerRectShadow", NULL
};
@@ -2547,7 +2578,7 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
return names[offset + type_idx];
}
case GLSL_SAMPLER_DIM_EXTERNAL: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"samplerExternalOES", NULL, NULL, NULL
};
@@ -2560,7 +2591,7 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
case GLSL_TYPE_INT:
switch (type->sampler_dimensionality) {
case GLSL_SAMPLER_DIM_1D: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"isampler1D", "isampler1DArray", NULL, NULL
};
@@ -2588,14 +2619,14 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
return names[offset + type_idx];
}
case GLSL_SAMPLER_DIM_MS: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"isampler2DMS", "isampler2DMSArray", NULL, NULL
};
return names[type_idx];
}
case GLSL_SAMPLER_DIM_RECT: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"isamplerRect", NULL, "isamplerRectShadow", NULL
};
@@ -2615,7 +2646,7 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
case GLSL_TYPE_UINT:
switch (type->sampler_dimensionality) {
case GLSL_SAMPLER_DIM_1D: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"usampler1D", "usampler1DArray", NULL, NULL
};
@@ -2643,14 +2674,14 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
return names[offset + type_idx];
}
case GLSL_SAMPLER_DIM_MS: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"usampler2DMS", "usampler2DMSArray", NULL, NULL
};
return names[type_idx];
}
case GLSL_SAMPLER_DIM_RECT: {
- assert(type->is_sampler());
+ assert(glsl_type_is_sampler(type));
static const char *const names[4] = {
"usamplerRect", NULL, "usamplerRectShadow", NULL
};
@@ -2676,6 +2707,8 @@ get_type_name_for_precision_qualifier(const glsl_type *type)
default:
unreachable("Unsupported type");
} /* base type */
+
+ return NULL;
}
static unsigned
@@ -2696,7 +2729,7 @@ select_gles_precision(unsigned qual_precision,
precision = qual_precision;
} else if (precision_qualifier_allowed(type)) {
const char *type_name =
- get_type_name_for_precision_qualifier(type->without_array());
+ get_type_name_for_precision_qualifier(glsl_without_array(type));
assert(type_name != NULL);
precision =
@@ -2704,7 +2737,7 @@ select_gles_precision(unsigned qual_precision,
if (precision == ast_precision_none) {
_mesa_glsl_error(loc, state,
"No precision specified in this scope for type `%s'",
- type->name);
+ glsl_get_type_name(type));
}
}
@@ -2715,7 +2748,7 @@ select_gles_precision(unsigned qual_precision,
* declare an atomic type with a different precision or to specify the
* default precision for an atomic type to be lowp or mediump."
*/
- if (type->is_atomic_uint() && precision != ast_precision_high) {
+ if (glsl_type_is_atomic_uint(type) && precision != ast_precision_high) {
_mesa_glsl_error(loc, state,
"atomic_uint can only have highp precision qualifier");
}
@@ -2760,6 +2793,42 @@ is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state)
if (is_varying_var(var, state->stage))
return true;
+ /* ES2 says:
+ *
+ * "For the built-in special variables, gl_FragCoord can only be declared
+ * invariant if and only if gl_Position is declared invariant. Similarly
+ * gl_PointCoord can only be declared invariant if and only if gl_PointSize
+ * is declared invariant. It is an error to declare gl_FrontFacing as
+ * invariant. The invariance of gl_FrontFacing is the same as the invariance
+ * of gl_Position."
+ *
+ * ES3.1 says about invariance:
+ *
+ * "How does this rule apply to the built-in special variables?
+ *
+ * Option 1: It should be the same as for varyings. But gl_Position is used
+ * internally by the rasterizer as well as for gl_FragCoord so there may be
+ * cases where rasterization is required to be invariant but gl_FragCoord is
+ * not.
+ *
+ * RESOLUTION: Option 1."
+ *
+ * and the ES3 spec has similar text but the "RESOLUTION" is missing.
+ *
+ * Any system values should be from built-in special variables.
+ */
+ if (var->data.mode == ir_var_system_value) {
+ if (state->is_version(0, 300)) {
+ return true;
+ } else {
+ /* Note: We don't actually have a check that the VS's PointSize is
+ * invariant, even when it's treated as a varying.
+ */
+ if (var->data.location == SYSTEM_VALUE_POINT_COORD)
+ return true;
+ }
+ }
+
/* From Section 4.6.1 ("The Invariant Qualifier") GLSL 1.20 spec:
* "Only variables output from a vertex shader can be candidates
* for invariance".
@@ -2782,21 +2851,21 @@ validate_component_layout_for_type(struct _mesa_glsl_parse_state *state,
YYLTYPE *loc, const glsl_type *type,
unsigned qual_component)
{
- type = type->without_array();
- unsigned components = type->component_slots();
+ type = glsl_without_array(type);
+ unsigned components = glsl_get_component_slots(type);
- if (type->is_matrix() || type->is_struct()) {
+ if (glsl_type_is_matrix(type) || glsl_type_is_struct(type)) {
_mesa_glsl_error(loc, state, "component layout qualifier "
"cannot be applied to a matrix, a structure, "
"a block, or an array containing any of these.");
- } else if (components > 4 && type->is_64bit()) {
+ } else if (components > 4 && glsl_type_is_64bit(type)) {
_mesa_glsl_error(loc, state, "component layout qualifier "
"cannot be applied to dvec%u.",
components / 2);
} else if (qual_component != 0 && (qual_component + components - 1) > 3) {
_mesa_glsl_error(loc, state, "component overflow (%u > 3)",
(qual_component + components - 1));
- } else if (qual_component == 1 && type->is_64bit()) {
+ } else if (qual_component == 1 && glsl_type_is_64bit(type)) {
/* We don't bother checking for 3 as it should be caught by the
* overflow check above.
*/
@@ -2821,7 +2890,7 @@ validate_matrix_layout_for_type(struct _mesa_glsl_parse_state *state,
"uniform block layout qualifiers row_major and "
"column_major may not be applied to variables "
"outside of uniform blocks");
- } else if (!type->without_array()->is_matrix()) {
+ } else if (!glsl_type_is_matrix(glsl_without_array(type))) {
/* The OpenGL ES 3.0 conformance tests did not originally allow
* matrix layout qualifiers on non-matrices. However, the OpenGL
* 4.4 and OpenGL ES 3.0 (revision TBD) specifications were
@@ -2866,9 +2935,9 @@ validate_xfb_offset_qualifier(YYLTYPE *loc,
struct _mesa_glsl_parse_state *state,
int xfb_offset, const glsl_type *type,
unsigned component_size) {
- const glsl_type *t_without_array = type->without_array();
+ const glsl_type *t_without_array = glsl_without_array(type);
- if (xfb_offset != -1 && type->is_unsized_array()) {
+ if (xfb_offset != -1 && glsl_type_is_unsized_array(type)) {
_mesa_glsl_error(loc, state,
"xfb_offset can't be used with unsized arrays.");
return false;
@@ -2877,7 +2946,7 @@ validate_xfb_offset_qualifier(YYLTYPE *loc,
/* Make sure nested structs don't contain unsized arrays, and validate
* any xfb_offsets on interface members.
*/
- if (t_without_array->is_struct() || t_without_array->is_interface())
+ if (glsl_type_is_struct(t_without_array) || glsl_type_is_interface(t_without_array))
for (unsigned int i = 0; i < t_without_array->length; i++) {
const glsl_type *member_t = t_without_array->fields.structure[i].type;
@@ -2885,7 +2954,7 @@ validate_xfb_offset_qualifier(YYLTYPE *loc,
* we apply the component size rules at the member level.
*/
if (xfb_offset == -1)
- component_size = member_t->contains_double() ? 8 : 4;
+ component_size = glsl_contains_double(member_t) ? 8 : 4;
int xfb_offset = t_without_array->fields.structure[i].offset;
validate_xfb_offset_qualifier(loc, state, xfb_offset, member_t,
@@ -2916,11 +2985,11 @@ static bool
validate_stream_qualifier(YYLTYPE *loc, struct _mesa_glsl_parse_state *state,
unsigned stream)
{
- if (stream >= state->ctx->Const.MaxVertexStreams) {
+ if (stream >= state->consts->MaxVertexStreams) {
_mesa_glsl_error(loc, state,
"invalid stream specified %d is larger than "
"MAX_VERTEX_STREAMS - 1 (%d).",
- stream, state->ctx->Const.MaxVertexStreams - 1);
+ stream, state->consts->MaxVertexStreams - 1);
return false;
}
@@ -2947,12 +3016,12 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state,
return;
}
- const struct gl_context *const ctx = state->ctx;
- unsigned elements = type->is_array() ? type->arrays_of_arrays_size() : 1;
+ const struct gl_constants *consts = state->consts;
+ unsigned elements = glsl_type_is_array(type) ? glsl_get_aoa_size(type) : 1;
unsigned max_index = qual_binding + elements - 1;
- const glsl_type *base_type = type->without_array();
+ const glsl_type *base_type = glsl_without_array(type);
- if (base_type->is_interface()) {
+ if (glsl_type_is_interface(base_type)) {
/* UBOs. From page 60 of the GLSL 4.20 specification:
* "If the binding point for any uniform block instance is less than zero,
* or greater than or equal to the implementation-dependent maximum
@@ -2964,11 +3033,11 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state,
* The implementation-dependent maximum is GL_MAX_UNIFORM_BUFFER_BINDINGS.
*/
if (qual->flags.q.uniform &&
- max_index >= ctx->Const.MaxUniformBufferBindings) {
+ max_index >= consts->MaxUniformBufferBindings) {
_mesa_glsl_error(loc, state, "layout(binding = %u) for %d UBOs exceeds "
"the maximum number of UBO binding points (%d)",
qual_binding, elements,
- ctx->Const.MaxUniformBufferBindings);
+ consts->MaxUniformBufferBindings);
return;
}
@@ -2982,14 +3051,14 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state,
* be within this range."
*/
if (qual->flags.q.buffer &&
- max_index >= ctx->Const.MaxShaderStorageBufferBindings) {
+ max_index >= consts->MaxShaderStorageBufferBindings) {
_mesa_glsl_error(loc, state, "layout(binding = %u) for %d SSBOs exceeds "
"the maximum number of SSBO binding points (%d)",
qual_binding, elements,
- ctx->Const.MaxShaderStorageBufferBindings);
+ consts->MaxShaderStorageBufferBindings);
return;
}
- } else if (base_type->is_sampler()) {
+ } else if (glsl_type_is_sampler(base_type)) {
/* Samplers. From page 63 of the GLSL 4.20 specification:
* "If the binding is less than zero, or greater than or equal to the
* implementation-dependent maximum supported number of units, a
@@ -2997,7 +3066,7 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state,
* with an array of size N, all elements of the array from binding
* through binding + N - 1 must be within this range."
*/
- unsigned limit = ctx->Const.MaxCombinedTextureImageUnits;
+ unsigned limit = consts->MaxCombinedTextureImageUnits;
if (max_index >= limit) {
_mesa_glsl_error(loc, state, "layout(binding = %d) for %d samplers "
@@ -3006,24 +3075,24 @@ apply_explicit_binding(struct _mesa_glsl_parse_state *state,
return;
}
- } else if (base_type->contains_atomic()) {
- assert(ctx->Const.MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS);
- if (qual_binding >= ctx->Const.MaxAtomicBufferBindings) {
+ } else if (glsl_contains_atomic(base_type)) {
+ assert(consts->MaxAtomicBufferBindings <= MAX_COMBINED_ATOMIC_BUFFERS);
+ if (qual_binding >= consts->MaxAtomicBufferBindings) {
_mesa_glsl_error(loc, state, "layout(binding = %d) exceeds the "
"maximum number of atomic counter buffer bindings "
"(%u)", qual_binding,
- ctx->Const.MaxAtomicBufferBindings);
+ consts->MaxAtomicBufferBindings);
return;
}
} else if ((state->is_version(420, 310) ||
state->ARB_shading_language_420pack_enable) &&
- base_type->is_image()) {
- assert(ctx->Const.MaxImageUnits <= MAX_IMAGE_UNITS);
- if (max_index >= ctx->Const.MaxImageUnits) {
+ glsl_type_is_image(base_type)) {
+ assert(consts->MaxImageUnits <= MAX_IMAGE_UNITS);
+ if (max_index >= consts->MaxImageUnits) {
_mesa_glsl_error(loc, state, "Image binding %d exceeds the "
"maximum number of image units (%d)", max_index,
- ctx->Const.MaxImageUnits);
+ consts->MaxImageUnits);
return;
}
@@ -3083,7 +3152,7 @@ validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state,
* an integer. See Khronos bug #15671.
*/
if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
- && var_type->contains_integer()) {
+ && glsl_contains_integer(var_type)) {
_mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
"an integer, then it must be qualified with 'flat'");
}
@@ -3106,7 +3175,7 @@ validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state,
* The 'double' type does not exist in GLSL ES so far.
*/
if (state->has_double()
- && var_type->contains_double()) {
+ && glsl_contains_double(var_type)) {
_mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
"a double, then it must be qualified with 'flat'");
}
@@ -3125,7 +3194,7 @@ validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state,
* interpolation qualifier "flat"."
*/
if (state->has_bindless()
- && (var_type->contains_sampler() || var_type->contains_image())) {
+ && (glsl_contains_sampler(var_type) || glsl_type_contains_image(var_type))) {
_mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
"a bindless sampler (or image), then it must be "
"qualified with 'flat'");
@@ -3267,13 +3336,13 @@ apply_explicit_location(const struct ast_type_qualifier *qual,
if (!state->check_explicit_uniform_location_allowed(loc, var))
return;
- const struct gl_context *const ctx = state->ctx;
- unsigned max_loc = qual_location + var->type->uniform_locations() - 1;
+ const struct gl_constants *consts = state->consts;
+ unsigned max_loc = qual_location + glsl_type_uniform_locations(var->type) - 1;
- if (max_loc >= ctx->Const.MaxUserAssignableUniformLocations) {
+ if (max_loc >= consts->MaxUserAssignableUniformLocations) {
_mesa_glsl_error(loc, state, "location(s) consumed by uniform %s "
">= MAX_UNIFORM_LOCATIONS (%u)", var->name,
- ctx->Const.MaxUserAssignableUniformLocations);
+ consts->MaxUserAssignableUniformLocations);
return;
}
@@ -3478,7 +3547,7 @@ validate_memory_qualifier_for_type(struct _mesa_glsl_parse_state *state,
* variables, buffer variables, and shader storage blocks; it is an error
* to use such qualifiers in any other declarations.
*/
- if (!type->is_image() && !qual->flags.q.buffer) {
+ if (!glsl_type_is_image(type) && !qual->flags.q.buffer) {
if (qual->flags.q.read_only ||
qual->flags.q.write_only ||
qual->flags.q.coherent ||
@@ -3504,7 +3573,7 @@ validate_image_format_qualifier_for_type(struct _mesa_glsl_parse_state *state,
* "Format layout qualifiers can be used on image variable declarations
* (those declared with a basic type having “image ” in its keyword)."
*/
- if (!type->is_image() && qual->flags.q.explicit_image_format) {
+ if (!glsl_type_is_image(type) && qual->flags.q.explicit_image_format) {
_mesa_glsl_error(loc, state, "format layout qualifiers may only be "
"applied to images");
return false;
@@ -3518,13 +3587,13 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
struct _mesa_glsl_parse_state *state,
YYLTYPE *loc)
{
- const glsl_type *base_type = var->type->without_array();
+ const glsl_type *base_type = glsl_without_array(var->type);
if (!validate_image_format_qualifier_for_type(state, loc, qual, base_type) ||
!validate_memory_qualifier_for_type(state, loc, qual, base_type))
return;
- if (!base_type->is_image())
+ if (!glsl_type_is_image(base_type))
return;
if (!validate_storage_for_sampler_image_types(var, state, loc))
@@ -3627,14 +3696,15 @@ static inline void
validate_array_dimensions(const glsl_type *t,
struct _mesa_glsl_parse_state *state,
YYLTYPE *loc) {
- if (t->is_array()) {
+ const glsl_type *top = t;
+ if (glsl_type_is_array(t)) {
t = t->fields.array;
- while (t->is_array()) {
- if (t->is_unsized_array()) {
+ while (glsl_type_is_array(t)) {
+ if (glsl_type_is_unsized_array(t)) {
_mesa_glsl_error(loc, state,
"only the outermost array dimension can "
- "be unsized",
- t->name);
+ "be unsized, but got %s",
+ glsl_get_type_name(top));
break;
}
t = t->fields.array;
@@ -3675,14 +3745,14 @@ apply_bindless_qualifier_to_variable(const struct ast_type_qualifier *qual,
* types.
*/
if ((qual->flags.q.bindless_sampler || qual->flags.q.bound_sampler) &&
- !var->type->contains_sampler()) {
+ !glsl_contains_sampler(var->type)) {
_mesa_glsl_error(loc, state, "bindless_sampler or bound_sampler can only "
"be applied to sampler types");
return;
}
if ((qual->flags.q.bindless_image || qual->flags.q.bound_image) &&
- !var->type->contains_image()) {
+ !glsl_type_contains_image(var->type)) {
_mesa_glsl_error(loc, state, "bindless_image or bound_image can only be "
"applied to image types");
return;
@@ -3692,7 +3762,7 @@ apply_bindless_qualifier_to_variable(const struct ast_type_qualifier *qual,
* bound_sampler/bound_image) layout qualifiers can be set at global and at
* local scope.
*/
- if (var->type->contains_sampler() || var->type->contains_image()) {
+ if (glsl_contains_sampler(var->type) || glsl_type_contains_image(var->type)) {
var->data.bindless = qual->flags.q.bindless_sampler ||
qual->flags.q.bindless_image ||
state->bindless_sampler_specified ||
@@ -3703,6 +3773,22 @@ apply_bindless_qualifier_to_variable(const struct ast_type_qualifier *qual,
state->bound_sampler_specified ||
state->bound_image_specified;
}
+
+ /* ARB_bindless_texture spec says:
+ *
+ * "When used as shader inputs, outputs, uniform block members,
+ * or temporaries, the value of the sampler is a 64-bit unsigned
+ * integer handle and never refers to a texture image unit."
+ *
+ * The spec doesn't reference images defined inside structs but it was
+ * clarified with the authors that bindless images are allowed in structs.
+ * So we treat these images as implicitly bindless just like the types
+ * in the spec quote above.
+ */
+ if (!var->data.bindless && glsl_type_is_struct(var->type) &&
+ glsl_type_contains_image(var->type)) {
+ var->data.bindless = true;
+ }
}
static void
@@ -3818,7 +3904,7 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
if (qual->flags.q.explicit_xfb_offset) {
unsigned qual_xfb_offset;
- unsigned component_size = var->type->contains_double() ? 8 : 4;
+ unsigned component_size = glsl_contains_double(var->type) ? 8 : 4;
if (process_qualifier_constant(state, loc, "xfb_offset",
qual->offset, &qual_xfb_offset) &&
@@ -3838,7 +3924,7 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
}
}
- if (var->type->contains_atomic()) {
+ if (glsl_contains_atomic(var->type)) {
if (var->data.mode == ir_var_uniform) {
if (var->data.explicit_binding) {
unsigned *offset =
@@ -3848,8 +3934,12 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
_mesa_glsl_error(loc, state,
"misaligned atomic counter offset");
+ if (*offset >= state->Const.MaxAtomicCounterBufferSize)
+ _mesa_glsl_error(loc, state,
+ "offset > max atomic counter buffer size");
+
var->data.offset = *offset;
- *offset += var->type->atomic_size();
+ *offset += glsl_atomic_size(var->type);
} else {
_mesa_glsl_error(loc, state,
@@ -3862,7 +3952,7 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
}
}
- if (var->type->contains_sampler() &&
+ if (glsl_contains_sampler(var->type) &&
!validate_storage_for_sampler_image_types(var, state, loc))
return;
@@ -4066,7 +4156,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
var->data.patch = 1;
if (qual->flags.q.attribute && state->stage != MESA_SHADER_VERTEX) {
- var->type = glsl_type::error_type;
+ var->type = &glsl_type_builtin_error;
_mesa_glsl_error(loc, state,
"`attribute' variables may not be declared in the "
"%s shader",
@@ -4117,16 +4207,25 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
else if (qual->flags.q.shared_storage)
var->data.mode = ir_var_shader_shared;
- if (!is_parameter && state->has_framebuffer_fetch() &&
- state->stage == MESA_SHADER_FRAGMENT) {
- if (state->is_version(130, 300))
- var->data.fb_fetch_output = qual->flags.q.in && qual->flags.q.out;
- else
- var->data.fb_fetch_output = (strcmp(var->name, "gl_LastFragData") == 0);
+ if (!is_parameter && state->stage == MESA_SHADER_FRAGMENT) {
+ if (state->has_framebuffer_fetch()) {
+ if (state->is_version(130, 300))
+ var->data.fb_fetch_output = qual->flags.q.in && qual->flags.q.out;
+ else
+ var->data.fb_fetch_output = (strcmp(var->name, "gl_LastFragData") == 0);
+ }
+
+ if (state->has_framebuffer_fetch_zs() &&
+ (strcmp(var->name, "gl_LastFragDepthARM") == 0 ||
+ strcmp(var->name, "gl_LastFragStencilARM") == 0)) {
+ var->data.fb_fetch_output = 1;
+ }
}
- if (var->data.fb_fetch_output) {
+ if (var->data.fb_fetch_output)
var->data.assigned = true;
+
+ if (var->is_fb_fetch_color_output()) {
var->data.memory_coherent = !qual->flags.q.non_coherent;
/* From the EXT_shader_framebuffer_fetch spec:
@@ -4199,10 +4298,15 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
* integer vectors, sampler or image types, or arrays or structures
* of any these."
*/
- switch (var->type->without_array()->base_type) {
+ switch (glsl_without_array(var->type)->base_type) {
case GLSL_TYPE_FLOAT:
/* Ok in all GLSL versions */
break;
+ case GLSL_TYPE_FLOAT16:
+ if (state->AMD_gpu_shader_half_float_enable)
+ break;
+ _mesa_glsl_error(loc, state, "illegal type for a varying variable");
+ break;
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
if (state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
@@ -4222,6 +4326,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
case GLSL_TYPE_INT64:
break;
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE:
if (state->has_bindless())
break;
@@ -4353,9 +4458,9 @@ get_variable_being_redeclared(ir_variable **var_ptr, YYLTYPE loc,
* later re-declare the same name as an array of the same
* type and specify a size."
*/
- if (earlier->type->is_unsized_array() && var->type->is_array()
+ if (glsl_type_is_unsized_array(earlier->type) && glsl_type_is_array(var->type)
&& (var->type->fields.array == earlier->type->fields.array)) {
- const int size = var->type->array_size();
+ const int size = glsl_array_size(var->type);
check_builtin_array_max_size(var->name, size, loc, state);
if ((size > 0) && (size <= earlier->data.max_array_access)) {
_mesa_glsl_error(& loc, state, "array size must be > %u due to "
@@ -4425,8 +4530,8 @@ get_variable_being_redeclared(ir_variable **var_ptr, YYLTYPE loc,
"gl_FragDepth: depth layout is declared here "
"as '%s, but it was previously declared as "
"'%s'",
- depth_layout_string(var->data.depth_layout),
- depth_layout_string(earlier->data.depth_layout));
+ depth_layout_string((ir_depth_layout)var->data.depth_layout),
+ depth_layout_string((ir_depth_layout)earlier->data.depth_layout));
}
earlier->data.depth_layout = var->data.depth_layout;
@@ -4537,8 +4642,8 @@ process_initializer(ir_variable *var, ast_declaration *decl,
* "Images may be declared as shader inputs and outputs, as uniform
* variables, as temporary variables, and as function parameters."
*/
- if (var->type->contains_atomic() ||
- (!state->has_bindless() && var->type->contains_opaque())) {
+ if (glsl_contains_atomic(var->type) ||
+ (!state->has_bindless() && glsl_contains_opaque(var->type))) {
_mesa_glsl_error(&initializer_loc, state,
"cannot initialize %s variable %s",
var->name, state->has_bindless() ? "atomic" : "opaque");
@@ -4652,7 +4757,7 @@ process_initializer(ir_variable *var, ast_declaration *decl,
"constant expression",
variable_mode,
decl->identifier);
- if (var->type->is_numeric()) {
+ if (glsl_type_is_numeric(var->type)) {
/* Reduce cascading errors. */
var->constant_value = type->qualifier.flags.q.constant
? ir_constant::zero(state, var->type) : NULL;
@@ -4664,7 +4769,7 @@ process_initializer(ir_variable *var, ast_declaration *decl,
? constant_value : NULL;
}
} else {
- if (var->type->is_numeric()) {
+ if (glsl_type_is_numeric(var->type)) {
/* Reduce cascading errors. */
rhs = var->constant_value = type->qualifier.flags.q.constant
? ir_constant::zero(state, var->type) : NULL;
@@ -4672,7 +4777,7 @@ process_initializer(ir_variable *var, ast_declaration *decl,
}
}
- if (rhs && !rhs->type->is_error()) {
+ if (rhs && !glsl_type_is_error(rhs->type)) {
bool temp = var->data.read_only;
if (type->qualifier.flags.q.constant)
var->data.read_only = false;
@@ -4732,7 +4837,7 @@ validate_layout_qualifier_vertex_count(struct _mesa_glsl_parse_state *state,
unsigned *size,
const char *var_category)
{
- if (var->type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(var->type)) {
/* Section 4.3.8.1 (Input Layout Qualifiers) of the GLSL 1.50 spec says:
*
* All geometry shader input unsized array declarations will be
@@ -4745,8 +4850,8 @@ validate_layout_qualifier_vertex_count(struct _mesa_glsl_parse_state *state,
* Similarly for tessellation control shader outputs.
*/
if (num_vertices != 0)
- var->type = glsl_type::get_array_instance(var->type->fields.array,
- num_vertices);
+ var->type = glsl_array_type(var->type->fields.array,
+ num_vertices, 0);
} else {
/* Section 4.3.8.1 (Input Layout Qualifiers) of the GLSL 1.50 spec
* includes the following examples of compile-time errors:
@@ -4803,7 +4908,7 @@ handle_tess_ctrl_shader_output_decl(struct _mesa_glsl_parse_state *state,
}
}
- if (!var->type->is_array() && !var->data.patch) {
+ if (!glsl_type_is_array(var->type) && !var->data.patch) {
_mesa_glsl_error(&loc, state,
"tessellation control shader outputs must be arrays");
@@ -4828,7 +4933,7 @@ static void
handle_tess_shader_input_decl(struct _mesa_glsl_parse_state *state,
YYLTYPE loc, ir_variable *var)
{
- if (!var->type->is_array() && !var->data.patch) {
+ if (!glsl_type_is_array(var->type) && !var->data.patch) {
_mesa_glsl_error(&loc, state,
"per-vertex tessellation shader inputs must be arrays");
/* Avoid cascading failures. */
@@ -4847,9 +4952,9 @@ handle_tess_shader_input_decl(struct _mesa_glsl_parse_state *state,
*
* This text appears twice, once for TCS inputs, and again for TES inputs.
*/
- if (var->type->is_unsized_array()) {
- var->type = glsl_type::get_array_instance(var->type->fields.array,
- state->Const.MaxPatchVertices);
+ if (glsl_type_is_unsized_array(var->type)) {
+ var->type = glsl_array_type(var->type->fields.array,
+ state->Const.MaxPatchVertices, 0);
} else if (var->type->length != state->Const.MaxPatchVertices) {
_mesa_glsl_error(&loc, state,
"per-vertex tessellation shader input arrays must be "
@@ -4870,13 +4975,14 @@ handle_geometry_shader_input_decl(struct _mesa_glsl_parse_state *state,
unsigned num_vertices = 0;
if (state->gs_input_prim_type_specified) {
- num_vertices = vertices_per_prim(state->in_qualifier->prim_type);
+ GLenum in_prim_type = state->in_qualifier->prim_type;
+ num_vertices = mesa_vertices_per_prim(gl_to_mesa_prim(in_prim_type));
}
/* Geometry shader input variables must be arrays. Caller should have
* reported an error for this.
*/
- if (!var->type->is_array()) {
+ if (!glsl_type_is_array(var->type)) {
assert(state->error);
/* To avoid cascading failures, short circuit the checks below. */
@@ -5028,7 +5134,7 @@ ast_declarator_list::hir(exec_list *instructions,
* This is done here, based on the layout qualifier and the type of the image var
*/
if (this->type->qualifier.flags.q.explicit_image_format &&
- this->type->specifier->type->is_image() &&
+ glsl_type_is_image(this->type->specifier->type) &&
this->type->qualifier.image_base_type == GLSL_TYPE_VOID) {
/* "The ARB_shader_image_load_store says:
* If both extensions are enabled in the shading language, the "size*" layout
@@ -5111,7 +5217,7 @@ ast_declarator_list::hir(exec_list *instructions,
* shader storage blocks. It is a compile-time error to declare buffer
* variables at global scope (outside a block)."
*/
- if (type->qualifier.flags.q.buffer && !decl_type->is_interface()) {
+ if (type->qualifier.flags.q.buffer && !glsl_type_is_interface(decl_type)) {
_mesa_glsl_error(&loc, state,
"buffer variables cannot be declared outside "
"interface blocks");
@@ -5121,7 +5227,7 @@ ast_declarator_list::hir(exec_list *instructions,
* offset for the next declaration within the same atomic counter
* buffer.
*/
- if (decl_type && decl_type->contains_atomic()) {
+ if (decl_type && glsl_contains_atomic(decl_type)) {
if (type->qualifier.flags.q.explicit_binding &&
type->qualifier.flags.q.explicit_offset) {
unsigned qual_binding;
@@ -5178,7 +5284,7 @@ ast_declarator_list::hir(exec_list *instructions,
"invalid type `%s' in empty declaration",
type_name);
} else {
- if (decl_type->is_array()) {
+ if (glsl_type_is_array(decl_type)) {
/* From Section 13.22 (Array Declarations) of the GLSL ES 3.2
* spec:
*
@@ -5186,7 +5292,7 @@ ast_declarator_list::hir(exec_list *instructions,
* disallowed as this would add complexity and there are no
* use-cases."
*/
- if (state->es_shader && decl_type->is_unsized_array()) {
+ if (state->es_shader && glsl_type_is_unsized_array(decl_type)) {
_mesa_glsl_error(&loc, state, "array size must be explicitly "
"or implicitly defined");
}
@@ -5200,7 +5306,7 @@ ast_declarator_list::hir(exec_list *instructions,
validate_array_dimensions(decl_type, state, &loc);
}
- if (decl_type->is_atomic_uint()) {
+ if (glsl_type_is_atomic_uint(decl_type)) {
/* Empty atomic counter declarations are allowed and useful
* to set the default offset qualifier.
*/
@@ -5240,7 +5346,7 @@ ast_declarator_list::hir(exec_list *instructions,
* FINISHME: declaration at a higher scope.
*/
- if ((decl_type == NULL) || decl_type->is_void()) {
+ if ((decl_type == NULL) || glsl_type_is_void(decl_type)) {
if (type_name != NULL) {
_mesa_glsl_error(& loc, state,
"invalid type `%s' in declaration of `%s'",
@@ -5333,7 +5439,7 @@ ast_declarator_list::hir(exec_list *instructions,
&loc);
if ((state->zero_init & (1u << var->data.mode)) &&
- (var->type->is_numeric() || var->type->is_boolean())) {
+ (glsl_type_is_numeric(var->type) || glsl_type_is_boolean(var->type))) {
const ir_constant_data data = { { 0 } };
var->data.has_initializer = true;
var->data.is_implicit_initializer = true;
@@ -5415,7 +5521,7 @@ ast_declarator_list::hir(exec_list *instructions,
* floating-point vectors, matrices, signed and unsigned
* integers and integer vectors, sampler and image types."
*/
- const glsl_type *check_type = var->type->without_array();
+ const glsl_type *check_type = glsl_without_array(var->type);
bool error = false;
switch (check_type->base_type) {
@@ -5432,6 +5538,7 @@ ast_declarator_list::hir(exec_list *instructions,
error = !state->is_version(410, 0) && !state->ARB_vertex_attrib_64bit_enable;
break;
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE:
error = !state->has_bindless();
break;
@@ -5443,9 +5550,9 @@ ast_declarator_list::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state,
"vertex shader input / attribute cannot have "
"type %s`%s'",
- var->type->is_array() ? "array of " : "",
- check_type->name);
- } else if (var->type->is_array() &&
+ glsl_type_is_array(var->type) ? "array of " : "",
+ glsl_get_type_name(check_type));
+ } else if (glsl_type_is_array(var->type) &&
!state->check_version(150, 0, &loc,
"vertex shader input / attribute "
"cannot have array type")) {
@@ -5459,7 +5566,7 @@ ast_declarator_list::hir(exec_list *instructions,
* vertices, each input varying variable (or input block, see
* interface blocks below) needs to be declared as an array.
*/
- if (!var->type->is_array()) {
+ if (!glsl_type_is_array(var->type)) {
_mesa_glsl_error(&loc, state,
"geometry shader inputs must be arrays");
}
@@ -5479,30 +5586,30 @@ ast_declarator_list::hir(exec_list *instructions,
* * A structure containing a structure
*/
if (state->es_shader) {
- const glsl_type *check_type = var->type->without_array();
- if (check_type->is_boolean() ||
- check_type->contains_opaque()) {
+ const glsl_type *check_type = glsl_without_array(var->type);
+ if (glsl_type_is_boolean(check_type) ||
+ glsl_contains_opaque(check_type)) {
_mesa_glsl_error(&loc, state,
"fragment shader input cannot have type %s",
- check_type->name);
+ glsl_get_type_name(check_type));
}
- if (var->type->is_array() &&
- var->type->fields.array->is_array()) {
+ if (glsl_type_is_array(var->type) &&
+ glsl_type_is_array(var->type->fields.array)) {
_mesa_glsl_error(&loc, state,
"%s shader output "
"cannot have an array of arrays",
_mesa_shader_stage_to_string(state->stage));
}
- if (var->type->is_array() &&
- var->type->fields.array->is_struct()) {
+ if (glsl_type_is_array(var->type) &&
+ glsl_type_is_struct(var->type->fields.array)) {
_mesa_glsl_error(&loc, state,
"fragment shader input "
"cannot have an array of structs");
}
- if (var->type->is_struct()) {
+ if (glsl_type_is_struct(var->type)) {
for (unsigned i = 0; i < var->type->length; i++) {
- if (var->type->fields.structure[i].type->is_array() ||
- var->type->fields.structure[i].type->is_struct())
+ if (glsl_type_is_array(var->type->fields.structure[i].type) ||
+ glsl_type_is_struct(var->type->fields.structure[i].type))
_mesa_glsl_error(&loc, state,
"fragment shader input cannot have "
"a struct that contains an "
@@ -5515,7 +5622,7 @@ ast_declarator_list::hir(exec_list *instructions,
handle_tess_shader_input_decl(state, loc, var);
}
} else if (var->data.mode == ir_var_shader_out) {
- const glsl_type *check_type = var->type->without_array();
+ const glsl_type *check_type = glsl_without_array(var->type);
/* From section 4.3.6 (Output variables) of the GLSL 4.40 spec:
*
@@ -5529,7 +5636,7 @@ ast_declarator_list::hir(exec_list *instructions,
* * A structure
*/
if (state->stage == MESA_SHADER_FRAGMENT) {
- if (check_type->is_struct() || check_type->is_matrix())
+ if (glsl_type_is_struct(check_type) || glsl_type_is_matrix(check_type))
_mesa_glsl_error(&loc, state,
"fragment shader output "
"cannot have struct or matrix type");
@@ -5541,7 +5648,7 @@ ast_declarator_list::hir(exec_list *instructions,
default:
_mesa_glsl_error(&loc, state,
"fragment shader output cannot have "
- "type %s", check_type->name);
+ "type %s", glsl_get_type_name(check_type));
}
}
@@ -5585,8 +5692,8 @@ ast_declarator_list::hir(exec_list *instructions,
* the old rules.
*/
if (state->es_shader) {
- if (var->type->is_array() &&
- var->type->fields.array->is_array()) {
+ if (glsl_type_is_array(var->type) &&
+ glsl_type_is_array(var->type->fields.array)) {
_mesa_glsl_error(&loc, state,
"%s shader output "
"cannot have an array of arrays",
@@ -5596,20 +5703,20 @@ ast_declarator_list::hir(exec_list *instructions,
const glsl_type *type = var->type;
if (state->stage == MESA_SHADER_TESS_CTRL &&
- !var->data.patch && var->type->is_array()) {
+ !var->data.patch && glsl_type_is_array(var->type)) {
type = var->type->fields.array;
}
- if (type->is_array() && type->fields.array->is_struct()) {
+ if (glsl_type_is_array(type) && glsl_type_is_struct(type->fields.array)) {
_mesa_glsl_error(&loc, state,
"%s shader output cannot have "
"an array of structs",
_mesa_shader_stage_to_string(state->stage));
}
- if (type->is_struct()) {
+ if (glsl_type_is_struct(type)) {
for (unsigned i = 0; i < type->length; i++) {
- if (type->fields.structure[i].type->is_array() ||
- type->fields.structure[i].type->is_struct())
+ if (glsl_type_is_array(type->fields.structure[i].type) ||
+ glsl_type_is_struct(type->fields.structure[i].type))
_mesa_glsl_error(&loc, state,
"%s shader output cannot have a "
"struct that contains an "
@@ -5623,7 +5730,7 @@ ast_declarator_list::hir(exec_list *instructions,
if (state->stage == MESA_SHADER_TESS_CTRL) {
handle_tess_ctrl_shader_output_decl(state, loc, var);
}
- } else if (var->type->contains_subroutine()) {
+ } else if (glsl_contains_subroutine(var->type)) {
/* declare subroutine uniforms as hidden */
var->data.how_declared = ir_var_hidden;
}
@@ -5684,8 +5791,8 @@ ast_declarator_list::hir(exec_list *instructions,
* variables, as temporary variables, and as function parameters."
*/
if (!this->type->qualifier.flags.q.uniform &&
- (var_type->contains_atomic() ||
- (!state->has_bindless() && var_type->contains_opaque()))) {
+ (glsl_contains_atomic(var_type) ||
+ (!state->has_bindless() && glsl_contains_opaque(var_type)))) {
_mesa_glsl_error(&loc, state,
"%s variables must be declared uniform",
state->has_bindless() ? "atomic" : "opaque");
@@ -5765,7 +5872,7 @@ ast_declarator_list::hir(exec_list *instructions,
(var->data.mode == ir_var_shader_out &&
state->stage == MESA_SHADER_TESS_CTRL);
- if (t->is_unsized_array() && !implicitly_sized)
+ if (glsl_type_is_unsized_array(t) && !implicitly_sized)
/* Section 10.17 of the GLSL ES 1.00 specification states that
* unsized array declarations have been removed from the language.
* Arrays that are sized using an initializer are still explicitly
@@ -5793,8 +5900,8 @@ ast_declarator_list::hir(exec_list *instructions,
* "It is a compile-time error to declare an unsized array of
* atomic_uint"
*/
- if (var->type->is_unsized_array() &&
- var->type->without_array()->base_type == GLSL_TYPE_ATOMIC_UINT) {
+ if (glsl_type_is_unsized_array(var->type) &&
+ glsl_without_array(var->type)->base_type == GLSL_TYPE_ATOMIC_UINT) {
_mesa_glsl_error(& loc, state,
"Unsized array of atomic_uint is not allowed");
}
@@ -5873,7 +5980,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
this->identifier);
}
- type = glsl_type::error_type;
+ type = &glsl_type_builtin_error;
}
/* From page 62 (page 68 of the PDF) of the GLSL 1.50 spec:
@@ -5888,7 +5995,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
* for a function, which avoids tripping up checks for main taking
* parameters and lookups of an unnamed symbol.
*/
- if (type->is_void()) {
+ if (glsl_type_is_void(type)) {
if (this->identifier != NULL)
_mesa_glsl_error(& loc, state,
"named parameter cannot have type `void'");
@@ -5907,10 +6014,10 @@ ast_parameter_declarator::hir(exec_list *instructions,
*/
type = process_array_type(&loc, type, this->array_specifier, state);
- if (!type->is_error() && type->is_unsized_array()) {
+ if (!glsl_type_is_error(type) && glsl_type_is_unsized_array(type)) {
_mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
"a declared size");
- type = glsl_type::error_type;
+ type = &glsl_type_builtin_error;
}
is_void = false;
@@ -5924,7 +6031,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
true);
if (((1u << var->data.mode) & state->zero_init) &&
- (var->type->is_numeric() || var->type->is_boolean())) {
+ (glsl_type_is_numeric(var->type) || glsl_type_is_boolean(var->type))) {
const ir_constant_data data = { { 0 } };
var->data.has_initializer = true;
var->data.is_implicit_initializer = true;
@@ -5948,12 +6055,12 @@ ast_parameter_declarator::hir(exec_list *instructions,
* "out" and "inout" function parameters."
*/
if ((var->data.mode == ir_var_function_inout || var->data.mode == ir_var_function_out)
- && (type->contains_atomic() ||
- (!state->has_bindless() && type->contains_opaque()))) {
+ && (glsl_contains_atomic(type) ||
+ (!state->has_bindless() && glsl_contains_opaque(type)))) {
_mesa_glsl_error(&loc, state, "out and inout parameters cannot "
"contain %s variables",
state->has_bindless() ? "atomic" : "opaque");
- type = glsl_type::error_type;
+ type = &glsl_type_builtin_error;
}
/* From page 39 (page 45 of the PDF) of the GLSL 1.10 spec:
@@ -5971,10 +6078,10 @@ ast_parameter_declarator::hir(exec_list *instructions,
* allowed. This restriction is removed in GLSL 1.20, and in GLSL ES.
*/
if ((var->data.mode == ir_var_function_inout || var->data.mode == ir_var_function_out)
- && type->is_array()
- && !state->check_version(120, 100, &loc,
+ && glsl_type_is_array(type)
+ && !state->check_version(state->allow_glsl_120_subset_in_110 ? 110 : 120, 100, &loc,
"arrays cannot be out or inout parameters")) {
- type = glsl_type::error_type;
+ type = &glsl_type_builtin_error;
}
instructions->push_tail(var);
@@ -6084,7 +6191,7 @@ ast_function::hir(exec_list *instructions,
_mesa_glsl_error(&loc, state,
"function `%s' has undeclared return type `%s'",
name, return_type_name);
- return_type = glsl_type::error_type;
+ return_type = &glsl_type_builtin_error;
}
/* ARB_shader_subroutine states:
@@ -6112,7 +6219,7 @@ ast_function::hir(exec_list *instructions,
* "Arrays are allowed as arguments and as the return type. In both
* cases, the array must be explicitly sized."
*/
- if (return_type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(return_type)) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(& loc, state,
"function `%s' return type array must be explicitly "
@@ -6125,7 +6232,7 @@ ast_function::hir(exec_list *instructions,
* The return type can also be a structure if the structure does not
* contain an array."
*/
- if (state->language_version == 100 && return_type->contains_array()) {
+ if (state->language_version == 100 && glsl_contains_array(return_type)) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(& loc, state,
"function `%s' return type contains an array", name);
@@ -6140,8 +6247,8 @@ ast_function::hir(exec_list *instructions,
* "Replace Section 4.1.7 (Samplers), p. 25" and, "Replace Section 4.1.X,
* (Images)", this should be allowed.
*/
- if (return_type->contains_atomic() ||
- (!state->has_bindless() && return_type->contains_opaque())) {
+ if (glsl_contains_atomic(return_type) ||
+ (!state->has_bindless() && glsl_contains_opaque(return_type))) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(&loc, state,
"function `%s' return type can't contain an %s type",
@@ -6149,7 +6256,7 @@ ast_function::hir(exec_list *instructions,
}
/**/
- if (return_type->is_subroutine()) {
+ if (glsl_type_is_subroutine(return_type)) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(&loc, state,
"function `%s' return type can't be a subroutine type",
@@ -6273,7 +6380,7 @@ ast_function::hir(exec_list *instructions,
/* Verify the return type of main() */
if (strcmp(name, "main") == 0) {
- if (! return_type->is_void()) {
+ if (! glsl_type_is_void(return_type)) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(& loc, state, "main() must return void");
@@ -6361,7 +6468,7 @@ ast_function::hir(exec_list *instructions,
}
if (this->return_type->qualifier.is_subroutine_decl()) {
- if (!state->symbols->add_type(this->identifier, glsl_type::get_subroutine_instance(this->identifier))) {
+ if (!state->symbols->add_type(this->identifier, glsl_subroutine_type(this->identifier))) {
_mesa_glsl_error(& loc, state, "type '%s' previously defined", this->identifier);
return NULL;
}
@@ -6425,12 +6532,12 @@ ast_function_definition::hir(exec_list *instructions,
assert(state->current_function == signature);
state->current_function = NULL;
- if (!signature->return_type->is_void() && !state->found_return) {
+ if (!glsl_type_is_void(signature->return_type) && !state->found_return) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(& loc, state, "function `%s' has non-void return type "
"%s, but no return statement",
signature->function_name(),
- signature->return_type->name);
+ glsl_get_type_name(signature->return_type));
}
/* Function definitions do not have r-values.
@@ -6461,7 +6568,7 @@ ast_jump_statement::hir(exec_list *instructions,
* also void, then this should compile without error. Seriously.
*/
const glsl_type *const ret_type =
- (ret == NULL) ? glsl_type::void_type : ret->type;
+ (ret == NULL) ? &glsl_type_builtin_void : ret->type;
/* Implicit conversions are not allowed for return values prior to
* ARB_shading_language_420pack.
@@ -6476,16 +6583,16 @@ ast_jump_statement::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state,
"could not implicitly convert return value "
"to %s, in function `%s'",
- state->current_function->return_type->name,
+ glsl_get_type_name(state->current_function->return_type),
state->current_function->function_name());
}
} else {
_mesa_glsl_error(& loc, state,
"`return' with wrong type %s, in function `%s' "
"returning %s",
- ret_type->name,
+ glsl_get_type_name(ret_type),
state->current_function->function_name(),
- state->current_function->return_type->name);
+ glsl_get_type_name(state->current_function->return_type));
}
} else if (state->current_function->return_type->base_type ==
GLSL_TYPE_VOID) {
@@ -6641,7 +6748,7 @@ ast_selection_statement::hir(exec_list *instructions,
* The checks are separated so that higher quality diagnostics can be
* generated for cases where both rules are violated.
*/
- if (!condition->type->is_boolean() || !condition->type->is_scalar()) {
+ if (!glsl_type_is_boolean(condition->type) || !glsl_type_is_scalar(condition->type)) {
YYLTYPE loc = this->condition->get_location();
_mesa_glsl_error(& loc, state, "if-statement condition must be scalar "
@@ -6725,8 +6832,8 @@ ast_switch_statement::hir(exec_list *instructions,
* "The type of init-expression in a switch statement must be a
* scalar integer."
*/
- if (!test_val->type->is_scalar() ||
- !test_val->type->is_integer_32()) {
+ if (!glsl_type_is_scalar(test_val->type) ||
+ !glsl_type_is_integer_32(test_val->type)) {
YYLTYPE loc = this->test_expression->get_location();
_mesa_glsl_error(& loc,
@@ -6751,7 +6858,7 @@ ast_switch_statement::hir(exec_list *instructions,
*/
ir_rvalue *const is_fallthru_val = new (ctx) ir_constant(false);
state->switch_state.is_fallthru_var =
- new(ctx) ir_variable(glsl_type::bool_type,
+ new(ctx) ir_variable(&glsl_type_builtin_bool,
"switch_is_fallthru_tmp",
ir_var_temporary);
instructions->push_tail(state->switch_state.is_fallthru_var);
@@ -6764,7 +6871,7 @@ ast_switch_statement::hir(exec_list *instructions,
/* Initialize continue_inside state to false.
*/
state->switch_state.continue_inside =
- new(ctx) ir_variable(glsl_type::bool_type,
+ new(ctx) ir_variable(&glsl_type_builtin_bool,
"continue_inside_tmp",
ir_var_temporary);
instructions->push_tail(state->switch_state.continue_inside);
@@ -6776,7 +6883,7 @@ ast_switch_statement::hir(exec_list *instructions,
false_val));
state->switch_state.run_default =
- new(ctx) ir_variable(glsl_type::bool_type,
+ new(ctx) ir_variable(&glsl_type_builtin_bool,
"run_default_tmp",
ir_var_temporary);
instructions->push_tail(state->switch_state.run_default);
@@ -7045,23 +7152,22 @@ ast_case_label::hir(exec_list *instructions,
/* Check if int->uint implicit conversion is supported. */
bool integer_conversion_supported =
- glsl_type::int_type->can_implicitly_convert_to(glsl_type::uint_type,
- state);
+ _mesa_glsl_can_implicitly_convert(&glsl_type_builtin_int, &glsl_type_builtin_uint, state);
- if ((!type_a->is_integer_32() || !type_b->is_integer_32()) ||
+ if ((!glsl_type_is_integer_32(type_a) || !glsl_type_is_integer_32(type_b)) ||
!integer_conversion_supported) {
_mesa_glsl_error(&loc, state, "type mismatch with switch "
"init-expression and case label (%s != %s)",
- type_a->name, type_b->name);
+ glsl_get_type_name(type_a), glsl_get_type_name(type_b));
} else {
/* Conversion of the case label. */
if (type_a->base_type == GLSL_TYPE_INT) {
- if (!apply_implicit_conversion(glsl_type::uint_type,
+ if (!apply_implicit_conversion(&glsl_type_builtin_uint,
label, state))
_mesa_glsl_error(&loc, state, "implicit type conversion error");
} else {
/* Conversion of the init-expression value. */
- if (!apply_implicit_conversion(glsl_type::uint_type,
+ if (!apply_implicit_conversion(&glsl_type_builtin_uint,
deref_test_var, state))
_mesa_glsl_error(&loc, state, "implicit type conversion error");
}
@@ -7109,7 +7215,7 @@ ast_iteration_statement::condition_to_hir(exec_list *instructions,
condition->hir(instructions, state);
if ((cond == NULL)
- || !cond->type->is_boolean() || !cond->type->is_scalar()) {
+ || !glsl_type_is_boolean(cond->type) || !glsl_type_is_scalar(cond->type)) {
YYLTYPE loc = condition->get_location();
_mesa_glsl_error(& loc, state,
@@ -7228,6 +7334,7 @@ is_valid_default_precision_type(const struct glsl_type *const type)
/* "int" and "float" are valid, but vectors and matrices are not. */
return type->vector_elements == 1 && type->matrix_columns == 1;
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_TEXTURE:
case GLSL_TYPE_IMAGE:
case GLSL_TYPE_ATOMIC_UINT:
return true;
@@ -7438,14 +7545,14 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
*
* * sampler types are not allowed
*/
- if (decl_type->contains_atomic() ||
- (!state->has_bindless() && decl_type->contains_opaque())) {
+ if (glsl_contains_atomic(decl_type) ||
+ (!state->has_bindless() && glsl_contains_opaque(decl_type))) {
_mesa_glsl_error(&loc, state, "uniform/buffer in non-default "
"interface block contains %s variable",
state->has_bindless() ? "atomic" : "opaque");
}
} else {
- if (decl_type->contains_atomic()) {
+ if (glsl_contains_atomic(decl_type)) {
/* From section 4.1.7.3 of the GLSL 4.40 spec:
*
* "Members of structures cannot be declared as atomic counter
@@ -7454,7 +7561,7 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
_mesa_glsl_error(&loc, state, "atomic counter in structure");
}
- if (!state->has_bindless() && decl_type->contains_image()) {
+ if (!state->has_bindless() && glsl_type_contains_image(decl_type)) {
/* FINISHME: Same problem as with atomic counters.
* FINISHME: Request clarification from Khronos and add
* FINISHME: spec quotation here.
@@ -7609,12 +7716,12 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
fields[i].location = qual_location +
(fields[i].patch ? VARYING_SLOT_PATCH0 : VARYING_SLOT_VAR0);
expl_location = fields[i].location +
- fields[i].type->count_attribute_slots(false);
+ glsl_count_attribute_slots(fields[i].type, false);
}
} else {
if (layout && layout->flags.q.explicit_location) {
fields[i].location = expl_location;
- expl_location += fields[i].type->count_attribute_slots(false);
+ expl_location += glsl_count_attribute_slots(fields[i].type, false);
} else {
fields[i].location = -1;
}
@@ -7635,7 +7742,7 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
/* Offset can only be used with std430 and std140 layouts an initial
* value of 0 is used for error detection.
*/
- unsigned align = 0;
+ unsigned base_alignment = 0;
unsigned size = 0;
if (layout) {
bool row_major;
@@ -7647,11 +7754,11 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
}
if(layout->flags.q.std140) {
- align = field_type->std140_base_alignment(row_major);
- size = field_type->std140_size(row_major);
+ base_alignment = glsl_get_std140_base_alignment(field_type, row_major);
+ size = glsl_get_std140_size(field_type, row_major);
} else if (layout->flags.q.std430) {
- align = field_type->std430_base_alignment(row_major);
- size = field_type->std430_size(row_major);
+ base_alignment = glsl_get_std430_base_alignment(field_type, row_major);
+ size = glsl_get_std430_size(field_type, row_major);
}
}
@@ -7659,15 +7766,15 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
unsigned qual_offset;
if (process_qualifier_constant(state, &loc, "offset",
qual->offset, &qual_offset)) {
- if (align != 0 && size != 0) {
+ if (base_alignment != 0 && size != 0) {
if (next_offset > qual_offset)
_mesa_glsl_error(&loc, state, "layout qualifier "
"offset overlaps previous member");
- if (qual_offset % align) {
+ if (qual_offset % base_alignment) {
_mesa_glsl_error(&loc, state, "layout qualifier offset "
"must be a multiple of the base "
- "alignment of %s", field_type->name);
+ "alignment of %s", glsl_get_type_name(field_type));
}
fields[i].offset = qual_offset;
next_offset = qual_offset + size;
@@ -7681,7 +7788,7 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
if (qual->flags.q.explicit_align || expl_align != 0) {
unsigned offset = fields[i].offset != -1 ? fields[i].offset :
next_offset;
- if (align == 0 || size == 0) {
+ if (base_alignment == 0 || size == 0) {
_mesa_glsl_error(&loc, state, "align can only be used with "
"std430 and std140 layouts");
} else if (qual->flags.q.explicit_align) {
@@ -7693,17 +7800,17 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
_mesa_glsl_error(&loc, state, "align layout qualifier "
"is not a power of 2");
} else {
- fields[i].offset = glsl_align(offset, member_align);
+ fields[i].offset = align(offset, member_align);
next_offset = fields[i].offset + size;
}
}
} else {
- fields[i].offset = glsl_align(offset, expl_align);
+ fields[i].offset = align(offset, expl_align);
next_offset = fields[i].offset + size;
}
} else if (!qual->flags.q.explicit_offset) {
- if (align != 0 && size != 0)
- next_offset = glsl_align(next_offset, align) + size;
+ if (base_alignment != 0 && size != 0)
+ next_offset = align(next_offset, base_alignment) + size;
}
/* From the ARB_enhanced_layouts spec:
@@ -7721,13 +7828,13 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
qual->offset, &xfb_offset)) {
fields[i].offset = xfb_offset;
block_xfb_offset = fields[i].offset +
- 4 * field_type->component_slots();
+ 4 * glsl_get_component_slots(field_type);
}
} else {
if (layout && layout->flags.q.explicit_xfb_offset) {
- unsigned align = field_type->is_64bit() ? 8 : 4;
- fields[i].offset = glsl_align(block_xfb_offset, align);
- block_xfb_offset += 4 * field_type->component_slots();
+ unsigned base_alignment = glsl_type_is_64bit(field_type) ? 8 : 4;
+ fields[i].offset = align(block_xfb_offset, base_alignment);
+ block_xfb_offset += 4 * glsl_get_component_slots(field_type);
}
}
@@ -7738,8 +7845,8 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
*/
if (is_interface && layout &&
(layout->flags.q.uniform || layout->flags.q.buffer) &&
- (field_type->without_array()->is_matrix()
- || field_type->without_array()->is_struct())) {
+ (glsl_type_is_matrix(glsl_without_array(field_type))
+ || glsl_type_is_struct(glsl_without_array(field_type)))) {
/* If no layout is specified for the field, inherit the layout
* from the block.
*/
@@ -7761,7 +7868,7 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
* the format qualifier is only accepted for images.
*/
if (var_mode == ir_var_shader_storage ||
- field_type->without_array()->is_image()) {
+ glsl_type_is_image(glsl_without_array(field_type))) {
/* For readonly and writeonly qualifiers the field definition,
* if set, overwrites the layout qualifier.
*/
@@ -7785,10 +7892,10 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
fields[i].memory_restrict = qual->flags.q.restrict_flag ||
(layout && layout->flags.q.restrict_flag);
- if (field_type->without_array()->is_image()) {
+ if (glsl_type_is_image(glsl_without_array(field_type))) {
if (qual->flags.q.explicit_image_format) {
if (qual->image_base_type !=
- field_type->without_array()->sampled_type) {
+ glsl_without_array(field_type)->sampled_type) {
_mesa_glsl_error(&loc, state, "format qualifier doesn't "
"match the base data type of the image");
}
@@ -7826,6 +7933,12 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
return decl_count;
}
+static bool
+is_anonymous(const glsl_type *t)
+{
+ /* See handling for struct_specifier in glsl_parser.yy. */
+ return !strncmp(glsl_get_type_name(t), "#anon", 5);
+}
ir_rvalue *
ast_struct_specifier::hir(exec_list *instructions,
@@ -7862,12 +7975,12 @@ ast_struct_specifier::hir(exec_list *instructions,
validate_identifier(this->name, loc, state);
- type = glsl_type::get_struct_instance(fields, decl_count, this->name);
+ type = glsl_struct_type(fields, decl_count, this->name, false /* packed */);
- if (!type->is_anonymous() && !state->symbols->add_type(name, type)) {
+ if (!is_anonymous(type) && !state->symbols->add_type(name, type)) {
const glsl_type *match = state->symbols->get_type(name);
/* allow struct matching for desktop GL - older UE4 does this */
- if (match != NULL && state->is_version(130, 0) && match->record_compare(type, true, false))
+ if (match != NULL && state->is_version(130, 0) && glsl_record_compare(match, type, true, false, true))
_mesa_glsl_warning(& loc, state, "struct `%s' previously defined", name);
else
_mesa_glsl_error(& loc, state, "struct `%s' previously defined", name);
@@ -7925,7 +8038,7 @@ is_unsized_array_last_element(ir_variable *v)
const glsl_type *interface_type = v->get_interface_type();
int length = interface_type->length;
- assert(v->type->is_unsized_array());
+ assert(glsl_type_is_unsized_array(v->type));
/* Check if it is the last element of the interface */
if (strcmp(interface_type->fields.structure[length-1].name, v->name) == 0)
@@ -8004,21 +8117,21 @@ ast_interface_block::hir(exec_list *instructions,
if (this->layout.flags.q.out) {
allowed_blk_qualifiers.flags.q.out = 1;
if (state->stage == MESA_SHADER_GEOMETRY ||
- state->stage == MESA_SHADER_TESS_CTRL ||
- state->stage == MESA_SHADER_TESS_EVAL ||
- state->stage == MESA_SHADER_VERTEX ) {
+ state->stage == MESA_SHADER_TESS_CTRL ||
+ state->stage == MESA_SHADER_TESS_EVAL ||
+ state->stage == MESA_SHADER_VERTEX ) {
allowed_blk_qualifiers.flags.q.explicit_xfb_offset = 1;
allowed_blk_qualifiers.flags.q.explicit_xfb_buffer = 1;
allowed_blk_qualifiers.flags.q.xfb_buffer = 1;
allowed_blk_qualifiers.flags.q.explicit_xfb_stride = 1;
allowed_blk_qualifiers.flags.q.xfb_stride = 1;
- if (state->stage == MESA_SHADER_GEOMETRY) {
- allowed_blk_qualifiers.flags.q.stream = 1;
- allowed_blk_qualifiers.flags.q.explicit_stream = 1;
- }
- if (state->stage == MESA_SHADER_TESS_CTRL) {
- allowed_blk_qualifiers.flags.q.patch = 1;
- }
+ }
+ if (state->stage == MESA_SHADER_GEOMETRY) {
+ allowed_blk_qualifiers.flags.q.stream = 1;
+ allowed_blk_qualifiers.flags.q.explicit_stream = 1;
+ }
+ if (state->stage == MESA_SHADER_TESS_CTRL) {
+ allowed_blk_qualifiers.flags.q.patch = 1;
}
} else {
allowed_blk_qualifiers.flags.q.in = 1;
@@ -8094,11 +8207,13 @@ ast_interface_block::hir(exec_list *instructions,
return NULL;
}
- unsigned qual_xfb_buffer;
- if (!process_qualifier_constant(state, &loc, "xfb_buffer",
- layout.xfb_buffer, &qual_xfb_buffer) ||
- !validate_xfb_buffer_qualifier(&loc, state, qual_xfb_buffer)) {
- return NULL;
+ unsigned qual_xfb_buffer = 0;
+ if (layout.flags.q.xfb_buffer) {
+ if (!process_qualifier_constant(state, &loc, "xfb_buffer",
+ layout.xfb_buffer, &qual_xfb_buffer) ||
+ !validate_xfb_buffer_qualifier(&loc, state, qual_xfb_buffer)) {
+ return NULL;
+ }
}
unsigned qual_xfb_offset = 0;
@@ -8168,7 +8283,7 @@ ast_interface_block::hir(exec_list *instructions,
* scope for anything other than as a block name."
*/
ir_variable *var = state->symbols->get_variable(this->block_name);
- if (var && !var->type->is_interface()) {
+ if (var && !glsl_type_is_interface(var->type)) {
_mesa_glsl_error(&loc, state, "Block name `%s' is "
"already used in the scope.",
this->block_name);
@@ -8249,7 +8364,7 @@ ast_interface_block::hir(exec_list *instructions,
/* Copy locations from the old gl_PerVertex interface block. */
for (unsigned i = 0; i < num_variables; i++) {
- int j = earlier_per_vertex->field_index(fields[i].name);
+ int j = glsl_get_field_index(earlier_per_vertex, fields[i].name);
if (j == -1) {
_mesa_glsl_error(&loc, state,
"redeclaration of gl_PerVertex must be a subset "
@@ -8300,20 +8415,20 @@ ast_interface_block::hir(exec_list *instructions,
}
const glsl_type *block_type =
- glsl_type::get_interface_instance(fields,
- num_variables,
- packing,
- matrix_layout ==
- GLSL_MATRIX_LAYOUT_ROW_MAJOR,
- this->block_name);
-
- unsigned component_size = block_type->contains_double() ? 8 : 4;
+ glsl_interface_type(fields,
+ num_variables,
+ packing,
+ matrix_layout ==
+ GLSL_MATRIX_LAYOUT_ROW_MAJOR,
+ this->block_name);
+
+ unsigned component_size = glsl_contains_double(block_type) ? 8 : 4;
int xfb_offset =
layout.flags.q.explicit_xfb_offset ? (int) qual_xfb_offset : -1;
validate_xfb_offset_qualifier(&loc, state, xfb_offset, block_type,
component_size);
- if (!state->symbols->add_interface(block_type->name, block_type, var_mode)) {
+ if (!state->symbols->add_interface(glsl_get_type_name(block_type), block_type, var_mode)) {
YYLTYPE loc = this->get_location();
_mesa_glsl_error(&loc, state, "interface block `%s' with type `%s' "
"already taken in the current scope",
@@ -8368,8 +8483,8 @@ ast_interface_block::hir(exec_list *instructions,
* of the interface that are arrays.
*/
for (unsigned i = 0; i < num_variables; i++) {
- if (fields[i].type->is_array()) {
- const unsigned size = fields[i].type->array_size();
+ if (glsl_type_is_array(fields[i].type)) {
+ const unsigned size = glsl_array_size(fields[i].type);
check_builtin_array_max_size(fields[i].name, size, loc, state);
}
}
@@ -8383,6 +8498,59 @@ ast_interface_block::hir(exec_list *instructions,
const glsl_type *block_array_type =
process_array_type(&loc, block_type, this->array_specifier, state);
+ /* From Section 4.4.1 (Input Layout Qualifiers) of the GLSL 4.50 spec:
+ *
+ * "For some blocks declared as arrays, the location can only be applied
+ * at the block level: When a block is declared as an array where
+ * additional locations are needed for each member for each block array
+ * element, it is a compile-time error to specify locations on the block
+ * members. That is, when locations would be under specified by applying
+ * them on block members, they are not allowed on block members. For
+ * arrayed interfaces (those generally having an extra level of
+ * arrayness due to interface expansion), the outer array is stripped
+ * before applying this rule"
+ *
+ * From 4.4.1 (Input Layout Qualifiers) and
+ * 4.4.2 (Output Layout Qualifiers) of GLSL ES 3.20
+ *
+ * "If an input is declared as an array of blocks, excluding
+ * per-vertex-arrays as required for tessellation, it is an error
+ * to declare a member of the block with a location qualifier."
+ *
+ * "If an output is declared as an array of blocks, excluding
+ * per-vertex-arrays as required for tessellation, it is an error
+ * to declare a member of the block with a location qualifier."
+ */
+ if (!redeclaring_per_vertex &&
+ (state->has_enhanced_layouts() || state->has_shader_io_blocks())) {
+ bool allow_location;
+ switch (state->stage)
+ {
+ case MESA_SHADER_TESS_CTRL:
+ allow_location = this->array_specifier->is_single_dimension();
+ break;
+ case MESA_SHADER_TESS_EVAL:
+ case MESA_SHADER_GEOMETRY:
+ allow_location = (this->array_specifier->is_single_dimension()
+ && var_mode == ir_var_shader_in);
+ break;
+ default:
+ allow_location = false;
+ break;
+ }
+
+ if (!allow_location) {
+ for (unsigned i = 0; i < num_variables; i++) {
+ if (fields[i].location != -1) {
+ _mesa_glsl_error(&loc, state,
+ "explicit member locations are not allowed in "
+ "blocks declared as arrays %s shader",
+ _mesa_shader_stage_to_string(state->stage));
+ }
+ }
+ }
+ }
+
/* Section 4.3.7 (Interface Blocks) of the GLSL 1.50 spec says:
*
* For uniform blocks declared an array, each individual array
@@ -8406,7 +8574,7 @@ ast_interface_block::hir(exec_list *instructions,
* tessellation control shader output, and tessellation evaluation
* shader input.
*/
- if (block_array_type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(block_array_type)) {
bool allow_inputs = state->stage == MESA_SHADER_GEOMETRY ||
state->stage == MESA_SHADER_TESS_CTRL ||
state->stage == MESA_SHADER_TESS_EVAL;
@@ -8437,8 +8605,8 @@ ast_interface_block::hir(exec_list *instructions,
*
* * Arrays of arrays of blocks are not allowed
*/
- if (state->es_shader && block_array_type->is_array() &&
- block_array_type->fields.array->is_array()) {
+ if (state->es_shader && glsl_type_is_array(block_array_type) &&
+ glsl_type_is_array(block_array_type->fields.array)) {
_mesa_glsl_error(&loc, state,
"arrays of arrays interface blocks are "
"not allowed");
@@ -8585,7 +8753,7 @@ ast_interface_block::hir(exec_list *instructions,
var->get_interface_type(), &this->layout);
}
- if (var->type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(var->type)) {
if (var->is_in_shader_storage_block() &&
is_unsized_array_last_element(var)) {
var->data.from_ssbo_unsized_array = true;
@@ -8696,7 +8864,7 @@ ast_tcs_output_layout::hir(exec_list *instructions,
continue;
/* Note: Not all tessellation control shader output are arrays. */
- if (!var->type->is_unsized_array() || var->data.patch)
+ if (!glsl_type_is_unsized_array(var->type) || var->data.patch)
continue;
if (var->data.max_array_access >= (int)num_vertices) {
@@ -8706,8 +8874,8 @@ ast_tcs_output_layout::hir(exec_list *instructions,
"%u of output `%s' already exists", num_vertices,
var->data.max_array_access, var->name);
} else {
- var->type = glsl_type::get_array_instance(var->type->fields.array,
- num_vertices);
+ var->type = glsl_array_type(var->type->fields.array,
+ num_vertices, 0);
}
}
@@ -8729,7 +8897,8 @@ ast_gs_input_layout::hir(exec_list *instructions,
* array size, make sure the size they specified is consistent with the
* primitive type.
*/
- unsigned num_vertices = vertices_per_prim(this->prim_type);
+ unsigned num_vertices =
+ mesa_vertices_per_prim(gl_to_mesa_prim(this->prim_type));
if (state->gs_input_size != 0 && state->gs_input_size != num_vertices) {
_mesa_glsl_error(&loc, state,
"this geometry shader input layout implies %u vertices"
@@ -8752,7 +8921,7 @@ ast_gs_input_layout::hir(exec_list *instructions,
* array; skip it.
*/
- if (var->type->is_unsized_array()) {
+ if (glsl_type_is_unsized_array(var->type)) {
if (var->data.max_array_access >= (int)num_vertices) {
_mesa_glsl_error(&loc, state,
"this geometry shader input layout implies %u"
@@ -8760,8 +8929,8 @@ ast_gs_input_layout::hir(exec_list *instructions,
" `%s' already exists", num_vertices,
var->data.max_array_access, var->name);
} else {
- var->type = glsl_type::get_array_instance(var->type->fields.array,
- num_vertices);
+ var->type = glsl_array_type(var->type->fields.array,
+ num_vertices, 0);
}
}
}
@@ -8804,20 +8973,20 @@ ast_cs_input_layout::hir(exec_list *instructions,
}
ralloc_free(local_size_str);
- if (qual_local_size[i] > state->ctx->Const.MaxComputeWorkGroupSize[i]) {
+ if (qual_local_size[i] > state->consts->MaxComputeWorkGroupSize[i]) {
_mesa_glsl_error(&loc, state,
"local_size_%c exceeds MAX_COMPUTE_WORK_GROUP_SIZE"
" (%d)", 'x' + i,
- state->ctx->Const.MaxComputeWorkGroupSize[i]);
+ state->consts->MaxComputeWorkGroupSize[i]);
break;
}
total_invocations *= qual_local_size[i];
if (total_invocations >
- state->ctx->Const.MaxComputeWorkGroupInvocations) {
+ state->consts->MaxComputeWorkGroupInvocations) {
_mesa_glsl_error(&loc, state,
"product of local_sizes exceeds "
"MAX_COMPUTE_WORK_GROUP_INVOCATIONS (%d)",
- state->ctx->Const.MaxComputeWorkGroupInvocations);
+ state->consts->MaxComputeWorkGroupInvocations);
break;
}
}
@@ -8859,7 +9028,7 @@ ast_cs_input_layout::hir(exec_list *instructions,
* declare it earlier).
*/
ir_variable *var = new(state->symbols)
- ir_variable(glsl_type::uvec3_type, "gl_WorkGroupSize", ir_var_auto);
+ ir_variable(&glsl_type_builtin_uvec3, "gl_WorkGroupSize", ir_var_auto);
var->data.how_declared = ir_var_declared_implicitly;
var->data.read_only = true;
instructions->push_tail(var);
@@ -8868,9 +9037,9 @@ ast_cs_input_layout::hir(exec_list *instructions,
memset(&data, 0, sizeof(data));
for (int i = 0; i < 3; i++)
data.u[i] = qual_local_size[i];
- var->constant_value = new(var) ir_constant(glsl_type::uvec3_type, &data);
+ var->constant_value = new(var) ir_constant(&glsl_type_builtin_uvec3, &data);
var->constant_initializer =
- new(var) ir_constant(glsl_type::uvec3_type, &data);
+ new(var) ir_constant(&glsl_type_builtin_uvec3, &data);
var->data.has_initializer = true;
var->data.is_implicit_initializer = false;
@@ -9047,7 +9216,8 @@ remove_per_vertex_blocks(exec_list *instructions,
foreach_in_list_safe(ir_instruction, node, instructions) {
ir_variable *const var = node->as_variable();
if (var != NULL && var->get_interface_type() == per_vertex &&
- var->data.mode == mode) {
+ var->data.mode == mode &&
+ var->data.how_declared == ir_var_declared_implicitly) {
state->symbols->disable_variable(var->name);
var->remove();
}