Skip to content

Commit e80724a

Browse files
authored
[spirv] Fail when unsupported options are used (#4518)
Some DXC options are not supported in combination with the SPIR-V backend. Rather than silently ignore them, we should emit a clear error message. This change adds appropriate error messages for a couple options that have been mentioned in issues #3111 and #4496, but more should be added in future.
1 parent 2a0833a commit e80724a

5 files changed

Lines changed: 51 additions & 1 deletion

File tree

lib/DxcSupport/HLSLOptions.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,34 @@ static bool handleVkShiftArgs(const InputArgList &args, OptSpecifier id,
322322
return true;
323323
}
324324

325+
// Check if any options that are unsupported with SPIR-V are used.
326+
static bool hasUnsupportedSpirvOption(const InputArgList &args,
327+
llvm::raw_ostream &errors) {
328+
// Note: The options checked here are non-exhaustive. A thorough audit of
329+
// available options and their current compatibility is needed to generate a
330+
// complete list.
331+
std::vector<OptSpecifier> unsupportedOpts = {OPT_Fd, OPT_Fre,
332+
OPT_Qstrip_reflect};
333+
334+
for (const auto &id : unsupportedOpts) {
335+
if (Arg *arg = args.getLastArg(id)) {
336+
errors << "-" << arg->getOption().getName()
337+
<< " is not supported with -spirv";
338+
return true;
339+
}
340+
}
341+
342+
return false;
343+
}
344+
325345
namespace {
326346

327347
/// Maximum size of OpString instruction minus two operands
328348
static const uint32_t kDefaultMaximumSourceLength = 0xFFFDu;
329349
static const uint32_t kTestingMaximumSourceLength = 13u;
330350

331351
}
332-
#endif
352+
#endif // ENABLE_SPIRV_CODEGEN
333353
// SPIRV Change Ends
334354

335355
namespace hlsl {
@@ -1071,6 +1091,11 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
10711091
opts.SpirvOptions.entrypointName =
10721092
Args.getLastArgValue(OPT_fspv_entrypoint_name_EQ);
10731093

1094+
// Check for use of options not implemented in the SPIR-V backend.
1095+
if (Args.hasFlag(OPT_spirv, OPT_INVALID, false) &&
1096+
hasUnsupportedSpirvOption(Args, errors))
1097+
return 1;
1098+
10741099
#else
10751100
if (Args.hasFlag(OPT_spirv, OPT_INVALID, false) ||
10761101
Args.hasFlag(OPT_fvk_invert_y, OPT_INVALID, false) ||
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %dxc -T ps_6_0 -E main -spirv -Fd file.ext
2+
3+
void main() {}
4+
5+
// CHECK: -Fd is not supported with -spirv
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %dxc -T ps_6_0 -E main -spirv -Fre file.ext
2+
3+
void main() {}
4+
5+
// CHECK: -Fre is not supported with -spirv
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %dxc -T ps_6_0 -E main -spirv -Qstrip_reflect
2+
3+
void main() {}
4+
5+
// CHECK: -Qstrip_reflect is not supported with -spirv

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,4 +3131,14 @@ TEST_F(FileTest, RenameEntrypoint) { runFileTest("fspv-entrypoint-name.hlsl"); }
31313131

31323132
TEST_F(FileTest, PrintAll) { runFileTest("fspv-print-all.hlsl"); }
31333133

3134+
TEST_F(FileTest, SpirvOptFd) {
3135+
runFileTest("spirv.opt.fd.hlsl", Expect::Failure);
3136+
}
3137+
TEST_F(FileTest, SpirvOptFre) {
3138+
runFileTest("spirv.opt.fre.hlsl", Expect::Failure);
3139+
}
3140+
TEST_F(FileTest, SpirvOptQStripReflect) {
3141+
runFileTest("spirv.opt.qstripreflect.hlsl", Expect::Failure);
3142+
}
3143+
31343144
} // namespace

0 commit comments

Comments
 (0)