Skip to content

Commit d436941

Browse files
committed
[SPIRV] Preserve NaN, Inf, and signed zeros w/ -Gis
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. ../tools/clang/test/CodeGenSPIRV/SignedZeroInfNanPreserve.hlsl
1 parent 50764ba commit d436941

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,18 @@ 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+
featureManager.getSpirvVersion(featureManager.getTargetEnv()) >=
869+
VersionTuple(1, 2)) {
870+
spvBuilder.addExecutionMode(entryFunction,
871+
spv::ExecutionMode::SignedZeroInfNanPreserve,
872+
{32}, SourceLocation());
873+
spvBuilder.requireCapability(spv::Capability::SignedZeroInfNanPreserve,
874+
SourceLocation());
875+
}
876+
865877
llvm::StringRef denormMode = spirvOptions.floatDenormalMode;
866878
if (!denormMode.empty()) {
867879
if (denormMode.equals_lower("preserve")) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %dxc -T cs_6_0 -spirv -Gis %s| FileCheck %s --check-prefixes=CHECK,OLD
2+
// RUN: %dxc -T cs_6_0 -spirv -Gis -fspv-target-env=vulkan1.2 %s| FileCheck %s --check-prefixes=CHECK,NEW
3+
4+
// OLD-NOT: OpCapability SignedZeroInfNanPreserve
5+
// NEW: OpCapability SignedZeroInfNanPreserve
6+
// CHECK: OpEntryPoint
7+
// OLD-NOT: OpExecutionMode %main SignedZeroInfNanPreserve 32
8+
// NEW: OpExecutionMode %main SignedZeroInfNanPreserve 32
9+
10+
[numthreads(8,1,1)]
11+
void main() {}

0 commit comments

Comments
 (0)