diff --git a/include/dxc/Support/SPIRVOptions.h b/include/dxc/Support/SPIRVOptions.h index 950c764367..537598994c 100644 --- a/include/dxc/Support/SPIRVOptions.h +++ b/include/dxc/Support/SPIRVOptions.h @@ -68,6 +68,7 @@ struct SpirvCodeGenOptions { bool fixFuncCallArguments; bool allowRWStructuredBufferArrays; bool enableMaximalReconvergence; + bool IEEEStrict; /// Maximum length in words for the OpString literal containing the shader /// source for DebugSource and DebugSourceContinued. If the source code length /// is larger than this number, we will use DebugSourceContinued instructions diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 94103077f2..b843ed2332 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -327,7 +327,7 @@ static bool hasUnsupportedSpirvOption(const InputArgList &args, // available options and their current compatibility is needed to generate a // complete list. std::vector unsupportedOpts = {OPT_Fd, OPT_Fre, OPT_Gec, - OPT_Gis, OPT_Qstrip_reflect}; + OPT_Qstrip_reflect}; for (const auto &id : unsupportedOpts) { if (Arg *arg = args.getLastArg(id)) { diff --git a/tools/clang/lib/SPIRV/EmitVisitor.cpp b/tools/clang/lib/SPIRV/EmitVisitor.cpp index 554173a3d4..d09bf76946 100644 --- a/tools/clang/lib/SPIRV/EmitVisitor.cpp +++ b/tools/clang/lib/SPIRV/EmitVisitor.cpp @@ -431,7 +431,8 @@ void EmitVisitor::initInstruction(SpirvInstruction *inst) { spv::Decoration::RelaxedPrecision, {}); } // Emit NoContraction decoration (if any). - if (inst->isPrecise() && inst->isArithmeticInstruction()) { + if ((spvOptions.IEEEStrict || inst->isPrecise()) && + inst->isArithmeticInstruction()) { typeHandler.emitDecoration(getOrAssignResultId(inst), spv::Decoration::NoContraction, {}); } diff --git a/tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl b/tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl index b38e10e7c0..ec798a5f9a 100644 --- a/tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl +++ b/tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl @@ -1,5 +1,12 @@ -// RUN: not %dxc -T ps_6_0 -E main -spirv -Gis %s 2>&1 | FileCheck %s +// RUN: %dxc -T ps_6_0 -E main -spirv -Gis %s 2>&1 | FileCheck %s -void main() {} +// Make sure the no-contraction is added for the arithmetic operation. +// CHECK: OpDecorate [[op:%[0-9]+]] NoContraction + +float4 v; +float4 main(uint col : COLOR) : SV_Target0 +{ + // [[op]] = OpVectorTimesScalar + return 3*v; +} -// CHECK: -Gis is not supported with -spirv diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index 0ee0d00765..5b213852ca 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -955,6 +955,7 @@ class DxcCompiler : public IDxcCompiler3, opts.SpirvOptions.codeGenHighLevel = opts.CodeGenHighLevel; opts.SpirvOptions.defaultRowMajor = opts.DefaultRowMajor; opts.SpirvOptions.disableValidation = opts.DisableValidation; + opts.SpirvOptions.IEEEStrict = opts.IEEEStrict; // Save a string representation of command line options and // input file name. if (opts.DebugInfo) {