[Mesa-dev] [PATCH 06/11] glsl: apply some 1.30 rules to EXT_gpu_shader4 as well

Marek Olšák maraeo at gmail.com
Wed Aug 8 05:42:03 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/compiler/glsl/ast_to_hir.cpp       | 14 +++++++++-----
 src/compiler/glsl/glsl_parser_extras.h |  3 ++-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 74160ec142b..d6f1c765790 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -603,21 +603,22 @@ bit_logic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
        return type_a;
 }
 
 static const struct glsl_type *
 modulus_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
                     struct _mesa_glsl_parse_state *state, YYLTYPE *loc)
 {
    const glsl_type *type_a = value_a->type;
    const glsl_type *type_b = value_b->type;
 
-   if (!state->check_version(130, 300, loc, "operator '%%' is reserved")) {
+   if (!state->EXT_gpu_shader4_enable &&
+       !state->check_version(130, 300, loc, "operator '%%' is reserved")) {
       return glsl_type::error_type;
    }
 
    /* Section 5.9 (Expressions) of the GLSL 4.00 specification says:
     *
     *    "The operator modulus (%) operates on signed or unsigned integers or
     *    integer vectors."
     */
    if (!type_a->is_integer_32_64()) {
       _mesa_glsl_error(loc, state, "LHS of operator %% must be an integer");
@@ -2992,21 +2993,21 @@ validate_fragment_flat_interpolation_input(struct _mesa_glsl_parse_state *state,
     * outputs rather than fragment inputs.  That creates problems in the
     * presence of geometry shaders, so we adopt the GLSL 1.50 rule for all
     * desktop GL shaders.  For GLSL ES shaders, we follow the spec and
     * apply the restriction to both vertex outputs and fragment inputs.
     *
     * Note also that the desktop GLSL specs are missing the text "or
     * contain"; this is presumably an oversight, since there is no
     * reasonable way to interpolate a fragment shader input that contains
     * an integer. See Khronos bug #15671.
     */
-   if (state->is_version(130, 300)
+   if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
        && var_type->contains_integer()) {
       _mesa_glsl_error(loc, state, "if a fragment input is (or contains) "
                        "an integer, then it must be qualified with 'flat'");
    }
 
    /* Double fragment inputs must be qualified with 'flat'.
     *
     * From the "Overview" of the ARB_gpu_shader_fp64 extension spec:
     *    "This extension does not support interpolation of double-precision
     *    values; doubles used as fragment shader inputs must be qualified as
@@ -3073,21 +3074,21 @@ validate_interpolation_qualifier(struct _mesa_glsl_parse_state *state,
     *
     * From section 4.3 ("Storage Qualifiers") of the GLSL ES 3.00 spec:
     *    "Outputs from a shader (out) and inputs to a shader (in) can be
     *    further qualified with one of these interpolation qualifiers."
     *    ...
     *    "These interpolation qualifiers may only precede the qualifiers
     *    in, centroid in, out, or centroid out in a declaration. They do
     *    not apply to inputs into a vertex shader or outputs from a
     *    fragment shader."
     */
-   if (state->is_version(130, 300)
+   if ((state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
        && interpolation != INTERP_MODE_NONE) {
       const char *i = interpolation_string(interpolation);
       if (mode != ir_var_shader_in && mode != ir_var_shader_out)
          _mesa_glsl_error(loc, state,
                           "interpolation qualifier `%s' can only be applied to "
                           "shader inputs or outputs.", i);
 
       switch (state->stage) {
       case MESA_SHADER_VERTEX:
          if (mode == ir_var_shader_in) {
@@ -3110,22 +3111,24 @@ validate_interpolation_qualifier(struct _mesa_glsl_parse_state *state,
 
    /* Interpolation qualifiers cannot be applied to 'centroid' and
     * 'centroid varying'.
     *
     * From section 4.3 ("Storage Qualifiers") of the GLSL 1.30 spec:
     *    "interpolation qualifiers may only precede the qualifiers in,
     *    centroid in, out, or centroid out in a declaration. They do not apply
     *    to the deprecated storage qualifiers varying or centroid varying."
     *
     * These deprecated storage qualifiers do not exist in GLSL ES 3.00.
+    *
+    * GL_EXT_gpu_shader4 allows this.
     */
-   if (state->is_version(130, 0)
+   if (state->is_version(130, 0) && !state->EXT_gpu_shader4_enable
        && interpolation != INTERP_MODE_NONE
        && qual->flags.q.varying) {
 
       const char *i = interpolation_string(interpolation);
       const char *s;
       if (qual->flags.q.centroid)
          s = "centroid varying";
       else
          s = "varying";
 
@@ -4101,21 +4104,21 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
        *     floating-point vectors, matrices, signed or unsigned integers or
        *     integer vectors, sampler or image types, or arrays or structures
        *     of any these."
        */
       switch (var->type->without_array()->base_type) {
       case GLSL_TYPE_FLOAT:
          /* Ok in all GLSL versions */
          break;
       case GLSL_TYPE_UINT:
       case GLSL_TYPE_INT:
-         if (state->is_version(130, 300))
+         if (state->is_version(130, 300) || state->EXT_gpu_shader4_enable)
             break;
          _mesa_glsl_error(loc, state,
                           "varying variables must be of base type float in %s",
                           state->get_version_string());
          break;
       case GLSL_TYPE_STRUCT:
          if (state->is_version(150, 300))
             break;
          _mesa_glsl_error(loc, state,
                           "varying variables may not be of type struct");
@@ -5094,20 +5097,21 @@ ast_declarator_list::hir(exec_list *instructions,
        *     "Global variables can only use the qualifiers const,
        *     attribute, uniform, or varying. Only one may be
        *     specified.
        *
        *     Local variables can only use the qualifier const."
        *
        * This is relaxed in GLSL 1.30 and GLSL ES 3.00.  It is also relaxed by
        * any extension that adds the 'layout' keyword.
        */
       if (!state->is_version(130, 300)
+          && !state->EXT_gpu_shader4_enable
           && !state->has_explicit_attrib_location()
           && !state->has_separate_shader_objects()
           && !state->ARB_fragment_coord_conventions_enable) {
          if (this->type->qualifier.flags.q.out) {
             _mesa_glsl_error(& loc, state,
                              "`out' qualifier in declaration of `%s' "
                              "only valid for function parameters in %s",
                              decl->identifier, state->get_version_string());
          }
          if (this->type->qualifier.flags.q.in) {
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 9e8c944e973..4b4e4556124 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -134,21 +134,22 @@ struct _mesa_glsl_parse_state {
    }
 
    bool check_precision_qualifiers_allowed(YYLTYPE *locp)
    {
       return check_version(130, 100, locp,
                            "precision qualifiers are forbidden");
    }
 
    bool check_bitwise_operations_allowed(YYLTYPE *locp)
    {
-      return check_version(130, 300, locp, "bit-wise operations are forbidden");
+      return EXT_gpu_shader4_enable ||
+             check_version(130, 300, locp, "bit-wise operations are forbidden");
    }
 
    bool check_explicit_attrib_stream_allowed(YYLTYPE *locp)
    {
       if (!this->has_explicit_attrib_stream()) {
          const char *const requirement = "GL_ARB_gpu_shader5 extension or GLSL 4.00";
 
          _mesa_glsl_error(locp, this, "explicit stream requires %s",
                           requirement);
          return false;
-- 
2.17.1



More information about the mesa-dev mailing list