Mesa (main): gallium/util: make pipe_vertex_buffer_reference safe for hashing dst

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 1 15:45:22 UTC 2021


Module: Mesa
Branch: main
Commit: d5218f08891650dd638c0484d237dfa4675f8d74
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d5218f08891650dd638c0484d237dfa4675f8d74

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Aug 20 20:49:34 2021 -0400

gallium/util: make pipe_vertex_buffer_reference safe for hashing dst

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13050>

---

 src/gallium/auxiliary/util/u_inlines.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
index cd6e9351352..7e040138ec2 100644
--- a/src/gallium/auxiliary/util/u_inlines.h
+++ b/src/gallium/auxiliary/util/u_inlines.h
@@ -252,9 +252,17 @@ pipe_vertex_buffer_reference(struct pipe_vertex_buffer *dst,
    }
 
    pipe_vertex_buffer_unreference(dst);
-   if (!src->is_user_buffer)
+   /* Don't use memcpy because there is a hole between variables.
+    * dst can be used as a hash key.
+    */
+   dst->stride = src->stride;
+   dst->is_user_buffer = src->is_user_buffer;
+   dst->buffer_offset = src->buffer_offset;
+
+   if (src->is_user_buffer)
+      dst->buffer.user = src->buffer.user;
+   else
       pipe_resource_reference(&dst->buffer.resource, src->buffer.resource);
-   memcpy(dst, src, sizeof(*src));
 }
 
 static inline void



More information about the mesa-commit mailing list