Mesa (glsl2): glsl2: Pass MaxDrawBuffers from core Mesa into the GLSL compiler

Ian Romanick idr at kemper.freedesktop.org
Tue Jun 29 15:35:16 PDT 2010


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Jun 29 14:21:05 2010 -0700

glsl2: Pass MaxDrawBuffers from core Mesa into the GLSL compiler

---

 src/glsl/glsl_parser_extras.h  |    9 +++++++
 src/glsl/ir_variable.cpp       |   46 +++++++++++++++++++--------------------
 src/glsl/main.cpp              |    2 +
 src/mesa/shader/ir_to_mesa.cpp |    2 +
 4 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index 726bafa..f957a92 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -44,6 +44,15 @@ struct _mesa_glsl_parse_state {
    enum _mesa_glsl_parser_targets target;
 
    /**
+    * Implementation defined limits that affect built-in variables, etc.
+    *
+    * \sa struct gl_constants (in mtypes.h)
+    */
+   struct {
+      unsigned MaxDrawBuffers;
+   } Const;
+
+   /**
     * During AST to IR conversion, pointer to current IR function
     *
     * Will be \c NULL whenever the AST to IR conversion is not inside a
diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp
index 15a4a92..44c3065 100644
--- a/src/glsl/ir_variable.cpp
+++ b/src/glsl/ir_variable.cpp
@@ -221,20 +221,20 @@ initialize_vs_variables(exec_list *instructions,
 
 static void
 generate_110_fs_variables(exec_list *instructions,
-			  glsl_symbol_table *symtab)
+			  struct _mesa_glsl_parse_state *state)
 {
    for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
       add_builtin_variable(& builtin_core_fs_variables[i],
-			   instructions, symtab);
+			   instructions, state->symbols);
    }
 
    for (unsigned i = 0
 	   ; i < Elements(builtin_110_deprecated_fs_variables)
 	   ; i++) {
       add_builtin_variable(& builtin_110_deprecated_fs_variables[i],
-			   instructions, symtab);
+			   instructions, state->symbols);
    }
-   generate_110_uniforms(instructions, symtab);
+   generate_110_uniforms(instructions, state->symbols);
 
    /* FINISHME: The size of this array is implementation dependent based on the
     * FINISHME: value of GL_MAX_TEXTURE_COORDS.  Every platform that supports
@@ -242,27 +242,25 @@ generate_110_fs_variables(exec_list *instructions,
     * FINISHME: for now.
     */
    const glsl_type *const vec4_array_type =
-      glsl_type::get_array_instance(symtab, glsl_type::vec4_type, 4);
+      glsl_type::get_array_instance(state->symbols, glsl_type::vec4_type, 4);
 
    add_variable("gl_TexCoord", ir_var_in, FRAG_ATTRIB_TEX0, vec4_array_type,
-		instructions, symtab);
+		instructions, state->symbols);
 }
 
 
 static void
 generate_ARB_draw_buffers_fs_variables(exec_list *instructions,
-				       glsl_symbol_table *symtab, bool warn)
+				       struct _mesa_glsl_parse_state *state,
+				       bool warn)
 {
-   /* FINISHME: The size of this array is implementation dependent based on the
-    * FINISHME: value of GL_MAX_DRAW_BUFFERS.  GL_MAX_DRAW_BUFFERS must be
-    * FINISHME: at least 1, so hard-code 1 for now.
-    */
    const glsl_type *const vec4_array_type =
-      glsl_type::get_array_instance(symtab, glsl_type::vec4_type, 1);
+      glsl_type::get_array_instance(state->symbols, glsl_type::vec4_type,
+				    state->Const.MaxDrawBuffers);
 
    ir_variable *const fd =
       add_variable("gl_FragData", ir_var_out, FRAG_RESULT_DATA0,
-		   vec4_array_type, instructions, symtab);
+		   vec4_array_type, instructions, state->symbols);
 
    if (warn)
       fd->warn_extension = "GL_ARB_draw_buffers";
@@ -271,18 +269,18 @@ generate_ARB_draw_buffers_fs_variables(exec_list *instructions,
 
 static void
 generate_120_fs_variables(exec_list *instructions,
-			  glsl_symbol_table *symtab)
+			  struct _mesa_glsl_parse_state *state)
 {
-   generate_110_fs_variables(instructions, symtab);
-   generate_ARB_draw_buffers_fs_variables(instructions, symtab, false);
+   generate_110_fs_variables(instructions, state);
+   generate_ARB_draw_buffers_fs_variables(instructions, state, false);
 }
 
 static void
 generate_130_fs_variables(exec_list *instructions,
-			  glsl_symbol_table *symtab)
+			  struct _mesa_glsl_parse_state *state)
 {
-   void *ctx = symtab;
-   generate_120_fs_variables(instructions, symtab);
+   void *ctx = state->symbols;
+   generate_120_fs_variables(instructions, state);
 
    /* FINISHME: The size of this array is implementation dependent based on
     * FINISHME: the value of GL_MAX_CLIP_DISTANCES.
@@ -292,7 +290,7 @@ generate_130_fs_variables(exec_list *instructions,
 
    /* FINISHME: gl_ClipDistance needs a real location assigned. */
    add_variable("gl_ClipDistance", ir_var_in, -1, clip_distance_array_type,
-		instructions, symtab);
+		instructions, state->symbols);
 }
 
 static void
@@ -302,13 +300,13 @@ initialize_fs_variables(exec_list *instructions,
 
    switch (state->language_version) {
    case 110:
-      generate_110_fs_variables(instructions, state->symbols);
+      generate_110_fs_variables(instructions, state);
       break;
    case 120:
-      generate_120_fs_variables(instructions, state->symbols);
+      generate_120_fs_variables(instructions, state);
       break;
    case 130:
-      generate_130_fs_variables(instructions, state->symbols);
+      generate_130_fs_variables(instructions, state);
       break;
    }
 
@@ -318,7 +316,7 @@ initialize_fs_variables(exec_list *instructions,
     */
    if (state->language_version < 120) {
       if (state->ARB_draw_buffers_enable) {
-	 generate_ARB_draw_buffers_fs_variables(instructions, state->symbols,
+	 generate_ARB_draw_buffers_fs_variables(instructions, state,
 						state->ARB_draw_buffers_warn);
       }
    }
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index 342cf98..f1dab7b 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -123,6 +123,8 @@ compile_shader(struct glsl_shader *shader)
    state->loop_or_switch_nesting = NULL;
    state->ARB_texture_rectangle_enable = true;
 
+   state->Const.MaxDrawBuffers = 2;
+
    /* Create a new context for the preprocessor output.  Ultimately, this
     * should probably be the parser context, but there isn't one yet.
    */
diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp
index 1232bad..ab8aca0 100644
--- a/src/mesa/shader/ir_to_mesa.cpp
+++ b/src/mesa/shader/ir_to_mesa.cpp
@@ -1526,6 +1526,8 @@ _mesa_get_glsl_shader(GLcontext *ctx, void *mem_ctx, struct gl_shader *sh)
    state->loop_or_switch_nesting = NULL;
    state->ARB_texture_rectangle_enable = true;
 
+   state->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
+
    /* Create a new context for the preprocessor output.  Ultimately, this
     * should probably be the parser context, but there isn't one yet.
     */



More information about the mesa-commit mailing list