int C_DECL main(int argc, char* argv[]) { if (argc < 6) { usage(); return 1; } const char* tempdir = argv[4]; //Options |= EOptionHumanReadableSpv; Options |= EOptionSpv; Options |= EOptionLinkProgram; //Options |= EOptionSuppressInfolog; NumWorkItems = 1; Work = new glslang::TWorkItem*[NumWorkItems]; Work[0] = 0; std::string name(argv[2]); if (!SetConfigFile(name)) { Work[0] = new glslang::TWorkItem(name); Worklist.add(Work[0]); } ProcessConfigFile(); glslang::InitializeProcess(); KrafixIncluder includer(name); krafix::Target target; target.system = getSystem(argv[5]); target.es = false; if (strcmp(argv[1], "d3d9") == 0) { target.lang = krafix::HLSL; target.version = 9; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "d3d11") == 0) { target.lang = krafix::HLSL; target.version = 11; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "glsl") == 0) { target.lang = krafix::GLSL; if (target.system == krafix::Linux) target.version = 100; else target.version = 330; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "essl") == 0) { target.lang = krafix::GLSL; target.version = 100; target.es = true; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "agal") == 0) { target.lang = krafix::AGAL; target.version = 100; target.es = true; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "metal") == 0) { target.lang = krafix::Metal; target.version = 1; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else if (strcmp(argv[1], "varlist") == 0) { target.lang = krafix::VarList; target.version = 1; CompileAndLinkShaders(target, argv[3], tempdir, includer); } else { std::cout << "Unknown profile " << argv[1] << std::endl; CompileFailed = true; } glslang::FinalizeProcess(); if (CompileFailed) return EFailCompile; if (LinkFailed) return EFailLink; return 0; }
// // Do all command-line argument parsing. This includes building up the work-items // to be processed later, and saving all the command-line options. // // Does not return (it exits) if command-line is fatally flawed. // void ProcessArguments(int argc, char* argv[]) { ExecutableName = argv[0]; NumWorkItems = argc; // will include some empties where the '-' options were, but it doesn't matter, they'll be 0 Work = new glslang::TWorkItem*[NumWorkItems]; for (int w = 0; w < NumWorkItems; ++w) Work[w] = 0; argc--; argv++; for (; argc >= 1; argc--, argv++) { if (argv[0][0] == '-') { switch (argv[0][1]) { case 'H': Options |= EOptionHumanReadableSpv; // fall through to -V case 'V': Options |= EOptionSpv; Options |= EOptionVulkanRules; Options |= EOptionLinkProgram; break; case 'G': Options |= EOptionSpv; Options |= EOptionLinkProgram; break; case 'E': Options |= EOptionOutputPreprocessed; break; case 'c': Options |= EOptionDumpConfig; break; case 'd': Options |= EOptionDefaultDesktop; break; case 'h': usage(); break; case 'i': Options |= EOptionIntermediate; break; case 'l': Options |= EOptionLinkProgram; break; case 'm': Options |= EOptionMemoryLeakMode; break; case 'o': binaryFileName = argv[1]; if (argc > 0) { argc--; argv++; } else Error("no <file> provided for -o"); break; case 'q': Options |= EOptionDumpReflection; break; case 'r': Options |= EOptionRelaxedErrors; break; case 's': Options |= EOptionSuppressInfolog; break; case 't': #ifdef _WIN32 Options |= EOptionMultiThreaded; #endif break; case 'v': Options |= EOptionDumpVersions; break; case 'w': Options |= EOptionSuppressWarnings; break; default: usage(); break; } } else { std::string name(argv[0]); if (! SetConfigFile(name)) { Work[argc] = new glslang::TWorkItem(name); Worklist.add(Work[argc]); } } } // Make sure that -E is not specified alongside linking (which includes SPV generation) if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram)) Error("can't use -E when linking is selected"); // -o makes no sense if there is no target binary if (binaryFileName && (Options & EOptionSpv) == 0) Error("no binary generation requested (e.g., -V)"); }
// // Do all command-line argument parsing. This includes building up the work-items // to be processed later, and saving all the command-line options. // // Does not return (it exits) if command-line is fatally flawed. // void ProcessArguments(int argc, char* argv[]) { baseSamplerBinding.fill(0); baseTextureBinding.fill(0); baseImageBinding.fill(0); baseUboBinding.fill(0); ExecutableName = argv[0]; NumWorkItems = argc; // will include some empties where the '-' options were, but it doesn't matter, they'll be 0 Work = new glslang::TWorkItem*[NumWorkItems]; for (int w = 0; w < NumWorkItems; ++w) Work[w] = 0; argc--; argv++; for (; argc >= 1; argc--, argv++) { if (argv[0][0] == '-') { switch (argv[0][1]) { case '-': { std::string lowerword(argv[0]+2); std::transform(lowerword.begin(), lowerword.end(), lowerword.begin(), ::tolower); // handle --word style options if (lowerword == "shift-sampler-bindings" || // synonyms lowerword == "shift-sampler-binding" || lowerword == "ssb") { ProcessBindingBase(argc, argv, baseSamplerBinding); } else if (lowerword == "shift-texture-bindings" || // synonyms lowerword == "shift-texture-binding" || lowerword == "stb") { ProcessBindingBase(argc, argv, baseTextureBinding); } else if (lowerword == "shift-image-bindings" || // synonyms lowerword == "shift-image-binding" || lowerword == "sib") { ProcessBindingBase(argc, argv, baseImageBinding); } else if (lowerword == "shift-ubo-bindings" || // synonyms lowerword == "shift-ubo-binding" || lowerword == "sub") { ProcessBindingBase(argc, argv, baseUboBinding); } else if (lowerword == "auto-map-bindings" || // synonyms lowerword == "auto-map-binding" || lowerword == "amb") { Options |= EOptionAutoMapBindings; } else if (lowerword == "flatten-uniform-arrays" || // synonyms lowerword == "flatten-uniform-array" || lowerword == "fua") { Options |= EOptionFlattenUniformArrays; } else if (lowerword == "no-storage-format" || // synonyms lowerword == "nsf") { Options |= EOptionNoStorageFormat; } else if (lowerword == "source-entrypoint" || // synonyms lowerword == "sep") { sourceEntryPointName = argv[1]; if (argc > 0) { argc--; argv++; } else Error("no <entry-point> provided for --source-entrypoint"); break; } else if (lowerword == "keep-uncalled" || // synonyms lowerword == "ku") { Options |= EOptionKeepUncalled; } else { usage(); } } break; case 'H': Options |= EOptionHumanReadableSpv; if ((Options & EOptionSpv) == 0) { // default to Vulkan Options |= EOptionSpv; Options |= EOptionVulkanRules; Options |= EOptionLinkProgram; } break; case 'V': Options |= EOptionSpv; Options |= EOptionVulkanRules; Options |= EOptionLinkProgram; break; case 'S': shaderStageName = argv[1]; if (argc > 0) { argc--; argv++; } else Error("no <stage> specified for -S"); break; case 'G': Options |= EOptionSpv; Options |= EOptionLinkProgram; // undo a -H default to Vulkan Options &= ~EOptionVulkanRules; break; case 'E': Options |= EOptionOutputPreprocessed; break; case 'c': Options |= EOptionDumpConfig; break; case 'C': Options |= EOptionCascadingErrors; break; case 'd': Options |= EOptionDefaultDesktop; break; case 'D': Options |= EOptionReadHlsl; break; case 'e': // HLSL todo: entry point handle needs much more sophistication. // This is okay for one compilation unit with one entry point. entryPointName = argv[1]; if (argc > 0) { argc--; argv++; } else Error("no <entry-point> provided for -e"); break; case 'h': usage(); break; case 'i': Options |= EOptionIntermediate; break; case 'l': Options |= EOptionLinkProgram; break; case 'm': Options |= EOptionMemoryLeakMode; break; case 'o': binaryFileName = argv[1]; if (argc > 0) { argc--; argv++; } else Error("no <file> provided for -o"); break; case 'q': Options |= EOptionDumpReflection; break; case 'r': Options |= EOptionRelaxedErrors; break; case 's': Options |= EOptionSuppressInfolog; break; case 't': #ifdef _WIN32 Options |= EOptionMultiThreaded; #endif break; case 'v': Options |= EOptionDumpVersions; break; case 'w': Options |= EOptionSuppressWarnings; break; case 'x': Options |= EOptionOutputHexadecimal; break; default: usage(); break; } } else { std::string name(argv[0]); if (! SetConfigFile(name)) { Work[argc] = new glslang::TWorkItem(name); Worklist.add(Work[argc]); } } } // Make sure that -E is not specified alongside linking (which includes SPV generation) if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram)) Error("can't use -E when linking is selected"); // -o or -x makes no sense if there is no target binary if (binaryFileName && (Options & EOptionSpv) == 0) Error("no binary generation requested (e.g., -V)"); if ((Options & EOptionFlattenUniformArrays) != 0 && (Options & EOptionReadHlsl) == 0) Error("uniform array flattening only valid when compiling HLSL source."); }