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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
This commit is contained in:
Shaobo 2022-01-26 00:22:40 +00:00 committed by Dawn LUCI CQ
parent df8b33f1a0
commit 5875ad7064
1 changed files with 12 additions and 2 deletions

View File

@ -259,6 +259,16 @@ class VertexFormatTest : public DawnTest {
return bitcast<f32>(fp32u); return bitcast<f32>(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<u32>(val);
return (floatToUint & 0x7fffffffu) > 0x7f800000u;
}
struct VertexOut { struct VertexOut {
@location(0) color : vec4<f32>; @location(0) color : vec4<f32>;
@builtin(position) position : vec4<f32>; @builtin(position) position : vec4<f32>;
@ -330,8 +340,8 @@ class VertexFormatTest : public DawnTest {
// TODO(shaobo.yan@intel.com) : a difference of 8 ULPs is allowed in this test // 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), // 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. // but that it might be possible to tighten.
vs << " if (isNan(" << expectedVal << ")) {\n"; vs << " if (isNaNCustom(" << expectedVal << ")) {\n";
vs << " success = success && isNan(" << testVal << ");\n"; vs << " success = success && isNaNCustom(" << testVal << ");\n";
vs << " } else {\n"; vs << " } else {\n";
vs << " let testValFloatToUint : u32 = bitcast<u32>(" << testVal << ");\n"; vs << " let testValFloatToUint : u32 = bitcast<u32>(" << testVal << ");\n";
vs << " let expectedValFloatToUint : u32 = bitcast<u32>(" << expectedVal vs << " let expectedValFloatToUint : u32 = bitcast<u32>(" << expectedVal