Mesa (master): i965: check if we run out of GRF/temp registers

Brian Paul brianp at kemper.freedesktop.org
Fri Mar 6 23:24:25 UTC 2009


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

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Mar  6 16:00:25 2009 -0700

i965: check if we run out of GRF/temp registers

Before this change we would up emitting instructions with invalid register
numbers.  This typically (but not always) hung the GPU.  For now, just
prevent emitting bad instructions to avoid hangs.  Still need to do some
kind of proper error recovery.

---

 src/mesa/drivers/dri/i965/brw_wm_glsl.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_glsl.c b/src/mesa/drivers/dri/i965/brw_wm_glsl.c
index bc82c01..ac7de6f 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_glsl.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_glsl.c
@@ -120,8 +120,14 @@ get_reg(struct brw_wm_compile *c, int file, int index, int component,
 	    break;
 	case PROGRAM_UNDEFINED:
 	    return brw_null_reg();	
-	default:
+	case PROGRAM_TEMPORARY:
+	case PROGRAM_INPUT:
+	case PROGRAM_OUTPUT:
+	case PROGRAM_PAYLOAD:
 	    break;
+	default:
+	    _mesa_problem(NULL, "Unexpected file in get_reg()");
+	    return brw_null_reg();
     }
 
     /* see if we've already allocated a HW register for this Mesa register */
@@ -140,6 +146,19 @@ get_reg(struct brw_wm_compile *c, int file, int index, int component,
 	c->reg_index++;
     }
 
+    if (c->reg_index >= BRW_WM_MAX_GRF - 12) {
+	/* ran out of temporary registers! */
+#if 1
+        /* This is a big hack for now.
+         * Return bad register index, but don't just crash hange the GPU.
+         */
+        _mesa_fprintf(stderr, "out of regs %d\n", c->reg_index);
+        c->reg_index = BRW_WM_MAX_GRF - 13;
+#else
+	return brw_null_reg();
+#endif
+    }
+ 
     if (neg & (1 << component)) {
 	reg = negate(reg);
     }
@@ -2573,6 +2592,11 @@ static void brw_wm_emit_glsl(struct brw_context *brw, struct brw_wm_compile *c)
 	    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
     }
     post_wm_emit(c);
+
+    if (c->reg_index >= BRW_WM_MAX_GRF) {
+        _mesa_problem(NULL, "Ran out of registers in brw_wm_emit_glsl()");
+        /* XXX we need to do some proper error recovery here */
+    }
 }
 
 




More information about the mesa-commit mailing list