From 5797fdf345e0af334745c957771b6a7a770eecbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 30 Aug 2013 13:53:48 +0200
Subject: wined3d: Put this into the query poll patch

---
 dlls/wined3d/cs.c    | 12 ++++++++++++
 dlls/wined3d/query.c |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 5c19a17..3540cb7 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -1728,6 +1728,18 @@ static UINT wined3d_cs_exec_query_issue(struct wined3d_cs *cs, const void *data)
             list_remove(&query->poll_list_entry);
             list_init(&query->poll_list_entry);
         }
+        else if (op->flags & WINED3DISSUE_END)
+        {
+            /* Can happen when an occlusion query is ended without being started,
+             * in which case we don't want to poll, but still have to counter-balance
+             * the increment of the main counter (!poll && list_empty).
+             *
+             * This can also happen if an event query is re-issued before the first
+             * fence was reached (poll && !list_empty). In this case the query is
+             * already in the list and the poll function will check the new fence.
+             * We have to counter-balance the discarded increment. */
+            InterlockedIncrement(&query->counter_retrieved);
+        }
     }
 
     return sizeof(*op);
diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c
index 39d663a..f33b30e 100644
--- a/dlls/wined3d/query.c
+++ b/dlls/wined3d/query.c
@@ -567,10 +567,10 @@ static BOOL wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DWORD
                     checkGLcall("glEndQuery()");
 
                     context_release(context);
+                    poll = TRUE;
                 }
             }
             oq->started = FALSE;
-            poll = TRUE;
         }
     }
     else
-- 
2.1.3

