Commit c45b908a authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

wined3d: Introduce wined3d fence objects.

Use fences for the APPLESYNC codepath, and implement event queries on top of fences. Signed-off-by: 's avatarJózef Kucia <jkucia@codeweavers.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 11c902eb
......@@ -185,11 +185,10 @@ static void buffer_destroy_buffer_object(struct wined3d_buffer *buffer, struct w
checkGLcall("glDeleteBuffers");
buffer->buffer_object = 0;
if (buffer->query)
if (buffer->fence)
{
struct wined3d_query *query = &buffer->query->query;
query->query_ops->query_destroy(query);
buffer->query = NULL;
wined3d_fence_destroy(buffer->fence);
buffer->fence = NULL;
}
buffer->flags &= ~WINED3D_BUFFER_APPLESYNC;
}
......@@ -814,8 +813,7 @@ void * CDECL wined3d_buffer_get_parent(const struct wined3d_buffer *buffer)
/* The caller provides a context and binds the buffer */
static void buffer_sync_apple(struct wined3d_buffer *buffer, DWORD flags, const struct wined3d_gl_info *gl_info)
{
enum wined3d_event_query_result ret;
struct wined3d_query *query;
enum wined3d_fence_result ret;
HRESULT hr;
/* No fencing needs to be done if the app promises not to overwrite
......@@ -830,23 +828,18 @@ static void buffer_sync_apple(struct wined3d_buffer *buffer, DWORD flags, const
return;
}
if (!buffer->query)
if (!buffer->fence)
{
TRACE("Creating event query for buffer %p.\n", buffer);
TRACE("Creating fence for buffer %p.\n", buffer);
hr = wined3d_query_create(buffer->resource.device, WINED3D_QUERY_TYPE_EVENT,
NULL, &wined3d_null_parent_ops, &query);
if (hr == WINED3DERR_NOTAVAILABLE)
if (FAILED(hr = wined3d_fence_create(buffer->resource.device, &buffer->fence)))
{
FIXME("Event queries not supported, dropping async buffer locks.\n");
goto drop_query;
}
if (FAILED(hr))
{
ERR("Failed to create event query, hr %#x.\n", hr);
goto drop_query;
if (hr == WINED3DERR_NOTAVAILABLE)
FIXME("Fences not supported, dropping async buffer locks.\n");
else
ERR("Failed to create fence, hr %#x.\n", hr);
goto drop_fence;
}
buffer->query = CONTAINING_RECORD(query, struct wined3d_event_query, query);
/* Since we don't know about old draws a glFinish is needed once */
gl_info->gl_ops.gl.p_glFinish();
......@@ -854,29 +847,28 @@ static void buffer_sync_apple(struct wined3d_buffer *buffer, DWORD flags, const
}
TRACE("Synchronizing buffer %p.\n", buffer);
ret = wined3d_event_query_finish(buffer->query, buffer->resource.device);
ret = wined3d_fence_wait(buffer->fence, buffer->resource.device);
switch (ret)
{
case WINED3D_EVENT_QUERY_NOT_STARTED:
case WINED3D_EVENT_QUERY_OK:
case WINED3D_FENCE_NOT_STARTED:
case WINED3D_FENCE_OK:
/* All done */
return;
case WINED3D_EVENT_QUERY_WRONG_THREAD:
case WINED3D_FENCE_WRONG_THREAD:
WARN("Cannot synchronize buffer lock due to a thread conflict.\n");
goto drop_query;
goto drop_fence;
default:
ERR("wined3d_event_query_finish returned %u, dropping async buffer locks.\n", ret);
goto drop_query;
ERR("wined3d_fence_wait() returned %u, dropping async buffer locks.\n", ret);
goto drop_fence;
}
drop_query:
if (buffer->query)
drop_fence:
if (buffer->fence)
{
struct wined3d_query *query = &buffer->query->query;
query->query_ops->query_destroy(query);
buffer->query = NULL;
wined3d_fence_destroy(buffer->fence);
buffer->fence = NULL;
}
gl_info->gl_ops.gl.p_glFinish();
......
......@@ -794,63 +794,63 @@ void context_free_occlusion_query(struct wined3d_occlusion_query *query)
}
/* Context activation is done by the caller. */
void context_alloc_event_query(struct wined3d_context *context, struct wined3d_event_query *query)
void context_alloc_fence(struct wined3d_context *context, struct wined3d_fence *fence)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
if (context->free_event_query_count)
if (context->free_fence_count)
{
query->object = context->free_event_queries[--context->free_event_query_count];
fence->object = context->free_fences[--context->free_fence_count];
}
else
{
if (gl_info->supported[ARB_SYNC])
{
/* Using ARB_sync, not much to do here. */
query->object.sync = NULL;
TRACE("Allocated event query %p in context %p.\n", query->object.sync, context);
fence->object.sync = NULL;
TRACE("Allocated sync object in context %p.\n", context);
}
else if (gl_info->supported[APPLE_FENCE])
{
GL_EXTCALL(glGenFencesAPPLE(1, &query->object.id));
GL_EXTCALL(glGenFencesAPPLE(1, &fence->object.id));
checkGLcall("glGenFencesAPPLE");
TRACE("Allocated event query %u in context %p.\n", query->object.id, context);
TRACE("Allocated fence %u in context %p.\n", fence->object.id, context);
}
else if(gl_info->supported[NV_FENCE])
{
GL_EXTCALL(glGenFencesNV(1, &query->object.id));
GL_EXTCALL(glGenFencesNV(1, &fence->object.id));
checkGLcall("glGenFencesNV");
TRACE("Allocated event query %u in context %p.\n", query->object.id, context);
TRACE("Allocated fence %u in context %p.\n", fence->object.id, context);
}
else
{
WARN("Event queries not supported, not allocating query id.\n");
query->object.id = 0;
WARN("Fences not supported, not allocating fence.\n");
fence->object.id = 0;
}
}
query->context = context;
list_add_head(&context->event_queries, &query->entry);
fence->context = context;
list_add_head(&context->fences, &fence->entry);
}
void context_free_event_query(struct wined3d_event_query *query)
void context_free_fence(struct wined3d_fence *fence)
{
struct wined3d_context *context = query->context;
struct wined3d_context *context = fence->context;
list_remove(&query->entry);
query->context = NULL;
list_remove(&fence->entry);
fence->context = NULL;
if (!wined3d_array_reserve((void **)&context->free_event_queries,
&context->free_event_query_size, context->free_event_query_count + 1,
sizeof(*context->free_event_queries)))
if (!wined3d_array_reserve((void **)&context->free_fences,
&context->free_fence_size, context->free_fence_count + 1,
sizeof(*context->free_fences)))
{
ERR("Failed to grow free list, leaking query %u in context %p.\n", query->object.id, context);
ERR("Failed to grow free list, leaking fence %u in context %p.\n", fence->object.id, context);
return;
}
context->free_event_queries[context->free_event_query_count++] = query->object;
context->free_fences[context->free_fence_count++] = fence->object;
}
/* Context activation is done by the caller. */
......@@ -1265,8 +1265,8 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
struct wined3d_so_statistics_query *so_statistics_query;
struct wined3d_timestamp_query *timestamp_query;
struct wined3d_occlusion_query *occlusion_query;
struct wined3d_event_query *event_query;
struct fbo_entry *entry, *entry2;
struct wined3d_fence *fence;
HGLRC restore_ctx;
HDC restore_dc;
unsigned int i;
......@@ -1309,18 +1309,25 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
occlusion_query->context = NULL;
}
LIST_FOR_EACH_ENTRY(event_query, &context->event_queries, struct wined3d_event_query, entry)
LIST_FOR_EACH_ENTRY(fence, &context->fences, struct wined3d_fence, entry)
{
if (context->valid)
{
if (gl_info->supported[ARB_SYNC])
{
if (event_query->object.sync) GL_EXTCALL(glDeleteSync(event_query->object.sync));
if (fence->object.sync)
GL_EXTCALL(glDeleteSync(fence->object.sync));
}
else if (gl_info->supported[APPLE_FENCE])
{
GL_EXTCALL(glDeleteFencesAPPLE(1, &fence->object.id));
}
else if (gl_info->supported[NV_FENCE])
{
GL_EXTCALL(glDeleteFencesNV(1, &fence->object.id));
}
else if (gl_info->supported[APPLE_FENCE]) GL_EXTCALL(glDeleteFencesAPPLE(1, &event_query->object.id));
else if (gl_info->supported[NV_FENCE]) GL_EXTCALL(glDeleteFencesNV(1, &event_query->object.id));
}
event_query->context = NULL;
fence->context = NULL;
}
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_destroy_list, struct fbo_entry, entry)
......@@ -1368,23 +1375,23 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
if (gl_info->supported[ARB_SYNC])
{
for (i = 0; i < context->free_event_query_count; ++i)
for (i = 0; i < context->free_fence_count; ++i)
{
GL_EXTCALL(glDeleteSync(context->free_event_queries[i].sync));
GL_EXTCALL(glDeleteSync(context->free_fences[i].sync));
}
}
else if (gl_info->supported[APPLE_FENCE])
{
for (i = 0; i < context->free_event_query_count; ++i)
for (i = 0; i < context->free_fence_count; ++i)
{
GL_EXTCALL(glDeleteFencesAPPLE(1, &context->free_event_queries[i].id));
GL_EXTCALL(glDeleteFencesAPPLE(1, &context->free_fences[i].id));
}
}
else if (gl_info->supported[NV_FENCE])
{
for (i = 0; i < context->free_event_query_count; ++i)
for (i = 0; i < context->free_fence_count; ++i)
{
GL_EXTCALL(glDeleteFencesNV(1, &context->free_event_queries[i].id));
GL_EXTCALL(glDeleteFencesNV(1, &context->free_fences[i].id));
}
}
......@@ -1395,7 +1402,7 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
HeapFree(GetProcessHeap(), 0, context->free_pipeline_statistics_queries);
HeapFree(GetProcessHeap(), 0, context->free_timestamp_queries);
HeapFree(GetProcessHeap(), 0, context->free_occlusion_queries);
HeapFree(GetProcessHeap(), 0, context->free_event_queries);
HeapFree(GetProcessHeap(), 0, context->free_fences);
context_restore_pixel_format(context);
if (restore_ctx)
......@@ -1849,11 +1856,10 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
goto out;
list_init(&ret->occlusion_queries);
ret->free_event_query_size = 4;
if (!(ret->free_event_queries = wined3d_calloc(ret->free_event_query_size,
sizeof(*ret->free_event_queries))))
ret->free_fence_size = 4;
if (!(ret->free_fences = wined3d_calloc(ret->free_fence_size, sizeof(*ret->free_fences))))
goto out;
list_init(&ret->event_queries);
list_init(&ret->fences);
list_init(&ret->so_statistics_queries);
......@@ -2211,7 +2217,7 @@ out:
device->shader_backend->shader_free_context_data(ret);
device->adapter->fragment_pipe->free_context_data(ret);
HeapFree(GetProcessHeap(), 0, ret->texture_type);
HeapFree(GetProcessHeap(), 0, ret->free_event_queries);
HeapFree(GetProcessHeap(), 0, ret->free_fences);
HeapFree(GetProcessHeap(), 0, ret->free_occlusion_queries);
HeapFree(GetProcessHeap(), 0, ret->free_timestamp_queries);
HeapFree(GetProcessHeap(), 0, ret->fbo_key);
......@@ -3483,7 +3489,7 @@ static void context_update_stream_info(struct wined3d_context *context, const st
wined3d_stream_info_from_declaration(stream_info, state, gl_info, d3d_info);
stream_info->all_vbo = 1;
context->num_buffer_queries = 0;
context->buffer_fence_count = 0;
for (i = 0, map = stream_info->use_map; map; map >>= 1, ++i)
{
struct wined3d_stream_info_element *element;
......@@ -3524,8 +3530,8 @@ static void context_update_stream_info(struct wined3d_context *context, const st
if (!element->data.buffer_object)
stream_info->all_vbo = 0;
if (buffer->query)
context->buffer_queries[context->num_buffer_queries++] = buffer->query;
if (buffer->fence)
context->buffer_fences[context->buffer_fence_count++] = buffer->fence;
TRACE("Load array %u {%#x:%p}.\n", i, element->data.buffer_object, element->data.addr);
}
......
......@@ -469,9 +469,9 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
BOOL emulation = FALSE, rasterizer_discard = FALSE;
const struct wined3d_fb_state *fb = state->fb;
const struct wined3d_stream_info *stream_info;
struct wined3d_event_query *ib_query = NULL;
struct wined3d_rendertarget_view *dsv, *rtv;
struct wined3d_stream_info si_emulated;
struct wined3d_fence *ib_fence = NULL;
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
unsigned int i, idx_size = 0;
......@@ -556,7 +556,7 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
}
else
{
ib_query = index_buffer->query;
ib_fence = index_buffer->fence;
idx_data = NULL;
}
idx_data = (const BYTE *)idx_data + state->index_offset;
......@@ -655,10 +655,10 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s
checkGLcall("disable rasterizer discard");
}
if (ib_query)
wined3d_event_query_issue(ib_query, device);
for (i = 0; i < context->num_buffer_queries; ++i)
wined3d_event_query_issue(context->buffer_queries[i], device);
if (ib_fence)
wined3d_fence_issue(ib_fence, device);
for (i = 0; i < context->buffer_fence_count; ++i)
wined3d_fence_issue(context->buffer_fences[i], device);
if (wined3d_settings.strict_draw_ordering)
gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
......
......@@ -1607,6 +1607,34 @@ enum fogsource {
FOGSOURCE_COORD,
};
union wined3d_gl_fence_object
{
GLuint id;
GLsync sync;
};
enum wined3d_fence_result
{
WINED3D_FENCE_OK,
WINED3D_FENCE_WAITING,
WINED3D_FENCE_NOT_STARTED,
WINED3D_FENCE_WRONG_THREAD,
WINED3D_FENCE_ERROR,
};
struct wined3d_fence
{
struct list entry;
union wined3d_gl_fence_object object;
struct wined3d_context *context;
};
HRESULT wined3d_fence_create(struct wined3d_device *device, struct wined3d_fence **fence) DECLSPEC_HIDDEN;
void wined3d_fence_destroy(struct wined3d_fence *fence) DECLSPEC_HIDDEN;
void wined3d_fence_issue(struct wined3d_fence *fence, const struct wined3d_device *device) DECLSPEC_HIDDEN;
enum wined3d_fence_result wined3d_fence_wait(const struct wined3d_fence *fence,
const struct wined3d_device *device) DECLSPEC_HIDDEN;
/* Direct3D terminology with little modifications. We do not have an issued
* state because only the driver knows about it, but we have a created state
* because D3D allows GetData() on a created query, but OpenGL doesn't. */
......@@ -1641,35 +1669,14 @@ struct wined3d_query
struct list poll_list_entry;
};
union wined3d_gl_query_object
{
GLuint id;
GLsync sync;
};
struct wined3d_event_query
{
struct wined3d_query query;
struct list entry;
union wined3d_gl_query_object object;
struct wined3d_context *context;
struct wined3d_fence fence;
BOOL signalled;
};
enum wined3d_event_query_result
{
WINED3D_EVENT_QUERY_OK,
WINED3D_EVENT_QUERY_WAITING,
WINED3D_EVENT_QUERY_NOT_STARTED,
WINED3D_EVENT_QUERY_WRONG_THREAD,
WINED3D_EVENT_QUERY_ERROR
};
enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query,
const struct wined3d_device *device) DECLSPEC_HIDDEN;
void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device) DECLSPEC_HIDDEN;
struct wined3d_occlusion_query
{
struct wined3d_query query;
......@@ -1875,10 +1882,10 @@ struct wined3d_context
unsigned int free_occlusion_query_count;
struct list occlusion_queries;
union wined3d_gl_query_object *free_event_queries;
SIZE_T free_event_query_size;
unsigned int free_event_query_count;
struct list event_queries;
union wined3d_gl_fence_object *free_fences;
SIZE_T free_fence_size;
unsigned int free_fence_count;
struct list fences;
GLuint *free_timestamp_queries;
SIZE_T free_timestamp_query_size;
......@@ -1898,8 +1905,8 @@ struct wined3d_context
struct wined3d_stream_info stream_info;
/* Fences for GL_APPLE_flush_buffer_range */
struct wined3d_event_query *buffer_queries[MAX_ATTRIBS];
unsigned int num_buffer_queries;
struct wined3d_fence *buffer_fences[MAX_ATTRIBS];
unsigned int buffer_fence_count;
DWORD tex_unit_map[MAX_COMBINED_SAMPLERS];
DWORD rev_tex_unit_map[MAX_GL_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS];
......@@ -2046,8 +2053,7 @@ BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other) DECLSP
struct wined3d_context *context_acquire(const struct wined3d_device *device,
struct wined3d_texture *texture, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
void context_alloc_event_query(struct wined3d_context *context,
struct wined3d_event_query *query) DECLSPEC_HIDDEN;
void context_alloc_fence(struct wined3d_context *context, struct wined3d_fence *fence) DECLSPEC_HIDDEN;
void context_alloc_occlusion_query(struct wined3d_context *context,
struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
void context_apply_blit_state(struct wined3d_context *context, const struct wined3d_device *device) DECLSPEC_HIDDEN;
......@@ -2071,7 +2077,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, stru
HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;
void context_destroy(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_end_transform_feedback(struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
void context_free_fence(struct wined3d_fence *fence) DECLSPEC_HIDDEN;
void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
GLenum context_get_offscreen_gl_buffer(const struct wined3d_context *context) DECLSPEC_HIDDEN;
......@@ -3532,7 +3538,7 @@ struct wined3d_buffer
struct wined3d_map_range *maps;
SIZE_T maps_size, modified_areas;
struct wined3d_event_query *query;
struct wined3d_fence *fence;
/* conversion stuff */
UINT decl_change_count, full_conversion_count;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment