i915: store reference to the context within struct intel_fence (v2)
authorMauro Rossi <issor.oruam@gmail.com>
Sat, 16 Jul 2016 00:02:58 +0000 (02:02 +0200)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 14 Oct 2016 14:43:57 +0000 (15:43 +0100)
Porting of the corresponding patch for i965.

Here follows the original commit message by Tomasz Figa:

"As the spec allows for {server,client}_wait_sync to be called without
currently bound context, while our implementation requires context
pointer.

v2: Add a mutex and acquire it for the duration of
    brw_fence_client_wait() and brw_fence_is_completed() as suggested
    by Chad."

NOTE: in i915 all references to 'brw' are replaced by 'intel'

Marshmallow-x86 boots ok with the following results of Android CTS.

Android CTS 6.0_r7 build:2906653
Session     Pass       Fail     Not Executed
0(EGL)      1410       24       0
1(GLES2)    13832      82       0

I get the same results as per i965GM.

[Emil Velikov: Include Mauro's test results]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
src/mesa/drivers/dri/i915/intel_syncobj.c

index ae3ad82169222d9af2e3a3983e9aa2542eac724e..d0a99aa2e6d92472b116437037fcb6544d17e8f7 100644 (file)
 #include "intel_reg.h"
 
 struct intel_fence {
+   struct intel_context *intel;
    /** The fence waits for completion of this batch. */
    drm_intel_bo *batch_bo;
 
+   mtx_t mutex;
    bool signalled;
 };
 
@@ -77,7 +79,7 @@ intel_fence_insert(struct intel_context *intel, struct intel_fence *fence)
 }
 
 static bool
-intel_fence_has_completed(struct intel_fence *fence)
+intel_fence_has_completed_locked(struct intel_fence *fence)
 {
    if (fence->signalled)
       return true;
@@ -92,13 +94,21 @@ intel_fence_has_completed(struct intel_fence *fence)
    return false;
 }
 
-/**
- * Return true if the function successfully signals or has already signalled.
- * (This matches the behavior expected from __DRI2fence::client_wait_sync).
- */
 static bool
-intel_fence_client_wait(struct intel_context *intel, struct intel_fence *fence,
-                      uint64_t timeout)
+intel_fence_has_completed(struct intel_fence *fence)
+{
+   bool ret;
+
+   mtx_lock(&fence->mutex);
+   ret = intel_fence_has_completed_locked(fence);
+   mtx_unlock(&fence->mutex);
+
+   return ret;
+}
+
+static bool
+intel_fence_client_wait_locked(struct intel_context *intel, struct intel_fence *fence,
+                             uint64_t timeout)
 {
    if (fence->signalled)
       return true;
@@ -123,6 +133,23 @@ intel_fence_client_wait(struct intel_context *intel, struct intel_fence *fence,
    return true;
 }
 
+/**
+ * Return true if the function successfully signals or has already signalled.
+ * (This matches the behavior expected from __DRI2fence::client_wait_sync).
+ */
+static bool
+intel_fence_client_wait(struct intel_context *intel, struct intel_fence *fence,
+                      uint64_t timeout)
+{
+   bool ret;
+
+   mtx_lock(&fence->mutex);
+   ret = intel_fence_client_wait_locked(intel, fence, timeout);
+   mtx_unlock(&fence->mutex);
+
+   return ret;
+}
+
 static void
 intel_fence_server_wait(struct intel_context *intel, struct intel_fence *fence)
 {
@@ -215,6 +242,8 @@ intel_dri_create_fence(__DRIcontext *ctx)
    if (!fence)
       return NULL;
 
+   mtx_init(&fence->mutex, mtx_plain);
+   fence->intel = intel;
    intel_fence_insert(intel, fence);
 
    return fence;
@@ -233,19 +262,23 @@ static GLboolean
 intel_dri_client_wait_sync(__DRIcontext *ctx, void *driver_fence, unsigned flags,
                            uint64_t timeout)
 {
-   struct intel_context *intel = ctx->driverPrivate;
    struct intel_fence *fence = driver_fence;
 
-   return intel_fence_client_wait(intel, fence, timeout);
+   return intel_fence_client_wait(fence->intel, fence, timeout);
 }
 
 static void
 intel_dri_server_wait_sync(__DRIcontext *ctx, void *driver_fence, unsigned flags)
 {
-   struct intel_context *intel = ctx->driverPrivate;
    struct intel_fence *fence = driver_fence;
 
-   intel_fence_server_wait(intel, fence);
+   /* We might be called here with a NULL fence as a result of WaitSyncKHR
+    * on a EGL_KHR_reusable_sync fence. Nothing to do here in such case.
+    */
+   if (!fence)
+      return;
+
+   intel_fence_server_wait(fence->intel, fence);
 }
 
 const __DRI2fenceExtension intelFenceExtension = {