Skip to content

Commit 7a8c90c

Browse files
llvm-beanzKeenuts
andauthored
[SPIRV] Preserve NaN, Inf, and signed zeros w/ -Gis (#7693)
The `-Gis` flag opts into "strict" IEEE math rules, which include preserving NaN, Inf and signed/unsigned zeros. This change adds the SPIRV SignedZeroInfNanPreserve capability and execution mode when `-Gis` is passed to DXC. --------- Co-authored-by: Nathan Gauër <[email protected]>
1 parent dc85cd7 commit 7a8c90c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,19 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
862862
SourceLocation());
863863
}
864864

865+
// For Vulkan 1.2 and later, add SignedZeroInfNanPreserve when -Gis is
866+
// provided to preserve NaN/Inf and signed zeros.
867+
if (spirvOptions.IEEEStrict) {
868+
if (featureManager.getSpirvVersion(featureManager.getTargetEnv()) <
869+
VersionTuple(1, 2))
870+
spvBuilder.requireExtension("SPV_KHR_float_controls", SourceLocation());
871+
spvBuilder.addExecutionMode(entryFunction,
872+
spv::ExecutionMode::SignedZeroInfNanPreserve,
873+
{32}, SourceLocation());
874+
spvBuilder.requireCapability(spv::Capability::SignedZeroInfNanPreserve,
875+
SourceLocation());
876+
}
877+
865878
llvm::StringRef denormMode = spirvOptions.floatDenormalMode;
866879
if (!denormMode.empty()) {
867880
if (denormMode.equals_lower("preserve")) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %dxc -T cs_6_0 -spirv -Gis %s| FileCheck %s --check-prefixes=CHECK,PRE_1_2
2+
// RUN: %dxc -T cs_6_0 -spirv -Gis -fspv-target-env=vulkan1.2 %s| FileCheck %s
3+
4+
// CHECK: OpCapability SignedZeroInfNanPreserve
5+
// PRE_1_2: OpExtension "SPV_KHR_float_controls"
6+
// CHECK: OpEntryPoint
7+
// CHECK: OpExecutionMode %main SignedZeroInfNanPreserve 32
8+
9+
[numthreads(8,1,1)]
10+
void main() {}

0 commit comments

Comments
 (0)