From efb8422ba051e1cf72b7058b2e72e1395ed09575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Tue, 5 Jan 2010 16:15:17 +0100 Subject: [PATCH 6/6] WineD3D: Implement D3DLOCK_DISCARD asynchronity --- dlls/wined3d/buffer.c | 31 ++++++++++++++++++++++++++++--- dlls/wined3d/device.c | 2 +- dlls/wined3d/drawprim.c | 13 +------------ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 905c140..510112d 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1052,6 +1052,8 @@ static WINED3DRESOURCETYPE STDMETHODCALLTYPE buffer_GetType(IWineD3DBuffer *ifac } /* IWineD3DBuffer methods */ + +/* The caller provides a GL context and holds the lock */ static void buffer_sync_apple(struct wined3d_buffer *This, DWORD flags) { HRESULT hr; @@ -1059,8 +1061,31 @@ static void buffer_sync_apple(struct wined3d_buffer *This, DWORD flags) /* No fencing needs to be done if the app promises not to override * existing data */ if(flags & WINED3DLOCK_NOOVERWRITE) return; + if(flags & WINED3DLOCK_DISCARD) + { + GL_EXTCALL(glBufferDataARB(This->buffer_type_hint, This->resource.size, NULL, This->buffer_object_usage)); + checkGLcall("glBufferDataARB\n"); + return; + } + + if(!This->query) + { + IWineD3DDevice *device = (IWineD3DDevice *) This->resource.device; + + LEAVE_GL(); + /* Since we don't know about old draws a glFinish is needed now. */ + wglFinish(); + + hr = IWineD3DDevice_CreateQuery(device, WINED3DQUERYTYPE_EVENT, &This->query, NULL); + if(FAILED(hr)) + { + ERR("Creating an event query for the buffer failed\n"); + } - if(!This->query) return; /* No draw yet */ + ENTER_GL(); + return; /* No draw yet */ + } + do { hr = IWineD3DQuery_GetData(This->query, NULL, 0, 0); @@ -1097,12 +1122,12 @@ static HRESULT STDMETHODCALLTYPE buffer_Map(IWineD3DBuffer *iface, UINT offset, IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_INDEXBUFFER); } - if(This->flags & WINED3D_BUFFER_APPLESYNC) buffer_sync_apple(This, flags); - context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD); ENTER_GL(); GL_EXTCALL(glBindBufferARB(This->buffer_type_hint, This->buffer_object)); + if(This->flags & WINED3D_BUFFER_APPLESYNC) buffer_sync_apple(This, flags); + This->resource.allocatedMemory = GL_EXTCALL(glMapBufferARB(This->buffer_type_hint, GL_READ_WRITE_ARB)); LEAVE_GL(); context_release(context); diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 94d9532..71d30a6 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -321,7 +321,7 @@ void device_stream_info_from_declaration(IWineD3DDeviceImpl *This, if (vb) { IWineD3DBuffer_PreLoad(vb); - if(((struct wined3d_buffer *) vb)->flags & WINED3D_BUFFER_APPLESYNC) + if(((struct wined3d_buffer *) vb)->query) { This->buffer_fences[This->num_buffer_fences++] = vb; } diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 160b73c..53860fe 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -696,18 +696,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT { struct wined3d_buffer *cur = (struct wined3d_buffer *) This->buffer_fences[i]; - if(!cur->query) - { - HRESULT hr; - hr = IWineD3DDevice_CreateQuery(iface, WINED3DQUERYTYPE_EVENT, &cur->query, NULL); - if(FAILED(hr)) - { - ERR("Creating an event query for the buffer failed\n"); - continue; - } - } - - IWineD3DQuery_Issue(cur->query, WINED3DISSUE_END); + if(cur->query) IWineD3DQuery_Issue(cur->query, WINED3DISSUE_END); } TRACE("Done all gl drawing\n"); -- 1.6.4.4