Use TypedInteger for BindGroupIndex

Bug: dawn:442
Change-Id: I889a943cbaf2d349c31a15fdf126d66964bdd0a7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23247
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Austin Eng
2020-06-20 01:30:32 +00:00
committed by Commit Bot service account
parent e5d94c31a0
commit 250f26229b
33 changed files with 218 additions and 149 deletions

View File

@@ -17,6 +17,7 @@
#include "common/Platform.h"
#include "common/TypedInteger.h"
#include "common/ityp_bitset.h"
#include <bitset>
#include <functional>
@@ -87,4 +88,14 @@ size_t Hash(const std::bitset<N>& value) {
}
#endif
namespace std {
template <typename Index, size_t N>
class 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));
}
};
} // namespace std
#endif // COMMON_HASHUTILS_H_

View File

@@ -62,12 +62,14 @@ using TypedInteger = T;
namespace detail {
template <typename Tag, typename T>
class TypedIntegerImpl {
class alignas(T) TypedIntegerImpl {
static_assert(std::is_integral<T>::value, "TypedInteger must be integral");
T mValue;
public:
constexpr TypedIntegerImpl() : mValue(0) {
static_assert(alignof(TypedIntegerImpl) == alignof(T), "");
static_assert(sizeof(TypedIntegerImpl) == sizeof(T), "");
}
// Construction from non-narrowing integral types.

View File

@@ -58,6 +58,14 @@ namespace ityp {
using Base::none;
using Base::size;
bool operator==(const bitset& other) const noexcept {
return Base::operator==(static_cast<const Base&>(other));
}
bool operator!=(const bitset& other) const noexcept {
return Base::operator!=(static_cast<const Base&>(other));
}
bitset& operator&=(const bitset& other) noexcept {
return static_cast<bitset&>(Base::operator&=(static_cast<const Base&>(other)));
}
@@ -117,6 +125,8 @@ namespace ityp {
friend BitSetIterator<N, Index> IterateBitSet(const bitset& bitset) {
return BitSetIterator<N, Index>(static_cast<const Base&>(bitset));
}
friend class std::hash<bitset>;
};
} // namespace ityp