[Mesa-dev] [PATCH 2/2] glsl: Create and use a has_uniform_buffer_objects() helper.

Kenneth Graunke kenneth at whitecape.org
Mon Sep 23 20:22:42 PDT 2013


This is better than overriding the extension enable based on the
language version; it's robust against shaders that do:

   #version 140
   #extension GL_ARB_uniform_buffer_object : disable

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Cc: Paul Berry <stereotype441 at gmail.com>
Cc: Ian Romanick <idr at freedesktop.org>
---
 src/glsl/glsl_parser.yy         | 6 +++---
 src/glsl/glsl_parser_extras.cpp | 4 ----
 src/glsl/glsl_parser_extras.h   | 5 +++++
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index 56ca4ad..912931a 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -1200,7 +1200,7 @@ layout_qualifier_id:
       }
 
       /* See also interface_block_layout_qualifier. */
-      if (!$$.flags.i && state->ARB_uniform_buffer_object_enable) {
+      if (!$$.flags.i && state->has_uniform_buffer_objects()) {
          if (strcmp($1, "std140") == 0) {
             $$.flags.q.std140 = 1;
          } else if (strcmp($1, "shared") == 0) {
@@ -1328,7 +1328,7 @@ layout_qualifier_id:
    {
       $$ = $1;
       /* Layout qualifiers for ARB_uniform_buffer_object. */
-      if ($$.flags.q.uniform && !state->ARB_uniform_buffer_object_enable) {
+      if ($$.flags.q.uniform && !state->has_uniform_buffer_objects()) {
          _mesa_glsl_error(& @1, state,
                           "#version 140 / GL_ARB_uniform_buffer_object "
                           "layout qualifier `%s' is used", $1);
@@ -2138,7 +2138,7 @@ basic_interface_block:
       block->declarations.push_degenerate_list_at_head(& $4->link);
 
       if ($1.flags.q.uniform) {
-         if (!state->ARB_uniform_buffer_object_enable) {
+         if (!state->has_uniform_buffer_objects()) {
             _mesa_glsl_error(& @1, state,
                              "#version 140 / GL_ARB_uniform_buffer_object "
                              "required for defining uniform blocks");
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index a2b52ef..e9922fc 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -299,10 +299,6 @@ _mesa_glsl_parse_state::process_version_directive(YYLTYPE *locp, int version,
 	 break;
       }
    }
-
-   if (this->language_version >= 140) {
-      this->ARB_uniform_buffer_object_enable = true;
-   }
 }
 
 extern "C" {
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 27ebbcf..cef4436 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -126,6 +126,11 @@ struct _mesa_glsl_parse_state {
       return ARB_explicit_attrib_location_enable || is_version(330, 300);
    }
 
+   bool has_uniform_buffer_objects() const
+   {
+      return ARB_uniform_buffer_object_enable || is_version(140, 300);
+   }
+
    void process_version_directive(YYLTYPE *locp, int version,
                                   const char *ident);
 
-- 
1.8.3.4



More information about the mesa-dev mailing list