From d90748b256bfb8a81e9df8c6eeb92c523d0bc561 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 23 Aug 2018 23:47:50 +0200 Subject: [PATCH] Fix VkNonDispatchableHandle's alignment on 32bit platforms On 32bit platforms, even if it contains a uint64_t the handle wrapper will align to 4 bytes because the assembly load operations can't take advantage of 64bit aligned loads. Fix this by forcing the alignment to the alignment of what would be the native Vulkan handle type. Also use macros with defined() Change-Id: I0de9b4a77e648c416b04311b854c956762248868 --- src/common/vulkan_platform.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/common/vulkan_platform.h b/src/common/vulkan_platform.h index 69a3dd9415..445fae60b4 100644 --- a/src/common/vulkan_platform.h +++ b/src/common/vulkan_platform.h @@ -32,9 +32,21 @@ // redefined to be nullptr). This keeps the type-safety of having the handles be different types // (like vulkan.h on 64 bit) but makes sure the types are different on 32 bit architectures. +// Force the handle type to have the same alignment as what would have been the Vulkan +// non-dispatchable handle type. +#if defined(DAWN_PLATFORM_64_BIT) +// In 64 bit handles are pointers to some structure, we just declare one inline here. +using NativeVulkanHandleType = struct VkSomeHandle*; +#elif defined(DAWN_PLATFORM_32_BIT) +using NativeVulkanHandleType = uint64_t; +# define ALIGNAS_VULKAN_HANDLE alignas(alignof(uint64_t)) +#else +# error "Unsupported platform" +#endif + // Simple handle types that supports "nullptr_t" as a 0 value. template -class VkNonDispatchableHandle { +class alignas(alignof(NativeVulkanHandleType)) VkNonDispatchableHandle { public: // Default constructor and assigning of VK_NULL_HANDLE VkNonDispatchableHandle() = default; @@ -77,7 +89,7 @@ class VkNonDispatchableHandle { return mHandle; } -#if DAWN_PLATFORM_64_BIT +#if defined(DAWN_PLATFORM_64_BIT) static VkNonDispatchableHandle CreateFromHandle(HandleType handle) { return CreateFromU64(static_cast(reinterpret_cast(handle))); } @@ -85,7 +97,7 @@ class VkNonDispatchableHandle { HandleType GetHandle() const { return mHandle; } -#elif DAWN_PLATFORM_32_BIT +#elif defined(DAWN_PLATFORM_32_BIT) static VkNonDispatchableHandle CreateFromHandle(HandleType handle) { return {handle}; } @@ -104,10 +116,10 @@ class VkNonDispatchableHandle { uint64_t mHandle = 0; }; -#if DAWN_PLATFORM_64_BIT +#if defined(DAWN_PLATFORM_64_BIT) # define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) \ using object##Native = struct object##_T*; -#elif DAWN_PLATFORM_32_BIT +#elif defined(DAWN_PLATFORM_32_BIT) # define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object##Native = uint64_t; #else # error "Unsupported platform"