From d84f4582c0caa656e7d0ca0e619651f8b4e5ed16 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 7 Jan 2021 13:16:18 -0800 Subject: Add a -capability command-line option (#1651) This provides a stand-alone option distinct from `-profile` that can be used to add capabilities to a target. A test has been added to confirm that `-profile X -capability Y` works the same as `-profile X+Y`. The intention is that this option could be used in applications that use the API to set up their target but then use the options-parsing logic to handle things like capabilities. Note: that latter bit has not been confirmed, so it is possible that this approach does not actually suffice for hybrid API + options usage. That will need to be confirmed in follow-up work. --- source/slang/slang-options.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index c3db39773..a89818c4f 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -717,6 +717,35 @@ struct OptionsParser addCapabilityAtom(getCurrentTarget(), atom); } } + else if( argStr == "-capability" ) + { + // The `-capability` option is similar to `-profile` but does not set the actual profile + // for a target (it just adds capabilities). + // + // TODO: Once profiles are treated as capabilities themselves, it might be possible + // to treat `-profile` and `-capability` as aliases, although there might still be + // value in only allowing a single `-profile` option per target while still allowing + // zero or more `-capability` options. + + String operand; + SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, operand)); + + List slices; + StringUtil::split(operand.getUnownedSlice(), '+', slices); + Index sliceCount = slices.getCount(); + for(Index i = 0; i < sliceCount; ++i) + { + UnownedStringSlice atomName = slices[i]; + CapabilityAtom atom = findCapabilityAtom(atomName); + if( atom == CapabilityAtom::Invalid ) + { + sink->diagnose(SourceLoc(), Diagnostics::unknownProfile, atomName); + return SLANG_FAIL; + } + + addCapabilityAtom(getCurrentTarget(), atom); + } + } else if (argStr == "-stage") { String name; -- cgit v1.2.3