Mesa (glsl2): glsl2: Fix standalone compiler to not crash horribly.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Jul 22 23:47:48 UTC 2010


Module: Mesa
Branch: glsl2
Commit: aa9f86ae8b3bb2172092ff9b50751677c509e6b4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=aa9f86ae8b3bb2172092ff9b50751677c509e6b4

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Thu Jul 22 16:20:36 2010 -0700

glsl2: Fix standalone compiler to not crash horribly.

ir_to_mesa was updated for the _mesa_glsl_parse_state constructor
changes, but main.cpp was not.

---

 src/glsl/glsl_parser_extras.cpp |   23 ++++++++++++++++++++
 src/glsl/main.cpp               |   45 +++-----------------------------------
 2 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index bcf2579..009aabc 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -68,10 +68,33 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct __GLcontextRec *ctx,
 
       this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
    } else {
+      /* If there is no GL context (standalone compiler), fill in constants
+       * with the minimum required values.
+       */
       static struct gl_extensions null_extensions;
 
       memset(&null_extensions, 0, sizeof(null_extensions));
       this->extensions = &null_extensions;
+
+      /* 1.10 minimums. */
+      this->Const.MaxLights = 8;
+      this->Const.MaxClipPlanes = 8;
+      this->Const.MaxTextureUnits = 2;
+
+      /* More than the 1.10 minimum to appease parser tests taken from
+       * apps that (hopefully) already checked the number of coords.
+       */
+      this->Const.MaxTextureCoords = 4;
+
+      this->Const.MaxVertexAttribs = 16;
+      this->Const.MaxVertexUniformComponents = 512;
+      this->Const.MaxVaryingFloats = 32;
+      this->Const.MaxVertexTextureImageUnits = 0;
+      this->Const.MaxCombinedTextureImageUnits = 2;
+      this->Const.MaxTextureImageUnits = 2;
+      this->Const.MaxFragmentUniformComponents = 64;
+
+      this->Const.MaxDrawBuffers = 2;
    }
 }
 
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 2ecf57f..5c0f647 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -121,49 +121,12 @@ const struct option compiler_opts[] = {
 void
 compile_shader(struct gl_shader *shader)
 {
-   struct _mesa_glsl_parse_state *state;
-   struct gl_extensions ext;
-
-   state = talloc_zero(talloc_parent(shader), struct _mesa_glsl_parse_state);
-
-   switch (shader->Type) {
-   case GL_VERTEX_SHADER:   state->target = vertex_shader; break;
-   case GL_FRAGMENT_SHADER: state->target = fragment_shader; break;
-   case GL_GEOMETRY_SHADER: state->target = geometry_shader; break;
-   }
-
-   state->scanner = NULL;
-   state->translation_unit.make_empty();
-   state->symbols = new(shader) glsl_symbol_table;
-   state->info_log = talloc_strdup(shader, "");
-   state->error = false;
-   state->loop_or_switch_nesting = NULL;
-   state->ARB_texture_rectangle_enable = true;
-
-   memset(&ext, 0, sizeof(ext));
-   state->extensions = &ext;
-   /* 1.10 minimums. */
-   state->Const.MaxLights = 8;
-   state->Const.MaxClipPlanes = 8;
-   state->Const.MaxTextureUnits = 2;
-
-   /* More than the 1.10 minimum to appease parser tests taken from
-    * apps that (hopefully) already checked the number of coords.
-    */
-   state->Const.MaxTextureCoords = 4;
-
-   state->Const.MaxVertexAttribs = 16;
-   state->Const.MaxVertexUniformComponents = 512;
-   state->Const.MaxVaryingFloats = 32;
-   state->Const.MaxVertexTextureImageUnits = 0;
-   state->Const.MaxCombinedTextureImageUnits = 2;
-   state->Const.MaxTextureImageUnits = 2;
-   state->Const.MaxFragmentUniformComponents = 64;
-
-   state->Const.MaxDrawBuffers = 2;
+   struct _mesa_glsl_parse_state *state =
+      new(shader) _mesa_glsl_parse_state(NULL, shader->Type, shader);
 
    const char *source = shader->Source;
-   state->error = preprocess(state, &source, &state->info_log, &ext);
+   state->error = preprocess(state, &source, &state->info_log,
+			     state->extensions);
 
    if (!state->error) {
       _mesa_glsl_lexer_ctor(state, source);




More information about the mesa-commit mailing list