[PATCH 08/12] wined3d/query: Add support for D3DQUERY_TIMESTAMP queries.

Adam Martinson amartinson at codeweavers.com
Wed May 4 12:46:13 CDT 2011


---
 dlls/wined3d/query.c |  173 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 161 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c
index 4e1eed2..cb471e3 100644
--- a/dlls/wined3d/query.c
+++ b/dlls/wined3d/query.c
@@ -4,6 +4,7 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  * Copyright 2009-2010 Henri Verbeet for CodeWeavers.
+ * Copyright 2011 Adam Martinson for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -251,17 +252,35 @@ ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
          * deleting the query will obviously leak it, but that's still better
          * than potentially deleting a different query with the same id in this
          * context, and (still) leaking the actual query. */
-        if (query->type == WINED3DQUERYTYPE_EVENT)
+        switch (query->type)
         {
-            struct wined3d_event_query *event_query = query->extendedData;
-            if (event_query) wined3d_event_query_destroy(event_query);
-        }
-        else if (query->type == WINED3DQUERYTYPE_OCCLUSION)
-        {
-            struct wined3d_occlusion_query *oq = query->extendedData;
+        case WINED3DQUERYTYPE_EVENT:
+            {
+                struct wined3d_event_query *event_query = query->extendedData;
+                if (event_query) wined3d_event_query_destroy(event_query);
+            }
+            break;
 
-            if (oq->context) context_free_occlusion_query(oq);
-            HeapFree(GetProcessHeap(), 0, query->extendedData);
+        case WINED3DQUERYTYPE_OCCLUSION:
+            {
+                struct wined3d_occlusion_query *oq = query->extendedData;
+
+                if (oq->context) context_free_occlusion_query(oq);
+                HeapFree(GetProcessHeap(), 0, query->extendedData);
+            }
+            break;
+
+        case WINED3DQUERYTYPE_TIMESTAMP:
+            {
+                struct wined3d_timestamp_query *tsq = query->extendedData;
+
+                if (tsq->context) context_free_timestamp_query(tsq);
+                HeapFree(GetProcessHeap(), 0, query->extendedData);
+            }
+            break;
+
+        default:
+            break;
         }
 
         HeapFree(GetProcessHeap(), 0, query);
@@ -412,6 +431,77 @@ static HRESULT wined3d_event_query_ops_get_data(struct wined3d_query *query,
     return S_OK;
 }
 
