From 519edd5890cb528c84a34e22e923a1f17c7d22ed Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 8 Jul 2020 18:50:30 +0000 Subject: [PATCH] Fix MSVC compilation. - Fix a struct vs. class in forward declaration of std::hash - Fix an unsigned vs. signed compare in BitSetIterator - Fix the assumption that std::array::[const_]iterator is a pointer. - Fix for reinterpret_cast from uint64_t to uint64_t not being allowed for vulkan_platform.h - Fix for a 32bit shift being expanded to 64bit. Bug: None Change-Id: I5f2bf8745aa1ef1eba9916fcf6ff7801b48f61cf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24501 Reviewed-by: Kai Ninomiya Reviewed-by: Austin Eng Commit-Queue: Kai Ninomiya --- src/common/BitSetIterator.h | 2 +- src/common/HashUtils.h | 2 +- src/common/ityp_array.h | 8 ++++---- src/common/ityp_bitset.h | 2 +- src/common/vulkan_platform.h | 10 ++++++++++ src/dawn_native/vulkan/SwapChainVk.cpp | 4 ++-- src/tests/unittests/ITypArrayTests.cpp | 4 ---- src/tests/unittests/ITypBitsetTests.cpp | 2 +- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/common/BitSetIterator.h b/src/common/BitSetIterator.h index d35bc8a2df..14ba4856ff 100644 --- a/src/common/BitSetIterator.h +++ b/src/common/BitSetIterator.h @@ -48,7 +48,7 @@ class BitSetIterator final { T operator*() const { using U = UnderlyingType; - ASSERT(mCurrentBit <= std::numeric_limits::max()); + ASSERT(static_cast(mCurrentBit) <= std::numeric_limits::max()); return static_cast(static_cast(mCurrentBit)); } diff --git a/src/common/HashUtils.h b/src/common/HashUtils.h index 9d10ca713c..1c33a3f2c1 100644 --- a/src/common/HashUtils.h +++ b/src/common/HashUtils.h @@ -90,7 +90,7 @@ size_t Hash(const std::bitset& value) { namespace std { template - class hash> { + struct hash> { public: size_t operator()(const ityp::bitset& value) const { return Hash(static_cast&>(value)); diff --git a/src/common/ityp_array.h b/src/common/ityp_array.h index d413ebc0ba..fc772178cc 100644 --- a/src/common/ityp_array.h +++ b/src/common/ityp_array.h @@ -65,19 +65,19 @@ namespace ityp { return Base::at(index); } - Value* begin() noexcept { + typename Base::iterator begin() noexcept { return Base::begin(); } - const Value* begin() const noexcept { + typename Base::const_iterator begin() const noexcept { return Base::begin(); } - Value* end() noexcept { + typename Base::iterator end() noexcept { return Base::end(); } - const Value* end() const noexcept { + typename Base::const_iterator end() const noexcept { return Base::end(); } diff --git a/src/common/ityp_bitset.h b/src/common/ityp_bitset.h index ef351d47d7..339cf18293 100644 --- a/src/common/ityp_bitset.h +++ b/src/common/ityp_bitset.h @@ -126,7 +126,7 @@ namespace ityp { return BitSetIterator(static_cast(bitset)); } - friend class std::hash; + friend struct std::hash; }; } // namespace ityp diff --git a/src/common/vulkan_platform.h b/src/common/vulkan_platform.h index 113e831f43..236c68236c 100644 --- a/src/common/vulkan_platform.h +++ b/src/common/vulkan_platform.h @@ -37,8 +37,18 @@ #if defined(DAWN_PLATFORM_64_BIT) # define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object = struct object##_T*; +// This function is needed because MSVC doesn't accept reinterpret_cast from uint64_t from uint64_t +// TODO(cwallez@chromium.org): Remove this once we rework vulkan_platform.h +template +T NativeNonDispatachableHandleFromU64(uint64_t u64) { + return reinterpret_cast(u64); +} #elif defined(DAWN_PLATFORM_32_BIT) # define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object = uint64_t; +template +T NativeNonDispatachableHandleFromU64(uint64_t u64) { + return u64; +} #else # error "Unsupported platform" #endif diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index 660128776d..30d774d195 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -47,8 +47,8 @@ namespace dawn_native { namespace vulkan { return nullptr; } - VkImage nativeTexture = - VkImage::CreateFromHandle(reinterpret_cast<::VkImage>(next.texture.u64)); + ::VkImage image = NativeNonDispatachableHandleFromU64<::VkImage>(next.texture.u64); + VkImage nativeTexture = VkImage::CreateFromHandle(image); return Texture::CreateForSwapChain(ToBackend(GetDevice()), descriptor, nativeTexture) .Detach(); } diff --git a/src/tests/unittests/ITypArrayTests.cpp b/src/tests/unittests/ITypArrayTests.cpp index d147b4b842..ce71cda5a8 100644 --- a/src/tests/unittests/ITypArrayTests.cpp +++ b/src/tests/unittests/ITypArrayTests.cpp @@ -79,16 +79,12 @@ TEST_F(ITypArrayTest, BeginEndFrontBackData) { Array arr; // non-const versions - ASSERT_EQ(arr.begin(), &arr[Key(0)]); - ASSERT_EQ(arr.end(), &arr[Key(0)] + static_cast(arr.size())); ASSERT_EQ(&arr.front(), &arr[Key(0)]); ASSERT_EQ(&arr.back(), &arr[Key(9)]); ASSERT_EQ(arr.data(), &arr[Key(0)]); // const versions const Array& constArr = arr; - ASSERT_EQ(constArr.begin(), &constArr[Key(0)]); - ASSERT_EQ(constArr.end(), &constArr[Key(0)] + static_cast(constArr.size())); ASSERT_EQ(&constArr.front(), &constArr[Key(0)]); ASSERT_EQ(&constArr.back(), &constArr[Key(9)]); ASSERT_EQ(constArr.data(), &constArr[Key(0)]); diff --git a/src/tests/unittests/ITypBitsetTests.cpp b/src/tests/unittests/ITypBitsetTests.cpp index 93f9be29d2..88390a51de 100644 --- a/src/tests/unittests/ITypBitsetTests.cpp +++ b/src/tests/unittests/ITypBitsetTests.cpp @@ -49,7 +49,7 @@ class ITypBitsetTest : public testing::Test { ASSERT_FALSE(bits[Key(i)]) << i; ASSERT_FALSE(bits.test(Key(i))) << i; } else { - mask |= (1 << i); + mask |= (size_t(1) << i); ASSERT_TRUE(bits[Key(i)]) << i; ASSERT_TRUE(bits.test(Key(i))) << i; }