Mesa (master): r300-gallium, radeon-gallium: Make add_buffer indicate when a flush is needed.

Corbin Simpson csimpson at kemper.freedesktop.org
Thu May 28 14:59:44 UTC 2009


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

Author: Corbin Simpson <MostAwesomeDude at gmail.com>
Date:   Thu May 28 07:46:34 2009 -0700

r300-gallium, radeon-gallium: Make add_buffer indicate when a flush is needed.

On a side note, why is RADEON_MAX_BOS 24? Should ask airlied about that.

---

 src/gallium/drivers/r300/r300_emit.c             |   28 +++++++++++++++------
 src/gallium/drivers/r300/r300_surface.c          |   21 +++++++++++----
 src/gallium/drivers/r300/r300_winsys.h           |    8 +++---
 src/gallium/winsys/drm/radeon/core/radeon_r300.c |   16 ++++++++----
 4 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 5e4b179..caeb73a 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -467,27 +467,39 @@ validate:
     for (i = 0; i < r300->framebuffer_state.nr_cbufs; i++) {
         tex = (struct r300_texture*)r300->framebuffer_state.cbufs[i]->texture;
         assert(tex && tex->buffer && "cbuf is marked, but NULL!");
-        r300->winsys->add_buffer(r300->winsys, tex->buffer,
-                0, RADEON_GEM_DOMAIN_VRAM);
+        if (!r300->winsys->add_buffer(r300->winsys, tex->buffer,
+                    0, RADEON_GEM_DOMAIN_VRAM)) {
+            r300->context.flush(&r300->context, 0, NULL);
+            goto validate;
+        }
     }
     /* ...depth buffer... */
     if (r300->framebuffer_state.zsbuf) {
         tex = (struct r300_texture*)r300->framebuffer_state.zsbuf->texture;
         assert(tex && tex->buffer && "zsbuf is marked, but NULL!");
-        r300->winsys->add_buffer(r300->winsys, tex->buffer,
-                0, RADEON_GEM_DOMAIN_VRAM);
+        if (!r300->winsys->add_buffer(r300->winsys, tex->buffer,
+                    0, RADEON_GEM_DOMAIN_VRAM)) {
+            r300->context.flush(&r300->context, 0, NULL);
+            goto validate;
+        }
     }
     /* ...textures... */
     for (i = 0; i < r300->texture_count; i++) {
         tex = r300->textures[i];
         assert(tex && tex->buffer && "texture is marked, but NULL!");
-        r300->winsys->add_buffer(r300->winsys, tex->buffer,
-                RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0);
+        if (!r300->winsys->add_buffer(r300->winsys, tex->buffer,
+                    RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) {
+            r300->context.flush(&r300->context, 0, NULL);
+            goto validate;
+        }
     }
     /* ...and vertex buffer. */
     if (r300->vbo) {
-        r300->winsys->add_buffer(r300->winsys, r300->vbo,
-                RADEON_GEM_DOMAIN_GTT, 0);
+        if (!r300->winsys->add_buffer(r300->winsys, r300->vbo,
+                    RADEON_GEM_DOMAIN_GTT, 0)) {
+            r300->context.flush(&r300->context, 0, NULL);
+            goto validate;
+        }
     } else {
         debug_printf("No VBO while emitting dirty state!\n");
     }
diff --git a/src/gallium/drivers/r300/r300_surface.c b/src/gallium/drivers/r300/r300_surface.c
index 7711e8f..c9e2dff 100644
--- a/src/gallium/drivers/r300/r300_surface.c
+++ b/src/gallium/drivers/r300/r300_surface.c
@@ -120,8 +120,11 @@ fallback:
 
     /* Make sure our target BO is okay. */
 validate:
-    r300->winsys->add_buffer(r300->winsys, tex->buffer,
-            0, RADEON_GEM_DOMAIN_VRAM);
+    if (!r300->winsys->add_buffer(r300->winsys, tex->buffer,
+                0, RADEON_GEM_DOMAIN_VRAM)) {
+        r300->context.flush(&r300->context, 0, NULL);
+        goto validate;
+    }
     if (r300->winsys->validate(r300->winsys)) {
         r300->context.flush(&r300->context, 0, NULL);
         if (invalid) {
@@ -242,10 +245,16 @@ fallback:
 
     /* Add our target BOs to the list. */
 validate:
-    r300->winsys->add_buffer(r300->winsys, srctex->buffer,
-            RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0);
-    r300->winsys->add_buffer(r300->winsys, desttex->buffer,
-            0, RADEON_GEM_DOMAIN_VRAM);
+    if (!r300->winsys->add_buffer(r300->winsys, srctex->buffer,
+                RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) {
+        r300->context.flush(&r300->context, 0, NULL);
+        goto validate;
+    }
+    if (!r300->winsys->add_buffer(r300->winsys, desttex->buffer,
+                0, RADEON_GEM_DOMAIN_VRAM)) {
+        r300->context.flush(&r300->context, 0, NULL);
+        goto validate;
+    }
     if (r300->winsys->validate(r300->winsys)) {
         r300->context.flush(&r300->context, 0, NULL);
         if (invalid) {
diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h
index a5ced80..d2893c3 100644
--- a/src/gallium/drivers/r300/r300_winsys.h
+++ b/src/gallium/drivers/r300/r300_winsys.h
@@ -52,10 +52,10 @@ struct r300_winsys {
     uint32_t vram_size;
 
     /* Add a pipe_buffer to the list of buffer objects to validate. */
-    void (*add_buffer)(struct r300_winsys* winsys,
-                       struct pipe_buffer* pbuffer,
-                       uint32_t rd,
-                       uint32_t wd);
+    boolean (*add_buffer)(struct r300_winsys* winsys,
+                          struct pipe_buffer* pbuffer,
+                          uint32_t rd,
+                          uint32_t wd);
 
     /* Revalidate all currently setup pipe_buffers.
      * Returns TRUE if a flush is required. */
diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c
index 995bf6a..63aa317 100644
--- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c
+++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c
@@ -22,10 +22,10 @@
 
 #include "radeon_r300.h"
 
-static void radeon_r300_add_buffer(struct r300_winsys* winsys,
-                                   struct pipe_buffer* pbuffer,
-                                   uint32_t rd,
-                                   uint32_t wd)
+static boolean radeon_r300_add_buffer(struct r300_winsys* winsys,
+                                      struct pipe_buffer* pbuffer,
+                                      uint32_t rd,
+                                      uint32_t wd)
 {
     int i;
     struct radeon_winsys_priv* priv =
@@ -35,7 +35,6 @@ static void radeon_r300_add_buffer(struct r300_winsys* winsys,
 
     /* Check to see if this BO is already in line for validation;
      * find a slot for it otherwise. */
-    assert(priv->bo_count <= RADEON_MAX_BOS);
     for (i = 0; i < priv->bo_count; i++) {
         if (sc[i].bo == bo) {
             sc[i].read_domains |= rd;
@@ -44,10 +43,17 @@ static void radeon_r300_add_buffer(struct r300_winsys* winsys,
         }
     }
 
+    if (priv->bo_count >= RADEON_MAX_BOS) {
+        /* Dohoho. Not falling for that one again. Request a flush. */
+        return FALSE;
+    }
+
     sc[priv->bo_count].bo = bo;
     sc[priv->bo_count].read_domains = rd;
     sc[priv->bo_count].write_domain = wd;
     priv->bo_count++;
+
+    return TRUE;
 }
 
 static boolean radeon_r300_validate(struct r300_winsys* winsys)




More information about the mesa-commit mailing list