Mesa (master): util/upload: catch failures to map_range and return error

Keith Whitwell keithw at kemper.freedesktop.org
Fri May 8 02:04:21 PDT 2009


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

Author: Keith Whitwell <keithw at vmware.com>
Date:   Thu May  7 09:24:37 2009 +0100

util/upload: catch failures to map_range and return error

Caller may be able to do something about this - eg flush and retry.

---

 src/gallium/auxiliary/util/u_upload_mgr.c |   30 ++++++++++++++++------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index d9c0d7a..2eb9806 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -70,7 +70,7 @@ struct u_upload_mgr *u_upload_create( struct pipe_screen *screen,
 }
 
 
-static INLINE void
+static INLINE enum pipe_error
 my_buffer_write(struct pipe_screen *screen,
                 struct pipe_buffer *buf,
                 unsigned offset, unsigned size, unsigned dirty_size,
@@ -84,12 +84,14 @@ my_buffer_write(struct pipe_screen *screen,
    assert(size);
 
    map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE);
-   assert(map);
-   if(map) {
-      memcpy(map + offset, data, size);
-      pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
-      pipe_buffer_unmap(screen, buf);
-   }
+   if (map == NULL) 
+      return PIPE_ERROR_OUT_OF_MEMORY;
+
+   memcpy(map + offset, data, size);
+   pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
+   pipe_buffer_unmap(screen, buf);
+
+   return PIPE_OK;
 }
 
 /* Release old buffer.
@@ -162,12 +164,14 @@ enum pipe_error u_upload_data( struct u_upload_mgr *upload,
 
    /* Copy the data, using map_range if available:
     */
-   my_buffer_write( upload->screen, 
-                    upload->buffer,
-                    upload->offset,
-                    size, 
-                    alloc_size,
-                    data );
+   ret = my_buffer_write( upload->screen, 
+                          upload->buffer,
+                          upload->offset,
+                          size, 
+                          alloc_size,
+                          data );
+   if (ret)
+      return ret;
 
    /* Emit the return values:
     */



More information about the mesa-commit mailing list