Преглед изворни кода

Bug fixes and minor changes to ExecutionTest (#2161)

Bug fixes and minor changes to ExecutionTest

Fixes 2 test bugs and a few razzle build warnings
Removes HlslTestUtils.h dependency on llvm/Support/Atomic.h
Brings it in sync with the HLK version of the tests
Remove HLK-only GetTestParamUseWARP modification
Helena Kotas пре 6 година
родитељ
комит
893d340c4f

+ 2 - 4
tools/clang/test/HLSL/ShaderOpArith.xml

@@ -496,7 +496,6 @@
     </RenderTargets>
     </RenderTargets>
 
 
     <Shader Name="VS" Target="vs_6_2" Arguments="/enable-16bit-types">
     <Shader Name="VS" Target="vs_6_2" Arguments="/enable-16bit-types">
-    <!--<Shader Name="VS" Target="vs_6_0"> -->
     <![CDATA[
     <![CDATA[
     struct PSInput {
     struct PSInput {
       half4 position : SV_POSITION;
       half4 position : SV_POSITION;
@@ -514,7 +513,6 @@
     </Shader>
     </Shader>
 
 
     <Shader Name="PS" Target="ps_6_2" Arguments="/enable-16bit-types">
     <Shader Name="PS" Target="ps_6_2" Arguments="/enable-16bit-types">
-    <!--<Shader Name="PS" Target="ps_6_0">-->
     <![CDATA[
     <![CDATA[
     struct PSInput {
     struct PSInput {
       half4 position : SV_POSITION;
       half4 position : SV_POSITION;
@@ -566,8 +564,8 @@
          result.position = position;
          result.position = position;
          return result;
          return result;
         }
         }
-        float4 PSMain(PSInput input) : SV_TARGET {
-         return float4(first, second, third, fourth);
+        half4 PSMain(PSInput input) : SV_TARGET {
+         return half4(first, second, third, fourth);
         }
         }
       ]]>
       ]]>
     </Shader>
     </Shader>

+ 27 - 48
tools/clang/unittests/HLSL/HlslTestUtils.h

@@ -12,6 +12,7 @@
 #include <sstream>
 #include <sstream>
 #include <fstream>
 #include <fstream>
 #include <atomic>
 #include <atomic>
+#include <cmath>
 #ifdef _WIN32
 #ifdef _WIN32
 #include <dxgiformat.h>
 #include <dxgiformat.h>
 #include "WexTestClass.h"
 #include "WexTestClass.h"
@@ -20,7 +21,10 @@
 #endif
 #endif
 #include "dxc/Support/Unicode.h"
 #include "dxc/Support/Unicode.h"
 #include "dxc/DXIL/DxilConstants.h" // DenormMode
 #include "dxc/DXIL/DxilConstants.h" // DenormMode
-#include "llvm/Support/Atomic.h"
+
+#ifndef HLSLDATAFILEPARAM
+#define HLSLDATAFILEPARAM L"HlslDataDir"
+#endif
 
 
 // If TAEF verify macros are available, use them to alias other legacy
 // If TAEF verify macros are available, use them to alias other legacy
 // comparison macros that don't have a direct translation.
 // comparison macros that don't have a direct translation.
@@ -67,8 +71,8 @@
 #define ASSERT_HRESULT_SUCCEEDED VERIFY_SUCCEEDED
 #define ASSERT_HRESULT_SUCCEEDED VERIFY_SUCCEEDED
 #ifndef EXPECT_EQ
 #ifndef EXPECT_EQ
 #define EXPECT_EQ(expected, actual) VERIFY_ARE_EQUAL(expected, actual)
 #define EXPECT_EQ(expected, actual) VERIFY_ARE_EQUAL(expected, actual)
-#endif
-#endif
+#endif 
+#endif // VERIFY_ARE_EQUAL
 
 
 namespace hlsl_test {
 namespace hlsl_test {
 
 
@@ -116,7 +120,7 @@ inline void LogErrorFmt(_In_z_ _Printf_format_string_ const wchar_t *fmt, ...) {
 inline std::wstring GetPathToHlslDataFile(const wchar_t* relative) {
 inline std::wstring GetPathToHlslDataFile(const wchar_t* relative) {
   WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
   WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
   WEX::Common::String HlslDataDirValue;
   WEX::Common::String HlslDataDirValue;
-  ASSERT_HRESULT_SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(L"HlslDataDir", HlslDataDirValue));
+  ASSERT_HRESULT_SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(HLSLDATAFILEPARAM, HlslDataDirValue));
 
 
   wchar_t envPath[MAX_PATH];
   wchar_t envPath[MAX_PATH];
   wchar_t expanded[MAX_PATH];
   wchar_t expanded[MAX_PATH];
@@ -202,7 +206,7 @@ inline bool GetTestParamBool(LPCWSTR name) {
 inline bool GetTestParamUseWARP(bool defaultVal) {
 inline bool GetTestParamUseWARP(bool defaultVal) {
   WEX::Common::String AdapterValue;
   WEX::Common::String AdapterValue;
   if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(
   if (FAILED(WEX::TestExecution::RuntimeParameters::TryGetValue(
-          L"Adapter", AdapterValue))) {
+        L"Adapter", AdapterValue))) {
     return defaultVal;
     return defaultVal;
   }
   }
   if ((defaultVal && AdapterValue.IsEmpty()) ||
   if ((defaultVal && AdapterValue.IsEmpty()) ||
@@ -214,14 +218,21 @@ inline bool GetTestParamUseWARP(bool defaultVal) {
 
 
 }
 }
 
 
+#ifdef FP_SUBNORMAL
+
 inline bool isdenorm(float f) {
 inline bool isdenorm(float f) {
   return FP_SUBNORMAL == std::fpclassify(f);
   return FP_SUBNORMAL == std::fpclassify(f);
 }
 }
 
 
-inline bool isdenorm(double d) {
-  return FP_SUBNORMAL == std::fpclassify(d);
+#else
+
+inline bool isdenorm(float f) {
+  return (std::numeric_limits<float>::denorm_min() <= f && f < std::numeric_limits<float>::min()) ||
+         (-std::numeric_limits<float>::min() < f && f <= -std::numeric_limits<float>::denorm_min());
 }
 }
 
 
+#endif // FP_SUBNORMAL
+
 inline float ifdenorm_flushf(float a) {
 inline float ifdenorm_flushf(float a) {
   return isdenorm(a) ? copysign(0.0f, a) : a;
   return isdenorm(a) ? copysign(0.0f, a) : a;
 }
 }
@@ -230,11 +241,6 @@ inline bool ifdenorm_flushf_eq(float a, float b) {
   return ifdenorm_flushf(a) == ifdenorm_flushf(b);
   return ifdenorm_flushf(a) == ifdenorm_flushf(b);
 }
 }
 
 
-inline bool ifdenorm_flushf_eq_or_nans(float a, float b) {
-  if (std::isnan(a) && std::isnan(b)) return true;
-  return ifdenorm_flushf(a) == ifdenorm_flushf(b);
-}
-
 static const uint16_t Float16NaN = 0xff80;
 static const uint16_t Float16NaN = 0xff80;
 static const uint16_t Float16PosInf = 0x7c00;
 static const uint16_t Float16PosInf = 0x7c00;
 static const uint16_t Float16NegInf = 0xfc00;
 static const uint16_t Float16NegInf = 0xfc00;
@@ -301,17 +307,17 @@ inline uint16_t ConvertFloat32ToFloat16(float val) {
 
 
   if (isLessThanNormal) {
   if (isLessThanNormal) {
     // Compute Denormal result
     // Compute Denormal result
-    return (uint16_t)(Abs.f_bits * *(const float*)(&DenormalRatio)) | (sign >> 16);
+    return (uint16_t)(Abs.f_bits * *(const float*)(&DenormalRatio)) | (uint16_t)(sign >> 16);
   }
   }
   else if (isInfOrNaN) {
   else if (isInfOrNaN) {
     // Compute Inf or Nan result
     // Compute Inf or Nan result
     uint32_t Fraction = Abs.u_bits & Fraction32Mask;
     uint32_t Fraction = Abs.u_bits & Fraction32Mask;
     uint16_t IsNaN = Fraction == 0 ? 0 : 0xffff;
     uint16_t IsNaN = Fraction == 0 ? 0 : 0xffff;
-    return (IsNaN & FLOAT16_BIT_MANTISSA) | FLOAT16_BIT_EXP | (sign >> 16);
+    return (IsNaN & FLOAT16_BIT_MANTISSA) | FLOAT16_BIT_EXP | (uint16_t)(sign >> 16);
   }
   }
   else {
   else {
     // Compute Normal result
     // Compute Normal result
-    return (uint16_t)((Abs.u_bits - NormalDelta) >> 13) | (sign >> 16);
+    return (uint16_t)((Abs.u_bits - NormalDelta) >> 13) | (uint16_t)(sign >> 16);
   }
   }
 }
 }
 
 
@@ -353,8 +359,8 @@ inline float ConvertFloat16ToFloat32(uint16_t x) {
 }
 }
 uint16_t ConvertFloat32ToFloat16(float val);
 uint16_t ConvertFloat32ToFloat16(float val);
 float ConvertFloat16ToFloat32(uint16_t val);
 float ConvertFloat16ToFloat32(uint16_t val);
-inline bool CompareFloatULP(const float &fsrc, const float &fref,
-                            int ULPTolerance,
+
+inline bool CompareFloatULP(const float &fsrc, const float &fref, int ULPTolerance,
                             hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
                             hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
   if (fsrc == fref) {
   if (fsrc == fref) {
     return true;
     return true;
@@ -375,8 +381,7 @@ inline bool CompareFloatULP(const float &fsrc, const float &fref,
   return uDiff <= (unsigned int)ULPTolerance;
   return uDiff <= (unsigned int)ULPTolerance;
 }
 }
 
 
-inline bool
-CompareFloatEpsilon(const float &fsrc, const float &fref, float epsilon,
+inline bool CompareFloatEpsilon(const float &fsrc, const float &fref, float epsilon,
                     hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
                     hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
   if (fsrc == fref) {
   if (fsrc == fref) {
     return true;
     return true;
@@ -396,9 +401,7 @@ CompareFloatEpsilon(const float &fsrc, const float &fref, float epsilon,
 }
 }
 
 
 // Compare using relative error (relative error < 2^{nRelativeExp})
 // Compare using relative error (relative error < 2^{nRelativeExp})
-inline bool
-CompareFloatRelativeEpsilon(const float &fsrc, const float &fref,
-                            int nRelativeExp,
+inline bool CompareFloatRelativeEpsilon(const float &fsrc, const float &fref, int nRelativeExp,
                             hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
                             hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
   return CompareFloatULP(fsrc, fref, 23 - nRelativeExp, mode);
   return CompareFloatULP(fsrc, fref, 23 - nRelativeExp, mode);
 }
 }
@@ -424,10 +427,8 @@ inline bool CompareHalfEpsilon(const uint16_t &fsrc, const uint16_t &fref, float
   return std::abs(src_f32-ref_f32) < epsilon;
   return std::abs(src_f32-ref_f32) < epsilon;
 }
 }
 
 
-inline bool
-CompareHalfRelativeEpsilon(const uint16_t &fsrc, const uint16_t &fref,
-  int nRelativeExp) {
-  return CompareHalfULP(fsrc, fref, 10 - nRelativeExp);
+inline bool CompareHalfRelativeEpsilon(const uint16_t &fsrc, const uint16_t &fref, int nRelativeExp) {
+  return CompareHalfULP(fsrc, fref, (float)(10 - nRelativeExp));
 }
 }
 
 
 #ifdef _WIN32
 #ifdef _WIN32
@@ -507,25 +508,3 @@ inline UINT GetByteSizeForFormat(DXGI_FORMAT value) {
     }
     }
 }
 }
 #endif
 #endif
-
-#define SIMPLE_IUNKNOWN_IMPL1(_IFACE_) \
-  private: volatile std::atomic<llvm::sys::cas_flag> m_dwRef; \
-  public:\
-  ULONG STDMETHODCALLTYPE AddRef() { return (ULONG)++m_dwRef; } \
-  ULONG STDMETHODCALLTYPE Release() { \
-    ULONG result = (ULONG)--m_dwRef; \
-    if (result == 0) delete this; \
-    return result; \
-  } \
-  HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject) { \
-    if (ppvObject == nullptr) return E_POINTER; \
-    if (IsEqualIID(iid, __uuidof(IUnknown)) || \
-      IsEqualIID(iid, __uuidof(INoMarshal)) || \
-      IsEqualIID(iid, __uuidof(_IFACE_))) { \
-      *ppvObject = reinterpret_cast<_IFACE_*>(this); \
-      reinterpret_cast<_IFACE_*>(this)->AddRef(); \
-      return S_OK; \
-    } \
-    return E_NOINTERFACE; \
-  }
-

+ 22 - 0
tools/clang/unittests/HLSL/MSFileSysTest.cpp

@@ -15,6 +15,7 @@
 #include "HlslTestUtils.h"
 #include "HlslTestUtils.h"
 
 
 #include "llvm/Support/MSFileSystem.h"
 #include "llvm/Support/MSFileSystem.h"
+#include "llvm/Support/Atomic.h"
 
 
 #include <D3Dcommon.h>
 #include <D3Dcommon.h>
 #include "dxc/dxcapi.internal.h"
 #include "dxc/dxcapi.internal.h"
@@ -29,6 +30,27 @@ using namespace llvm::sys::fs;
 
 
 const GUID DECLSPEC_SELECTANY GUID_NULL = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
 const GUID DECLSPEC_SELECTANY GUID_NULL = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
 
 
+#define SIMPLE_IUNKNOWN_IMPL1(_IFACE_) \
+  private: volatile std::atomic<llvm::sys::cas_flag> m_dwRef; \
+  public:\
+  ULONG STDMETHODCALLTYPE AddRef() { return (ULONG)++m_dwRef; } \
+  ULONG STDMETHODCALLTYPE Release() { \
+    ULONG result = (ULONG)--m_dwRef; \
+    if (result == 0) delete this; \
+    return result; \
+  } \
+  HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject) { \
+    if (ppvObject == nullptr) return E_POINTER; \
+    if (IsEqualIID(iid, __uuidof(IUnknown)) || \
+      IsEqualIID(iid, __uuidof(INoMarshal)) || \
+      IsEqualIID(iid, __uuidof(_IFACE_))) { \
+      *ppvObject = reinterpret_cast<_IFACE_*>(this); \
+      reinterpret_cast<_IFACE_*>(this)->AddRef(); \
+      return S_OK; \
+    } \
+    return E_NOINTERFACE; \
+  }
+
 class MSFileSysTest
 class MSFileSysTest
 {
 {
 public:
 public:

+ 5 - 3
tools/clang/unittests/HLSL/ShaderOpTest.cpp

@@ -699,7 +699,7 @@ void ShaderOpTest::CreateShaders() {
           pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
           pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
       CHECK_HR(m_pDxcSupport->CreateInstance(CLSID_DxcCompiler, &pCompiler));
       CHECK_HR(m_pDxcSupport->CreateInstance(CLSID_DxcCompiler, &pCompiler));
       CHECK_HR(pCompiler->Compile(pTextBlob, nameW, entryPointW, targetW,
       CHECK_HR(pCompiler->Compile(pTextBlob, nameW, entryPointW, targetW,
-                                  (LPCWSTR *)argumentsWList.data(), argumentsWList.size(),
+                                  (LPCWSTR *)argumentsWList.data(), (UINT32)argumentsWList.size(),
                                   nullptr, 0,
                                   nullptr, 0,
                                   nullptr, &pResult));
                                   nullptr, &pResult));
       CHECK_HR(pResult->GetStatus(&resultCode));
       CHECK_HR(pResult->GetStatus(&resultCode));
@@ -717,7 +717,9 @@ void ShaderOpTest::CreateShaders() {
       CHECK_HR(pResult->GetResult(&pCode));
       CHECK_HR(pResult->GetResult(&pCode));
       CComPtr<IDxcBlobEncoding> pBlob;
       CComPtr<IDxcBlobEncoding> pBlob;
       CHECK_HR(pCompiler->Disassemble((IDxcBlob *)pCode, (IDxcBlobEncoding **)&pBlob));
       CHECK_HR(pCompiler->Disassemble((IDxcBlob *)pCode, (IDxcBlobEncoding **)&pBlob));
-      dxc::WriteUtf8ToConsoleSizeT((char *)pBlob->GetBufferPointer(), pBlob->GetBufferSize());
+      CComPtr<IDxcBlobEncoding> pUtf16Blob;
+      pLibrary->GetBlobAsUtf16(pBlob, &pUtf16Blob);
+      hlsl_test::LogCommentFmt(L"%*s", (int)pUtf16Blob->GetBufferSize() / 2, (LPCWSTR)pUtf16Blob->GetBufferPointer());
 #endif
 #endif
     } else {
     } else {
       CComPtr<ID3DBlob> pError;
       CComPtr<ID3DBlob> pError;
@@ -1429,7 +1431,7 @@ static HRESULT ReadAttrEnumT(IXmlReader *pReader, LPCWSTR pAttrName, ParserEnumK
   }
   }
   LPCWSTR pText;
   LPCWSTR pText;
   CHECK_HR(pReader->GetValue(&pText, nullptr));
   CHECK_HR(pReader->GetValue(&pText, nullptr));
-  if (pStripPrefix && *pStripPrefix && _wcsnicmp(pAttrName, pText, wcslen(pStripPrefix)) == 0)
+  if (pStripPrefix && *pStripPrefix && _wcsnicmp(pStripPrefix, pText, wcslen(pStripPrefix)) == 0)
     pText += wcslen(pStripPrefix);
     pText += wcslen(pStripPrefix);
   CHECK_HR(GetEnumValueT(pText, K, pValue));
   CHECK_HR(GetEnumValueT(pText, K, pValue));
   CHECK_HR(pReader->MoveToElement());
   CHECK_HR(pReader->MoveToElement());