Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1305703
Implement -fp-denorm-mode slangc arg
aidanfnv Jun 16, 2025
fff66d9
Split fp-denorm-mode into 3 args for fp16/32/64
aidanfnv Jun 17, 2025
9429c42
Remove redundant option categories
aidanfnv Jun 17, 2025
1b11b0a
Use emitInst for multiple of the same OpExecutionMode
aidanfnv Jun 17, 2025
5942bb5
Fix formatting
aidanfnv Jun 17, 2025
8ce0a06
Merge remote-tracking branch 'upstream/master' into feature/denorm-mo…
aidanfnv Jun 17, 2025
8742880
Remove -denorm any
aidanfnv Jun 17, 2025
7ff1d35
Re-add option categories
aidanfnv Jun 17, 2025
45ce62a
emitinst for ftz
aidanfnv Jun 17, 2025
985654d
Use enums for type text
aidanfnv Jun 17, 2025
3c01225
Remove extra categories again
aidanfnv Jun 17, 2025
5ae8ea0
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 17, 2025
ceb4774
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 18, 2025
8ebb6f7
Add tests for denorm mode
aidanfnv Jun 19, 2025
e2f2c86
Move denorm mode to post linking
aidanfnv Jun 19, 2025
a851c39
format code (#8)
slangbot Jun 24, 2025
4620e01
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 24, 2025
6903fd4
regenerate command line reference (#9)
slangbot Jun 24, 2025
228fc4a
Clean up tests
aidanfnv Jun 24, 2025
0a59641
Fix option text
aidanfnv Jun 24, 2025
2cf81e4
Merge branch 'feature/denorm-mode-ctrl' of https://github.com/aidanfn…
aidanfnv Jun 24, 2025
745ea29
format code (#10)
slangbot Jun 24, 2025
486aa1e
Add tests for "any" mode
aidanfnv Jun 24, 2025
193273c
Return "any" enum if option not set
aidanfnv Jun 26, 2025
6eddb6d
Simplify emission logic
aidanfnv Jun 26, 2025
d2eec0e
Add support for generic entrypoints
aidanfnv Jun 26, 2025
f10ede2
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 26, 2025
0c60900
Merge branch 'feature/denorm-mode-ctrl' of https://github.com/aidanfn…
aidanfnv Jun 26, 2025
3b99357
Move denorm modes to end of CompilerOptionName enum
aidanfnv Jun 26, 2025
2de8378
format code (#11)
slangbot Jun 26, 2025
6a0280e
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 26, 2025
57824b3
Move new enum members to before CountOf
aidanfnv Jun 27, 2025
5b0300b
Add not checks to tests, fix generic test, add functionality tests
aidanfnv Jun 28, 2025
780d4f2
Rename denorm to fpDenormal
aidanfnv Jun 28, 2025
94db6e8
Clean up functional test
aidanfnv Jun 28, 2025
309b48c
Rename denorm test dir
aidanfnv Jun 28, 2025
88f04de
Fix formatting, regenerate cmdline ref
aidanfnv Jun 28, 2025
363259c
Fold simple tests into functional tests, add more dxil checks
aidanfnv Jun 28, 2025
847a21d
Remove no-op DX tests, make tests more consistent
aidanfnv Jun 28, 2025
f297c2a
Disable VK functionality tests that will fail on the CI configs
aidanfnv Jun 30, 2025
e8ae3df
Fix formatting
aidanfnv Jun 30, 2025
14c46d2
Add comments to disabled tests explaining why
aidanfnv Jun 30, 2025
e790d5e
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 30, 2025
a233173
Merge branch 'master' into feature/denorm-mode-ctrl
aidanfnv Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/command-line-slangc-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ slangc -help-style markdown -h
* [line-directive-mode](#line-directive-mode)
* [debug-info-format](#debug-info-format)
* [fp-mode](#fp-mode)
* [fp-denormal-mode](#fp-denormal-mode)
* [help-style](#help-style)
* [optimization-level](#optimization-level)
* [debug-level](#debug-level)
Expand Down Expand Up @@ -396,6 +397,30 @@ Disables generics and specialization pass.
Control floating point optimizations


<a id="denorm-mode-fp16"></a>
### -denorm-mode-fp16

**-denorm-mode-fp16 &lt;[fp-denormal-mode](#fp-denormal-mode)&gt;**

Control handling of 16-bit denormal floating point values in SPIR-V (any, preserve, ftz)


<a id="denorm-mode-fp32"></a>
### -denorm-mode-fp32

**-denorm-mode-fp32 &lt;[fp-denormal-mode](#fp-denormal-mode)&gt;**

Control handling of 32-bit denormal floating point values in SPIR-V and DXIL (any, preserve, ftz)


<a id="denorm-mode-fp64"></a>
### -denorm-mode-fp64

**-denorm-mode-fp64 &lt;[fp-denormal-mode](#fp-denormal-mode)&gt;**

Control handling of 64-bit denormal floating point values in SPIR-V (any, preserve, ftz)


<a id="g"></a>
### -g

Expand Down Expand Up @@ -962,6 +987,15 @@ Floating Point Mode
* `fast` : Allow optimizations that may change results of floating-point computations. Prefer the fastest version of special functions supported by the target.
* `default` : Default floating point mode

<a id="fp-denormal-mode"></a>
## fp-denormal-mode

Floating Point Denormal Handling Mode

* `any` : Use any denormal handling mode (default). The mode used is implementation defined.
* `preserve` : Preserve denormal values
* `ftz` : Flush denormals to zero

<a id="help-style"></a>
## help-style

Expand Down
17 changes: 17 additions & 0 deletions include/slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,17 @@ typedef uint32_t SlangSizeT;
SLANG_FLOATING_POINT_MODE_PRECISE,
};

/*!
@brief Options to control floating-point denormal handling mode for a target.
*/
typedef unsigned int SlangFpDenormalModeIntegral;
enum SlangFpDenormalMode : SlangFpDenormalModeIntegral
{
SLANG_FP_DENORM_MODE_ANY = 0,
SLANG_FP_DENORM_MODE_PRESERVE,
SLANG_FP_DENORM_MODE_FTZ,
};

/*!
@brief Options to control emission of `#line` directives
*/
Expand Down Expand Up @@ -1026,6 +1037,12 @@ typedef uint32_t SlangSizeT;
DumpModule,

EmitSeparateDebug, // bool

// Floating point denormal handling modes
DenormalModeFp16,
DenormalModeFp32,
DenormalModeFp64,

CountOf,
};

Expand Down
13 changes: 13 additions & 0 deletions source/compiler-core/slang-downstream-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ struct DownstreamCompileOptions
Precise,
};

enum class FloatingPointDenormalMode : uint8_t
{
Any,
Preserve,
FlushToZero,
};

enum PipelineType : uint8_t
{
Unknown,
Expand Down Expand Up @@ -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<DownstreamCompileOptions>);

Expand Down Expand Up @@ -482,6 +494,7 @@ struct DownstreamCompilerUtilBase
typedef CompileOptions::DebugInfoType DebugInfoType;

typedef CompileOptions::FloatingPointMode FloatingPointMode;
typedef CompileOptions::FloatingPointDenormalMode FloatingPointDenormalMode;

typedef DownstreamProductFlag ProductFlag;
typedef DownstreamProductFlags ProductFlags;
Expand Down
16 changes: 16 additions & 0 deletions source/compiler-core/slang-dxc-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 13 additions & 0 deletions source/core/slang-type-text-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ static const NamesDescriptionValue s_floatingPointModes[] = {
"by the target."},
{SLANG_FLOATING_POINT_MODE_DEFAULT, "default", "Default floating point mode"}};

static const NamesDescriptionValue s_fpDenormalModes[] = {
{SLANG_FP_DENORM_MODE_ANY,
"any",
"Use any denormal handling mode (default). The mode used is implementation defined."},
{SLANG_FP_DENORM_MODE_PRESERVE, "preserve", "Preserve denormal values"},
{SLANG_FP_DENORM_MODE_FTZ, "ftz", "Flush denormals to zero"},
};

static const NamesDescriptionValue s_optimizationLevels[] = {
{SLANG_OPTIMIZATION_LEVEL_NONE, "0,none", "Disable all optimizations"},
{SLANG_OPTIMIZATION_LEVEL_DEFAULT,
Expand Down Expand Up @@ -253,6 +261,11 @@ static const NamesDescriptionValue s_fileSystemTypes[] = {
return makeConstArrayView(s_floatingPointModes);
}

/* static */ ConstArrayView<NamesDescriptionValue> TypeTextUtil::getFpDenormalModeInfos()
{
return makeConstArrayView(s_fpDenormalModes);
}

/* static */ ConstArrayView<NamesDescriptionValue> TypeTextUtil::getOptimizationLevelInfos()
{
return makeConstArrayView(s_optimizationLevels);
Expand Down
2 changes: 2 additions & 0 deletions source/core/slang-type-text-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct TypeTextUtil
static ConstArrayView<NamesDescriptionValue> getDebugLevelInfos();
/// Get the floating point modes
static ConstArrayView<NamesDescriptionValue> getFloatingPointModeInfos();
/// Get the floating point denormal handling modes
static ConstArrayView<NamesDescriptionValue> getFpDenormalModeInfos();
// Get the line directive infos
static ConstArrayView<NamesDescriptionValue> getLineDirectiveInfos();
/// Get the optimization level info
Expand Down
28 changes: 28 additions & 0 deletions source/slang/slang-compiler-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using slang::CompilerOptionValueKind;
enum MatrixLayoutMode : SlangMatrixLayoutModeIntegral;
enum class LineDirectiveMode : SlangLineDirectiveModeIntegral;
enum class FloatingPointMode : SlangFloatingPointModeIntegral;
enum class FloatingPointDenormalMode : SlangFpDenormalModeIntegral;
enum class OptimizationLevel : SlangOptimizationLevelIntegral;
enum class DebugInfoLevel : SlangDebugInfoLevelIntegral;
enum class CodeGenTarget : SlangCompileTargetIntegral;
Expand Down Expand Up @@ -375,6 +376,33 @@ struct CompilerOptionSet
return getEnumOption<FloatingPointMode>(CompilerOptionName::FloatingPointMode);
}

FloatingPointDenormalMode getDenormalModeFp16()
{
if (!hasOption(CompilerOptionName::DenormalModeFp16))
{
return (FloatingPointDenormalMode)SLANG_FP_DENORM_MODE_ANY;
}
return getEnumOption<FloatingPointDenormalMode>(CompilerOptionName::DenormalModeFp16);
}

FloatingPointDenormalMode getDenormalModeFp32()
{
if (!hasOption(CompilerOptionName::DenormalModeFp32))
{
return (FloatingPointDenormalMode)SLANG_FP_DENORM_MODE_ANY;
}
return getEnumOption<FloatingPointDenormalMode>(CompilerOptionName::DenormalModeFp32);
}

FloatingPointDenormalMode getDenormalModeFp64()
{
if (!hasOption(CompilerOptionName::DenormalModeFp64))
{
return (FloatingPointDenormalMode)SLANG_FP_DENORM_MODE_ANY;
}
return getEnumOption<FloatingPointDenormalMode>(CompilerOptionName::DenormalModeFp64);
}

LineDirectiveMode getLineDirectiveMode()
{
return getEnumOption<LineDirectiveMode>(CompilerOptionName::LineDirectiveMode);
Expand Down
63 changes: 63 additions & 0 deletions source/slang/slang-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,69 @@ SlangResult CodeGenContext::emitWithDownstreamForEntryPoints(ComPtr<IArtifact>&
SLANG_ASSERT(!"Unhandled floating point mode");
}

if (getTargetProgram()->getOptionSet().hasOption(CompilerOptionName::DenormalModeFp16))
{
switch (getTargetProgram()->getOptionSet().getEnumOption<FloatingPointDenormalMode>(
CompilerOptionName::DenormalModeFp16))
{
case FloatingPointDenormalMode::Any:
options.denormalModeFp16 = DownstreamCompileOptions::FloatingPointDenormalMode::Any;
break;
case FloatingPointDenormalMode::Preserve:
options.denormalModeFp16 =
DownstreamCompileOptions::FloatingPointDenormalMode::Preserve;
break;
case FloatingPointDenormalMode::FlushToZero:
options.denormalModeFp16 =
DownstreamCompileOptions::FloatingPointDenormalMode::FlushToZero;
break;
default:
SLANG_ASSERT(!"Unhandled fp16 denormal handling mode");
}
}

if (getTargetProgram()->getOptionSet().hasOption(CompilerOptionName::DenormalModeFp32))
{
switch (getTargetProgram()->getOptionSet().getEnumOption<FloatingPointDenormalMode>(
CompilerOptionName::DenormalModeFp32))
{
case FloatingPointDenormalMode::Any:
options.denormalModeFp32 = DownstreamCompileOptions::FloatingPointDenormalMode::Any;
break;
case FloatingPointDenormalMode::Preserve:
options.denormalModeFp32 =
DownstreamCompileOptions::FloatingPointDenormalMode::Preserve;
break;
case FloatingPointDenormalMode::FlushToZero:
options.denormalModeFp32 =
DownstreamCompileOptions::FloatingPointDenormalMode::FlushToZero;
break;
default:
SLANG_ASSERT(!"Unhandled fp32 denormal handling mode");
}
}

if (getTargetProgram()->getOptionSet().hasOption(CompilerOptionName::DenormalModeFp64))
{
switch (getTargetProgram()->getOptionSet().getEnumOption<FloatingPointDenormalMode>(
CompilerOptionName::DenormalModeFp64))
{
case FloatingPointDenormalMode::Any:
options.denormalModeFp64 = DownstreamCompileOptions::FloatingPointDenormalMode::Any;
break;
case FloatingPointDenormalMode::Preserve:
options.denormalModeFp64 =
DownstreamCompileOptions::FloatingPointDenormalMode::Preserve;
break;
case FloatingPointDenormalMode::FlushToZero:
options.denormalModeFp64 =
DownstreamCompileOptions::FloatingPointDenormalMode::FlushToZero;
break;
default:
SLANG_ASSERT(!"Unhandled fp64 denormal handling mode");
}
}

{
// We need to look at the stage of the entry point(s) we are
// being asked to compile, since this will determine the
Expand Down
7 changes: 7 additions & 0 deletions source/slang/slang-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,13 @@ enum class FloatingPointMode : SlangFloatingPointModeIntegral
Precise = SLANG_FLOATING_POINT_MODE_PRECISE,
};

enum class FloatingPointDenormalMode : SlangFpDenormalModeIntegral
{
Any = SLANG_FP_DENORM_MODE_ANY,
Preserve = SLANG_FP_DENORM_MODE_PRESERVE,
FlushToZero = SLANG_FP_DENORM_MODE_FTZ,
};

enum class WriterChannel : SlangWriterChannelIntegral
{
Diagnostic = SLANG_WRITER_CHANNEL_DIAGNOSTIC,
Expand Down
36 changes: 36 additions & 0 deletions source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5121,6 +5121,42 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex
}
}
break;
case kIROp_FpDenormalPreserveDecoration:
{
auto fpDenormalDecor = cast<IRFpDenormalPreserveDecoration>(decoration);
auto width = int32_t(getIntVal(fpDenormalDecor->getWidth()));
ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_float_controls"));
requireSPIRVCapability(SpvCapabilityDenormPreserve);
// emitInst is used instead of requireSPIRVExecutionMode because
// we need to be able to emit the same execution mode with different
// operands for different widths
emitInst(
getSection(SpvLogicalSectionID::ExecutionModes),
decoration,
SpvOpExecutionMode,
dstID,
SpvExecutionModeDenormPreserve,
SpvLiteralInteger::from32(width));
}
break;
case kIROp_FpDenormalFlushToZeroDecoration:
{
auto fpDenormalDecor = cast<IRFpDenormalFlushToZeroDecoration>(decoration);
auto width = int32_t(getIntVal(fpDenormalDecor->getWidth()));
ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_float_controls"));
requireSPIRVCapability(SpvCapabilityDenormFlushToZero);
// emitInst is used instead of requireSPIRVExecutionMode because
// we need to be able to emit the same execution mode with different
// operands for different widths
emitInst(
getSection(SpvLogicalSectionID::ExecutionModes),
decoration,
SpvOpExecutionMode,
dstID,
SpvExecutionModeDenormFlushToZero,
SpvLiteralInteger::from32(width));
}
break;
case kIROp_MaxVertexCountDecoration:
// Don't do anything here, instead wait until we see OutputTopologyDecoration
// and emit them together to ensure MaxVertexCount always appears before
Expand Down
Loading
Loading