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 <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2020-07-08 18:50:30 +00:00 committed by Commit Bot service account
parent a9c7d64aad
commit 519edd5890
8 changed files with 20 additions and 14 deletions

View File

@ -48,7 +48,7 @@ class BitSetIterator final {
T operator*() const {
using U = UnderlyingType<T>;
ASSERT(mCurrentBit <= std::numeric_limits<U>::max());
ASSERT(static_cast<U>(mCurrentBit) <= std::numeric_limits<U>::max());
return static_cast<T>(static_cast<U>(mCurrentBit));
}

View File

@ -90,7 +90,7 @@ size_t Hash(const std::bitset<N>& value) {
namespace std {
template <typename Index, size_t N>
class hash<ityp::bitset<Index, N>> {
struct hash<ityp::bitset<Index, N>> {
public:
size_t operator()(const ityp::bitset<Index, N>& value) const {
return Hash(static_cast<const std::bitset<N>&>(value));

View File

@ -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();
}

View File

@ -126,7 +126,7 @@ namespace ityp {
return BitSetIterator<N, Index>(static_cast<const Base&>(bitset));
}
friend class std::hash<bitset>;
friend struct std::hash<bitset>;
};
} // namespace ityp

View File

@ -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 <typename T>
T NativeNonDispatachableHandleFromU64(uint64_t u64) {
return reinterpret_cast<T>(u64);
}
#elif defined(DAWN_PLATFORM_32_BIT)
# define DAWN_DEFINE_NATIVE_NON_DISPATCHABLE_HANDLE(object) using object = uint64_t;
template <typename T>
T NativeNonDispatachableHandleFromU64(uint64_t u64) {
return u64;
}
#else
# error "Unsupported platform"
#endif

View File

@ -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();
}

View File

@ -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<uint32_t>(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<uint32_t>(constArr.size()));
ASSERT_EQ(&constArr.front(), &constArr[Key(0)]);
ASSERT_EQ(&constArr.back(), &constArr[Key(9)]);
ASSERT_EQ(constArr.data(), &constArr[Key(0)]);

View File

@ -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;
}