diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 5019fe3926..f231625001 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -862,6 +862,19 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) { SourceLocation()); } + // For Vulkan 1.2 and later, add SignedZeroInfNanPreserve when -Gis is + // provided to preserve NaN/Inf and signed zeros. + if (spirvOptions.IEEEStrict) { + if (featureManager.getSpirvVersion(featureManager.getTargetEnv()) < + VersionTuple(1, 2)) + spvBuilder.requireExtension("SPV_KHR_float_controls", SourceLocation()); + spvBuilder.addExecutionMode(entryFunction, + spv::ExecutionMode::SignedZeroInfNanPreserve, + {32}, SourceLocation()); + spvBuilder.requireCapability(spv::Capability::SignedZeroInfNanPreserve, + SourceLocation()); + } + llvm::StringRef denormMode = spirvOptions.floatDenormalMode; if (!denormMode.empty()) { if (denormMode.equals_lower("preserve")) { diff --git a/tools/clang/test/CodeGenSPIRV/SignedZeroInfNanPreserve.hlsl b/tools/clang/test/CodeGenSPIRV/SignedZeroInfNanPreserve.hlsl new file mode 100644 index 0000000000..41ca4f7d63 --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/SignedZeroInfNanPreserve.hlsl @@ -0,0 +1,10 @@ +// RUN: %dxc -T cs_6_0 -spirv -Gis %s| FileCheck %s --check-prefixes=CHECK,PRE_1_2 +// RUN: %dxc -T cs_6_0 -spirv -Gis -fspv-target-env=vulkan1.2 %s| FileCheck %s + +// CHECK: OpCapability SignedZeroInfNanPreserve +// PRE_1_2: OpExtension "SPV_KHR_float_controls" +// CHECK: OpEntryPoint +// CHECK: OpExecutionMode %main SignedZeroInfNanPreserve 32 + +[numthreads(8,1,1)] +void main() {}