Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions tools/clang/lib/SPIRV/SpirvEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
10 changes: 10 additions & 0 deletions tools/clang/test/CodeGenSPIRV/SignedZeroInfNanPreserve.hlsl
Original file line number Diff line number Diff line change
@@ -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() {}