Module: Mesa
Branch: master
Commit: 2809d707231fba0e91abe1dd32e9f2d3284b9d3a
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=2809d707231fba0e91abe1dd32e9f2d3284b9d3a

Author: Kenneth Graunke <kenn...@whitecape.org>
Date:   Sat Sep  4 01:55:55 2010 -0700

ir_reader: Emit global variables at the top of the instruction list.

Since functions are emitted when scanning for prototypes, functions
always come first, even if the original IR listed the variable
declarations first.

Fixes an ir_validate error (to be turned on in the next commit).

---

 src/glsl/ir_reader.cpp |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
index 1b08157..408c20e 100644
--- a/src/glsl/ir_reader.cpp
+++ b/src/glsl/ir_reader.cpp
@@ -337,8 +337,17 @@ read_instructions(_mesa_glsl_parse_state *st, exec_list 
*instructions,
    foreach_iter(exec_list_iterator, it, list->subexpressions) {
       s_expression *sub = (s_expression*) it.get();
       ir_instruction *ir = read_instruction(st, sub, loop_ctx);
-      if (ir != NULL)
-        instructions->push_tail(ir);
+      if (ir != NULL) {
+        /* Global variable declarations should be moved to the top, before
+         * any functions that might use them.  Functions are added to the
+         * instruction stream when scanning for prototypes, so without this
+         * hack, they always appear before variable declarations.
+         */
+        if (st->current_function == NULL && ir->as_variable() != NULL)
+           instructions->push_head(ir);
+        else
+           instructions->push_tail(ir);
+      }
    }
 }
 

_______________________________________________
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to