Mesa (staging/21.1): glsl: force_glsl_version to shaders with no defined version

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 30 08:10:55 UTC 2021


Module: Mesa
Branch: staging/21.1
Commit: 7086b413de7f500dd3150c73ac8d430f1c6807ca
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7086b413de7f500dd3150c73ac8d430f1c6807ca

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Fri Jun 25 20:30:32 2021 +1000

glsl: force_glsl_version to shaders with no defined version

If a shader has no defined version force_glsl_version was
previous ignored and the shader would default to 110. This updates
the code so that those shaders are forced to a new level also.

We reused the existing code to make sure a sensible value is set
for the version.

Cc: mesa-stable

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11602>
(cherry picked from commit e607205af06ed22a4ac8e32a9b92fe0d7197aac9)

---

 .pick_status.json                        |  2 +-
 src/compiler/glsl/glsl_parser_extras.cpp | 86 +++++++++++++++++++-------------
 src/compiler/glsl/glsl_parser_extras.h   |  2 +
 3 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 5b36ef9ef8a..baa8338cd7f 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -490,7 +490,7 @@
         "description": "glsl: force_glsl_version to shaders with no defined version",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 7daf65bef6d..f210b08392d 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -329,6 +329,10 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
    this->bindless_image_specified = false;
    this->bound_sampler_specified = false;
    this->bound_image_specified = false;
+
+   this->language_version = this->forced_language_version ?
+      this->forced_language_version : this->language_version;
+   set_valid_gl_and_glsl_versions(NULL);
 }
 
 /**
@@ -382,6 +386,52 @@ _mesa_glsl_parse_state::check_version(unsigned required_glsl_version,
    return false;
 }
 
+/**
+ * This makes sure any GLSL versions defined or overridden are valid. If not it
+ * sets a valid value.
+ */
+void
+_mesa_glsl_parse_state::set_valid_gl_and_glsl_versions(YYLTYPE *locp)
+{
+   bool supported = false;
+   for (unsigned i = 0; i < this->num_supported_versions; i++) {
+      if (this->supported_versions[i].ver == this->language_version
+          && this->supported_versions[i].es == this->es_shader) {
+         this->gl_version = this->supported_versions[i].gl_ver;
+         supported = true;
+         break;
+      }
+   }
+
+   if (!supported) {
+      if (locp) {
+         _mesa_glsl_error(locp, this, "%s is not supported. "
+                          "Supported versions are: %s",
+                          this->get_version_string(),
+                          this->supported_version_string);
+      }
+
+      /* On exit, the language_version must be set to a valid value.
+       * Later calls to _mesa_glsl_initialize_types will misbehave if
+       * the version is invalid.
+       */
+      switch (this->ctx->API) {
+      case API_OPENGL_COMPAT:
+      case API_OPENGL_CORE:
+	 this->language_version = this->ctx->Const.GLSLVersion;
+	 break;
+
+      case API_OPENGLES:
+	 assert(!"Should not get here.");
+	 /* FALLTHROUGH */
+
+      case API_OPENGLES2:
+	 this->language_version = 100;
+	 break;
+      }
+   }
+}
+
 /**
  * Process a GLSL #version directive.
  *
@@ -447,41 +497,7 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version,
                           this->language_version == 140) ||
                          (!this->es_shader && this->language_version < 140);
 
-   bool supported = false;
-   for (unsigned i = 0; i < this->num_supported_versions; i++) {
-      if (this->supported_versions[i].ver == this->language_version
-          && this->supported_versions[i].es == this->es_shader) {
-         this->gl_version = this->supported_versions[i].gl_ver;
-         supported = true;
-         break;
-      }
-   }
-
-   if (!supported) {
-      _mesa_glsl_error(locp, this, "%s is not supported. "
-                       "Supported versions are: %s",
-                       this->get_version_string(),
-                       this->supported_version_string);
-
-      /* On exit, the language_version must be set to a valid value.
-       * Later calls to _mesa_glsl_initialize_types will misbehave if
-       * the version is invalid.
-       */
-      switch (this->ctx->API) {
-      case API_OPENGL_COMPAT:
-      case API_OPENGL_CORE:
-	 this->language_version = this->ctx->Const.GLSLVersion;
-	 break;
-
-      case API_OPENGLES:
-	 assert(!"Should not get here.");
-	 /* FALLTHROUGH */
-
-      case API_OPENGLES2:
-	 this->language_version = 100;
-	 break;
-      }
-   }
+   set_valid_gl_and_glsl_versions(locp);
 }
 
 
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index efd9e05f4d5..18e3f86a64f 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -368,6 +368,8 @@ struct _mesa_glsl_parse_state {
              is_version(400, 0);
    }
 
+   void set_valid_gl_and_glsl_versions(YYLTYPE *locp);
+
    void process_version_directive(YYLTYPE *locp, int version,
                                   const char *ident);
 



More information about the mesa-commit mailing list