Mesa (7.9): r300g: fix rendering with no vertex elements

Marek Olšák mareko at kemper.freedesktop.org
Thu Dec 2 00:58:19 UTC 2010


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Sun Nov 14 18:57:14 2010 +0100

r300g: fix rendering with no vertex elements

Fixes glsl-vs-point-size, although I meant to fix glsl-novertexdata.
Since swrast fails glsl-novertexdata too, I guess it's a core issue.
(cherry picked from commit ffb732d8bd51f0a40379590a6485de2a56a2a306)

---

 src/gallium/drivers/r300/r300_context.c |   17 +++++++++++++++++
 src/gallium/drivers/r300/r300_context.h |    4 ++++
 src/gallium/drivers/r300/r300_render.c  |    3 ---
 src/gallium/drivers/r300/r300_state.c   |   20 +++++++++++++++++++-
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index 624dadd..46504f5 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -79,6 +79,9 @@ static void r300_release_referenced_objects(struct r300_context *r300)
                 NULL);
     }
 
+    /* The dummy VBO. */
+    pipe_resource_reference(&r300->dummy_vb, NULL);
+
     /* The SWTCL VBO. */
     pipe_resource_reference(&r300->vbo, NULL);
 
@@ -488,6 +491,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
         rtempl.target = PIPE_TEXTURE_2D;
         rtempl.format = PIPE_FORMAT_I8_UNORM;
         rtempl.bind = PIPE_BIND_SAMPLER_VIEW;
+        rtempl.usage = PIPE_USAGE_IMMUTABLE;
         rtempl.width0 = 1;
         rtempl.height0 = 1;
         rtempl.depth0 = 1;
@@ -501,6 +505,19 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
         pipe_resource_reference(&tex, NULL);
     }
 
+    {
+        struct pipe_resource vb = {};
+        vb.target = PIPE_BUFFER;
+        vb.format = PIPE_FORMAT_R8_UNORM;
+        vb.bind = PIPE_BIND_VERTEX_BUFFER;
+        vb.usage = PIPE_USAGE_IMMUTABLE;
+        vb.width0 = sizeof(float) * 16;
+        vb.height0 = 1;
+        vb.depth0 = 1;
+
+        r300->dummy_vb = screen->resource_create(screen, &vb);
+    }
+
     return &r300->context;
 
  fail:
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 8f4e2de..743e9da 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -470,6 +470,10 @@ struct r300_context {
      * dummy texture there. */
     struct r300_sampler_view *texkill_sampler;
 
+    /* When no vertex buffer is set, this one is used instead to prevent
+     * hardlocks. */
+    struct pipe_resource *dummy_vb;
+
     /* The currently active query. */
     struct r300_query *query_current;
     /* The saved query for blitter operations. */
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 2f00c87..7a3eb09 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -676,9 +676,6 @@ static void r300_draw_vbo(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
 
-    if (!r300->velems->count || !r300->vertex_buffer_count)
-	    return;
-
     if (info->indexed && r300->index_buffer.buffer) {
         unsigned offset;
 
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 53c1657..105b3e5 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1464,6 +1464,15 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
     struct pipe_vertex_buffer *vbo;
     unsigned i, max_index = (1 << 24) - 1;
     boolean any_user_buffer = FALSE;
+    struct pipe_vertex_buffer dummy_vb = {0};
+
+    /* There must be at least one vertex buffer set, otherwise it locks up. */
+    if (!count) {
+        dummy_vb.buffer = r300->dummy_vb;
+        dummy_vb.max_index = r300->dummy_vb->width0 / 4;
+        buffers = &dummy_vb;
+        count = 1;
+    }
 
     if (count == r300->vertex_buffer_count &&
         memcmp(r300->vertex_buffer, buffers,
@@ -1617,6 +1626,14 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
     struct r300_vertex_element_state *velems;
     unsigned i;
     enum pipe_format *format;
+    struct pipe_vertex_element dummy_attrib = {0};
+
+    /* R300 Programmable Stream Control (PSC) doesn't support 0 vertex elements. */
+    if (!count) {
+        dummy_attrib.src_format = PIPE_FORMAT_R8G8B8A8_UNORM;
+        attribs = &dummy_attrib;
+        count = 1;
+    }
 
     assert(count <= PIPE_MAX_ATTRIBS);
     velems = CALLOC_STRUCT(r300_vertex_element_state);
@@ -1683,7 +1700,8 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
              * swizzles are already set up.
              * Also compute the vertex size. */
             for (i = 0; i < count; i++) {
-                /* This is OK because we check for aligned strides too. */
+                /* This is OK because we check for aligned strides too
+                 * elsewhere. */
                 velems->hw_format_size[i] =
                     align(util_format_get_blocksize(velems->hw_format[i]), 4);
                 velems->vertex_size_dwords += velems->hw_format_size[i] / 4;




More information about the mesa-commit mailing list