From 8128dc31020143b426bc4f4987f13b10158eebc5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 29 May 2016 21:01:57 +0200 Subject: [PATCH] Fix other type-punning strict aliasing violations. Refs #274 --- renderdoc/driver/vulkan/vk_replay.cpp | 33 ++++++++++++++++++++++++--- renderdoc/serialise/utf8printf.cpp | 19 +++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index f54d603ed..5edc8f94f 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -1723,7 +1723,8 @@ void VulkanReplay::RenderMesh(uint32_t eventID, const vector &second MeshUBOData *data = (MeshUBOData *)GetDebugManager()->m_MeshUBO.Map(&uboOffs); data->mvp = ModelViewProj; - data->color = (Vec4f &)cfg.prevMeshColour; + data->color = Vec4f(cfg.prevMeshColour.x, cfg.prevMeshColour.y, cfg.prevMeshColour.z, + cfg.prevMeshColour.w); data->homogenousInput = cfg.position.unproject; data->pointSpriteSize = Vec2f(0.0f, 0.0f); data->displayFormat = MESHDISPLAY_SOLID; @@ -3498,7 +3499,20 @@ void VulkanReplay::SavePipelineState() dst.bindings[b].binds[a].res = rm->GetOriginalID(c.m_BufferView[viewid].buffer); dst.bindings[b].binds[a].offset = c.m_BufferView[viewid].offset; if(dynamicOffset) - dst.bindings[b].binds[a].offset += *(uint32_t *)&info[a].imageInfo.imageLayout; + { + union + { + VkImageLayout l; + uint32_t u; + } offs; + + RDCCOMPILE_ASSERT(sizeof(VkImageLayout) == sizeof(uint32_t), + "VkImageLayout isn't 32-bit sized"); + + offs.l = info[a].imageInfo.imageLayout; + + dst.bindings[b].binds[a].offset += offs.u; + } dst.bindings[b].binds[a].size = c.m_BufferView[viewid].size; } else @@ -3522,7 +3536,20 @@ void VulkanReplay::SavePipelineState() dst.bindings[b].binds[a].offset = info[a].bufferInfo.offset; if(dynamicOffset) - dst.bindings[b].binds[a].offset += *(uint32_t *)&info[a].imageInfo.imageLayout; + { + union + { + VkImageLayout l; + uint32_t u; + } offs; + + RDCCOMPILE_ASSERT(sizeof(VkImageLayout) == sizeof(uint32_t), + "VkImageLayout isn't 32-bit sized"); + + offs.l = info[a].imageInfo.imageLayout; + + dst.bindings[b].binds[a].offset += offs.u; + } dst.bindings[b].binds[a].size = info[a].bufferInfo.range; } diff --git a/renderdoc/serialise/utf8printf.cpp b/renderdoc/serialise/utf8printf.cpp index 2e6cbf54b..80f8ba35e 100644 --- a/renderdoc/serialise/utf8printf.cpp +++ b/renderdoc/serialise/utf8printf.cpp @@ -117,15 +117,26 @@ void PrintInteger(bool typeUnsigned, uint64_t argu, int base, uint64_t numbits, { int64_t argi = 0; + union + { + uint64_t *u64; + signed int *i; + signed char *c; + signed short *s; + int64_t *i64; + } typepun; + + typepun.u64 = &argu; + // cast the appropriate size to signed version switch(formatter.Length) { default: case None: - case Long: argi = (int64_t) * (signed int *)&argu; break; - case HalfHalf: argi = (int64_t) * (signed char *)&argu; break; - case Half: argi = (int64_t) * (signed short *)&argu; break; - case LongLong: argi = (int64_t) * (int64_t *)&argu; break; + case Long: argi = (int64_t)*typepun.i; break; + case HalfHalf: argi = (int64_t)*typepun.c; break; + case Half: argi = (int64_t)*typepun.s; break; + case LongLong: argi = (int64_t)*typepun.i64; break; } bool negative = false;