From 04ae0a61e0f9801d2ebc525ee50a268c08536a66 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 26 Mar 2020 11:14:03 -0400 Subject: [PATCH] Replace use of memcmp() with mvkAreEqual(). --- .../Commands/MVKCommandResourceFactory.h | 22 +++++-------------- MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h index 3f1e769a..1bf9bd19 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h +++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h @@ -112,9 +112,9 @@ namespace std { * This structure can be used as a key in a std::map and std::unordered_map. */ typedef struct MVKRPSKeyClearAtt { - uint16_t attachmentMTLPixelFormats[kMVKClearAttachmentCount]; + uint16_t flags; // bitcount > kMVKClearAttachmentLayeredRenderingBitIndex uint16_t mtlSampleCount; - uint16_t flags; // bitcount > kMVKClearAttachmentLayeredRenderingBitIndex + uint16_t attachmentMTLPixelFormats[kMVKClearAttachmentCount]; const static uint32_t bitFlag = 1; @@ -126,11 +126,7 @@ typedef struct MVKRPSKeyClearAtt { bool isLayeredRenderingEnabled() { return mvkIsAnyFlagEnabled(flags, bitFlag << kMVKClearAttachmentLayeredRenderingBitIndex); } - bool operator==(const MVKRPSKeyClearAtt& rhs) const { - return ((flags == rhs.flags) && - (mtlSampleCount == rhs.mtlSampleCount) && - (memcmp(attachmentMTLPixelFormats, rhs.attachmentMTLPixelFormats, sizeof(attachmentMTLPixelFormats)) == 0)); - } + bool operator==(const MVKRPSKeyClearAtt& rhs) const { return mvkAreEqual(this, &rhs); } std::size_t hash() const { std::size_t hash = mvkHash(&flags); @@ -212,9 +208,7 @@ typedef struct MVKMTLDepthStencilDescriptorData { MVKMTLStencilDescriptorData frontFaceStencilData; MVKMTLStencilDescriptorData backFaceStencilData; - bool operator==(const MVKMTLDepthStencilDescriptorData& rhs) const { - return (memcmp(this, &rhs, sizeof(*this)) == 0); - } + bool operator==(const MVKMTLDepthStencilDescriptorData& rhs) const { return mvkAreEqual(this, &rhs); } std::size_t hash() const { return mvkHash((uint64_t*)this, sizeof(*this) / sizeof(uint64_t)); @@ -270,9 +264,7 @@ typedef struct MVKImageDescriptorData { VkSampleCountFlagBits samples; VkImageUsageFlags usage; - bool operator==(const MVKImageDescriptorData& rhs) const { - return (memcmp(this, &rhs, sizeof(*this)) == 0); - } + bool operator==(const MVKImageDescriptorData& rhs) const { return mvkAreEqual(this, &rhs); } std::size_t hash() const { return mvkHash((uint64_t*)this, sizeof(*this) / sizeof(uint64_t)); @@ -307,9 +299,7 @@ typedef struct MVKBufferDescriptorData { VkDeviceSize size; VkBufferUsageFlags usage; - bool operator==(const MVKBufferDescriptorData& rhs) const { - return (memcmp(this, &rhs, sizeof(*this)) == 0); - } + bool operator==(const MVKBufferDescriptorData& rhs) const { return mvkAreEqual(this, &rhs); } std::size_t hash() const { return mvkHash((uint64_t*)this, sizeof(*this) / sizeof(uint64_t)); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index c7a1aad7..cadf19ba 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -1544,7 +1544,7 @@ void MVKPipelineCache::readData(const VkPipelineCacheCreateInfo* pCreateInfo) { if (NSSwapLittleIntToHost(hdrComponent) != pDevProps->deviceID) { return; } reader(pcUUID); // Pipeline cache UUID - if (memcmp(pcUUID, pDevProps->pipelineCacheUUID, VK_UUID_SIZE) != 0) { return; } + if (mvkAreEqual(pcUUID, pDevProps->pipelineCacheUUID, VK_UUID_SIZE)) { return; } bool done = false; while ( !done ) {