From: Zhongmin Wu <zhongmin...@intel.com>

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

Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Signed-off-by: Yogesh Marathe <yogesh.mara...@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 d0b22d4..869287d 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -984,6 +984,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) {
@@ -1067,6 +1069,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 a4a04da..1fea5d8 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1235,6 +1235,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 e2f208a..e779bd1 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -642,9 +642,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);
@@ -678,8 +687,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;
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to