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/compiler-core/slang-downstream-compiler.h | 13 +++++++++++++ source/compiler-core/slang-dxc-compiler.cpp | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'source/compiler-core') diff --git a/source/compiler-core/slang-downstream-compiler.h b/source/compiler-core/slang-downstream-compiler.h index c23a6eff0..6ffcf7aea 100644 --- a/source/compiler-core/slang-downstream-compiler.h +++ b/source/compiler-core/slang-downstream-compiler.h @@ -197,6 +197,13 @@ struct DownstreamCompileOptions Precise, }; + enum class FloatingPointDenormalMode : uint8_t + { + Any, + Preserve, + FlushToZero, + }; + enum PipelineType : uint8_t { Unknown, @@ -277,6 +284,11 @@ struct DownstreamCompileOptions // The debug info format to use. SlangDebugInfoFormat m_debugInfoFormat = SLANG_DEBUG_INFO_FORMAT_DEFAULT; + + // The floating point denormal handling mode to use for each floating point precision + FloatingPointDenormalMode denormalModeFp16 = FloatingPointDenormalMode::Any; + FloatingPointDenormalMode denormalModeFp32 = FloatingPointDenormalMode::Any; + FloatingPointDenormalMode denormalModeFp64 = FloatingPointDenormalMode::Any; }; static_assert(std::is_trivially_copyable_v); @@ -482,6 +494,7 @@ struct DownstreamCompilerUtilBase typedef CompileOptions::DebugInfoType DebugInfoType; typedef CompileOptions::FloatingPointMode FloatingPointMode; + typedef CompileOptions::FloatingPointDenormalMode FloatingPointDenormalMode; typedef DownstreamProductFlag ProductFlag; typedef DownstreamProductFlags ProductFlags; diff --git a/source/compiler-core/slang-dxc-compiler.cpp b/source/compiler-core/slang-dxc-compiler.cpp index 0d4bc0a59..e27a0fc37 100644 --- a/source/compiler-core/slang-dxc-compiler.cpp +++ b/source/compiler-core/slang-dxc-compiler.cpp @@ -512,6 +512,22 @@ SlangResult DXCDownstreamCompiler::compile(const CompileOptions& inOptions, IArt break; } + switch (options.denormalModeFp32) + { + default: + case CompileOptions::FloatingPointDenormalMode::Any: + break; + + case CompileOptions::FloatingPointDenormalMode::Preserve: + args.add(L"-denorm"); + args.add(L"preserve"); + break; + + case CompileOptions::FloatingPointDenormalMode::FlushToZero: + args.add(L"-denorm"); + args.add(L"ftz"); + break; + } switch (options.optimizationLevel) { -- cgit v1.2.3