Skip to content

Commit 4fabd7a

Browse files
authored
[SPIRV] Implement Gis option for spir-v (microsoft#6840)
Fixes microsoft#3331
1 parent 01fa18a commit 4fabd7a

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

include/dxc/Support/SPIRVOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct SpirvCodeGenOptions {
6868
bool fixFuncCallArguments;
6969
bool allowRWStructuredBufferArrays;
7070
bool enableMaximalReconvergence;
71+
bool IEEEStrict;
7172
/// Maximum length in words for the OpString literal containing the shader
7273
/// source for DebugSource and DebugSourceContinued. If the source code length
7374
/// is larger than this number, we will use DebugSourceContinued instructions

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static bool hasUnsupportedSpirvOption(const InputArgList &args,
327327
// available options and their current compatibility is needed to generate a
328328
// complete list.
329329
std::vector<OptSpecifier> unsupportedOpts = {OPT_Fd, OPT_Fre, OPT_Gec,
330-
OPT_Gis, OPT_Qstrip_reflect};
330+
OPT_Qstrip_reflect};
331331

332332
for (const auto &id : unsupportedOpts) {
333333
if (Arg *arg = args.getLastArg(id)) {

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ void EmitVisitor::initInstruction(SpirvInstruction *inst) {
431431
spv::Decoration::RelaxedPrecision, {});
432432
}
433433
// Emit NoContraction decoration (if any).
434-
if (inst->isPrecise() && inst->isArithmeticInstruction()) {
434+
if ((spvOptions.IEEEStrict || inst->isPrecise()) &&
435+
inst->isArithmeticInstruction()) {
435436
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
436437
spv::Decoration::NoContraction, {});
437438
}

tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
// RUN: not %dxc -T ps_6_0 -E main -spirv -Gis %s 2>&1 | FileCheck %s
1+
// RUN: %dxc -T ps_6_0 -E main -spirv -Gis %s 2>&1 | FileCheck %s
22

3-
void main() {}
3+
// Make sure the no-contraction is added for the arithmetic operation.
4+
// CHECK: OpDecorate [[op:%[0-9]+]] NoContraction
5+
6+
float4 v;
7+
float4 main(uint col : COLOR) : SV_Target0
8+
{
9+
// [[op]] = OpVectorTimesScalar
10+
return 3*v;
11+
}
412

5-
// CHECK: -Gis is not supported with -spirv

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ class DxcCompiler : public IDxcCompiler3,
955955
opts.SpirvOptions.codeGenHighLevel = opts.CodeGenHighLevel;
956956
opts.SpirvOptions.defaultRowMajor = opts.DefaultRowMajor;
957957
opts.SpirvOptions.disableValidation = opts.DisableValidation;
958+
opts.SpirvOptions.IEEEStrict = opts.IEEEStrict;
958959
// Save a string representation of command line options and
959960
// input file name.
960961
if (opts.DebugInfo) {

0 commit comments

Comments
 (0)