From d9ed9ae33193c9db1ee7616363848d5b0b65196c Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 3 Nov 2022 02:25:08 -0500 Subject: [PATCH] VideoCommon: Zero PortableVertexDeclarations on initialization Fixes an issue where the default initializer wouldn't initialize padding, making for fun non-determinism --- Source/Core/VideoCommon/NativeVertexFormat.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Core/VideoCommon/NativeVertexFormat.h b/Source/Core/VideoCommon/NativeVertexFormat.h index 89f3a06db5..c2761c9514 100644 --- a/Source/Core/VideoCommon/NativeVertexFormat.h +++ b/Source/Core/VideoCommon/NativeVertexFormat.h @@ -63,6 +63,9 @@ struct PortableVertexDeclaration std::array texcoords; AttributeFormat posmtx; + // Make sure we initialize padding to 0 since padding is included in the == memcmp + PortableVertexDeclaration() { memset(this, 0, sizeof(*this)); } + inline bool operator<(const PortableVertexDeclaration& b) const { return memcmp(this, &b, sizeof(PortableVertexDeclaration)) < 0; @@ -73,6 +76,9 @@ struct PortableVertexDeclaration } }; +static_assert(std::is_trivially_copyable_v, + "Make sure we can memset-initialize"); + namespace std { template <>