glsl: simplify apply_image_qualifier_to_variable()

This removes one level of indentation and will improve readability
for bindless images.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Samuel Pitoiset
2017-04-12 14:36:32 +02:00
parent 6bb0f75bb6
commit d5cd4990cd

View File

@@ -3303,7 +3303,19 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
{ {
const glsl_type *base_type = var->type->without_array(); const glsl_type *base_type = var->type->without_array();
if (base_type->is_image()) { if (!base_type->is_image()) {
if (qual->flags.q.read_only ||
qual->flags.q.write_only ||
qual->flags.q.coherent ||
qual->flags.q._volatile ||
qual->flags.q.restrict_flag ||
qual->flags.q.explicit_image_format) {
_mesa_glsl_error(loc, state, "memory qualifiers may only be applied "
"to images");
}
return;
}
if (var->data.mode != ir_var_uniform && if (var->data.mode != ir_var_uniform &&
var->data.mode != ir_var_function_in) { var->data.mode != ir_var_function_in) {
_mesa_glsl_error(loc, state, "image variables may only be declared as " _mesa_glsl_error(loc, state, "image variables may only be declared as "
@@ -3320,37 +3332,34 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
if (qual->flags.q.explicit_image_format) { if (qual->flags.q.explicit_image_format) {
if (var->data.mode == ir_var_function_in) { if (var->data.mode == ir_var_function_in) {
_mesa_glsl_error(loc, state, "format qualifiers cannot be " _mesa_glsl_error(loc, state, "format qualifiers cannot be used on "
"used on image function parameters"); "image function parameters");
} }
if (qual->image_base_type != base_type->sampled_type) { if (qual->image_base_type != base_type->sampled_type) {
_mesa_glsl_error(loc, state, "format qualifier doesn't match the " _mesa_glsl_error(loc, state, "format qualifier doesn't match the base "
"base data type of the image"); "data type of the image");
} }
var->data.image_format = qual->image_format; var->data.image_format = qual->image_format;
} else { } else {
if (var->data.mode == ir_var_uniform) { if (var->data.mode == ir_var_uniform) {
if (state->es_shader) { if (state->es_shader) {
_mesa_glsl_error(loc, state, "all image uniforms " _mesa_glsl_error(loc, state, "all image uniforms must have a "
"must have a format layout qualifier"); "format layout qualifier");
} else if (!qual->flags.q.write_only) { } else if (!qual->flags.q.write_only) {
_mesa_glsl_error(loc, state, "image uniforms not qualified with " _mesa_glsl_error(loc, state, "image uniforms not qualified with "
"`writeonly' must have a format layout " "`writeonly' must have a format layout qualifier");
"qualifier");
} }
} }
var->data.image_format = GL_NONE; var->data.image_format = GL_NONE;
} }
/* From page 70 of the GLSL ES 3.1 specification: /* From page 70 of the GLSL ES 3.1 specification:
* *
* "Except for image variables qualified with the format qualifiers * "Except for image variables qualified with the format qualifiers r32f,
* r32f, r32i, and r32ui, image variables must specify either memory * r32i, and r32ui, image variables must specify either memory qualifier
* qualifier readonly or the memory qualifier writeonly." * readonly or the memory qualifier writeonly."
*/ */
if (state->es_shader && if (state->es_shader &&
var->data.image_format != GL_R32F && var->data.image_format != GL_R32F &&
@@ -3358,20 +3367,10 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
var->data.image_format != GL_R32UI && var->data.image_format != GL_R32UI &&
!var->data.image_read_only && !var->data.image_read_only &&
!var->data.image_write_only) { !var->data.image_write_only) {
_mesa_glsl_error(loc, state, "image variables of format other than " _mesa_glsl_error(loc, state, "image variables of format other than r32f, "
"r32f, r32i or r32ui must be qualified `readonly' or " "r32i or r32ui must be qualified `readonly' or "
"`writeonly'"); "`writeonly'");
} }
} else if (qual->flags.q.read_only ||
qual->flags.q.write_only ||
qual->flags.q.coherent ||
qual->flags.q._volatile ||
qual->flags.q.restrict_flag ||
qual->flags.q.explicit_image_format) {
_mesa_glsl_error(loc, state, "memory qualifiers may only be applied to "
"images");
}
} }
static inline const char* static inline const char*