Mesa (master): r300g, radeong: fix the CS overflow

Corbin Simpson csimpson at kemper.freedesktop.org
Fri Dec 4 09:24:18 PST 2009


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Wed Dec  2 17:15:27 2009 +0100

r300g, radeong: fix the CS overflow

---

 src/gallium/drivers/r300/r300_cs.h               |    2 +-
 src/gallium/drivers/r300/r300_emit.c             |    9 ++++++++-
 src/gallium/winsys/drm/radeon/core/radeon_r300.c |    5 +++--
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h
index 8b10037..9fcf3ab 100644
--- a/src/gallium/drivers/r300/r300_cs.h
+++ b/src/gallium/drivers/r300/r300_cs.h
@@ -55,7 +55,7 @@
     int cs_count = 0;
 
 #define CHECK_CS(size) \
-    cs_winsys->check_cs(cs_winsys, (size))
+    assert(cs_winsys->check_cs(cs_winsys, (size)))
 
 #define BEGIN_CS(size) do { \
     CHECK_CS(size); \
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index a479842..3bb42f9 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -871,10 +871,17 @@ void r300_emit_dirty_state(struct r300_context* r300)
         return;
     }
 
+    /* Check size of CS. */
+    /* Make sure we have at least 8*1024 spare dwords. */
+    /* XXX It would be nice to know the number of dwords we really need to
+     * XXX emit. */
+    if (!r300->winsys->check_cs(r300->winsys, 8*1024)) {
+        r300->context.flush(&r300->context, 0, NULL);
+    }
+
     /* Clean out BOs. */
     r300->winsys->reset_bos(r300->winsys);
 
-    /* XXX check size */
 validate:
     /* Color buffers... */
     for (i = 0; i < r300->framebuffer_state.nr_cbufs; i++) {
diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c
index 7362279..ba0596c 100644
--- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c
+++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c
@@ -52,8 +52,9 @@ static boolean radeon_validate(struct radeon_winsys* winsys)
 
 static boolean radeon_check_cs(struct radeon_winsys* winsys, int size)
 {
-    /* XXX check size here, lazy ass! */
-    return radeon_validate(winsys);
+    struct radeon_cs* cs = winsys->priv->cs;
+
+    return radeon_validate(winsys) && cs->cdw + size <= cs->ndw;
 }
 
 static void radeon_begin_cs(struct radeon_winsys* winsys,



More information about the mesa-commit mailing list