Commit 803274ac authored by Jan Sikorski's avatar Jan Sikorski Committed by Alexandre Julliard

wined3d: Reduce locking of device context operations.

Only actually take the lock for the immediate context. According to the d3d11 documentation, operations on device contexts are not thread safe, and testing on Windows confirms this. Signed-off-by: 's avatarJan Sikorski <jsikorski@codeweavers.com> Signed-off-by: 's avatarHenri Verbeet <hverbeet@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent ce93526f
...@@ -1019,7 +1019,7 @@ void CDECL wined3d_device_context_dispatch(struct wined3d_device_context *contex ...@@ -1019,7 +1019,7 @@ void CDECL wined3d_device_context_dispatch(struct wined3d_device_context *contex
{ {
struct wined3d_cs_dispatch *op; struct wined3d_cs_dispatch *op;
wined3d_mutex_lock(); wined3d_device_context_lock(context);
op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
op->opcode = WINED3D_CS_OP_DISPATCH; op->opcode = WINED3D_CS_OP_DISPATCH;
op->parameters.indirect = FALSE; op->parameters.indirect = FALSE;
...@@ -1030,7 +1030,7 @@ void CDECL wined3d_device_context_dispatch(struct wined3d_device_context *contex ...@@ -1030,7 +1030,7 @@ void CDECL wined3d_device_context_dispatch(struct wined3d_device_context *contex
acquire_compute_pipeline_resources(context); acquire_compute_pipeline_resources(context);
wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT);
wined3d_mutex_unlock(); wined3d_device_context_unlock(context);
} }
void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_context *context, void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_context *context,
...@@ -1038,7 +1038,7 @@ void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_contex ...@@ -1038,7 +1038,7 @@ void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_contex
{ {
struct wined3d_cs_dispatch *op; struct wined3d_cs_dispatch *op;
wined3d_mutex_lock(); wined3d_device_context_lock(context);
op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
op->opcode = WINED3D_CS_OP_DISPATCH; op->opcode = WINED3D_CS_OP_DISPATCH;
op->parameters.indirect = TRUE; op->parameters.indirect = TRUE;
...@@ -1049,7 +1049,7 @@ void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_contex ...@@ -1049,7 +1049,7 @@ void CDECL wined3d_device_context_dispatch_indirect(struct wined3d_device_contex
wined3d_device_context_acquire_resource(context, &buffer->resource); wined3d_device_context_acquire_resource(context, &buffer->resource);
wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT);
wined3d_mutex_unlock(); wined3d_device_context_unlock(context);
} }
static void wined3d_cs_exec_draw(struct wined3d_cs *cs, const void *data) static void wined3d_cs_exec_draw(struct wined3d_cs *cs, const void *data)
...@@ -1206,7 +1206,7 @@ void CDECL wined3d_device_context_draw_indirect(struct wined3d_device_context *c ...@@ -1206,7 +1206,7 @@ void CDECL wined3d_device_context_draw_indirect(struct wined3d_device_context *c
const struct wined3d_state *state = context->state; const struct wined3d_state *state = context->state;
struct wined3d_cs_draw *op; struct wined3d_cs_draw *op;
wined3d_mutex_lock(); wined3d_device_context_lock(context);
op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); op = wined3d_device_context_require_space(context, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT);
op->opcode = WINED3D_CS_OP_DRAW; op->opcode = WINED3D_CS_OP_DRAW;
op->primitive_type = state->primitive_type; op->primitive_type = state->primitive_type;
...@@ -1220,7 +1220,7 @@ void CDECL wined3d_device_context_draw_indirect(struct wined3d_device_context *c ...@@ -1220,7 +1220,7 @@ void CDECL wined3d_device_context_draw_indirect(struct wined3d_device_context *c
wined3d_device_context_acquire_resource(context, &buffer->resource); wined3d_device_context_acquire_resource(context, &buffer->resource);
wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT); wined3d_device_context_submit(context, WINED3D_CS_QUEUE_DEFAULT);
wined3d_mutex_unlock(); wined3d_device_context_unlock(context);
} }
static void wined3d_cs_exec_flush(struct wined3d_cs *cs, const void *data) static void wined3d_cs_exec_flush(struct wined3d_cs *cs, const void *data)
...@@ -3824,7 +3824,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device ...@@ -3824,7 +3824,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device
TRACE("context %p, list %p.\n", context, list); TRACE("context %p, list %p.\n", context, list);
wined3d_mutex_lock(); wined3d_device_context_lock(context);
memory = heap_alloc(sizeof(*object) + deferred->resource_count * sizeof(*object->resources) memory = heap_alloc(sizeof(*object) + deferred->resource_count * sizeof(*object->resources)
+ deferred->upload_count * sizeof(*object->uploads) + deferred->upload_count * sizeof(*object->uploads)
+ deferred->command_list_count * sizeof(*object->command_lists) + deferred->command_list_count * sizeof(*object->command_lists)
...@@ -3833,7 +3833,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device ...@@ -3833,7 +3833,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device
if (!memory) if (!memory)
{ {
wined3d_mutex_unlock(); wined3d_device_context_unlock(context);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
...@@ -3886,7 +3886,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device ...@@ -3886,7 +3886,7 @@ HRESULT CDECL wined3d_deferred_context_record_command_list(struct wined3d_device
TRACE("Created command list %p.\n", object); TRACE("Created command list %p.\n", object);
*list = object; *list = object;
wined3d_mutex_unlock(); wined3d_device_context_unlock(context);
return S_OK; return S_OK;
} }
...@@ -4839,6 +4839,18 @@ struct wined3d_cs ...@@ -4839,6 +4839,18 @@ struct wined3d_cs
LONG pending_presents; LONG pending_presents;
}; };
static inline void wined3d_device_context_lock(struct wined3d_device_context *context)
{
if (context == &context->device->cs->c)
wined3d_mutex_lock();
}
static inline void wined3d_device_context_unlock(struct wined3d_device_context *context)
{
if (context == &context->device->cs->c)
wined3d_mutex_unlock();
}
struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device, struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN; const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN;
void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN; void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
......
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