intel: fix waiting of present fences

For presentation fences, we should wait until the server has submitted the
presentation command to the kernel _and_ the GPU has executed the command.
We failed to wait for the latter until this fix.
diff --git a/icd/intel/fence.c b/icd/intel/fence.c
index 75c2843..debcd7e 100644
--- a/icd/intel/fence.c
+++ b/icd/intel/fence.c
@@ -81,36 +81,41 @@
 void intel_fence_set_x11(struct intel_fence *fence,
                          struct intel_wsi_x11 *x11,
                          struct intel_wsi_x11_window *win,
-                         uint32_t serial)
+                         uint32_t serial,
+                         struct intel_bo *seqno_bo)
 {
-    if (fence->seqno_bo) {
-        intel_bo_unreference(fence->seqno_bo);
-        fence->seqno_bo = NULL;
-    }
-
 #ifdef ENABLE_WSI_X11
     fence->x11 = x11;
     fence->x11_win = win;
     fence->x11_serial = serial;
 #endif
+
+    if (fence->seqno_bo)
+        intel_bo_unreference(fence->seqno_bo);
+
+    fence->seqno_bo = seqno_bo;
+    intel_bo_reference(fence->seqno_bo);
 }
 
 XGL_RESULT intel_fence_wait(struct intel_fence *fence, int64_t timeout_ns)
 {
+#ifdef ENABLE_WSI_X11
+    if (fence->x11) {
+        const bool wait = (timeout_ns != 0);
+        XGL_RESULT ret;
+
+        ret = intel_wsi_x11_wait(fence->x11, fence->x11_win,
+                fence->x11_serial, wait);
+        if (ret != XGL_SUCCESS)
+            return ret;
+    }
+#endif
+
     if (fence->seqno_bo) {
         return (intel_bo_wait(fence->seqno_bo, timeout_ns)) ?
             XGL_NOT_READY : XGL_SUCCESS;
     }
 
-#ifdef ENABLE_WSI_X11
-    if (fence->x11) {
-        const bool wait = (timeout_ns != 0);
-
-        return intel_wsi_x11_wait(fence->x11, fence->x11_win,
-                fence->x11_serial, wait);
-    }
-#endif
-
     return XGL_ERROR_UNAVAILABLE;
 }
 
diff --git a/icd/intel/fence.h b/icd/intel/fence.h
index 70b4f2a..3ed450b 100644
--- a/icd/intel/fence.h
+++ b/icd/intel/fence.h
@@ -70,6 +70,7 @@
 void intel_fence_set_x11(struct intel_fence *fence,
                          struct intel_wsi_x11 *x11,
                          struct intel_wsi_x11_window *win,
-                         uint32_t serial);
+                         uint32_t serial,
+                         struct intel_bo *seqno_bo);
 
 #endif /* FENCE_H */
diff --git a/icd/intel/wsi_x11.c b/icd/intel/wsi_x11.c
index c8dfd0a..582aa70 100644
--- a/icd/intel/wsi_x11.c
+++ b/icd/intel/wsi_x11.c
@@ -639,8 +639,12 @@
     if (ret != XGL_SUCCESS)
         return ret;
 
-    if (fence)
-        intel_fence_set_x11(fence, x11, win, win->local.serial);
+    if (fence) {
+        struct intel_img *img = intel_img(pPresentInfo->srcImage);
+
+        intel_fence_set_x11(fence, x11, win, win->local.serial,
+                img->obj.mem->bo);
+    }
 
     return XGL_SUCCESS;
 }