[PATCH 05/11] wined3d/query: Add support for D3DQUERY_TIMESTAMPDISJOINT queries.

Adam Martinson amartinson at codeweavers.com
Mon May 23 15:19:50 CDT 2011


---
 dlls/wined3d/query.c |  176 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c
index c0d5c63..a9ff6f4 100644
--- a/dlls/wined3d/query.c
+++ b/dlls/wined3d/query.c
@@ -273,6 +273,7 @@ ULONG CDECL wined3d_query_decref(struct wined3d_query *query)
             break;
 
         case WINED3DQUERYTYPE_TIMESTAMP:
+        case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
             {
                 struct wined3d_timestamp_query *tsq = query->extendedData;
 
@@ -496,6 +497,78 @@ static HRESULT wined3d_timestamp_query_ops_get_data(struct wined3d_query *query,
     return res;
 }
 
+/* Only called when GL_ARB_timer_query is supported. */
+static HRESULT wined3d_timestampdisjoint_query_ops_get_data(struct wined3d_query *query,
+                                                            void *data, DWORD size, DWORD flags)
+{
+    const struct wined3d_gl_info *gl_info = &query->device->adapter->gl_info;
+    struct wined3d_timestamp_query *timestamp_query = query->extendedData;
+    struct wined3d_context *context;
+    BOOL *disjoint = data;
+    GLuint available;
+    UINT64 time_start, time_end, time_elapsed;
+    HRESULT res;
+
+    TRACE("(%p) : type D3DQUERY_TIMESTAMPDISJOINT, data %p, size %#x, flags %#x.\n", query, data, size, flags);
+
+    if (!timestamp_query->context)
+        query->state = QUERY_CREATED;
+
+    if (query->state != QUERY_SIGNALLED)
+    {
+        /* 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 (disjoint)
+            *disjoint = TRUE;
+
+        return S_OK;
+    }
+
+    if (timestamp_query->context->tid != GetCurrentThreadId())
+    {
+        FIXME("%p Wrong thread, setting data to TRUE.\n", query);
+        if (disjoint)
+            *disjoint = TRUE;
+
+        return S_OK;
+    }
+
+    context = context_acquire(query->device, timestamp_query->context->current_rt);
+
+    ENTER_GL();
+
+    GL_EXTCALL(glGetQueryObjectuivARB(timestamp_query->ids[2], GL_QUERY_RESULT_AVAILABLE_ARB, &available));
+    checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
+    TRACE("available %#x.\n", available);
+
+    if (available)
+    {
+        if (disjoint)
+        {
+            GL_EXTCALL(glGetQueryObjectui64v(timestamp_query->ids[0], GL_QUERY_RESULT_ARB, &time_start));
+            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
+            GL_EXTCALL(glGetQueryObjectui64v(timestamp_query->ids[1], GL_QUERY_RESULT_ARB, &time_end));
+            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
+            GL_EXTCALL(glGetQueryObjectui64v(timestamp_query->ids[2], GL_QUERY_RESULT_ARB, &time_elapsed));
+            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
+
+            *disjoint = ((time_start >= time_end) || ((time_end - time_start) > time_elapsed));
+        }
+
+        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);
@@ -652,6 +725,83 @@ static HRESULT wined3d_timestamp_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_timestampdisjoint_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 *timestamp_query = query->extendedData;
+    struct wined3d_context *context;
+
+    TRACE("query %p, flags %#x.\n", query, flags);
+
+    if (flags & WINED3DISSUE_BEGIN)
+    {
+        if (query->state == QUERY_BUILDING)
+        {
+            if (timestamp_query->context->tid != GetCurrentThreadId())
+            {
+                FIXME("Wrong thread, can't restart query.\n");
+
+                context_free_timestamp_query(timestamp_query);
+                context = context_acquire(query->device, NULL);
+                context_alloc_timestamp_query(context, timestamp_query);
+            }
+            else
+            {
+                context = context_acquire(query->device, timestamp_query->context->current_rt);
+
+                ENTER_GL();
+                GL_EXTCALL(glEndQueryARB(GL_TIME_ELAPSED_ARB));
+                checkGLcall("glEndQuery(GL_TIME_ELAPSED)");
+                LEAVE_GL();
+            }
+        }
+        else
+        {
+            if (timestamp_query->context) context_free_timestamp_query(timestamp_query);
+            context = context_acquire(query->device, NULL);
+            context_alloc_timestamp_query(context, timestamp_query);
+        }
+
+        ENTER_GL();
+        GL_EXTCALL(glBeginQueryARB(GL_TIME_ELAPSED_ARB, timestamp_query->ids[2]));
+        checkGLcall("glBeginQuery(GL_TIME_ELAPSED)");
+        GL_EXTCALL(glQueryCounter(timestamp_query->ids[0], GL_TIMESTAMP_ARB));
+        checkGLcall("glQueryCounter(GL_TIMESTAMP)");
+        LEAVE_GL();
+
+        context_release(context);
+        query->state = QUERY_BUILDING;
+    }
+    if (flags & WINED3DISSUE_END)
+    {
+        if (query->state == QUERY_BUILDING)
+        {
+            if (timestamp_query->context->tid != GetCurrentThreadId())
+            {
+                FIXME("Wrong thread, can't end query.\n");
+            }
+            else
+            {
+                context = context_acquire(query->device, timestamp_query->context->current_rt);
+
+                ENTER_GL();
+                GL_EXTCALL(glQueryCounter(timestamp_query->ids[1], GL_TIMESTAMP_ARB));
+                checkGLcall("glQueryCounter(GL_TIMESTAMP)");
+                GL_EXTCALL(glEndQueryARB(GL_TIME_ELAPSED_ARB));
+                checkGLcall("glEndQuery(GL_TIME_ELAPSED)");
+                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,
@@ -670,6 +820,12 @@ static const struct wined3d_query_ops timestamp_query_ops =
     wined3d_timestamp_query_ops_issue,
 };
 
+static const struct wined3d_query_ops timestampdisjoint_query_ops =
+{
+    wined3d_timestampdisjoint_query_ops_get_data,
+    wined3d_timestampdisjoint_query_ops_issue,
+};
+
 static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *device, WINED3DQUERYTYPE type)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -736,6 +892,26 @@ static HRESULT query_init(struct wined3d_query *query, struct wined3d_device *de
             break;
 
         case WINED3DQUERYTYPE_TIMESTAMPDISJOINT:
+            TRACE("Timestampdisjoint 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(BOOL);
+            query->query_ops = &timestampdisjoint_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 = 3;
+            ((struct wined3d_timestamp_query *)query->extendedData)->context = NULL;
+
+            break;
+
         case WINED3DQUERYTYPE_TIMESTAMPFREQ:
         case WINED3DQUERYTYPE_VCACHE:
         case WINED3DQUERYTYPE_RESOURCEMANAGER:
-- 
1.7.1


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



More information about the wine-devel mailing list