Zebediah Figura : wined3d: Treat NOOVERWRITE maps on a previously discarded buffer as if they were DISCARD maps.
Alexandre Julliard
julliard at winehq.org
Fri Feb 18 15:14:59 CST 2022
Module: wine
Branch: master
Commit: 83fc1807f9f85ce6c1a2e05a1d772c2e28eafd27
URL: https://source.winehq.org/git/wine.git/?a=commit;h=83fc1807f9f85ce6c1a2e05a1d772c2e28eafd27
Author: Zebediah Figura <zfigura at codeweavers.com>
Date: Thu Feb 17 23:01:39 2022 -0600
wined3d: Treat NOOVERWRITE maps on a previously discarded buffer as if they were DISCARD maps.
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 at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 4a3b805c0bd..7280739b8b2 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -67,6 +67,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;
@@ -2430,7 +2438,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;
@@ -3134,6 +3142,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
More information about the wine-cvs
mailing list