Skip to content

Commit b290990

Browse files
committed
Need to implement ComparDoubleULP
1 parent e1a179f commit b290990

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11565,7 +11565,7 @@ template <typename T> class DeterministicNumberGenerator {
1156511565
if constexpr (std::is_same_v<T, int64_t>)
1156611566
return Int64Dist(generator);
1156711567
if constexpr (std::is_same_v<T, float>)
11568-
return FloatDist(generator);
11568+
return FloatDist(generator);
1156911569
if constexpr (std::is_same_v<T, double>)
1157011570
return DoubleDist(generator);
1157111571
if constexpr (std::is_same_v<T, uint16_t>)
@@ -11592,9 +11592,9 @@ template <typename T> class DeterministicNumberGenerator {
1159211592
std::uniform_real_distribution<float> FloatDist;
1159311593
std::uniform_real_distribution<double> DoubleDist;
1159411594

11595-
// The ranges for generation. A std::uniform_real_distribution can only have
11596-
// a range that is equal to the types largest value. This is due to precision
11597-
// issues. So instead we define some large values.
11595+
// The ranges for generation. A std::uniform_real_distribution can only have
11596+
// a range that is equal to the types largest value. This is due to precision
11597+
// issues. So instead we define some large values.
1159811598
const float FLOAT_RANGE_MIN = -1e20f;
1159911599
const float FLOAT_RANGE_MAX = 1e20f;
1160011600
const double DOUBLE_RANGE_MIN = -1e100;
@@ -11615,6 +11615,23 @@ bool DoArraysMatch(const std::array<T, N> &ActualValues,
1161511615
if (ActualValues[Index] != ExpectedValues[Index]) {
1161611616
MismatchedIndexes.push_back(Index);
1161711617
}
11618+
} else if constexpr (std::is_same_v<T, HLSLHalf_t>) {
11619+
const DirectX::PackedVector::HALF a = ActualValues[Index].val;
11620+
const DirectX::PackedVector::HALF b = ExpectedValues[Index].val;
11621+
if(!CompareHalfULP(a, b, Tolerance))
11622+
{
11623+
MismatchedIndexes.push_back(Index);
11624+
}
11625+
} else if constexpr (std::is_same_v<T, float>) {
11626+
const int IntTolerance = static_cast<int>(Tolerance);
11627+
if(!CompareFloatULP(ActualValues[Index], ExpectedValues[Index], IntTolerance))
11628+
{
11629+
MismatchedIndexes.push_back(Index);
11630+
}
11631+
} else if constexpr (std::is_same_v<T, double>) {
11632+
Log::Warning(L"Double comparison not implemented yet. Defaulting to simple comparison for now.");
11633+
if(ActualValues[Index] != ExpectedValues[Index])
11634+
MismatchedIndexes.push_back(Index);
1161811635
} else if (Tolerance == 0 && ActualValues[Index] != ExpectedValues[Index]) {
1161911636
MismatchedIndexes.push_back(Index);
1162011637
} else {
@@ -12176,8 +12193,8 @@ void ExecutionTest::LongVectorOpTestBase(
1217612193

1217712194
// We pass these values into the shader and they're requried to compile. So
1217812195
// they need to set to something.
12179-
T ClampArgC = 0;
12180-
T ClampArgT = 0;
12196+
T ClampArgMin = 0;
12197+
T ClampArgMax = 0;
1218112198
if (TestConfig.OpType == LongVectorOpType_Clamp) {
1218212199
if constexpr (std::is_same_v<T, HLSLBool_t>) {
1218312200
// Attempting to generate a clamp value for HLSLBool_t will result in an
@@ -12186,12 +12203,12 @@ void ExecutionTest::LongVectorOpTestBase(
1218612203
LogErrorFmtThrow(L"Clamp is not supported for HLSLBool_t.");
1218712204
}
1218812205

12189-
ClampArgC = NumberGenerator.generate();
12190-
ClampArgT = NumberGenerator.generate();
12191-
while (ClampArgC >= ClampArgT) {
12192-
// Generate a new value for ClampArgC. It needs to be smaller than
12193-
// or equal to ClampArgT.
12194-
ClampArgT = NumberGenerator.generate();
12206+
ClampArgMin = NumberGenerator.generate();
12207+
ClampArgMax = NumberGenerator.generate();
12208+
while (ClampArgMin >= ClampArgMax) {
12209+
// Generate a new value for ClampArgMin. It needs to be smaller than
12210+
// or equal to ClampArgMax.
12211+
ClampArgMax = NumberGenerator.generate();
1219512212
}
1219612213
}
1219712214

@@ -12221,7 +12238,7 @@ void ExecutionTest::LongVectorOpTestBase(
1222112238
{
1222212239
if (TestConfig.OpType == LongVectorOpType_Clamp) {
1222312240
ExpectedVector[Index] =
12224-
std::clamp(InputVector1[Index], ClampArgC, ClampArgT);
12241+
std::clamp(InputVector1[Index], ClampArgMin, ClampArgMax);
1222512242
} else if (TestConfig.OpType = LongVectorOpType_Initialize) {
1222612243
ExpectedVector[Index] = InputVector1[Index];
1222712244
} else {
@@ -12252,10 +12269,12 @@ void ExecutionTest::LongVectorOpTestBase(
1225212269
switch (TestConfig.OpType) {
1225312270
case LongVectorOpType_Clamp:
1225412271
CompilerOptions << " -DFUNC_CLAMP=1";
12255-
CompilerOptions << " -DCLAMP_ARGC=";
12256-
CompilerOptions << ClampArgC;
12257-
CompilerOptions << " -DCLAMP_ARGT=";
12258-
CompilerOptions << ClampArgT;
12272+
CompilerOptions << " -DCLAMP_ARGMIN=";
12273+
// We need to set the precision for the float values.
12274+
CompilerOptions << std::setprecision(16);
12275+
CompilerOptions << ClampArgMin;
12276+
CompilerOptions << " -DCLAMP_ARGMAX=";
12277+
CompilerOptions << ClampArgMax;
1225912278
break;
1226012279
case LongVectorOpType_Initialize:
1226112280
CompilerOptions << " -DFUNC_INITIALIZE=1";

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,15 +3788,15 @@ void MSMain(uint GID : SV_GroupIndex,
37883788
#ifdef FUNC_CLAMP
37893789
vector<TYPE, NUM> TestClamp(vector<TYPE, NUM> Vector)
37903790
{
3791-
return clamp(Vector, TYPE(CLAMP_ARGC), TYPE(CLAMP_ARGT));
3791+
return clamp(Vector, TYPE(CLAMP_ARGMIN), TYPE(CLAMP_ARGMAX));
37923792
}
37933793
#endif
37943794
37953795
RWByteAddressBuffer g_InputScalar : register(u0);
37963796
RWByteAddressBuffer g_InputVector1 : register(u1);
37973797
RWByteAddressBuffer g_InputVector2 : register(u2);
37983798
RWByteAddressBuffer g_OutputVector : register(u3);
3799-
[numthreads(8,8,1)]
3799+
[numthreads(1,1,1)]
38003800
void main(uint GI : SV_GroupIndex) {
38013801
vector<TYPE, NUM> InputVector1 = g_InputVector1.Load< vector<TYPE, NUM> >(0);
38023802
vector<TYPE, NUM> InputVector2 = g_InputVector2.Load< vector<TYPE, NUM> >(0);

0 commit comments

Comments
 (0)