Fix 64 to 32 bit narrowing in dawn/utils
Bug: dawn:1377 Change-Id: Iece057afeeca43092e5e16d7f00d2388dde31d13 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87673 Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
04912aa836
commit
7e03dc7f63
|
@ -16,6 +16,9 @@
|
|||
#define SRC_DAWN_COMMON_NUMERIC_H_
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#include "dawn/common/Assert.h"
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
@ -39,4 +42,12 @@ inline constexpr uint32_t u32_sizeof = detail::u32_sizeof<T>();
|
|||
template <typename T>
|
||||
inline constexpr uint32_t u32_alignof = detail::u32_alignof<T>();
|
||||
|
||||
// Only defined for unsigned integers because that is all that is
|
||||
// needed at the time of writing.
|
||||
template <typename Dst, typename Src, typename = std::enable_if_t<std::is_unsigned_v<Src>>>
|
||||
inline Dst checked_cast(const Src& value) {
|
||||
ASSERT(value <= std::numeric_limits<Dst>::max());
|
||||
return static_cast<Dst>(value);
|
||||
}
|
||||
|
||||
#endif // SRC_DAWN_COMMON_NUMERIC_H_
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "dawn/common/Constants.h"
|
||||
#include "dawn/common/Log.h"
|
||||
#include "dawn/common/Numeric.h"
|
||||
|
||||
#include "spirv-tools/optimizer.hpp"
|
||||
|
||||
|
@ -382,7 +383,7 @@ namespace utils {
|
|||
|
||||
wgpu::BindGroupDescriptor descriptor;
|
||||
descriptor.layout = layout;
|
||||
descriptor.entryCount = entries.size();
|
||||
descriptor.entryCount = checked_cast<uint32_t>(entries.size());
|
||||
descriptor.entries = entries.data();
|
||||
|
||||
return device.CreateBindGroup(&descriptor);
|
||||
|
|
Loading…
Reference in New Issue