[Mesa-dev] [EGL android: accquire fence implementation 1/2] i965: Return the last fence if the batch buffer is empty and nothing to be flushed when _intel_batchbuffer_flush_fence.

Zhongmin Wu zhongmin.wu at intel.com
Fri Jul 21 03:07:34 UTC 2017


Always save the last fence in the brw context when flushing
buffer. If the buffer is nothing to be flushed, then return
the last fence when asked for.

Change-Id: Ic47035bcd1a27e402609afd9e2d1e3972548b97d
Signed-off-by: Zhongmin Wu <zhongmin.wu at intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.c       |    5 +++++
 src/mesa/drivers/dri/i965/brw_context.h       |    1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   16 ++++++++++++++--
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..ed0b056 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1086,6 +1086,8 @@ brwCreateContext(gl_api api,
    ctx->VertexProgram._MaintainTnlProgram = true;
    ctx->FragmentProgram._MaintainTexEnvProgram = true;
 
+   brw->out_fence_fd = -1;
+
    brw_draw_init( brw );
 
    if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
@@ -1169,6 +1171,9 @@ intelDestroyContext(__DRIcontext * driContextPriv)
    brw->throttle_batch[1] = NULL;
    brw->throttle_batch[0] = NULL;
 
+   if (brw->out_fence_fd >= 0)
+      close(brw->out_fence_fd);
+
    driDestroyOptionCache(&brw->optionCache);
 
    /* free the Mesa context */
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..692ea2c 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1217,6 +1217,7 @@ struct brw_context
 
    __DRIcontext *driContext;
    struct intel_screen *screen;
+   int out_fence_fd;
 };
 
 /* brw_clear.c */
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 62d2fe8..d342e5d 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -648,9 +648,18 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, int *out_fence_fd)
          /* Add the batch itself to the end of the validation list */
          add_exec_bo(batch, batch->bo);
 
+         if (brw->out_fence_fd >= 0) {
+            close(brw->out_fence_fd);
+            brw->out_fence_fd = -1;
+         }
+
+         int fd = -1;
          ret = execbuffer(dri_screen->fd, batch, hw_ctx,
                           4 * USED_BATCH(*batch),
-                          in_fence_fd, out_fence_fd, flags);
+                          in_fence_fd, &fd, flags);
+         brw->out_fence_fd = fd;
+         if (out_fence_fd)
+            *out_fence_fd = (fd >=0) ? dup(fd) : -1;
       }
 
       throttle(brw);
@@ -684,8 +693,11 @@ _intel_batchbuffer_flush_fence(struct brw_context *brw,
 {
    int ret;
 
-   if (USED_BATCH(brw->batch) == 0)
+   if (USED_BATCH(brw->batch) == 0) {
+      if (out_fence_fd && brw->out_fence_fd >= 0)
+         *out_fence_fd = dup(brw->out_fence_fd);
       return 0;
+   }
 
    if (brw->throttle_batch[0] == NULL) {
       brw->throttle_batch[0] = brw->batch.bo;
-- 
1.7.9.5



More information about the mesa-dev mailing list