summaryrefslogtreecommitdiffstats
path: root/source/slang/options.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-01 15:08:54 -0700
committerGitHub <noreply@github.com>2018-11-01 15:08:54 -0700
commit453331951b0df2a612f9bc0d68eab2ad786ec5bf (patch)
tree5514782a6c8247941d5aa3396930aa479e504db9 /source/slang/options.cpp
parent82f57ae3561e9f9e8ece8ab6c12c2b318580bc38 (diff)
Add support for a "strict" floating-point mode (#709)
This change adds an API function and command line options for controlling the default floating-point behavior for a target, with options for "fast" and "precise" computation. The "precise" option gets mapped to the "IEEE strictness" mode in `fxc` and `dxc` (there is currently no equivalent option for glslang that I could find).
Diffstat (limited to 'source/slang/options.cpp')
-rw-r--r--source/slang/options.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/slang/options.cpp b/source/slang/options.cpp
index 485b7d78b..cfa631340 100644
--- a/source/slang/options.cpp
+++ b/source/slang/options.cpp
@@ -147,6 +147,7 @@ struct OptionsParser
ProfileVersion profileVersion = ProfileVersion::Unknown;
SlangTargetFlags targetFlags = 0;
int targetID = -1;
+ FloatingPointMode floatingPointMode = FloatingPointMode::Default;
// State for tracking command-line errors
bool conflictingProfilesSet = false;
@@ -402,6 +403,11 @@ struct OptionsParser
rawTarget->profileVersion = profileVersion;
}
+ void setFloatingPointMode(RawTarget* rawTarget, FloatingPointMode mode)
+ {
+ rawTarget->floatingPointMode = mode;
+ }
+
SlangResult parse(
int argc,
char const* const* argv)
@@ -660,6 +666,28 @@ struct OptionsParser
spSetLineDirectiveMode(compileRequest, mode);
}
+ else if( argStr == "-fp-mode" || argStr == "-floating-point-mode" )
+ {
+ String name;
+ SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, name));
+
+ FloatingPointMode mode = FloatingPointMode::Default;
+ if(name == "fast")
+ {
+ mode = FloatingPointMode::Fast;
+ }
+ else if(name == "precise")
+ {
+ mode = FloatingPointMode::Precise;
+ }
+ else
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::unknownFloatingPointMode, name);
+ return SLANG_FAIL;
+ }
+
+ setFloatingPointMode(getCurrentTarget(), mode);
+ }
else if (argStr == "--")
{
// The `--` option causes us to stop trying to parse options,
@@ -983,6 +1011,11 @@ struct OptionsParser
}
getCurrentTarget()->targetFlags |= defaultTarget.targetFlags;
+
+ if( defaultTarget.floatingPointMode != FloatingPointMode::Default )
+ {
+ setFloatingPointMode(getCurrentTarget(), defaultTarget.floatingPointMode);
+ }
}
else
{
@@ -1018,6 +1051,18 @@ struct OptionsParser
}
}
+ if( defaultTarget.floatingPointMode != FloatingPointMode::Default )
+ {
+ if( rawTargets.Count() == 0 )
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::targetFlagsIgnoredBecauseNoTargets);
+ }
+ else
+ {
+ sink->diagnose(SourceLoc(), Diagnostics::targetFlagsIgnoredBecauseBeforeAllTargets);
+ }
+ }
+
}
for(auto& rawTarget : rawTargets)
@@ -1054,6 +1099,11 @@ struct OptionsParser
{
spSetTargetFlags(compileRequest, targetID, rawTarget.targetFlags);
}
+
+ if( rawTarget.floatingPointMode != FloatingPointMode::Default )
+ {
+ spSetTargetFloatingPointMode(compileRequest, targetID, SlangFloatingPointMode(rawTarget.floatingPointMode));
+ }
}
if(defaultMatrixLayoutMode != SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)