HLSLOptions.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. //===--- HLSLOptions.cpp - Driver Options Table ---------------------------===//
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // HLSLOptions.cpp //
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. // This file is distributed under the University of Illinois Open Source //
  7. // License. See LICENSE.TXT for details. //
  8. // //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "llvm/ADT/STLExtras.h"
  11. #include "llvm/Option/OptTable.h"
  12. #include "llvm/Option/Option.h"
  13. #include "llvm/Support/raw_ostream.h"
  14. #include "dxc/Support/Global.h"
  15. #include "dxc/Support/WinIncludes.h"
  16. #include "dxc/Support/HLSLOptions.h"
  17. #include "dxc/Support/Unicode.h"
  18. #include "dxc/Support/dxcapi.use.h"
  19. #include "dxc/HLSL/DxilShaderModel.h"
  20. using namespace llvm::opt;
  21. using namespace dxc;
  22. using namespace hlsl;
  23. using namespace hlsl::options;
  24. #define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
  25. #include "dxc/Support/HLSLOptions.inc"
  26. #undef PREFIX
  27. static const OptTable::Info HlslInfoTable[] = {
  28. #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
  29. HELPTEXT, METAVAR) \
  30. { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \
  31. FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },
  32. #include "dxc/Support/HLSLOptions.inc"
  33. #undef OPTION
  34. };
  35. namespace {
  36. class HlslOptTable : public OptTable {
  37. public:
  38. HlslOptTable()
  39. : OptTable(HlslInfoTable, llvm::array_lengthof(HlslInfoTable)) {}
  40. };
  41. }
  42. static HlslOptTable *g_HlslOptTable;
  43. std::error_code hlsl::options::initHlslOptTable() {
  44. DXASSERT(g_HlslOptTable == nullptr, "else double-init");
  45. g_HlslOptTable = new (std::nothrow) HlslOptTable();
  46. if (g_HlslOptTable == nullptr)
  47. return std::error_code(E_OUTOFMEMORY, std::system_category());
  48. return std::error_code();
  49. }
  50. void hlsl::options::cleanupHlslOptTable() {
  51. delete g_HlslOptTable;
  52. g_HlslOptTable = nullptr;
  53. }
  54. const OptTable * hlsl::options::getHlslOptTable() {
  55. return g_HlslOptTable;
  56. }
  57. void DxcDefines::push_back(llvm::StringRef value) {
  58. // Skip empty defines.
  59. if (value.size() > 0) {
  60. DefineStrings.push_back(value);
  61. }
  62. }
  63. UINT32 DxcDefines::ComputeNumberOfWCharsNeededForDefines() {
  64. UINT32 wcharSize = 0;
  65. for (llvm::StringRef &S : DefineStrings) {
  66. DXASSERT(S.size() > 0,
  67. "else DxcDefines::push_back should not have added this");
  68. const int utf16Length = ::MultiByteToWideChar(
  69. CP_UTF8, MB_ERR_INVALID_CHARS, S.data(), S.size(), nullptr, 0);
  70. IFTARG(utf16Length != 0);
  71. wcharSize += utf16Length + 1; // adding null terminated character
  72. }
  73. return wcharSize;
  74. }
  75. void DxcDefines::BuildDefines() {
  76. // Calculate and prepare the size of the backing buffer.
  77. DXASSERT(DefineValues == nullptr, "else DxcDefines is already built");
  78. UINT32 wcharSize = ComputeNumberOfWCharsNeededForDefines();
  79. DefineValues = new wchar_t[wcharSize];
  80. DefineVector.resize(DefineStrings.size());
  81. // Build up the define structures while filling in the backing buffer.
  82. UINT32 remaining = wcharSize;
  83. LPWSTR pWriteCursor = DefineValues;
  84. for (size_t i = 0; i < DefineStrings.size(); ++i) {
  85. llvm::StringRef &S = DefineStrings[i];
  86. DxcDefine &D = DefineVector[i];
  87. const int utf16Length =
  88. ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, S.data(), S.size(),
  89. pWriteCursor, remaining);
  90. DXASSERT(utf16Length > 0,
  91. "else it should have failed during size calculation");
  92. LPWSTR pDefineEnd = pWriteCursor + utf16Length;
  93. D.Name = pWriteCursor;
  94. LPWSTR pEquals = std::find(pWriteCursor, pDefineEnd, L'=');
  95. if (pEquals == pDefineEnd) {
  96. D.Value = nullptr;
  97. } else {
  98. *pEquals = L'\0';
  99. D.Value = pEquals + 1;
  100. }
  101. // Advance past converted characters and include the null terminator.
  102. pWriteCursor += utf16Length;
  103. *pWriteCursor = L'\0';
  104. ++pWriteCursor;
  105. DXASSERT(pWriteCursor <= DefineValues + wcharSize,
  106. "else this function is calculating this incorrectly");
  107. remaining -= (utf16Length + 1);
  108. }
  109. }
  110. bool DxcOpts::IsRootSignatureProfile() {
  111. return TargetProfile == "rootsig_1_0" ||
  112. TargetProfile == "rootsig_1_1";
  113. }
  114. bool DxcOpts::IsLibraryProfile() {
  115. return TargetProfile.startswith("lib_");
  116. }
  117. MainArgs::MainArgs(int argc, const wchar_t **argv, int skipArgCount) {
  118. if (argc > skipArgCount) {
  119. Utf8StringVector.reserve(argc - skipArgCount);
  120. Utf8CharPtrVector.reserve(argc - skipArgCount);
  121. for (int i = skipArgCount; i < argc; ++i) {
  122. Utf8StringVector.emplace_back(Unicode::UTF16ToUTF8StringOrThrow(argv[i]));
  123. Utf8CharPtrVector.push_back(Utf8StringVector.back().data());
  124. }
  125. }
  126. }
  127. MainArgs::MainArgs(llvm::ArrayRef<llvm::StringRef> args) {
  128. Utf8StringVector.reserve(args.size());
  129. Utf8CharPtrVector.reserve(args.size());
  130. for (llvm::StringRef str : args) {
  131. Utf8StringVector.emplace_back(str.str());
  132. Utf8CharPtrVector.push_back(Utf8StringVector.back().data());
  133. }
  134. }
  135. MainArgs& MainArgs::operator=(const MainArgs &other) {
  136. Utf8StringVector.clear();
  137. Utf8CharPtrVector.clear();
  138. for (const std::string &str : other.Utf8StringVector) {
  139. Utf8StringVector.emplace_back(str);
  140. Utf8CharPtrVector.push_back(Utf8StringVector.back().data());
  141. }
  142. return *this;
  143. }
  144. StringRefUtf16::StringRefUtf16(llvm::StringRef value) {
  145. if (!value.empty())
  146. m_value = Unicode::UTF8ToUTF16StringOrThrow(value.data());
  147. }
  148. namespace hlsl {
  149. namespace options {
  150. /// Reads all options from the given argument strings, populates opts, and
  151. /// validates reporting errors and warnings.
  152. int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
  153. const MainArgs &argStrings, DxcOpts &opts,
  154. llvm::raw_ostream &errors) {
  155. DXASSERT_NOMSG(optionTable != nullptr);
  156. unsigned missingArgIndex = 0, missingArgCount = 0;
  157. InputArgList Args = optionTable->ParseArgs(
  158. argStrings.getArrayRef(), missingArgIndex, missingArgCount, flagsToInclude);
  159. opts.ShowHelp = Args.hasFlag(OPT_help, OPT_INVALID, false);
  160. if (opts.ShowHelp) {
  161. return 0;
  162. }
  163. if (missingArgCount) {
  164. errors << "Argument to '" << Args.getArgString(missingArgIndex)
  165. << "' is missing.";
  166. return 1;
  167. }
  168. if (!Args.hasArg(hlsl::options::OPT_Qunused_arguments)) {
  169. for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
  170. errors << "Unknown argument: '" << A->getAsString(Args).c_str() << "'";
  171. return 1;
  172. }
  173. }
  174. // Add macros from the command line.
  175. for (const Arg *A : Args.filtered(OPT_D)) {
  176. opts.Defines.push_back(A->getValue());
  177. // If supporting OPT_U and included in filter, handle undefs.
  178. }
  179. opts.Defines.BuildDefines(); // Must be called after all defines are pushed back
  180. opts.ExternalLib = Args.getLastArgValue(OPT_external_lib);
  181. opts.ExternalFn = Args.getLastArgValue(OPT_external_fn);
  182. // Verify consistency for external library support.
  183. if (opts.ExternalLib.empty()) {
  184. if (!opts.ExternalFn.empty()) {
  185. errors << "External function cannot be specified without an external "
  186. "library name.";
  187. return 1;
  188. }
  189. }
  190. else {
  191. if (opts.ExternalFn.empty()) {
  192. errors << "External library name requires specifying an external "
  193. "function name.";
  194. return 1;
  195. }
  196. }
  197. DXASSERT(opts.ExternalLib.empty() == opts.ExternalFn.empty(),
  198. "else flow above is incorrect");
  199. // when no-warnings option is present, do not output warnings.
  200. opts.OutputWarnings = Args.hasFlag(OPT_INVALID, OPT_no_warnings, true);
  201. opts.EntryPoint = Args.getLastArgValue(OPT_entrypoint);
  202. // Entry point is required in arguments only for drivers; APIs take this through an argument.
  203. // The value should default to 'main', but we let the caller apply this policy.
  204. if (opts.TargetProfile.empty()) {
  205. opts.TargetProfile = Args.getLastArgValue(OPT_target_profile);
  206. }
  207. if (opts.IsLibraryProfile()) {
  208. if (Args.getLastArg(OPT_entrypoint)) {
  209. errors << "cannot specify entry point for a library";
  210. return 1;
  211. } else {
  212. // Set entry point to impossible name.
  213. opts.EntryPoint = "lib.no::entry";
  214. }
  215. }
  216. llvm::StringRef ver = Args.getLastArgValue(OPT_hlsl_version);
  217. opts.HLSL2015 = opts.HLSL2016 = opts.HLSL2017 = false;
  218. if (ver.empty() || ver == "2016") { opts.HLSL2016 = true; } // Default to 2016
  219. else if (ver == "2015") { opts.HLSL2015 = true; }
  220. else if (ver == "2017") { opts.HLSL2017 = true; }
  221. else {
  222. errors << "Unknown HLSL version";
  223. return 1;
  224. }
  225. if (opts.HLSL2015 && !(flagsToInclude & HlslFlags::ISenseOption)) {
  226. errors << "HLSL Version 2015 is only supported for language services";
  227. return 1;
  228. }
  229. // AssemblyCodeHex not supported (Fx)
  230. // OutputLibrary not supported (Fl)
  231. opts.AssemblyCode = Args.getLastArgValue(OPT_Fc);
  232. opts.DebugFile = Args.getLastArgValue(OPT_Fd);
  233. opts.ExtractPrivateFile = Args.getLastArgValue(OPT_getprivate);
  234. opts.NoMinPrecision = Args.hasFlag(OPT_no_min_precision, OPT_INVALID, false);
  235. opts.OutputObject = Args.getLastArgValue(OPT_Fo);
  236. opts.OutputHeader = Args.getLastArgValue(OPT_Fh);
  237. opts.OutputWarningsFile = Args.getLastArgValue(OPT_Fe);
  238. opts.UseColor = Args.hasFlag(OPT_Cc, OPT_INVALID);
  239. opts.UseInstructionNumbers = Args.hasFlag(OPT_Ni, OPT_INVALID);
  240. opts.UseInstructionByteOffsets = Args.hasFlag(OPT_No, OPT_INVALID);
  241. opts.UseHexLiterals = Args.hasFlag(OPT_Lx, OPT_INVALID);
  242. opts.Preprocess = Args.getLastArgValue(OPT_P);
  243. opts.AstDump = Args.hasFlag(OPT_ast_dump, OPT_INVALID, false);
  244. opts.CodeGenHighLevel = Args.hasFlag(OPT_fcgl, OPT_INVALID, false);
  245. opts.DebugInfo = Args.hasFlag(OPT__SLASH_Zi, OPT_INVALID, false);
  246. opts.DebugNameForBinary = Args.hasFlag(OPT_Zsb, OPT_INVALID, false);
  247. opts.DebugNameForSource = Args.hasFlag(OPT_Zsb, OPT_INVALID, false);
  248. opts.VariableName = Args.getLastArgValue(OPT_Vn);
  249. opts.InputFile = Args.getLastArgValue(OPT_INPUT);
  250. opts.ForceRootSigVer = Args.getLastArgValue(OPT_force_rootsig_ver);
  251. opts.PrivateSource = Args.getLastArgValue(OPT_setprivate);
  252. opts.RootSignatureSource = Args.getLastArgValue(OPT_setrootsignature);
  253. opts.VerifyRootSignatureSource = Args.getLastArgValue(OPT_verifyrootsignature);
  254. opts.RootSignatureDefine = Args.getLastArgValue(OPT_rootsig_define);
  255. if (!opts.ForceRootSigVer.empty() && opts.ForceRootSigVer != "rootsig_1_0" &&
  256. opts.ForceRootSigVer != "rootsig_1_1") {
  257. errors << "Unsupported value '" << opts.ForceRootSigVer
  258. << "' for root signature profile.";
  259. return 1;
  260. }
  261. opts.IEEEStrict = Args.hasFlag(OPT_Gis, OPT_INVALID, false);
  262. opts.IgnoreLineDirectives = Args.hasFlag(OPT_ignore_line_directives, OPT_INVALID, false);
  263. opts.FPDenormalMode = Args.getLastArgValue(OPT_denorm);
  264. // Check if a given denormalized value is valid
  265. if (!opts.FPDenormalMode.empty()) {
  266. if (!(opts.FPDenormalMode.equals_lower("preserve") ||
  267. opts.FPDenormalMode.equals_lower("ftz") ||
  268. opts.FPDenormalMode.equals_lower("any"))) {
  269. errors << "Unsupported value '" << opts.FPDenormalMode
  270. << "' for denorm option.";
  271. return 1;
  272. }
  273. }
  274. // Check options only allowed in shader model >= 6.2
  275. if (opts.TargetProfile.empty() || !opts.TargetProfile.endswith_lower("6_2")) {
  276. if (!opts.FPDenormalMode.empty()) {
  277. errors << "denorm option is only allowed for shader model 6.2 and above.";
  278. return 1;
  279. }
  280. if (opts.NoMinPrecision) {
  281. errors << "no min precision mode is only allowed for shader model 6.2 and above.";
  282. return 1;
  283. }
  284. }
  285. if (Arg *A = Args.getLastArg(OPT_O0, OPT_O1, OPT_O2, OPT_O3)) {
  286. if (A->getOption().matches(OPT_O0))
  287. opts.OptLevel = 0;
  288. if (A->getOption().matches(OPT_O1))
  289. opts.OptLevel = 1;
  290. if (A->getOption().matches(OPT_O2))
  291. opts.OptLevel = 2;
  292. if (A->getOption().matches(OPT_O3))
  293. opts.OptLevel = 3;
  294. }
  295. else
  296. opts.OptLevel = 3;
  297. opts.OptDump = Args.hasFlag(OPT_Odump, OPT_INVALID, false);
  298. opts.DisableOptimizations = Args.hasFlag(OPT_Od, OPT_INVALID, false);
  299. if (opts.DisableOptimizations)
  300. opts.OptLevel = 0;
  301. opts.DisableValidation = Args.hasFlag(OPT_VD, OPT_INVALID, false);
  302. opts.AllResourcesBound = Args.hasFlag(OPT_all_resources_bound, OPT_INVALID, false);
  303. opts.ColorCodeAssembly = Args.hasFlag(OPT_Cc, OPT_INVALID, false);
  304. opts.DefaultRowMajor = Args.hasFlag(OPT_Zpr, OPT_INVALID, false);
  305. opts.DefaultColMajor = Args.hasFlag(OPT_Zpc, OPT_INVALID, false);
  306. opts.DumpBin = Args.hasFlag(OPT_dumpbin, OPT_INVALID, false);
  307. opts.NotUseLegacyCBufLoad = Args.hasFlag(OPT_not_use_legacy_cbuf_load, OPT_INVALID, false);
  308. opts.PackPrefixStable = Args.hasFlag(OPT_pack_prefix_stable, OPT_INVALID, false);
  309. opts.PackOptimized = Args.hasFlag(OPT_pack_optimized, OPT_INVALID, false);
  310. opts.DisplayIncludeProcess = Args.hasFlag(OPT_H, OPT_INVALID, false);
  311. opts.WarningAsError = Args.hasFlag(OPT__SLASH_WX, OPT_INVALID, false);
  312. opts.AvoidFlowControl = Args.hasFlag(OPT_Gfa, OPT_INVALID, false);
  313. opts.PreferFlowControl = Args.hasFlag(OPT_Gfp, OPT_INVALID, false);
  314. opts.RecompileFromBinary = Args.hasFlag(OPT_recompile, OPT_INVALID, false);
  315. opts.StripDebug = Args.hasFlag(OPT_Qstrip_debug, OPT_INVALID, false);
  316. opts.StripRootSignature = Args.hasFlag(OPT_Qstrip_rootsignature, OPT_INVALID, false);
  317. opts.StripPrivate = Args.hasFlag(OPT_Qstrip_priv, OPT_INVALID, false);
  318. opts.StripReflection = Args.hasFlag(OPT_Qstrip_reflect, OPT_INVALID, false);
  319. opts.ExtractRootSignature = Args.hasFlag(OPT_extractrootsignature, OPT_INVALID, false);
  320. opts.DisassembleColorCoded = Args.hasFlag(OPT_Cc, OPT_INVALID, false);
  321. opts.DisassembleInstNumbers = Args.hasFlag(OPT_Ni, OPT_INVALID, false);
  322. opts.DisassembleByteOffset = Args.hasFlag(OPT_No, OPT_INVALID, false);
  323. opts.DisaseembleHex = Args.hasFlag(OPT_Lx, OPT_INVALID, false);
  324. if (opts.DefaultColMajor && opts.DefaultRowMajor) {
  325. errors << "Cannot specify /Zpr and /Zpc together, use /? to get usage information";
  326. return 1;
  327. }
  328. if (opts.AvoidFlowControl && opts.PreferFlowControl) {
  329. errors << "Cannot specify /Gfa and /Gfp together, use /? to get usage information";
  330. return 1;
  331. }
  332. if (opts.PackPrefixStable && opts.PackOptimized) {
  333. errors << "Cannot specify /pack_prefix_stable and /pack_optimized together, use /? to get usage information";
  334. return 1;
  335. }
  336. // TODO: more fxc option check.
  337. // ERR_RES_MAY_ALIAS_ONLY_IN_CS_5
  338. // ERR_NOT_ABLE_TO_FLATTEN on if that contain side effects
  339. // TODO: other front-end error.
  340. // ERR_RESOURCE_NOT_IN_TEMPLATE
  341. // ERR_COMPLEX_TEMPLATE_RESOURCE
  342. // ERR_RESOURCE_BIND_CONFLICT
  343. // ERR_TEMPLATE_VAR_CONFLICT
  344. // ERR_ATTRIBUTE_PARAM_SIDE_EFFECT
  345. if ((flagsToInclude & hlsl::options::DriverOption) && opts.InputFile.empty()) {
  346. // Input file is required in arguments only for drivers; APIs take this through an argument.
  347. errors << "Required input file argument is missing. use -help to get more information.";
  348. return 1;
  349. }
  350. if (opts.OutputHeader.empty() && !opts.VariableName.empty()) {
  351. errors << "Cannot specify a header variable name when not writing a header.";
  352. return 1;
  353. }
  354. if (!opts.Preprocess.empty() &&
  355. (!opts.OutputHeader.empty() || !opts.OutputObject.empty() ||
  356. !opts.OutputWarnings || !opts.OutputWarningsFile.empty())) {
  357. errors << "Preprocess cannot be specified with other options.";
  358. return 1;
  359. }
  360. if (opts.DumpBin) {
  361. if (opts.DisplayIncludeProcess || opts.AstDump) {
  362. errors << "Cannot perform actions related to sources from a binary file.";
  363. return 1;
  364. }
  365. if (opts.AllResourcesBound || opts.AvoidFlowControl ||
  366. opts.CodeGenHighLevel || opts.DebugInfo || opts.DefaultColMajor ||
  367. opts.DefaultRowMajor || opts.Defines.size() != 0 ||
  368. opts.DisableOptimizations ||
  369. !opts.EntryPoint.empty() || !opts.ForceRootSigVer.empty() ||
  370. opts.PreferFlowControl || !opts.TargetProfile.empty()) {
  371. errors << "Cannot specify compilation options when reading a binary file.";
  372. return 1;
  373. }
  374. }
  375. if ((flagsToInclude & hlsl::options::DriverOption) &&
  376. opts.TargetProfile.empty() && !opts.DumpBin && opts.Preprocess.empty() && !opts.RecompileFromBinary) {
  377. // Target profile is required in arguments only for drivers when compiling;
  378. // APIs take this through an argument.
  379. errors << "Target profile argument is missing";
  380. return 1;
  381. }
  382. if (!opts.DebugNameForBinary && !opts.DebugNameForSource) {
  383. opts.DebugNameForSource = true;
  384. }
  385. else if (opts.DebugNameForBinary && opts.DebugNameForSource) {
  386. errors << "Cannot specify both /Zss and /Zsb";
  387. return 1;
  388. }
  389. // SPIRV Change Starts
  390. #ifdef ENABLE_SPIRV_CODEGEN
  391. opts.GenSPIRV = Args.hasFlag(OPT_spirv, OPT_INVALID, false);
  392. opts.VkStageIoOrder = Args.getLastArgValue(OPT_fvk_stage_io_order_EQ, "decl");
  393. if (opts.VkStageIoOrder != "alpha" && opts.VkStageIoOrder != "decl") {
  394. errors << "Unknown Vulkan stage I/O location assignment order : "
  395. << opts.VkStageIoOrder;
  396. return 1;
  397. }
  398. #else
  399. if (Args.hasFlag(OPT_spirv, OPT_INVALID, false) ||
  400. !Args.getLastArgValue(OPT_fvk_stage_io_order_EQ).empty()) {
  401. errors << "SPIR-V CodeGen not available. "
  402. "Please recompile with -DENABLE_SPIRV_CODEGEN=ON.";
  403. return 1;
  404. }
  405. #endif
  406. // SPIRV Change Ends
  407. opts.Args = std::move(Args);
  408. return 0;
  409. }
  410. /// Sets up the specified DxcDllSupport instance as per the given options.
  411. int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport,
  412. llvm::raw_ostream &errors) {
  413. if (!opts.ExternalLib.empty()) {
  414. DXASSERT(!opts.ExternalFn.empty(), "else ReadDxcOpts should have failed");
  415. StringRefUtf16 externalLib(opts.ExternalLib);
  416. HRESULT hrLoad =
  417. dxcSupport.InitializeForDll(externalLib, opts.ExternalFn.data());
  418. if (DXC_FAILED(hrLoad)) {
  419. errors << "Unable to load support for external DLL " << opts.ExternalLib
  420. << " with function " << opts.ExternalFn << " - error 0x";
  421. errors.write_hex(hrLoad);
  422. return 1;
  423. }
  424. }
  425. return 0;
  426. }
  427. void CopyArgsToWStrings(const InputArgList &inArgs, unsigned flagsToInclude,
  428. std::vector<std::wstring> &outArgs) {
  429. ArgStringList stringList;
  430. for (const Arg *A : inArgs) {
  431. if (A->getOption().hasFlag(flagsToInclude)) {
  432. A->renderAsInput(inArgs, stringList);
  433. }
  434. }
  435. for (const char *argText : stringList) {
  436. outArgs.emplace_back(Unicode::UTF8ToUTF16StringOrThrow(argText));
  437. }
  438. }
  439. } } // hlsl::options