For the purposes of wined3d_cs_map_upload_bo().
That is, if a buffer was just created or just discarded [e.g. with wined3d_device_evict_managed_resources()], and then subsequently mapped with WINED3D_MAP_NOOVERWRITE, treat it as if it had been mapped with WINED3D_MAP_DISCARD instead, thus allowing the adapter_alloc_upload_bo callback to allocate a new buffer from the client thread.
This was the source of a bunch of stalls in Grand Theft Auto V, although it's hard to measure a difference in performance.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/buffer.c | 3 +++ dlls/wined3d/cs.c | 13 ++++++++++++- dlls/wined3d/wined3d_private.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 16308a098e3..63afa01bb2e 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1321,6 +1321,9 @@ static HRESULT wined3d_buffer_init(struct wined3d_buffer *buffer, struct wined3d } buffer->maps_size = 1;
+ if (buffer->locations & WINED3D_LOCATION_DISCARDED) + buffer->resource.client.addr.buffer_object = CLIENT_BO_DISCARDED; + if (data) wined3d_buffer_init_data(buffer, device, data);
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c index af3ee9e7624..ae1f4ad18e0 100644 --- a/dlls/wined3d/cs.c +++ b/dlls/wined3d/cs.c @@ -69,6 +69,14 @@ struct wined3d_command_list struct wined3d_deferred_query_issue *queries; };
+static void discard_client_address(struct wined3d_resource *resource) +{ + struct wined3d_client_resource *client = &resource->client; + + client->addr.buffer_object = CLIENT_BO_DISCARDED; + client->addr.addr = NULL; +} + static void invalidate_client_address(struct wined3d_resource *resource) { struct wined3d_client_resource *client = &resource->client; @@ -2432,7 +2440,7 @@ void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resou { struct wined3d_cs_unload_resource *op;
- invalidate_client_address(resource); + discard_client_address(resource);
op = wined3d_device_context_require_space(&cs->c, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); op->opcode = WINED3D_CS_OP_UNLOAD_RESOURCE; @@ -3136,6 +3144,9 @@ static bool wined3d_cs_map_upload_bo(struct wined3d_device_context *context, str return NULL; }
+ if ((flags & WINED3D_MAP_NOOVERWRITE) && client->addr.buffer_object == CLIENT_BO_DISCARDED) + flags = (flags & ~WINED3D_MAP_NOOVERWRITE) | WINED3D_MAP_DISCARD; + if (flags & WINED3D_MAP_DISCARD) { if (!device->adapter->adapter_ops->adapter_alloc_bo(device, resource, sub_resource_idx, &addr)) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index eff42be3aa6..989fd33d2bf 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -4276,6 +4276,8 @@ static inline ULONG wined3d_atomic_decrement_mutex_lock(volatile LONG *refcount) return count - 1; }
+#define CLIENT_BO_DISCARDED ((struct wined3d_bo *)~(UINT_PTR)0) + struct wined3d_client_resource { /* The resource's persistently mapped address, which we may use to perform