From 5875ad7064c38d3e9288cf247821c4a2046c59bb Mon Sep 17 00:00:00 2001 From: Shaobo Date: Wed, 26 Jan 2022 00:22:40 +0000 Subject: [PATCH] Implement platform-independent isNaNCustom for VertexFormatTest Wgsl removes inNaN from spec (https://github.com/gpuweb/gpuweb/pull/2311) and VertexFormatTest needs to cover NaN input. So we implement a platform-independent isNaNCustom based on the rules in IEEE 754-1985. Bug: dawn:1268 Change-Id: I53aef428c72d34381efc6b3ba0250685fc685965 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/78140 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Shaobo Yan --- src/tests/end2end/VertexFormatTests.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tests/end2end/VertexFormatTests.cpp b/src/tests/end2end/VertexFormatTests.cpp index d38fe3223e..f66054f00a 100644 --- a/src/tests/end2end/VertexFormatTests.cpp +++ b/src/tests/end2end/VertexFormatTests.cpp @@ -259,6 +259,16 @@ class VertexFormatTest : public DawnTest { return bitcast(fp32u); } + // NaN defination in IEEE 754-1985 is : + // - sign = either 0 or 1. + // - biased exponent = all 1 bits. + // - fraction = anything except all 0 bits (since all 0 bits represents infinity). + // https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers + fn isNaNCustom(val: f32) -> bool { + let floatToUint: u32 = bitcast(val); + return (floatToUint & 0x7fffffffu) > 0x7f800000u; + } + struct VertexOut { @location(0) color : vec4; @builtin(position) position : vec4; @@ -330,8 +340,8 @@ class VertexFormatTest : public DawnTest { // TODO(shaobo.yan@intel.com) : a difference of 8 ULPs is allowed in this test // because it is required on MacbookPro 11.5,AMD Radeon HD 8870M(on macOS 10.13.6), // but that it might be possible to tighten. - vs << " if (isNan(" << expectedVal << ")) {\n"; - vs << " success = success && isNan(" << testVal << ");\n"; + vs << " if (isNaNCustom(" << expectedVal << ")) {\n"; + vs << " success = success && isNaNCustom(" << testVal << ");\n"; vs << " } else {\n"; vs << " let testValFloatToUint : u32 = bitcast(" << testVal << ");\n"; vs << " let expectedValFloatToUint : u32 = bitcast(" << expectedVal