pb: add void * for flush ctx to mapping functions
authorDave Airlie <airlied@redhat.com>
Sat, 28 Aug 2010 08:59:32 +0000 (18:59 +1000)
committerDave Airlie <airlied@redhat.com>
Sun, 12 Sep 2010 03:32:43 +0000 (13:32 +1000)
If the buffer we are attempting to map is referenced by the unsubmitted
command stream for this context, we need to flush the command stream,
however to do that we need to be able to access the context at the lowest
level map function, currently we set the buffer in the toplevel map, but this
racy between context. (we probably have a lot more issues than that.)

I'll look into a proper solution as suggested by jrfonseca when I get some time.

src/gallium/auxiliary/pipebuffer/pb_buffer.h
src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_ondemand.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c
src/gallium/drivers/r600/r600_buffer.c
src/gallium/winsys/radeon/drm/radeon_drm_buffer.c
src/gallium/winsys/svga/drm/vmw_screen_svga.c

index a6c50dcf0c16773490fd613fc5af17a647e5a163..5a13f39849fb2c4bc3d1b4e52b62bf5c4bc76073 100644 (file)
@@ -130,7 +130,7 @@ struct pb_vtbl
     * flags is bitmask of PB_USAGE_CPU_READ/WRITE. 
     */
    void *(*map)( struct pb_buffer *buf, 
-                 unsigned flags );
+                 unsigned flags, void *flush_ctx );
    
    void (*unmap)( struct pb_buffer *buf );
 
@@ -164,13 +164,13 @@ struct pb_vtbl
  */
 static INLINE void *
 pb_map(struct pb_buffer *buf, 
-       unsigned flags)
+       unsigned flags, void *flush_ctx)
 {
    assert(buf);
    if(!buf)
       return NULL;
    assert(pipe_is_referenced(&buf->base.reference));
-   return buf->vtbl->map(buf, flags);
+   return buf->vtbl->map(buf, flags, flush_ctx);
 }
 
 
index d6cf64058253b0b53e8dedbcec649c4942683e49..c310f28f51fd31d83dd53baf2b982ae8cb3ed553 100644 (file)
@@ -624,7 +624,7 @@ fenced_buffer_copy_storage_to_gpu_locked(struct fenced_buffer *fenced_buf)
    assert(fenced_buf->data);
    assert(fenced_buf->buffer);
 
-   map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_WRITE);
+   map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_WRITE, NULL);
    if(!map)
       return PIPE_ERROR;
 
@@ -644,7 +644,7 @@ fenced_buffer_copy_storage_to_cpu_locked(struct fenced_buffer *fenced_buf)
    assert(fenced_buf->data);
    assert(fenced_buf->buffer);
 
-   map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_READ);
+   map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_READ, NULL);
    if(!map)
       return PIPE_ERROR;
 
@@ -674,7 +674,7 @@ fenced_buffer_destroy(struct pb_buffer *buf)
 
 static void *
 fenced_buffer_map(struct pb_buffer *buf,
-                  unsigned flags)
+                  unsigned flags, void *flush_ctx)
 {
    struct fenced_buffer *fenced_buf = fenced_buffer(buf);
    struct fenced_manager *fenced_mgr = fenced_buf->mgr;
@@ -712,7 +712,7 @@ fenced_buffer_map(struct pb_buffer *buf,
    }
 
    if(fenced_buf->buffer) {
-      map = pb_map(fenced_buf->buffer, flags);
+      map = pb_map(fenced_buf->buffer, flags, flush_ctx);
    }
    else {
       assert(fenced_buf->data);
index 88501e8d72df0449787af7698c6a754da9842f26..b4d8107372639b59cd22054e7703c04210ff2755 100644 (file)
@@ -167,10 +167,10 @@ pb_cache_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_cache_buffer_map(struct pb_buffer *_buf, 
-                  unsigned flags)
+                   unsigned flags, void *flush_ctx)
 {
    struct pb_cache_buffer *buf = pb_cache_buffer(_buf);   
-   return pb_map(buf->buffer, flags);
+   return pb_map(buf->buffer, flags, flush_ctx);
 }
 
 
@@ -242,7 +242,7 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf,
    if(!pb_check_usage(desc->usage, buf->base.base.usage))
       return FALSE;
 
-   map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK);
+   map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK, NULL);
    if (!map) {
       return FALSE;
    }
