[PATCH 4/5] wined3d: Properly compare integers in wined3d_pipeline_layout_vk_compare().

Henri Verbeet hverbeet at codeweavers.com
Thu Jan 20 10:30:56 CST 2022


As pointed out by Giovanni, modular subtraction doesn't produce a total order;
in particular, it's not transitive. For the values likely to be encountered by
wined3d_pipeline_layout_vk_compare(), this is perhaps unlikely to be an issue
in practice. However, that's not necessarily the case for e.g. handles or
masks.

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/context_vk.c      | 5 +++--
 dlls/wined3d/wined3d_private.h | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c
index fd6d810f0e2..cf6247387ca 100644
--- a/dlls/wined3d/context_vk.c
+++ b/dlls/wined3d/context_vk.c
@@ -1797,9 +1797,10 @@ static int wined3d_pipeline_layout_vk_compare(const void *key, const struct wine
     const struct wined3d_pipeline_layout_key_vk *a = key;
     const struct wined3d_pipeline_layout_key_vk *b = &WINE_RB_ENTRY_VALUE(entry,
             const struct wined3d_pipeline_layout_vk, entry)->key;
+    int ret;
 
-    if (a->binding_count != b->binding_count)
-        return a->binding_count - b->binding_count;
+    if ((ret = wined3d_uint32_compare(a->binding_count, b->binding_count)))
+        return ret;
     return memcmp(a->bindings, b->bindings, a->binding_count * sizeof(*a->bindings));
 }
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 5fa51a844ac..c9d83b3fbc7 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -447,6 +447,11 @@ static inline unsigned int wined3d_popcount(unsigned int x)
 #endif
 }
 
+static inline int wined3d_uint32_compare(uint32_t x, uint32_t y)
+{
+    return (x > y) - (x < y);
+}
+
 #define ORM_BACKBUFFER  0
 #define ORM_FBO         1
 
-- 
2.30.2




More information about the wine-devel mailing list