r300g: more solid is_buffer_referenced implementation
authorMarek Olšák <maraeo@gmail.com>
Sun, 18 Apr 2010 15:19:45 +0000 (17:19 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 18 Apr 2010 15:49:12 +0000 (17:49 +0200)
This fixes crash from 7a1b5c937fa32968a04a11649e456a1ef8c5b442,
and also removes the unused "map" pointer.

src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_screen_buffer.h

index 26ff71c..a3fd8cc 100644 (file)
@@ -152,9 +152,9 @@ static boolean immd_is_good_idea(struct r300_context *r300,
         if (!checked[vbi]) {
             vbuf = &r300->vertex_buffer[vbi];
 
-            if (r300->rws->is_buffer_referenced(r300->rws,
-                                                r300_buffer(vbuf->buffer)->buf,
-                                                R300_REF_CS | R300_REF_HW)) {
+            if (r300_buffer_is_referenced(&r300->context,
+                                          vbuf->buffer,
+                                          R300_REF_CS | R300_REF_HW)) {
                 /* It's a very bad idea to map it... */
                 return FALSE;
             }
index c5c10af..6d33c13 100644 (file)
@@ -34,9 +34,9 @@
 #include "r300_screen_buffer.h"
 #include "r300_winsys.h"
 
-static unsigned r300_buffer_is_referenced(struct pipe_context *context,
-                                        struct pipe_resource *buf,
-                                        unsigned face, unsigned level)
+unsigned r300_buffer_is_referenced(struct pipe_context *context,
+                                  struct pipe_resource *buf,
+                                   enum r300_reference_domain domain)
 {
     struct r300_context *r300 = r300_context(context);
     struct r300_buffer *rbuf = r300_buffer(buf);
@@ -44,12 +44,19 @@ static unsigned r300_buffer_is_referenced(struct pipe_context *context,
     if (r300_buffer_is_user_buffer(buf))
        return PIPE_UNREFERENCED;
 
-    if (r300->rws->is_buffer_referenced(r300->rws, rbuf->buf, R300_REF_CS))
+    if (r300->rws->is_buffer_referenced(r300->rws, rbuf->buf, domain))
         return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
 
     return PIPE_UNREFERENCED;
 }
 
+static unsigned r300_buffer_is_referenced_by_cs(struct pipe_context *context,
+                                                struct pipe_resource *buf,
+                                                unsigned face, unsigned level)
+{
+    return r300_buffer_is_referenced(context, buf, R300_REF_CS);
+}
+
 /* External helper, not required to implent u_resource_vtbl:
  */
 int r300_upload_index_buffer(struct r300_context *r300,
@@ -174,7 +181,6 @@ r300_buffer_transfer_map( struct pipe_context *pipe,
                rws->buffer_reference(rws, &rbuf->buf, NULL);
 
                rbuf->num_ranges = 0;
-               rbuf->map = NULL;
                rbuf->buf = r300_winsys_buffer_create(r300screen,
                                                      16,
                                                      rbuf->b.b.bind, /* XXX */
@@ -243,7 +249,7 @@ struct u_resource_vtbl r300_buffer_vtbl =
 {
    u_default_resource_get_handle,      /* get_handle */
    r300_buffer_destroy,                     /* resource_destroy */
-   r300_buffer_is_referenced,       /* is_buffer_referenced */
+   r300_buffer_is_referenced_by_cs,  /* is_buffer_referenced */
    u_default_get_transfer,          /* get_transfer */
    u_default_transfer_destroy,      /* transfer_destroy */
    r300_buffer_transfer_map,        /* transfer_map */
index 82660d3..57f4822 100644 (file)
@@ -55,8 +55,6 @@ struct r300_buffer
     void *user_buffer;
     struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES];
     unsigned num_ranges;
-
-    void *map;
 };
 
 /* Functions. */
@@ -77,6 +75,10 @@ struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen,
                                              unsigned bytes,
                                              unsigned usage);
 
+unsigned r300_buffer_is_referenced(struct pipe_context *context,
+                                  struct pipe_resource *buf,
+                                   enum r300_reference_domain domain);
+
 /* Inline functions. */
 
 static INLINE struct r300_buffer *r300_buffer(struct pipe_resource *buffer)