+/* Only called when GL_ARB_timer_query is supported. */
+static HRESULT wined3d_timestamp_query_ops_get_data(struct wined3d_query *query,
+                                                    void *pData, DWORD dwSize, DWORD flags)
+{
+    const struct wined3d_gl_info *gl_info = &query->device->adapter->gl_info;
+    struct wined3d_timestamp_query *This = query->extendedData;
+    struct wined3d_context *context;
+    GLuint available;
+    UINT64 *data = pData;
+    HRESULT res;
+
+    TRACE("(%p) : type D3DQUERY_TIMESTAMP, pData %p, dwSize %#x, flags %#x.\n", query, pData, dwSize, flags);
+
+    if (dwSize != sizeof(UINT64))
+        data = 0;
+
+    if (!This->context)
+        query->state = QUERY_CREATED;
+
+    if (query->state == QUERY_CREATED)
+    {
+        /* D3D allows GetData on a new query, OpenGL doesn't. So just invent the data ourselves */
+        TRACE("Query wasn't yet started, returning S_OK\n");
+        if (data) *data = 0;
+        return S_OK;
+    }
+
+    if (query->state == QUERY_BUILDING)
+    {
+        /* Msdn says this returns an error, but our tests show that S_FALSE is returned */
+        TRACE("Query is building, returning S_FALSE\n");
+        return S_FALSE;
+    }
+
+    if (This->context->tid != GetCurrentThreadId())
+    {
+        FIXME("%p Wrong thread, returning 0.\n", query);
+        if (data) *data = 0;
+        return S_OK;
+    }
+
+    context = context_acquire(query->device, This->context->current_rt);
+
+    ENTER_GL();
+
+    GL_EXTCALL(glGetQueryObjectuivARB(This->ids[0], GL_QUERY_RESULT_AVAILABLE_ARB, &available));
+    checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
+    TRACE("available %#x.\n", available);
+
+    if (available)
+    {
+        if (data)
+        {
+            GL_EXTCALL(glGetQueryObjectui64v(This->ids[0], GL_QUERY_RESULT_ARB, data));
+            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
+            TRACE("Returning 0x%08x%08x.\n", (UINT)((*data) >> 32), (UINT)((*data) & 0xFFFFFFFF));
+        }
+        res = S_OK;
+    }
+    else
+    {
+        res = S_FALSE;
+    }
+
+    LEAVE_GL();
+
+    context_release(context);
+
+    return res;
+}
+
 WINED3DQUERYTYPE CDECL wined3d_query_get_type(const struct wined3d_query *query)
 {
     TRACE("query %p.\n", query);
@@ -535,6 +625,39 @@ static HRESULT wined3d_occlusion_query_ops_issue(struct wined3d_query *query, DW
     return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL.    */
 }
 
+/* Only called when GL_ARB_timer_query is supported. */
+static HRESULT wined3d_timestamp_query_ops_issue(struct wined3d_query *query, DWORD flags)
+{
+    const struct wined3d_gl_info *gl_info = &query->device->adapter->gl_info;
+    struct wined3d_timestamp_query *This = query->extendedData;
+    struct wined3d_context *context;
+
+    TRACE("query %p, flags %#x.\n", query, flags);
+
+    /* MSDN: D3DISSUE_BEGIN not supported */
+
+    if (!This->context)
+    {
+        context = context_acquire(query->device, NULL);
+        context_alloc_timestamp_query(context, This);
+    }
+    else
+    {
+        context = context_acquire(query->device, This->context->current_rt);
+    }
+
+    ENTER_GL();
+    GL_EXTCALL(glQueryCounter(This->ids[0], GL_TIMESTAMP_ARB));
+    checkGLcall("glQueryCounter(GL_TIMESTAMP)");
+    LEAVE_GL();
+
+    context_release(context);
+
+    query->state = QUERY_SIGNALLED;
+
+    return WINED3D_OK; /* can be WINED3DERR_INVALIDCALL.    */
+}
+
 static const struct wined3d_query_ops event_query_ops =
 {
     wined3d_event_query_ops_get_data,
@@ -547,6 +670,12 @@ static const struct wined3d_query_ops occlusion_query_ops =
     wined3d_occlusion_query_ops_issue,
 };
 
+static const struct wined3d_query_ops timestamp_query_ops =
+{
+    wined3d_timestamp_query_ops_get_data,
+    wined3d_timestamp_query_ops_issue,
+};
+
 HRESULT query_init(struct wined3d_query *query, IWineD3DDeviceImpl *device, WINED3DQUERYTYPE type)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -591,12 +720,32 @@ HRESULT query_init(struct wined3d_query *query, IWineD3DDeviceImpl *device, WINE
             }
             break;
 
-        case WINED3DQUERYTYPE_VCACHE:
-        case WINED3DQUERYTYPE_RESOURCEMANAGER:
-        case WINED3DQUERYTYPE_VERTEXSTATS:
         case WINED3DQUERYTYPE_TIMESTAMP:
+            TRACE("Timestamp query.\n");
+            if (!gl_info->supported[ARB_TIMER_QUERY])
+            {
+                WARN("GL_ARB_timer_query not supported, returning WINED3DERR_NOTAVAILABLE.\n");
+                return WINED3DERR_NOTAVAILABLE;
+            }
+
+            query->data_size = sizeof(UINT64);
+            query->query_ops = &timestamp_query_ops;
+            query->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_timestamp_query));
+            if (!query->extendedData)
+            {
+                ERR("Failed to allocate event query memory.\n");
+                return E_OUTOFMEMORY;
+            }
+            ((struct wined3d_timestamp_query *)query->extendedData)->n_ids = 1;
+            ((struct wined3d_timestamp_query *)query->extendedData)->context = NULL;
+
+            break;
+
         case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
         case WINED3DQUERYTYPE_TIMESTAMPFREQ:
+        case WINED3DQUERYTYPE_VCACHE:
+        case WINED3DQUERYTYPE_RESOURCEMANAGER:
+        case WINED3DQUERYTYPE_VERTEXSTATS:
         case WINED3DQUERYTYPE_PIPELINETIMINGS:
         case WINED3DQUERYTYPE_INTERFACETIMINGS:
         case WINED3DQUERYTYPE_VERTEXTIMINGS:
-- 
1.7.1


--------------020407030507000107030307
Content-Type: text/x-patch;
 name="0009-wined3d-query-Add-support-for-D3DQUERY_TIMESTAMPDISJ.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0009-wined3d-query-Add-support-for-D3DQUERY_TIMESTAMPDISJ.pa";
 filename*1="tch"



More information about the wine-devel mailing list