index 0dc5b31a7548caa28e5fb0141f918ec9c10f1bc5..4a01c7371bf874074356671b23e8cde90e02e8ee 100644 (file)
@@ -181,7 +181,7 @@ pb_debug_buffer_check(struct pb_debug_buffer *buf)
    
    map = pb_map(buf->buffer,
                 PB_USAGE_CPU_READ |
-                PB_USAGE_UNSYNCHRONIZED);
+                PB_USAGE_UNSYNCHRONIZED, NULL);
    assert(map);
    if(map) {
       boolean underflow, overflow;
@@ -247,14 +247,14 @@ pb_debug_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_debug_buffer_map(struct pb_buffer *_buf, 
-                    unsigned flags)
+                    unsigned flags, void *flush_ctx)
 {
    struct pb_debug_buffer *buf = pb_debug_buffer(_buf);
    void *map;
    
    pb_debug_buffer_check(buf);
 
-   map = pb_map(buf->buffer, flags);
+   map = pb_map(buf->buffer, flags, flush_ctx);
    if(!map)
       return NULL;
    
index faf7c35267454c552db025261524b4e87998b144..f35b4ce0601d089459abf31764552b14b1ca2450 100644 (file)
@@ -269,7 +269,7 @@ mm_bufmgr_create_from_buffer(struct pb_buffer *buffer,
 
    mm->map = pb_map(mm->buffer, 
                    PB_USAGE_CPU_READ |
-                   PB_USAGE_CPU_WRITE);
+                   PB_USAGE_CPU_WRITE, NULL);
    if(!mm->map)
       goto failure;
 
index 31f1ebbeb7c7b32bbde50a2aff8193779ba040e3..694a092f3c2fdfb50606f012c0b69915df009b5d 100644 (file)
@@ -103,13 +103,13 @@ pb_ondemand_buffer_destroy(struct pb_buffer *_buf)
 
 static void *
 pb_ondemand_buffer_map(struct pb_buffer *_buf, 
-                       unsigned flags)
+                       unsigned flags, void *flush_ctx)
 {
    struct pb_ondemand_buffer *buf = pb_ondemand_buffer(_buf);
 
    if(buf->buffer) {
       assert(!buf->data);
-      return pb_map(buf->buffer, flags);
+      return pb_map(buf->buffer, flags, flush_ctx);
    }
    else {
       assert(buf->data);
@@ -150,7 +150,7 @@ pb_ondemand_buffer_instantiate(struct pb_ondemand_buffer *buf)
       if(!buf->buffer)
          return PIPE_ERROR_OUT_OF_MEMORY;
       
-      map = pb_map(buf->buffer, PB_USAGE_CPU_READ);
+      map = pb_map(buf->buffer, PB_USAGE_CPU_READ, NULL);
       if(!map) {
          pb_reference(&buf->buffer, NULL);
          return PIPE_ERROR;
index fdcce428784a27c2bed4ecd59ae15564704f894f..4f46cfc9e32adc0ad31d70499b3b390cac97c644 100644 (file)
@@ -285,7 +285,7 @@ pool_bufmgr_create(struct pb_manager *provider,
 
    pool->map = pb_map(pool->buffer,
                           PB_USAGE_CPU_READ |
-                          PB_USAGE_CPU_WRITE);
+                          PB_USAGE_CPU_WRITE, NULL);
    if(!pool->map)
       goto failure;
 
index 7a3305aaf37234ae5d8891417d0ce20c2cecfa99..275eb76bf52a7859f39486b5af601f92b5317fe3 100644 (file)
@@ -316,7 +316,7 @@ pb_slab_create(struct pb_slab_manager *mgr)
     * through this address so it is required that the buffer is pinned. */
    slab->virtual = pb_map(slab->bo, 
                           PB_USAGE_CPU_READ |
-                          PB_USAGE_CPU_WRITE);
+                          PB_USAGE_CPU_WRITE, NULL);
    if(!slab->virtual) {
       ret = PIPE_ERROR_OUT_OF_MEMORY;
       goto out_err1;
index d8188ae65621d3b88a9f3835c56dc75939632d4d..06197d3d7d9061e53273ff7eafd75d64a709b755 100644 (file)
@@ -156,7 +156,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
        int write = 0;
 
        if (rbuffer->pb) {
-               return (uint8_t*)pb_map(rbuffer->pb, transfer->usage) + transfer->box.x;
+               return (uint8_t*)pb_map(rbuffer->pb, transfer->usage, NULL) + transfer->box.x;
        }
        if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) {
                /* FIXME */
index 017eac8464e16b04d7c0e87ec3bc4ad8559bb1af..cef59975ca8b4a7dd5cff6392a693519b151c480 100644 (file)
@@ -89,10 +89,10 @@ static unsigned get_pb_usage_from_transfer_flags(enum pipe_transfer_usage usage)
 
 static void *
 radeon_drm_buffer_map_internal(struct pb_buffer *_buf,
-                     unsigned flags)
+                              unsigned flags, void *flush_ctx)
 {
     struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf);
-    struct radeon_libdrm_cs *cs = buf->cs;
+    struct radeon_libdrm_cs *cs = flush_ctx;
     int write = 0;
 
     if (flags & PB_USAGE_DONTBLOCK) {
@@ -293,12 +293,8 @@ void *radeon_drm_buffer_map(struct r300_winsys_screen *ws,
                             enum pipe_transfer_usage usage)
 {
     struct pb_buffer *_buf = radeon_pb_buffer(buf);
-    struct radeon_drm_buffer *rbuf = get_drm_buffer(_buf);
 
-    if (rbuf)
-        rbuf->cs = radeon_libdrm_cs(cs);
-
-    return pb_map(_buf, get_pb_usage_from_transfer_flags(usage));
+    return pb_map(_buf, get_pb_usage_from_transfer_flags(usage), radeon_libdrm_cs(cs));
 }
 
 void radeon_drm_buffer_unmap(struct r300_winsys_screen *ws,
index 2b4e80f003929e2f49541abed9b58916b20ba3cf..d96b2b97427281c6edafeb4b3fde9fc62538d9a0 100644 (file)
@@ -81,7 +81,7 @@ vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws,
                            unsigned flags)
 {
    (void)sws;
-   return pb_map(vmw_pb_buffer(buf), flags);
+   return pb_map(vmw_pb_buffer(buf), flags, NULL);
 }