Add end2end test for all vertex formats

BUG=dawn:41

Change-Id: I37bde37843522a8d7c8b3bea1cb24c0971efd8e2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/6340
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
This commit is contained in:
Yan, Shaobo
2019-04-26 15:25:18 +00:00
committed by Commit Bot service account
parent a32e3bd014
commit 9286adcb0f
5 changed files with 877 additions and 4 deletions

View File

@@ -16,6 +16,8 @@
#include "common/Assert.h"
#include <algorithm>
#if defined(DAWN_COMPILER_MSVC)
# include <intrin.h>
#endif
@@ -77,3 +79,29 @@ uint32_t Align(uint32_t value, size_t alignment) {
uint32_t alignment32 = static_cast<uint32_t>(alignment);
return (value + (alignment32 - 1)) & ~(alignment32 - 1);
}
uint16_t Float32ToFloat16(float fp32) {
uint32_t fp32i = BitCast<uint32_t>(fp32);
uint32_t sign16 = (fp32i & 0x80000000) >> 16;
uint32_t mantissaAndExponent = fp32i & 0x7FFFFFFF;
if (mantissaAndExponent > 0x47FFEFFF) { // Infinity
return static_cast<uint16_t>(sign16 | 0x7FFF);
} else if (mantissaAndExponent < 0x38800000) { // Denormal
uint32_t mantissa = (mantissaAndExponent & 0x007FFFFF) | 0x00800000;
int32_t exponent = 113 - (mantissaAndExponent >> 23);
if (exponent < 24) {
mantissaAndExponent = mantissa >> exponent;
} else {
mantissaAndExponent = 0;
}
return static_cast<uint16_t>(
sign16 | (mantissaAndExponent + 0x00000FFF + ((mantissaAndExponent >> 13) & 1)) >> 13);
} else {
return static_cast<uint16_t>(sign16 | (mantissaAndExponent + 0xC8000000 + 0x00000FFF +
((mantissaAndExponent >> 13) & 1)) >>
13);
}
}

View File

@@ -17,6 +17,10 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <type_traits>
// The following are not valid for 0
uint32_t ScanForward(uint32_t bits);
@@ -38,4 +42,14 @@ const T* AlignPtr(const T* ptr, size_t alignment) {
return reinterpret_cast<const T*>(AlignVoidPtr(const_cast<T*>(ptr), alignment));
}
template <typename destType, typename sourceType>
destType BitCast(const sourceType& source) {
static_assert(sizeof(destType) == sizeof(sourceType), "BitCast: cannot lose precision.");
destType output;
std::memcpy(&output, &source, sizeof(destType));
return output;
}
uint16_t Float32ToFloat16(float fp32);
#endif // COMMON_MATH_H_