|
@@ -46,6 +46,7 @@
|
|
#endif
|
|
#endif
|
|
#include "dxillib.h"
|
|
#include "dxillib.h"
|
|
#include <algorithm>
|
|
#include <algorithm>
|
|
|
|
+#include <cfloat>
|
|
|
|
|
|
// SPIRV change starts
|
|
// SPIRV change starts
|
|
#ifdef ENABLE_SPIRV_CODEGEN
|
|
#ifdef ENABLE_SPIRV_CODEGEN
|
|
@@ -100,6 +101,28 @@ static void CreateOperationResultFromOutputs(
|
|
ppResult);
|
|
ppResult);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+struct DefaultFPEnvScope
|
|
|
|
+{
|
|
|
|
+ // _controlfp_s is non-standard and <cfenv>.feholdexceptions doesn't work on windows...?
|
|
|
|
+#ifdef _WIN32
|
|
|
|
+ unsigned int previousValue;
|
|
|
|
+ DefaultFPEnvScope() {
|
|
|
|
+ // No exceptions, preserve denormals & round to nearest.
|
|
|
|
+ errno_t error = _controlfp_s(&previousValue, _MCW_EM | _DN_SAVE | _RC_NEAR, _MCW_EM | _MCW_DN | _MCW_RC);
|
|
|
|
+ IFT(error == 0 ? S_OK : E_FAIL);
|
|
|
|
+ }
|
|
|
|
+ ~DefaultFPEnvScope() {
|
|
|
|
+ unsigned int newValue;
|
|
|
|
+ errno_t error = _controlfp_s(&newValue, previousValue, _MCW_EM | _MCW_DN | _MCW_RC);
|
|
|
|
+ // During cleanup we can't throw as we might already be handling another one.
|
|
|
|
+ DXASSERT(error == 0, "Failed to restore floating-point environment.");
|
|
|
|
+ (void)error;
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
+ DefaultFPEnvScope() {} // Dummy ctor to avoid unused local warning
|
|
|
|
+#endif
|
|
|
|
+};
|
|
|
|
+
|
|
class HLSLExtensionsCodegenHelperImpl : public HLSLExtensionsCodegenHelper {
|
|
class HLSLExtensionsCodegenHelperImpl : public HLSLExtensionsCodegenHelper {
|
|
private:
|
|
private:
|
|
CompilerInstance &m_CI;
|
|
CompilerInstance &m_CI;
|
|
@@ -311,6 +334,8 @@ public:
|
|
DxcThreadMalloc TM(m_pMalloc);
|
|
DxcThreadMalloc TM(m_pMalloc);
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ DefaultFPEnvScope fpEnvScope;
|
|
|
|
+
|
|
IFT(CreateMemoryStream(m_pMalloc, &pOutputStream));
|
|
IFT(CreateMemoryStream(m_pMalloc, &pOutputStream));
|
|
|
|
|
|
// Parse command-line options into DxcOpts
|
|
// Parse command-line options into DxcOpts
|
|
@@ -649,6 +674,8 @@ public:
|
|
IFC(hlsl::DxcGetBlobAsUtf8(pSource, &utf8Source));
|
|
IFC(hlsl::DxcGetBlobAsUtf8(pSource, &utf8Source));
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ DefaultFPEnvScope fpEnvScope;
|
|
|
|
+
|
|
CComPtr<AbstractMemoryStream> pOutputStream;
|
|
CComPtr<AbstractMemoryStream> pOutputStream;
|
|
dxcutil::DxcArgsFileSystem *msfPtr = dxcutil::CreateDxcArgsFileSystem(utf8Source, pSourceName, pIncludeHandler);
|
|
dxcutil::DxcArgsFileSystem *msfPtr = dxcutil::CreateDxcArgsFileSystem(utf8Source, pSourceName, pIncludeHandler);
|
|
std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
|
|
std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
|
|
@@ -756,6 +783,8 @@ public:
|
|
DxcEtw_DXCompilerDisassemble_Start();
|
|
DxcEtw_DXCompilerDisassemble_Start();
|
|
DxcThreadMalloc TM(m_pMalloc);
|
|
DxcThreadMalloc TM(m_pMalloc);
|
|
try {
|
|
try {
|
|
|
|
+ DefaultFPEnvScope fpEnvScope;
|
|
|
|
+
|
|
::llvm::sys::fs::MSFileSystem *msfPtr;
|
|
::llvm::sys::fs::MSFileSystem *msfPtr;
|
|
IFT(CreateMSFileSystemForDisk(&msfPtr));
|
|
IFT(CreateMSFileSystemForDisk(&msfPtr));
|
|
std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
|
|
std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
|