Mesa (7.9): prog_optimize: Fix reallocating registers for shaders with loops

Tom Stellard tstellar at kemper.freedesktop.org
Fri Apr 1 05:05:04 UTC 2011


Module: Mesa
Branch: 7.9
Commit: 9e2c9cdf4864eb4f707790573bfa7bcf725f7006
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9e2c9cdf4864eb4f707790573bfa7bcf725f7006

Author: Tom Stellard <tstellar at gmail.com>
Date:   Sun Mar 27 01:17:43 2011 -0700

prog_optimize: Fix reallocating registers for shaders with loops

Registers that are used inside of loops need to be considered live
starting with the first instruction of the outermost loop.

https://bugs.freedesktop.org/show_bug.cgi?id=34370

(cherry picked from commit 18dcbd358f1d4fd5e4a40fa26c6d3bf99485884e)

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/mesa/program/prog_optimize.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c
index 0dc7790..760901a 100644
--- a/src/mesa/program/prog_optimize.c
+++ b/src/mesa/program/prog_optimize.c
@@ -937,24 +937,35 @@ update_interval(GLint intBegin[], GLint intEnd[],
 		GLuint index, GLuint ic)
 {
    int i;
+   GLuint begin = ic;
+   GLuint end = ic;
 
    /* If the register is used in a loop, extend its lifetime through the end
     * of the outermost loop that doesn't contain its definition.
     */
    for (i = 0; i < loopStackDepth; i++) {
       if (intBegin[index] < loopStack[i].Start) {
-	 ic = loopStack[i].End;
+	 end = loopStack[i].End;
 	 break;
       }
    }
 
+   /* Variables that are live at the end of a loop will also be live at the
+    * beginning, so an instruction inside of a loop should have its live
+    * interval begin at the start of the outermost loop.
+    */
+   if (loopStackDepth > 0 && ic > loopStack[0].Start && ic < loopStack[0].End) {
+      begin = loopStack[0].Start;
+   }
+
    ASSERT(index < REG_ALLOCATE_MAX_PROGRAM_TEMPS);
    if (intBegin[index] == -1) {
       ASSERT(intEnd[index] == -1);
-      intBegin[index] = intEnd[index] = ic;
+      intBegin[index] = begin;
+      intEnd[index] = end;
    }
    else {
-      intEnd[index] = ic;
+      intEnd[index] = end;
    }
 }
 




More information about the mesa-commit mailing list