From d50c3f34a2eda5bf5e278c78d32cc9923fd83b82 Mon Sep 17 00:00:00 2001 From: aidanfnv Date: Tue, 1 Jul 2025 00:41:52 -0700 Subject: Add arguments for controlling floating point denormal mode (#7461) * Implement -fp-denorm-mode slangc arg * Split fp-denorm-mode into 3 args for fp16/32/64 * Remove redundant option categories * Use emitInst for multiple of the same OpExecutionMode * Fix formatting * Remove -denorm any * Re-add option categories * emitinst for ftz * Use enums for type text * Remove extra categories again * Add tests for denorm mode * Move denorm mode to post linking * format code (#8) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * regenerate command line reference (#9) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Clean up tests * Fix option text * format code (#10) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Add tests for "any" mode * Return "any" enum if option not set * Simplify emission logic * Add support for generic entrypoints * Move denorm modes to end of CompilerOptionName enum * format code (#11) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Move new enum members to before CountOf * Add not checks to tests, fix generic test, add functionality tests * Rename denorm to fpDenormal * Clean up functional test * Rename denorm test dir * Fix formatting, regenerate cmdline ref * Fold simple tests into functional tests, add more dxil checks * Remove no-op DX tests, make tests more consistent * Disable VK functionality tests that will fail on the CI configs * Fix formatting * Add comments to disabled tests explaining why --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-options.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'source/slang/slang-options.cpp') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 3227e2de4..9141188df 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -53,6 +53,7 @@ enum class ValueCategory Target, Language, FloatingPointMode, + FloatingPointDenormalMode, ArchiveType, Stage, LineDirectiveMode, @@ -85,6 +86,7 @@ SLANG_GET_VALUE_CATEGORY(Compiler, SlangPassThrough) SLANG_GET_VALUE_CATEGORY(ArchiveType, SlangArchiveType) SLANG_GET_VALUE_CATEGORY(LineDirectiveMode, SlangLineDirectiveMode) SLANG_GET_VALUE_CATEGORY(FloatingPointMode, FloatingPointMode) +SLANG_GET_VALUE_CATEGORY(FloatingPointDenormalMode, FloatingPointDenormalMode) SLANG_GET_VALUE_CATEGORY(FileSystemType, TypeTextUtil::FileSystemType) SLANG_GET_VALUE_CATEGORY(HelpStyle, CommandOptionsWriter::Style) SLANG_GET_VALUE_CATEGORY(OptimizationLevel, SlangOptimizationLevel) @@ -184,6 +186,13 @@ void initCommandOptions(CommandOptions& options) UserValue(ValueCategory::FloatingPointMode)); options.addValues(TypeTextUtil::getFloatingPointModeInfos()); + options.addCategory( + CategoryKind::Value, + "fp-denormal-mode", + "Floating Point Denormal Handling Mode", + UserValue(ValueCategory::FloatingPointDenormalMode)); + options.addValues(TypeTextUtil::getFpDenormalModeInfos()); + options.addCategory( CategoryKind::Value, "help-style", @@ -580,6 +589,21 @@ void initCommandOptions(CommandOptions& options) "-fp-mode,-floating-point-mode", "-fp-mode , -floating-point-mode ", "Control floating point optimizations"}, + {OptionKind::DenormalModeFp16, + "-denorm-mode-fp16", + "-denorm-mode-fp16 ", + "Control handling of 16-bit denormal floating point values in SPIR-V (any, preserve, " + "ftz)"}, + {OptionKind::DenormalModeFp32, + "-denorm-mode-fp32", + "-denorm-mode-fp32 ", + "Control handling of 32-bit denormal floating point values in SPIR-V and DXIL (any, " + "preserve, ftz)"}, + {OptionKind::DenormalModeFp64, + "-denorm-mode-fp64", + "-denorm-mode-fp64 ", + "Control handling of 64-bit denormal floating point values in SPIR-V (any, preserve, " + "ftz)"}, {OptionKind::DebugInformation, "-g...", "-g, -g, -g", @@ -2802,6 +2826,27 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv) setFloatingPointMode(getCurrentTarget(), value); break; } + case OptionKind::DenormalModeFp16: + { + FloatingPointDenormalMode value; + SLANG_RETURN_ON_FAIL(_expectValue(value)); + linkage->m_optionSet.set(CompilerOptionName::DenormalModeFp16, value); + break; + } + case OptionKind::DenormalModeFp32: + { + FloatingPointDenormalMode value; + SLANG_RETURN_ON_FAIL(_expectValue(value)); + linkage->m_optionSet.set(CompilerOptionName::DenormalModeFp32, value); + break; + } + case OptionKind::DenormalModeFp64: + { + FloatingPointDenormalMode value; + SLANG_RETURN_ON_FAIL(_expectValue(value)); + linkage->m_optionSet.set(CompilerOptionName::DenormalModeFp64, value); + break; + } case OptionKind::Optimization: { UnownedStringSlice levelSlice = argValue.getUnownedSlice().tail(2); -- cgit v1.2.3