Skip to content

Commit

Permalink
[SPIRV] Implement Gis option for spir-v (#6840)
Browse files Browse the repository at this point in the history
Fixes #3331
  • Loading branch information
s-perron authored Jul 31, 2024
1 parent 01fa18a commit 4fabd7a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/dxc/Support/SPIRVOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/DxcSupport/HLSLOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<OptSpecifier> 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)) {
Expand Down
3 changes: 2 additions & 1 deletion tools/clang/lib/SPIRV/EmitVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpirvInstruction>(inst),
spv::Decoration::NoContraction, {});
}
Expand Down
13 changes: 10 additions & 3 deletions tools/clang/test/CodeGenSPIRV/spirv.opt.gis.hlsl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tools/clang/tools/dxcompiler/dxcompilerobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4fabd7a

Please sign in to comment.