[Mesa-dev] [PATCH 3/4] i965: Use async maps for BufferSubData to regions with no valid data.

Chris Wilson chris at chris-wilson.co.uk
Tue Jun 13 11:57:05 UTC 2017


Quoting Kenneth Graunke (2017-06-13 01:33:31)
> When writing a region of a buffer via glBufferSubData(), we can write
> the data asynchronously if the destination doesn't contain any data.
> Even if it's busy, the data was undefined, so the new data is fine too.
> 
> Decreases the number of stall avoidance blits in Manhattan 3.1:
> - Skylake GT4: -18.3544% +/- 6.76483% (n=13)
> - Apollolake:  -12.1095% +/- 5.24458% (n=13)

Makes sense, but MAP_ASYNC is currently disabled on apl.

We first need something like:

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 6860769..7530806 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -332,6 +332,7 @@ retry:
 
       bo->size = bo_size;
       bo->idle = true;
+      bo->cpu = true;
 
       memclear(create);
       create.size = bo_size;
@@ -711,6 +712,7 @@ brw_bo_map_cpu(struct brw_context *brw, struct brw_bo *bo, unsigned flags)
    if (!(flags & MAP_ASYNC)) {
       set_domain(brw, "CPU mapping", bo, I915_GEM_DOMAIN_CPU,
                  flags & MAP_WRITE ? I915_GEM_DOMAIN_CPU : 0);
+      bo->cpu |= flags & MAP_WRITE;
    }
 
    bo_mark_mmaps_incoherent(bo);
@@ -761,10 +763,11 @@ brw_bo_map_gtt(struct brw_context *brw, struct brw_bo *bo, unsigned flags)
    DBG("bo_map_gtt: %d (%s) -> %p\n", bo->gem_handle, bo->name,
        bo->map_gtt);
 
-   if (!(flags & MAP_ASYNC)) {
+   if (!(flags & MAP_ASYNC) || bo->cpu) {
       set_domain(brw, "GTT mapping", bo,
                  I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
    }
+   bo->cpu = false;
 
    bo_mark_mmaps_incoherent(bo);
    VG(VALGRIND_MAKE_MEM_DEFINED(bo->map_gtt, bo->size));
@@ -785,7 +788,10 @@ can_map_cpu(struct brw_bo *bo, unsigned flags)
    if (flags & MAP_COHERENT)
       return false;
 
-   return !(flags & MAP_WRITE);
+   if (bo->cpu)
+      return true;
+
+   return !(flags & (MAP_WRITE | MAP_ASYNC));
 }
 
 void *
diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h b/src/mesa/drivers/dri/i965/brw_bufmgr.h
index 188d6c5..6aac8c1 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.h
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h
@@ -87,7 +87,8 @@ struct brw_bo {
     * buffers are those that have been shared with other
     * processes, so we don't know their state.
     */
-   bool idle;
+   bool idle : 1;
+   bool cpu : 1;
 
    int refcount;
    const char *name;
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 222612b..70c6015 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -633,6 +633,7 @@ execbuffer(int fd,
       struct brw_bo *bo = batch->exec_bos[i];
 
       bo->idle = false;
+      bo->cpu = false;
       bo->index = -1;
 
       /* Update brw_bo::offset64 */



More information about the mesa-dev mailing list