[PATCH vkd3d 2/4] vkd3d: Skip redundant descriptor copies.

Conor McCarthy cmccarthy at codeweavers.com
Wed Dec 8 09:00:21 CST 2021


Greatly improves performance in Control.

Based on a vkd3d-proton patch by Philip Rebohle.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 libs/vkd3d/resource.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c
index 19912231..d7888f2f 100644
--- a/libs/vkd3d/resource.c
+++ b/libs/vkd3d/resource.c
@@ -2159,7 +2159,27 @@ void d3d12_desc_copy(struct d3d12_desc *dst, const struct d3d12_desc *src,
     assert(dst != src);
 
     /* Shadow of the Tomb Raider and possibly other titles sometimes destroy
-     * and rewrite a descriptor in another thread while it is being copied. */
+     * and rewrite a descriptor in another thread while it is being copied.
+     * We don't need to lock either descriptor for the update check. The purpose
+     * of locking descriptors is not to make descriptor writes thread safe,
+     * but only to prevent use-after-free of the vkd3d_view caused by a race
+     * condition in the calling app. It's not important if the update check
+     * falls out of date as it's their race condition, not ours. */
+    if (dst->magic == src->magic)
+    {
+        if (dst->magic & VKD3D_DESCRIPTOR_MAGIC_HAS_VIEW)
+        {
+            if (dst->u.view == src->u.view)
+                return;
+        }
+        else if (dst->u.vk_cbv_info.buffer == src->u.vk_cbv_info.buffer
+                && dst->u.vk_cbv_info.offset == src->u.vk_cbv_info.offset
+                && dst->u.vk_cbv_info.range == src->u.vk_cbv_info.range)
+        {
+            return;
+        }
+    }
+
     mutex = d3d12_device_get_descriptor_mutex(device, src);
     pthread_mutex_lock(mutex);
 
-- 
2.33.0




More information about the wine-devel mailing list