[Mesa-dev] [PATCH 11/23] glsl/ast: Validate and apply memory qualifiers to image variables.
Francisco Jerez
currojerez at riseup.net
Tue Nov 26 00:02:27 PST 2013
---
src/glsl/ast_to_hir.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index e7c4ff4..1d13a2c 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2154,6 +2154,54 @@ validate_explicit_location(const struct ast_type_qualifier *qual,
}
static void
+apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
+ ir_variable *var,
+ struct _mesa_glsl_parse_state *state,
+ YYLTYPE *loc)
+{
+ const glsl_type *base_type =
+ (var->type->is_array() ? var->type->element_type() : var->type);
+
+ if (base_type->is_image()) {
+ if (var->mode != ir_var_uniform &&
+ var->mode != ir_var_function_in) {
+ _mesa_glsl_error(loc, state, "image variables may only be declared as "
+ "function parameters or uniform-qualified "
+ "global variables");
+ }
+
+ var->image.read_only |= qual->flags.q.read_only;
+ var->image.write_only |= qual->flags.q.write_only;
+ var->image.coherent |= qual->flags.q.coherent;
+ var->image._volatile |= qual->flags.q._volatile;
+ var->image._restrict |= qual->flags.q._restrict;
+ var->read_only = true;
+
+ if (qual->flags.q.explicit_image_format) {
+ if (var->mode == ir_var_function_in) {
+ _mesa_glsl_error(loc, state, "format qualifiers cannot be "
+ "used on image function parameters");
+ }
+
+ if (qual->image_base_type != base_type->fields.image.type) {
+ _mesa_glsl_error(loc, state, "format qualifier doesn't match the "
+ "base data type of the image");
+ }
+
+ var->image.format = qual->image_format;
+ } else {
+ if (var->mode == ir_var_uniform && !qual->flags.q.write_only) {
+ _mesa_glsl_error(loc, state, "uniforms not qualified with "
+ "`writeonly' must have a format layout "
+ "qualifier");
+ }
+
+ var->image.format = GL_NONE;
+ }
+ }
+}
+
+static void
apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
ir_variable *var,
struct _mesa_glsl_parse_state *state,
@@ -2429,6 +2477,9 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
if (qual->flags.q.row_major || qual->flags.q.column_major) {
validate_matrix_layout_for_type(state, loc, var->type, var);
}
+
+ if (var->type->contains_image())
+ apply_image_qualifier_to_variable(qual, var, state, loc);
}
/**
--
1.8.3.4
More information about the mesa-dev
mailing list