Module: Mesa Branch: staging/21.1 Commit: e288e88bcfb7f85987f7d7ee2b8b4e5a3d06d9d5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e288e88bcfb7f85987f7d7ee2b8b4e5a3d06d9d5
Author: Timothy Arceri <[email protected]> Date: Wed May 12 15:42:44 2021 +1000 glsl: create validate_component_layout_for_type() helper This will be used in the following patch. Reviewed-by: Alejandro PiƱeiro <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10763> (cherry picked from commit 1a71d6aa6e13179526b41e627f00af25b1612556) --- .pick_status.json | 2 +- src/compiler/glsl/ast_to_hir.cpp | 57 ++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index d45e07daf32..55a7ba96c74 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -805,7 +805,7 @@ "description": "glsl: create validate_component_layout_for_type() helper", "nominated": false, "nomination_type": null, - "resolution": 4, + "resolution": 1, "master_sha": null, "because_sha": null }, diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 137ef66ca60..b0918386cbb 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -2740,6 +2740,33 @@ is_allowed_invariant(ir_variable *var, struct _mesa_glsl_parse_state *state) return false; } +static void +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(); + + if (type->is_matrix() || type->is_struct()) { + _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()) { + _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()) { + /* We don't bother checking for 3 as it should be caught by the + * overflow check above. + */ + _mesa_glsl_error(loc, state, "doubles cannot begin at component 1 or 3"); + } +} + /** * Matrix layout qualifiers are only allowed on certain types */ @@ -3712,32 +3739,10 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual, unsigned qual_component; if (process_qualifier_constant(state, loc, "component", qual->component, &qual_component)) { - const glsl_type *type = var->type->without_array(); - unsigned components = type->component_slots(); - - if (type->is_matrix() || type->is_struct()) { - _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()) { - _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()) { - /* We don't bother checking for 3 as it should be caught by the - * overflow check above. - */ - _mesa_glsl_error(loc, state, "doubles cannot begin at " - "component 1 or 3"); - } else { - var->data.explicit_component = true; - var->data.location_frac = qual_component; - } + validate_component_layout_for_type(state, loc, var->type, + qual_component); + var->data.explicit_component = true; + var->data.location_frac = qual_component; } } } else if (qual->flags.q.explicit_index) { _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
