2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013-2016 LunarG, Inc.
4 // Copyright (C) 2016-2020 Google, Inc.
5 // Modifications Copyright(C) 2021 Advanced Micro Devices, Inc.All rights reserved.
7 // All rights reserved.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
13 // Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // Redistributions in binary form must reproduce the above
17 // copyright notice, this list of conditions and the following
18 // disclaimer in the documentation and/or other materials provided
19 // with the distribution.
21 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
22 // contributors may be used to endorse or promote products derived
23 // from this software without specific prior written permission.
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 // POSSIBILITY OF SUCH DAMAGE.
39 // this only applies to the standalone wrapper, not the front end in general
40 #ifndef _CRT_SECURE_NO_WARNINGS
41 #define _CRT_SECURE_NO_WARNINGS
44 #include "glslang/Public/ResourceLimits.h"
46 #include "DirStackFileIncluder.h"
47 #include "./../glslang/Include/ShHandle.h"
48 #include "./../glslang/Public/ShaderLang.h"
49 #include "../SPIRV/GlslangToSpv.h"
50 #include "../SPIRV/GLSL.std.450.h"
51 #include "../SPIRV/doc.h"
52 #include "../SPIRV/disassemble.h"
64 #include "../glslang/OSDependent/osinclude.h"
66 // Build-time generated includes
67 #include "glslang/build_info.h"
69 #include "glslang/glsl_intrinsic_header.h"
72 GLSLANG_EXPORT void ShOutputHtml();
75 // Command-line options
78 EOptionIntermediate = (1 << 0),
79 EOptionSuppressInfolog = (1 << 1),
80 EOptionMemoryLeakMode = (1 << 2),
81 EOptionRelaxedErrors = (1 << 3),
82 EOptionGiveWarnings = (1 << 4),
83 EOptionLinkProgram = (1 << 5),
84 EOptionMultiThreaded = (1 << 6),
85 EOptionDumpConfig = (1 << 7),
86 EOptionDumpReflection = (1 << 8),
87 EOptionSuppressWarnings = (1 << 9),
88 EOptionDumpVersions = (1 << 10),
89 EOptionSpv = (1 << 11),
90 EOptionHumanReadableSpv = (1 << 12),
91 EOptionVulkanRules = (1 << 13),
92 EOptionDefaultDesktop = (1 << 14),
93 EOptionOutputPreprocessed = (1 << 15),
94 EOptionOutputHexadecimal = (1 << 16),
95 EOptionReadHlsl = (1 << 17),
96 EOptionCascadingErrors = (1 << 18),
97 EOptionAutoMapBindings = (1 << 19),
98 EOptionFlattenUniformArrays = (1 << 20),
99 EOptionNoStorageFormat = (1 << 21),
100 EOptionKeepUncalled = (1 << 22),
101 EOptionHlslOffsets = (1 << 23),
102 EOptionHlslIoMapping = (1 << 24),
103 EOptionAutoMapLocations = (1 << 25),
104 EOptionDebug = (1 << 26),
105 EOptionStdin = (1 << 27),
106 EOptionOptimizeDisable = (1 << 28),
107 EOptionOptimizeSize = (1 << 29),
108 EOptionInvertY = (1 << 30),
109 EOptionDumpBareVersion = (1 << 31),
111 bool targetHlslFunctionality1 = false;
112 bool SpvToolsDisassembler = false;
113 bool SpvToolsValidate = false;
114 bool NaNClamp = false;
115 bool stripDebugInfo = false;
116 bool emitNonSemanticShaderDebugInfo = false;
117 bool emitNonSemanticShaderDebugSource = false;
118 bool beQuiet = false;
119 bool VulkanRulesRelaxed = false;
120 bool autoSampledTextures = false;
123 // Return codes from main/exit().
136 // Forward declarations.
138 EShLanguage FindLanguage(const std::string& name, bool parseSuffix=true);
139 void CompileFile(const char* fileName, ShHandle);
141 char* ReadFileData(const char* fileName);
142 void FreeFileData(char* data);
143 void InfoLogMsg(const char* msg, const char* name, const int num);
145 // Globally track if any compile or link failure.
146 bool CompileFailed = false;
147 bool LinkFailed = false;
149 // array of unique places to leave the shader names and infologs for the asynchronous compiles
150 std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
152 std::string ConfigFile;
155 // Parse either a .conf file provided by the user or the default from glslang::DefaultTBuiltInResource
157 void ProcessConfigFile()
159 if (ConfigFile.size() == 0)
160 *GetResources() = *GetDefaultResources();
163 char* configString = ReadFileData(ConfigFile.c_str());
164 DecodeResourceLimits(GetResources(), configString);
165 FreeFileData(configString);
170 int ReflectOptions = EShReflectionDefault;
172 const char* ExecutableName = nullptr;
173 const char* binaryFileName = nullptr;
174 const char* depencyFileName = nullptr;
175 const char* entryPointName = nullptr;
176 const char* sourceEntryPointName = nullptr;
177 const char* shaderStageName = nullptr;
178 const char* variableName = nullptr;
179 bool HlslEnable16BitTypes = false;
180 bool HlslDX9compatible = false;
181 bool HlslDxPositionW = false;
182 bool EnhancedMsgs = false;
183 bool DumpBuiltinSymbols = false;
184 std::vector<std::string> IncludeDirectoryList;
186 // Source environment
187 // (source 'Client' is currently the same as target 'Client')
188 int ClientInputSemanticsVersion = 100;
190 // Target environment
191 glslang::EShClient Client = glslang::EShClientNone; // will stay EShClientNone if only validating
192 glslang::EShTargetClientVersion ClientVersion; // not valid until Client is set
193 glslang::EShTargetLanguage TargetLanguage = glslang::EShTargetNone;
194 glslang::EShTargetLanguageVersion TargetVersion; // not valid until TargetLanguage is set
197 int GlslVersion = 0; // GLSL version specified on CLI, overrides #version in shader source
199 std::vector<std::string> Processes; // what should be recorded by OpModuleProcessed, or equivalent
201 // Per descriptor-set binding base data
202 typedef std::map<unsigned int, unsigned int> TPerSetBaseBinding;
204 std::vector<std::pair<std::string, int>> uniformLocationOverrides;
207 std::array<std::array<unsigned int, EShLangCount>, glslang::EResCount> baseBinding;
208 std::array<std::array<TPerSetBaseBinding, EShLangCount>, glslang::EResCount> baseBindingForSet;
209 std::array<std::vector<std::string>, EShLangCount> baseResourceSetBinding;
211 std::vector<std::pair<std::string, glslang::TBlockStorageClass>> blockStorageOverrides;
213 bool setGlobalUniformBlock = false;
214 std::string globalUniformName;
215 unsigned int globalUniformBinding;
216 unsigned int globalUniformSet;
218 bool setGlobalBufferBlock = false;
219 std::string atomicCounterBlockName;
220 unsigned int atomicCounterBlockSet;
222 // Add things like "#define ..." to a preamble to use in the beginning of the shader.
227 bool isSet() const { return text.size() > 0; }
228 const char* get() const { return text.c_str(); }
231 void addDef(std::string def)
233 text.append("#define ");
236 Processes.push_back("define-macro ");
237 Processes.back().append(def);
239 // The first "=" needs to turn into a space
240 const size_t equal = def.find_first_of("=");
241 if (equal != def.npos)
249 void addUndef(std::string undef)
251 text.append("#undef ");
254 Processes.push_back("undef-macro ");
255 Processes.back().append(undef);
262 void fixLine(std::string& line)
264 // Can't go past a newline in the line
265 const size_t end = line.find_first_of("\n");
266 if (end != line.npos)
267 line = line.substr(0, end);
270 std::string text; // contents of preamble
273 // Track the user's #define and #undef from the command line.
274 TPreamble UserPreamble;
275 std::string PreambleString;
278 // Create the default name for saving a binary if -o is not provided.
280 const char* GetBinaryName(EShLanguage stage)
283 if (binaryFileName == nullptr) {
285 case EShLangVertex: name = "vert.spv"; break;
286 case EShLangTessControl: name = "tesc.spv"; break;
287 case EShLangTessEvaluation: name = "tese.spv"; break;
288 case EShLangGeometry: name = "geom.spv"; break;
289 case EShLangFragment: name = "frag.spv"; break;
290 case EShLangCompute: name = "comp.spv"; break;
291 case EShLangRayGen: name = "rgen.spv"; break;
292 case EShLangIntersect: name = "rint.spv"; break;
293 case EShLangAnyHit: name = "rahit.spv"; break;
294 case EShLangClosestHit: name = "rchit.spv"; break;
295 case EShLangMiss: name = "rmiss.spv"; break;
296 case EShLangCallable: name = "rcall.spv"; break;
297 case EShLangMesh : name = "mesh.spv"; break;
298 case EShLangTask : name = "task.spv"; break;
299 default: name = "unknown"; break;
302 name = binaryFileName;
308 // *.conf => this is a config file that can set limits/resources
310 bool SetConfigFile(const std::string& name)
315 if (name.compare(name.size() - 5, 5, ".conf") == 0) {
324 // Give error and exit with failure code.
326 void Error(const char* message, const char* detail = nullptr)
328 fprintf(stderr, "%s: Error: ", ExecutableName);
329 if (detail != nullptr)
330 fprintf(stderr, "%s: ", detail);
331 fprintf(stderr, "%s (use -h for usage)\n", message);
336 // Process an optional binding base of one the forms:
337 // --argname [stage] base // base for stage (if given) or all stages (if not)
338 // --argname [stage] [base set]... // set/base pairs: set the base for given binding set.
340 // Where stage is one of the forms accepted by FindLanguage, and base is an integer
342 void ProcessBindingBase(int& argc, char**& argv, glslang::TResourceType res)
347 EShLanguage lang = EShLangCount;
349 TPerSetBaseBinding perSetBase;
352 // Parse stage, if given
353 if (!isdigit(argv[arg][0])) {
354 if (argc < 3) // this form needs one more argument
357 lang = FindLanguage(argv[arg++], false);
360 if ((argc - arg) >= 2 && isdigit(argv[arg+0][0]) && isdigit(argv[arg+1][0])) {
361 // Parse a per-set binding base
363 const int baseNum = atoi(argv[arg++]);
364 const int setNum = atoi(argv[arg++]);
365 perSetBase[setNum] = baseNum;
366 } while ((argc - arg) >= 2 && isdigit(argv[arg + 0][0]) && isdigit(argv[arg + 1][0]));
368 // Parse single binding base
369 singleBase = atoi(argv[arg++]);
375 // Set one or all languages
376 const int langMin = (lang < EShLangCount) ? lang+0 : 0;
377 const int langMax = (lang < EShLangCount) ? lang+1 : EShLangCount;
379 for (int lang = langMin; lang < langMax; ++lang) {
380 if (!perSetBase.empty())
381 baseBindingForSet[res][lang].insert(perSetBase.begin(), perSetBase.end());
383 baseBinding[res][lang] = singleBase;
387 void ProcessResourceSetBindingBase(int& argc, char**& argv, std::array<std::vector<std::string>, EShLangCount>& base)
392 if (!isdigit(argv[1][0])) {
393 if (argc < 3) // this form needs one more argument
396 // Parse form: --argname stage [regname set base...], or:
397 // --argname stage set
398 const EShLanguage lang = FindLanguage(argv[1], false);
403 while (argc > 1 && argv[1] != nullptr && argv[1][0] != '-') {
404 base[lang].push_back(argv[1]);
410 // Must have one arg, or a multiple of three (for [regname set binding] triples)
411 if (base[lang].size() != 1 && (base[lang].size() % 3) != 0)
415 // Parse form: --argname set
416 for (int lang=0; lang<EShLangCount; ++lang)
417 base[lang].push_back(argv[1]);
425 // Process an optional binding base of one the forms:
426 // --argname name {uniform|buffer|push_constant}
427 void ProcessBlockStorage(int& argc, char**& argv, std::vector<std::pair<std::string, glslang::TBlockStorageClass>>& storage)
432 glslang::TBlockStorageClass blockStorage = glslang::EbsNone;
434 std::string strBacking(argv[2]);
435 if (strBacking == "uniform")
436 blockStorage = glslang::EbsUniform;
437 else if (strBacking == "buffer")
438 blockStorage = glslang::EbsStorageBuffer;
439 else if (strBacking == "push_constant")
440 blockStorage = glslang::EbsPushConstant;
442 printf("%s: invalid block storage\n", strBacking.c_str());
446 storage.push_back(std::make_pair(std::string(argv[1]), blockStorage));
452 inline bool isNonDigit(char c) {
453 // a non-digit character valid in a glsl identifier
454 return (c == '_') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
457 // whether string isa valid identifier to be used in glsl
458 bool isValidIdentifier(const char* str) {
459 std::string idn(str);
461 if (idn.length() == 0) {
465 if (idn.length() >= 3 && idn.substr(0, 3) == "gl_") {
466 // identifiers startin with "gl_" are reserved
470 if (!isNonDigit(idn[0])) {
474 for (unsigned int i = 1; i < idn.length(); ++i) {
475 if (!(isdigit(idn[i]) || isNonDigit(idn[i]))) {
483 // Process settings for either the global buffer block or global unfirom block
485 // --argname name set binding
486 void ProcessGlobalBlockSettings(int& argc, char**& argv, std::string* name, unsigned int* set, unsigned int* binding)
491 unsigned int curArg = 1;
493 assert(name || set || binding);
496 if (!isValidIdentifier(argv[curArg])) {
497 printf("%s: invalid identifier\n", argv[curArg]);
500 *name = argv[curArg];
507 int setVal = ::strtol(argv[curArg], NULL, 10);
508 if (errno || setVal < 0) {
509 printf("%s: invalid set\n", argv[curArg]);
519 int bindingVal = ::strtol(argv[curArg], NULL, 10);
520 if (errno || bindingVal < 0) {
521 printf("%s: invalid binding\n", argv[curArg]);
524 *binding = bindingVal;
529 argc -= (curArg - 1);
530 argv += (curArg - 1);
534 // Do all command-line argument parsing. This includes building up the work-items
535 // to be processed later, and saving all the command-line options.
537 // Does not return (it exits) if command-line is fatally flawed.
539 void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItems, int argc, char* argv[])
541 for (int res = 0; res < glslang::EResCount; ++res)
542 baseBinding[res].fill(0);
544 ExecutableName = argv[0];
545 workItems.reserve(argc);
547 const auto bumpArg = [&]() {
554 // read a string directly attached to a single-letter option
555 const auto getStringOperand = [&](const char* desc) {
556 if (argv[0][2] == 0) {
557 printf("%s must immediately follow option (no spaces)\n", desc);
563 // read a number attached to a single-letter option
564 const auto getAttachedNumber = [&](const char* desc) {
565 int num = atoi(argv[0] + 2);
567 printf("%s: expected attached non-0 number\n", desc);
573 // minimum needed (without overriding something else) to target Vulkan SPIR-V
574 const auto setVulkanSpv = []() {
575 if (Client == glslang::EShClientNone)
576 ClientVersion = glslang::EShTargetVulkan_1_0;
577 Client = glslang::EShClientVulkan;
578 Options |= EOptionSpv;
579 Options |= EOptionVulkanRules;
580 Options |= EOptionLinkProgram;
583 // minimum needed (without overriding something else) to target OpenGL SPIR-V
584 const auto setOpenGlSpv = []() {
585 if (Client == glslang::EShClientNone)
586 ClientVersion = glslang::EShTargetOpenGL_450;
587 Client = glslang::EShClientOpenGL;
588 Options |= EOptionSpv;
589 Options |= EOptionLinkProgram;
590 // undo a -H default to Vulkan
591 Options &= ~EOptionVulkanRules;
594 const auto getUniformOverride = [getStringOperand]() {
595 const char *arg = getStringOperand("-u<name>:<location>");
596 const char *split = strchr(arg, ':');
598 printf("%s: missing location\n", arg);
602 int location = ::strtol(split + 1, NULL, 10);
604 printf("%s: invalid location\n", arg);
607 return std::make_pair(std::string(arg, split - arg), location);
610 for (bumpArg(); argc >= 1; bumpArg()) {
611 if (argv[0][0] == '-') {
612 switch (argv[0][1]) {
615 std::string lowerword(argv[0]+2);
616 std::transform(lowerword.begin(), lowerword.end(), lowerword.begin(), ::tolower);
618 // handle --word style options
619 if (lowerword == "auto-map-bindings" || // synonyms
620 lowerword == "auto-map-binding" ||
621 lowerword == "amb") {
622 Options |= EOptionAutoMapBindings;
623 } else if (lowerword == "auto-map-locations" || // synonyms
624 lowerword == "aml") {
625 Options |= EOptionAutoMapLocations;
626 } else if (lowerword == "uniform-base") {
628 Error("no <base> provided", lowerword.c_str());
629 uniformBase = ::strtol(argv[1], NULL, 10);
632 } else if (lowerword == "client") {
634 if (strcmp(argv[1], "vulkan100") == 0)
636 else if (strcmp(argv[1], "opengl100") == 0)
639 Error("expects vulkan100 or opengl100", lowerword.c_str());
641 Error("expects vulkan100 or opengl100", lowerword.c_str());
643 } else if (lowerword == "define-macro" ||
646 UserPreamble.addDef(argv[1]);
648 Error("expects <name[=def]>", argv[0]);
650 } else if (lowerword == "dump-builtin-symbols") {
651 DumpBuiltinSymbols = true;
652 } else if (lowerword == "entry-point") {
653 entryPointName = argv[1];
655 Error("no <name> provided", lowerword.c_str());
657 } else if (lowerword == "flatten-uniform-arrays" || // synonyms
658 lowerword == "flatten-uniform-array" ||
659 lowerword == "fua") {
660 Options |= EOptionFlattenUniformArrays;
661 } else if (lowerword == "glsl-version") {
663 if (strcmp(argv[1], "100") == 0) {
665 } else if (strcmp(argv[1], "110") == 0) {
667 } else if (strcmp(argv[1], "120") == 0) {
669 } else if (strcmp(argv[1], "130") == 0) {
671 } else if (strcmp(argv[1], "140") == 0) {
673 } else if (strcmp(argv[1], "150") == 0) {
675 } else if (strcmp(argv[1], "300es") == 0) {
677 } else if (strcmp(argv[1], "310es") == 0) {
679 } else if (strcmp(argv[1], "320es") == 0) {
681 } else if (strcmp(argv[1], "330") == 0) {
683 } else if (strcmp(argv[1], "400") == 0) {
685 } else if (strcmp(argv[1], "410") == 0) {
687 } else if (strcmp(argv[1], "420") == 0) {
689 } else if (strcmp(argv[1], "430") == 0) {
691 } else if (strcmp(argv[1], "440") == 0) {
693 } else if (strcmp(argv[1], "450") == 0) {
695 } else if (strcmp(argv[1], "460") == 0) {
698 Error("--glsl-version expected one of: 100, 110, 120, 130, 140, 150,\n"
699 "300es, 310es, 320es, 330\n"
700 "400, 410, 420, 430, 440, 450, 460");
703 } else if (lowerword == "hlsl-offsets") {
704 Options |= EOptionHlslOffsets;
705 } else if (lowerword == "hlsl-iomap" ||
706 lowerword == "hlsl-iomapper" ||
707 lowerword == "hlsl-iomapping") {
708 Options |= EOptionHlslIoMapping;
709 } else if (lowerword == "hlsl-enable-16bit-types") {
710 HlslEnable16BitTypes = true;
711 } else if (lowerword == "hlsl-dx9-compatible") {
712 HlslDX9compatible = true;
713 } else if (lowerword == "hlsl-dx-position-w") {
714 HlslDxPositionW = true;
715 } else if (lowerword == "enhanced-msgs") {
717 } else if (lowerword == "auto-sampled-textures") {
718 autoSampledTextures = true;
719 } else if (lowerword == "invert-y" || // synonyms
721 Options |= EOptionInvertY;
722 } else if (lowerword == "keep-uncalled" || // synonyms
724 Options |= EOptionKeepUncalled;
725 } else if (lowerword == "nan-clamp") {
727 } else if (lowerword == "no-storage-format" || // synonyms
728 lowerword == "nsf") {
729 Options |= EOptionNoStorageFormat;
730 } else if (lowerword == "relaxed-errors") {
731 Options |= EOptionRelaxedErrors;
732 } else if (lowerword == "reflect-strict-array-suffix") {
733 ReflectOptions |= EShReflectionStrictArraySuffix;
734 } else if (lowerword == "reflect-basic-array-suffix") {
735 ReflectOptions |= EShReflectionBasicArraySuffix;
736 } else if (lowerword == "reflect-intermediate-io") {
737 ReflectOptions |= EShReflectionIntermediateIO;
738 } else if (lowerword == "reflect-separate-buffers") {
739 ReflectOptions |= EShReflectionSeparateBuffers;
740 } else if (lowerword == "reflect-all-block-variables") {
741 ReflectOptions |= EShReflectionAllBlockVariables;
742 } else if (lowerword == "reflect-unwrap-io-blocks") {
743 ReflectOptions |= EShReflectionUnwrapIOBlocks;
744 } else if (lowerword == "reflect-all-io-variables") {
745 ReflectOptions |= EShReflectionAllIOVariables;
746 } else if (lowerword == "reflect-shared-std140-ubo") {
747 ReflectOptions |= EShReflectionSharedStd140UBO;
748 } else if (lowerword == "reflect-shared-std140-ssbo") {
749 ReflectOptions |= EShReflectionSharedStd140SSBO;
750 } else if (lowerword == "resource-set-bindings" || // synonyms
751 lowerword == "resource-set-binding" ||
752 lowerword == "rsb") {
753 ProcessResourceSetBindingBase(argc, argv, baseResourceSetBinding);
754 } else if (lowerword == "set-block-storage" ||
755 lowerword == "sbs") {
756 ProcessBlockStorage(argc, argv, blockStorageOverrides);
757 } else if (lowerword == "set-atomic-counter-block" ||
758 lowerword == "sacb") {
759 ProcessGlobalBlockSettings(argc, argv, &atomicCounterBlockName, &atomicCounterBlockSet, nullptr);
760 setGlobalBufferBlock = true;
761 } else if (lowerword == "set-default-uniform-block" ||
762 lowerword == "sdub") {
763 ProcessGlobalBlockSettings(argc, argv, &globalUniformName, &globalUniformSet, &globalUniformBinding);
764 setGlobalUniformBlock = true;
765 } else if (lowerword == "shift-image-bindings" || // synonyms
766 lowerword == "shift-image-binding" ||
767 lowerword == "sib") {
768 ProcessBindingBase(argc, argv, glslang::EResImage);
769 } else if (lowerword == "shift-sampler-bindings" || // synonyms
770 lowerword == "shift-sampler-binding" ||
771 lowerword == "ssb") {
772 ProcessBindingBase(argc, argv, glslang::EResSampler);
773 } else if (lowerword == "shift-uav-bindings" || // synonyms
774 lowerword == "shift-uav-binding" ||
775 lowerword == "suavb") {
776 ProcessBindingBase(argc, argv, glslang::EResUav);
777 } else if (lowerword == "shift-texture-bindings" || // synonyms
778 lowerword == "shift-texture-binding" ||
779 lowerword == "stb") {
780 ProcessBindingBase(argc, argv, glslang::EResTexture);
781 } else if (lowerword == "shift-ubo-bindings" || // synonyms
782 lowerword == "shift-ubo-binding" ||
783 lowerword == "shift-cbuffer-bindings" ||
784 lowerword == "shift-cbuffer-binding" ||
785 lowerword == "sub" ||
786 lowerword == "scb") {
787 ProcessBindingBase(argc, argv, glslang::EResUbo);
788 } else if (lowerword == "shift-ssbo-bindings" || // synonyms
789 lowerword == "shift-ssbo-binding" ||
790 lowerword == "sbb") {
791 ProcessBindingBase(argc, argv, glslang::EResSsbo);
792 } else if (lowerword == "source-entrypoint" || // synonyms
793 lowerword == "sep") {
795 Error("no <entry-point> provided", lowerword.c_str());
796 sourceEntryPointName = argv[1];
799 } else if (lowerword == "spirv-dis") {
800 SpvToolsDisassembler = true;
801 } else if (lowerword == "spirv-val") {
802 SpvToolsValidate = true;
803 } else if (lowerword == "stdin") {
804 Options |= EOptionStdin;
805 shaderStageName = argv[1];
806 } else if (lowerword == "suppress-warnings") {
807 Options |= EOptionSuppressWarnings;
808 } else if (lowerword == "target-env") {
810 if (strcmp(argv[1], "vulkan1.0") == 0) {
812 ClientVersion = glslang::EShTargetVulkan_1_0;
813 } else if (strcmp(argv[1], "vulkan1.1") == 0) {
815 ClientVersion = glslang::EShTargetVulkan_1_1;
816 } else if (strcmp(argv[1], "vulkan1.2") == 0) {
818 ClientVersion = glslang::EShTargetVulkan_1_2;
819 } else if (strcmp(argv[1], "vulkan1.3") == 0) {
821 ClientVersion = glslang::EShTargetVulkan_1_3;
822 } else if (strcmp(argv[1], "opengl") == 0) {
824 ClientVersion = glslang::EShTargetOpenGL_450;
825 } else if (strcmp(argv[1], "spirv1.0") == 0) {
826 TargetLanguage = glslang::EShTargetSpv;
827 TargetVersion = glslang::EShTargetSpv_1_0;
828 } else if (strcmp(argv[1], "spirv1.1") == 0) {
829 TargetLanguage = glslang::EShTargetSpv;
830 TargetVersion = glslang::EShTargetSpv_1_1;
831 } else if (strcmp(argv[1], "spirv1.2") == 0) {
832 TargetLanguage = glslang::EShTargetSpv;
833 TargetVersion = glslang::EShTargetSpv_1_2;
834 } else if (strcmp(argv[1], "spirv1.3") == 0) {
835 TargetLanguage = glslang::EShTargetSpv;
836 TargetVersion = glslang::EShTargetSpv_1_3;
837 } else if (strcmp(argv[1], "spirv1.4") == 0) {
838 TargetLanguage = glslang::EShTargetSpv;
839 TargetVersion = glslang::EShTargetSpv_1_4;
840 } else if (strcmp(argv[1], "spirv1.5") == 0) {
841 TargetLanguage = glslang::EShTargetSpv;
842 TargetVersion = glslang::EShTargetSpv_1_5;
843 } else if (strcmp(argv[1], "spirv1.6") == 0) {
844 TargetLanguage = glslang::EShTargetSpv;
845 TargetVersion = glslang::EShTargetSpv_1_6;
847 Error("--target-env expected one of: vulkan1.0, vulkan1.1, vulkan1.2,\n"
848 "vulkan1.3, opengl, spirv1.0, spirv1.1, spirv1.2, spirv1.3,\n"
849 "spirv1.4, spirv1.5 or spirv1.6");
852 } else if (lowerword == "undef-macro" ||
855 UserPreamble.addUndef(argv[1]);
857 Error("expects <name>", argv[0]);
859 } else if (lowerword == "variable-name" || // synonyms
861 Options |= EOptionOutputHexadecimal;
863 Error("no <C-variable-name> provided", lowerword.c_str());
864 variableName = argv[1];
867 } else if (lowerword == "quiet") {
869 } else if (lowerword == "depfile") {
871 Error("no <depfile-name> provided", lowerword.c_str());
872 depencyFileName = argv[1];
874 } else if (lowerword == "version") {
875 Options |= EOptionDumpVersions;
876 } else if (lowerword == "help") {
880 Error("unrecognized command-line option", argv[0]);
885 Options |= EOptionCascadingErrors;
889 Options |= EOptionReadHlsl;
891 UserPreamble.addDef(getStringOperand("-D<name[=def]>"));
894 uniformLocationOverrides.push_back(getUniformOverride());
897 Options |= EOptionOutputPreprocessed;
903 ClientInputSemanticsVersion = getAttachedNumber("-G<num> client input semantics");
904 if (ClientInputSemanticsVersion != 100)
905 Error("unknown client version for -G, should be 100");
908 Options |= EOptionHumanReadableSpv;
909 if ((Options & EOptionSpv) == 0) {
915 IncludeDirectoryList.push_back(getStringOperand("-I<dir> include path"));
918 if (argv[0][2] == 'd')
919 Options |= EOptionOptimizeDisable;
920 else if (argv[0][2] == 's')
922 Options |= EOptionOptimizeSize;
924 Error("-Os not available; optimizer not linked");
927 Error("unknown -O option");
930 VulkanRulesRelaxed = true;
934 Error("no <stage> specified for -S");
935 shaderStageName = argv[1];
939 UserPreamble.addUndef(getStringOperand("-U<name>"));
944 ClientInputSemanticsVersion = getAttachedNumber("-V<num> client input semantics");
945 if (ClientInputSemanticsVersion != 100)
946 Error("unknown client version for -V, should be 100");
949 Options |= EOptionDumpConfig;
952 if (strncmp(&argv[0][1], "dumpversion", strlen(&argv[0][1]) + 1) == 0 ||
953 strncmp(&argv[0][1], "dumpfullversion", strlen(&argv[0][1]) + 1) == 0)
954 Options |= EOptionDumpBareVersion;
956 Options |= EOptionDefaultDesktop;
959 entryPointName = argv[1];
961 Error("no <name> provided for -e");
965 if (strcmp(&argv[0][2], "hlsl_functionality1") == 0)
966 targetHlslFunctionality1 = true;
968 Error("-f: expected hlsl_functionality1");
971 // Override previous -g or -g0 argument
972 stripDebugInfo = false;
973 emitNonSemanticShaderDebugInfo = false;
974 Options &= ~EOptionDebug;
975 if (argv[0][2] == '0')
976 stripDebugInfo = true;
978 Options |= EOptionDebug;
979 if (argv[0][2] == 'V') {
980 emitNonSemanticShaderDebugInfo = true;
981 if (argv[0][3] == 'S') {
982 emitNonSemanticShaderDebugSource = true;
984 emitNonSemanticShaderDebugSource = false;
993 Options |= EOptionIntermediate;
996 Options |= EOptionLinkProgram;
999 Options |= EOptionMemoryLeakMode;
1003 Error("no <file> provided for -o");
1004 binaryFileName = argv[1];
1008 Options |= EOptionDumpReflection;
1011 Options |= EOptionRelaxedErrors;
1014 Options |= EOptionSuppressInfolog;
1017 Options |= EOptionMultiThreaded;
1020 Options |= EOptionDumpVersions;
1023 Options |= EOptionSuppressWarnings;
1026 Options |= EOptionOutputHexadecimal;
1029 Error("unrecognized command-line option", argv[0]);
1033 std::string name(argv[0]);
1034 if (! SetConfigFile(name)) {
1035 workItems.push_back(std::unique_ptr<glslang::TWorkItem>(new glslang::TWorkItem(name)));
1040 // Make sure that -S is always specified if --stdin is specified
1041 if ((Options & EOptionStdin) && shaderStageName == nullptr)
1042 Error("must provide -S when --stdin is given");
1044 // Make sure that -E is not specified alongside linking (which includes SPV generation)
1045 // Or things that require linking
1046 if (Options & EOptionOutputPreprocessed) {
1047 if (Options & EOptionLinkProgram)
1048 Error("can't use -E when linking is selected");
1049 if (Options & EOptionDumpReflection)
1050 Error("reflection requires linking, which can't be used when -E when is selected");
1053 // reflection requires linking
1054 if ((Options & EOptionDumpReflection) && !(Options & EOptionLinkProgram))
1055 Error("reflection requires -l for linking");
1057 // -o or -x makes no sense if there is no target binary
1058 if (binaryFileName && (Options & EOptionSpv) == 0)
1059 Error("no binary generation requested (e.g., -V)");
1061 if ((Options & EOptionFlattenUniformArrays) != 0 &&
1062 (Options & EOptionReadHlsl) == 0)
1063 Error("uniform array flattening only valid when compiling HLSL source.");
1065 if ((Options & EOptionReadHlsl) && (Client == glslang::EShClientOpenGL)) {
1066 Error("Using HLSL input under OpenGL semantics is not currently supported.");
1069 // rationalize client and target language
1070 if (TargetLanguage == glslang::EShTargetNone) {
1071 switch (ClientVersion) {
1072 case glslang::EShTargetVulkan_1_0:
1073 TargetLanguage = glslang::EShTargetSpv;
1074 TargetVersion = glslang::EShTargetSpv_1_0;
1076 case glslang::EShTargetVulkan_1_1:
1077 TargetLanguage = glslang::EShTargetSpv;
1078 TargetVersion = glslang::EShTargetSpv_1_3;
1080 case glslang::EShTargetVulkan_1_2:
1081 TargetLanguage = glslang::EShTargetSpv;
1082 TargetVersion = glslang::EShTargetSpv_1_5;
1084 case glslang::EShTargetVulkan_1_3:
1085 TargetLanguage = glslang::EShTargetSpv;
1086 TargetVersion = glslang::EShTargetSpv_1_6;
1088 case glslang::EShTargetOpenGL_450:
1089 TargetLanguage = glslang::EShTargetSpv;
1090 TargetVersion = glslang::EShTargetSpv_1_0;
1096 if (TargetLanguage != glslang::EShTargetNone && Client == glslang::EShClientNone)
1097 Error("To generate SPIR-V, also specify client semantics. See -G and -V.");
1101 // Translate the meaningful subset of command-line options to parser-behavior options.
1103 void SetMessageOptions(EShMessages& messages)
1105 if (Options & EOptionRelaxedErrors)
1106 messages = (EShMessages)(messages | EShMsgRelaxedErrors);
1107 if (Options & EOptionIntermediate)
1108 messages = (EShMessages)(messages | EShMsgAST);
1109 if (Options & EOptionSuppressWarnings)
1110 messages = (EShMessages)(messages | EShMsgSuppressWarnings);
1111 if (Options & EOptionSpv)
1112 messages = (EShMessages)(messages | EShMsgSpvRules);
1113 if (Options & EOptionVulkanRules)
1114 messages = (EShMessages)(messages | EShMsgVulkanRules);
1115 if (Options & EOptionOutputPreprocessed)
1116 messages = (EShMessages)(messages | EShMsgOnlyPreprocessor);
1117 if (Options & EOptionReadHlsl)
1118 messages = (EShMessages)(messages | EShMsgReadHlsl);
1119 if (Options & EOptionCascadingErrors)
1120 messages = (EShMessages)(messages | EShMsgCascadingErrors);
1121 if (Options & EOptionKeepUncalled)
1122 messages = (EShMessages)(messages | EShMsgKeepUncalled);
1123 if (Options & EOptionHlslOffsets)
1124 messages = (EShMessages)(messages | EShMsgHlslOffsets);
1125 if (Options & EOptionDebug)
1126 messages = (EShMessages)(messages | EShMsgDebugInfo);
1127 if (HlslEnable16BitTypes)
1128 messages = (EShMessages)(messages | EShMsgHlslEnable16BitTypes);
1129 if ((Options & EOptionOptimizeDisable) || !ENABLE_OPT)
1130 messages = (EShMessages)(messages | EShMsgHlslLegalization);
1131 if (HlslDX9compatible)
1132 messages = (EShMessages)(messages | EShMsgHlslDX9Compatible);
1133 if (DumpBuiltinSymbols)
1134 messages = (EShMessages)(messages | EShMsgBuiltinSymbolTable);
1136 messages = (EShMessages)(messages | EShMsgEnhanced);
1140 // Thread entry point, for non-linking asynchronous mode.
1142 void CompileShaders(glslang::TWorklist& worklist)
1144 if (Options & EOptionDebug)
1145 Error("cannot generate debug information unless linking to generate code");
1147 glslang::TWorkItem* workItem;
1148 if (Options & EOptionStdin) {
1149 if (worklist.remove(workItem)) {
1150 ShHandle compiler = ShConstructCompiler(FindLanguage("stdin"), Options);
1151 if (compiler == nullptr)
1154 CompileFile("stdin", compiler);
1156 if (! (Options & EOptionSuppressInfolog))
1157 workItem->results = ShGetInfoLog(compiler);
1159 ShDestruct(compiler);
1162 while (worklist.remove(workItem)) {
1163 ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options);
1167 CompileFile(workItem->name.c_str(), compiler);
1169 if (! (Options & EOptionSuppressInfolog))
1170 workItem->results = ShGetInfoLog(compiler);
1172 ShDestruct(compiler);
1177 // Outputs the given string, but only if it is non-null and non-empty.
1178 // This prevents erroneous newlines from appearing.
1179 void PutsIfNonEmpty(const char* str)
1181 if (str && str[0]) {
1186 // Outputs the given string to stderr, but only if it is non-null and non-empty.
1187 // This prevents erroneous newlines from appearing.
1188 void StderrIfNonEmpty(const char* str)
1191 fprintf(stderr, "%s\n", str);
1194 // Simple bundling of what makes a compilation unit for ease in passing around,
1195 // and separation of handling file IO versus API (programmatic) compilation.
1196 struct ShaderCompUnit {
1198 static const int maxCount = 1;
1199 int count; // live number of strings/names
1200 const char* text[maxCount]; // memory owned/managed externally
1201 std::string fileName[maxCount]; // hold's the memory, but...
1202 const char* fileNameList[maxCount]; // downstream interface wants pointers
1204 ShaderCompUnit(EShLanguage stage) : stage(stage), count(0) { }
1206 ShaderCompUnit(const ShaderCompUnit& rhs)
1210 for (int i = 0; i < count; ++i) {
1211 fileName[i] = rhs.fileName[i];
1212 text[i] = rhs.text[i];
1213 fileNameList[i] = rhs.fileName[i].c_str();
1217 void addString(std::string& ifileName, const char* itext)
1219 assert(count < maxCount);
1220 fileName[count] = ifileName;
1221 text[count] = itext;
1222 fileNameList[count] = fileName[count].c_str();
1227 // Writes a string into a depfile, escaping some special characters following the Makefile rules.
1228 static void writeEscapedDepString(std::ofstream& file, const std::string& str)
1230 for (char c : str) {
1248 // Writes a depfile similar to gcc -MMD foo.c
1249 bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, const std::vector<std::string>& sources)
1251 std::ofstream file(depfile);
1255 for (auto binaryFile = binaryFiles.begin(); binaryFile != binaryFiles.end(); binaryFile++) {
1256 writeEscapedDepString(file, *binaryFile);
1258 for (auto sourceFile = sources.begin(); sourceFile != sources.end(); sourceFile++) {
1260 writeEscapedDepString(file, *sourceFile);
1268 // For linking mode: Will independently parse each compilation unit, but then put them
1269 // in the same program and link them together, making at most one linked module per
1272 // Uses the new C++ interface instead of the old handle-based interface.
1275 void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
1277 // keep track of what to free
1278 std::list<glslang::TShader*> shaders;
1280 EShMessages messages = EShMsgDefault;
1281 SetMessageOptions(messages);
1283 DirStackFileIncluder includer;
1284 std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) {
1285 includer.pushExternalLocalDirectory(dir); });
1287 std::vector<std::string> sources;
1290 // Per-shader processing...
1293 glslang::TProgram& program = *new glslang::TProgram;
1294 for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) {
1295 const auto &compUnit = *it;
1296 for (int i = 0; i < compUnit.count; i++) {
1297 sources.push_back(compUnit.fileNameList[i]);
1299 glslang::TShader* shader = new glslang::TShader(compUnit.stage);
1300 shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, compUnit.count);
1302 shader->setEntryPoint(entryPointName);
1303 if (sourceEntryPointName) {
1304 if (entryPointName == nullptr)
1305 printf("Warning: Changing source entry point name without setting an entry-point name.\n"
1306 "Use '-e <name>'.\n");
1307 shader->setSourceEntryPoint(sourceEntryPointName);
1310 shader->setOverrideVersion(GlslVersion);
1312 std::string intrinsicString = getIntrinsic(compUnit.text, compUnit.count);
1314 PreambleString = "";
1315 if (UserPreamble.isSet())
1316 PreambleString.append(UserPreamble.get());
1318 if (!intrinsicString.empty())
1319 PreambleString.append(intrinsicString);
1321 shader->setPreamble(PreambleString.c_str());
1322 shader->addProcesses(Processes);
1325 // Set IO mapper binding shift values
1326 for (int r = 0; r < glslang::EResCount; ++r) {
1327 const glslang::TResourceType res = glslang::TResourceType(r);
1329 // Set base bindings
1330 shader->setShiftBinding(res, baseBinding[res][compUnit.stage]);
1332 // Set bindings for particular resource sets
1333 // TODO: use a range based for loop here, when available in all environments.
1334 for (auto i = baseBindingForSet[res][compUnit.stage].begin();
1335 i != baseBindingForSet[res][compUnit.stage].end(); ++i)
1336 shader->setShiftBindingForSet(res, i->second, i->first);
1338 shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0);
1339 shader->setResourceSetBinding(baseResourceSetBinding[compUnit.stage]);
1341 if (autoSampledTextures)
1342 shader->setTextureSamplerTransformMode(EShTexSampTransUpgradeTextureRemoveSampler);
1344 if (Options & EOptionAutoMapBindings)
1345 shader->setAutoMapBindings(true);
1347 if (Options & EOptionAutoMapLocations)
1348 shader->setAutoMapLocations(true);
1350 for (auto& uniOverride : uniformLocationOverrides) {
1351 shader->addUniformLocationOverride(uniOverride.first.c_str(),
1352 uniOverride.second);
1355 shader->setUniformLocationBase(uniformBase);
1358 if (VulkanRulesRelaxed) {
1359 for (auto& storageOverride : blockStorageOverrides) {
1360 shader->addBlockStorageOverride(storageOverride.first.c_str(),
1361 storageOverride.second);
1364 if (setGlobalBufferBlock) {
1365 shader->setAtomicCounterBlockName(atomicCounterBlockName.c_str());
1366 shader->setAtomicCounterBlockSet(atomicCounterBlockSet);
1369 if (setGlobalUniformBlock) {
1370 shader->setGlobalUniformBlockName(globalUniformName.c_str());
1371 shader->setGlobalUniformSet(globalUniformSet);
1372 shader->setGlobalUniformBinding(globalUniformBinding);
1376 shader->setNanMinMaxClamp(NaNClamp);
1379 shader->setFlattenUniformArrays((Options & EOptionFlattenUniformArrays) != 0);
1380 if (Options & EOptionHlslIoMapping)
1381 shader->setHlslIoMapping(true);
1384 if (Options & EOptionInvertY)
1385 shader->setInvertY(true);
1387 if (HlslDxPositionW)
1388 shader->setDxPositionW(true);
1391 shader->setEnhancedMsgs();
1393 if (emitNonSemanticShaderDebugInfo)
1394 shader->setDebugInfo(true);
1396 // Set up the environment, some subsettings take precedence over earlier
1397 // ways of setting things.
1398 if (Options & EOptionSpv) {
1399 shader->setEnvInput((Options & EOptionReadHlsl) ? glslang::EShSourceHlsl
1400 : glslang::EShSourceGlsl,
1401 compUnit.stage, Client, ClientInputSemanticsVersion);
1402 shader->setEnvClient(Client, ClientVersion);
1403 shader->setEnvTarget(TargetLanguage, TargetVersion);
1405 if (targetHlslFunctionality1)
1406 shader->setEnvTargetHlslFunctionality1();
1408 if (VulkanRulesRelaxed)
1409 shader->setEnvInputVulkanRulesRelaxed();
1412 shaders.push_back(shader);
1414 const int defaultVersion = Options & EOptionDefaultDesktop ? 110 : 100;
1417 if (Options & EOptionOutputPreprocessed) {
1419 if (shader->preprocess(GetResources(), defaultVersion, ENoProfile, false, false, messages, &str, includer)) {
1420 PutsIfNonEmpty(str.c_str());
1422 CompileFailed = true;
1424 StderrIfNonEmpty(shader->getInfoLog());
1425 StderrIfNonEmpty(shader->getInfoDebugLog());
1430 if (! shader->parse(GetResources(), defaultVersion, false, messages, includer))
1431 CompileFailed = true;
1433 program.addShader(shader);
1435 if (! (Options & EOptionSuppressInfolog) &&
1436 ! (Options & EOptionMemoryLeakMode)) {
1438 PutsIfNonEmpty(compUnit.fileName[0].c_str());
1439 PutsIfNonEmpty(shader->getInfoLog());
1440 PutsIfNonEmpty(shader->getInfoDebugLog());
1445 // Program-level processing...
1449 if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages))
1454 if (Options & EOptionSpv) {
1455 if (!program.mapIO())
1461 if (! (Options & EOptionSuppressInfolog) &&
1462 ! (Options & EOptionMemoryLeakMode)) {
1463 PutsIfNonEmpty(program.getInfoLog());
1464 PutsIfNonEmpty(program.getInfoDebugLog());
1469 if (Options & EOptionDumpReflection) {
1470 program.buildReflection(ReflectOptions);
1471 program.dumpReflection();
1475 std::vector<std::string> outputFiles;
1478 if (Options & EOptionSpv) {
1479 if (CompileFailed || LinkFailed)
1480 printf("SPIR-V is not generated for failed compile or link\n");
1482 for (int stage = 0; stage < EShLangCount; ++stage) {
1483 if (program.getIntermediate((EShLanguage)stage)) {
1484 std::vector<unsigned int> spirv;
1485 spv::SpvBuildLogger logger;
1486 glslang::SpvOptions spvOptions;
1487 if (Options & EOptionDebug) {
1488 spvOptions.generateDebugInfo = true;
1489 if (emitNonSemanticShaderDebugInfo) {
1490 spvOptions.emitNonSemanticShaderDebugInfo = true;
1491 if (emitNonSemanticShaderDebugSource) {
1492 spvOptions.emitNonSemanticShaderDebugSource = true;
1495 } else if (stripDebugInfo)
1496 spvOptions.stripDebugInfo = true;
1497 spvOptions.disableOptimizer = (Options & EOptionOptimizeDisable) != 0;
1498 spvOptions.optimizeSize = (Options & EOptionOptimizeSize) != 0;
1499 spvOptions.disassemble = SpvToolsDisassembler;
1500 spvOptions.validate = SpvToolsValidate;
1501 glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger, &spvOptions);
1503 // Dump the spv to a file or stdout, etc., but only if not doing
1504 // memory/perf testing, as it's not internal to programmatic use.
1505 if (! (Options & EOptionMemoryLeakMode)) {
1506 printf("%s", logger.getAllMessages().c_str());
1507 if (Options & EOptionOutputHexadecimal) {
1508 glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage), variableName);
1510 glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
1513 outputFiles.push_back(GetBinaryName((EShLanguage)stage));
1515 if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv))
1516 spv::Disassemble(std::cout, spirv);
1524 if (depencyFileName && !(CompileFailed || LinkFailed)) {
1525 std::set<std::string> includedFiles = includer.getIncludedFiles();
1526 sources.insert(sources.end(), includedFiles.begin(), includedFiles.end());
1528 writeDepFile(depencyFileName, outputFiles, sources);
1531 // Free everything up, program has to go before the shaders
1532 // because it might have merged stuff from the shaders, and
1533 // the stuff from the shaders has to have its destructors called
1534 // before the pools holding the memory in the shaders is freed.
1536 while (shaders.size() > 0) {
1537 delete shaders.back();
1543 // Do file IO part of compile and link, handing off the pure
1544 // API/programmatic mode to CompileAndLinkShaderUnits(), which can
1545 // be put in a loop for testing memory footprint and performance.
1547 // This is just for linking mode: meaning all the shaders will be put into the
1548 // the same program linked together.
1550 // This means there are a limited number of work items (not multi-threading mode)
1551 // and that the point is testing at the linking level. Hence, to enable
1552 // performance and memory testing, the actual compile/link can be put in
1553 // a loop, independent of processing the work items and file IO.
1555 void CompileAndLinkShaderFiles(glslang::TWorklist& Worklist)
1557 std::vector<ShaderCompUnit> compUnits;
1559 // If this is using stdin, we can't really detect multiple different file
1560 // units by input type. We need to assume that we're just being given one
1561 // file of a certain type.
1562 if ((Options & EOptionStdin) != 0) {
1563 ShaderCompUnit compUnit(FindLanguage("stdin"));
1564 std::istreambuf_iterator<char> begin(std::cin), end;
1565 std::string tempString(begin, end);
1566 char* fileText = strdup(tempString.c_str());
1567 std::string fileName = "stdin";
1568 compUnit.addString(fileName, fileText);
1569 compUnits.push_back(compUnit);
1571 // Transfer all the work items from to a simple list of
1572 // of compilation units. (We don't care about the thread
1573 // work-item distribution properties in this path, which
1574 // is okay due to the limited number of shaders, know since
1575 // they are all getting linked together.)
1576 glslang::TWorkItem* workItem;
1577 while (Worklist.remove(workItem)) {
1578 ShaderCompUnit compUnit(FindLanguage(workItem->name));
1579 char* fileText = ReadFileData(workItem->name.c_str());
1580 if (fileText == nullptr)
1582 compUnit.addString(workItem->name, fileText);
1583 compUnits.push_back(compUnit);
1587 // Actual call to programmatic processing of compile and link,
1588 // in a loop for testing memory and performance. This part contains
1589 // all the perf/memory that a programmatic consumer will care about.
1590 for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
1591 for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j)
1592 CompileAndLinkShaderUnits(compUnits);
1594 if (Options & EOptionMemoryLeakMode)
1595 glslang::OS_DumpMemoryCounters();
1598 // free memory from ReadFileData, which got stored in a const char*
1599 // as the first string above
1600 for (auto it = compUnits.begin(); it != compUnits.end(); ++it)
1601 FreeFileData(const_cast<char*>(it->text[0]));
1606 glslang::TWorklist workList;
1607 std::for_each(WorkItems.begin(), WorkItems.end(), [&workList](std::unique_ptr<glslang::TWorkItem>& item) {
1609 workList.add(item.get());
1613 if (Options & EOptionDumpConfig) {
1614 printf("%s", GetDefaultTBuiltInResourceString().c_str());
1615 if (workList.empty())
1620 if (Options & EOptionDumpBareVersion) {
1621 printf("%d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR, GLSLANG_VERSION_MINOR,
1622 GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR);
1623 if (workList.empty())
1625 } else if (Options & EOptionDumpVersions) {
1626 printf("Glslang Version: %d:%d.%d.%d%s\n", glslang::GetSpirvGeneratorVersion(), GLSLANG_VERSION_MAJOR,
1627 GLSLANG_VERSION_MINOR, GLSLANG_VERSION_PATCH, GLSLANG_VERSION_FLAVOR);
1628 printf("ESSL Version: %s\n", glslang::GetEsslVersionString());
1629 printf("GLSL Version: %s\n", glslang::GetGlslVersionString());
1630 std::string spirvVersion;
1631 glslang::GetSpirvVersion(spirvVersion);
1632 printf("SPIR-V Version %s\n", spirvVersion.c_str());
1633 printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision);
1634 printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId());
1635 printf("SPIR-V Generator Version %d\n", glslang::GetSpirvGeneratorVersion());
1636 printf("GL_KHR_vulkan_glsl version %d\n", 100);
1637 printf("ARB_GL_gl_spirv version %d\n", 100);
1638 if (workList.empty())
1642 if (workList.empty() && ((Options & EOptionStdin) == 0)) {
1646 if (Options & EOptionStdin) {
1647 WorkItems.push_back(std::unique_ptr<glslang::TWorkItem>{new glslang::TWorkItem("stdin")});
1648 workList.add(WorkItems.back().get());
1651 ProcessConfigFile();
1653 if ((Options & EOptionReadHlsl) && !((Options & EOptionOutputPreprocessed) || (Options & EOptionSpv)))
1654 Error("HLSL requires SPIR-V code generation (or preprocessing only)");
1658 // 1) linking all arguments together, single-threaded, new C++ interface
1659 // 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface
1661 if (Options & (EOptionLinkProgram | EOptionOutputPreprocessed)) {
1662 glslang::InitializeProcess();
1663 glslang::InitializeProcess(); // also test reference counting of users
1664 glslang::InitializeProcess(); // also test reference counting of users
1665 glslang::FinalizeProcess(); // also test reference counting of users
1666 glslang::FinalizeProcess(); // also test reference counting of users
1667 CompileAndLinkShaderFiles(workList);
1668 glslang::FinalizeProcess();
1671 ShInitialize(); // also test reference counting of users
1672 ShFinalize(); // also test reference counting of users
1674 bool printShaderNames = workList.size() > 1;
1676 if (Options & EOptionMultiThreaded) {
1677 std::array<std::thread, 16> threads;
1678 for (unsigned int t = 0; t < threads.size(); ++t) {
1679 threads[t] = std::thread(CompileShaders, std::ref(workList));
1680 if (threads[t].get_id() == std::thread::id()) {
1681 fprintf(stderr, "Failed to create thread\n");
1682 return EFailThreadCreate;
1686 std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
1688 CompileShaders(workList);
1690 // Print out all the resulting infologs
1691 for (size_t w = 0; w < WorkItems.size(); ++w) {
1693 if (printShaderNames || WorkItems[w]->results.size() > 0)
1694 PutsIfNonEmpty(WorkItems[w]->name.c_str());
1695 PutsIfNonEmpty(WorkItems[w]->results.c_str());
1703 return EFailCompile;
1710 int C_DECL main(int argc, char* argv[])
1712 ProcessArguments(WorkItems, argc, argv);
1716 // Loop over the entire init/finalize cycle to watch memory changes
1717 const int iterations = 1;
1719 glslang::OS_DumpMemoryCounters();
1720 for (int i = 0; i < iterations; ++i) {
1723 glslang::OS_DumpMemoryCounters();
1730 // Deduce the language from the filename. Files must end in one of the
1731 // following extensions:
1734 // .tesc = tessellation control
1735 // .tese = tessellation evaluation
1739 // .rgen = ray generation
1740 // .rint = ray intersection
1741 // .rahit = ray any hit
1742 // .rchit = ray closest hit
1743 // .rmiss = ray miss
1744 // .rcall = ray callable
1747 // Additionally, the file names may end in .<stage>.glsl and .<stage>.hlsl
1748 // where <stage> is one of the stages listed above.
1750 EShLanguage FindLanguage(const std::string& name, bool parseStageName)
1752 std::string stageName;
1753 if (shaderStageName)
1754 stageName = shaderStageName;
1755 else if (parseStageName) {
1756 // Note: "first" extension means "first from the end", i.e.
1757 // if the file is named foo.vert.glsl, then "glsl" is first,
1758 // "vert" is second.
1759 size_t firstExtStart = name.find_last_of(".");
1760 bool hasFirstExt = firstExtStart != std::string::npos;
1761 size_t secondExtStart = hasFirstExt ? name.find_last_of(".", firstExtStart - 1) : std::string::npos;
1762 bool hasSecondExt = secondExtStart != std::string::npos;
1763 std::string firstExt = name.substr(firstExtStart + 1, std::string::npos);
1764 bool usesUnifiedExt = hasFirstExt && (firstExt == "glsl" || firstExt == "hlsl");
1765 if (usesUnifiedExt && firstExt == "hlsl")
1766 Options |= EOptionReadHlsl;
1767 if (hasFirstExt && !usesUnifiedExt)
1768 stageName = firstExt;
1769 else if (usesUnifiedExt && hasSecondExt)
1770 stageName = name.substr(secondExtStart + 1, firstExtStart - secondExtStart - 1);
1773 return EShLangVertex;
1778 if (stageName == "vert")
1779 return EShLangVertex;
1780 else if (stageName == "tesc")
1781 return EShLangTessControl;
1782 else if (stageName == "tese")
1783 return EShLangTessEvaluation;
1784 else if (stageName == "geom")
1785 return EShLangGeometry;
1786 else if (stageName == "frag")
1787 return EShLangFragment;
1788 else if (stageName == "comp")
1789 return EShLangCompute;
1790 else if (stageName == "rgen")
1791 return EShLangRayGen;
1792 else if (stageName == "rint")
1793 return EShLangIntersect;
1794 else if (stageName == "rahit")
1795 return EShLangAnyHit;
1796 else if (stageName == "rchit")
1797 return EShLangClosestHit;
1798 else if (stageName == "rmiss")
1800 else if (stageName == "rcall")
1801 return EShLangCallable;
1802 else if (stageName == "mesh")
1804 else if (stageName == "task")
1808 return EShLangVertex;
1812 // Read a file's data into a string, and compile it using the old interface ShCompile,
1813 // for non-linkable results.
1815 void CompileFile(const char* fileName, ShHandle compiler)
1819 if ((Options & EOptionStdin) != 0) {
1820 std::istreambuf_iterator<char> begin(std::cin), end;
1821 std::string tempString(begin, end);
1822 shaderString = strdup(tempString.c_str());
1824 shaderString = ReadFileData(fileName);
1827 // move to length-based strings, rather than null-terminated strings
1828 int* lengths = new int[1];
1829 lengths[0] = (int)strlen(shaderString);
1831 EShMessages messages = EShMsgDefault;
1832 SetMessageOptions(messages);
1834 if (UserPreamble.isSet())
1835 Error("-D and -U options require -l (linking)\n");
1837 for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) {
1838 for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) {
1839 // ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
1840 ret = ShCompile(compiler, &shaderString, 1, nullptr, EShOptNone, GetResources(), Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
1841 // const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err",
1842 // "or should be l", "ine 1", "string 5\n", "float glo", "bal",
1843 // ";\n#error should be line 2\n void main() {", "global = 2.3;}" };
1844 // const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" };
1845 // ret = ShCompile(compiler, multi, 7, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages);
1848 if (Options & EOptionMemoryLeakMode)
1849 glslang::OS_DumpMemoryCounters();
1853 FreeFileData(shaderString);
1856 CompileFailed = true;
1860 // print usage to stdout
1864 printf("Usage: glslangValidator [option]... [file]...\n"
1866 "'file' can end in .<stage> for auto-stage classification, where <stage> is:\n"
1867 " .conf to provide a config file that replaces the default configuration\n"
1868 " (see -c option below for generating a template)\n"
1869 " .vert for a vertex shader\n"
1870 " .tesc for a tessellation control shader\n"
1871 " .tese for a tessellation evaluation shader\n"
1872 " .geom for a geometry shader\n"
1873 " .frag for a fragment shader\n"
1874 " .comp for a compute shader\n"
1875 " .mesh for a mesh shader\n"
1876 " .task for a task shader\n"
1877 " .rgen for a ray generation shader\n"
1878 " .rint for a ray intersection shader\n"
1879 " .rahit for a ray any hit shader\n"
1880 " .rchit for a ray closest hit shader\n"
1881 " .rmiss for a ray miss shader\n"
1882 " .rcall for a ray callable shader\n"
1883 " .glsl for .vert.glsl, .tesc.glsl, ..., .comp.glsl compound suffixes\n"
1884 " .hlsl for .vert.hlsl, .tesc.hlsl, ..., .comp.hlsl compound suffixes\n"
1887 " -C cascading errors; risk crash from accumulation of error recoveries\n"
1888 " -D input is HLSL (this is the default when any suffix is .hlsl)\n"
1889 " -D<name[=def]> | --define-macro <name[=def]> | --D <name[=def]>\n"
1890 " define a pre-processor macro\n"
1891 " -E print pre-processed GLSL; cannot be used with -l;\n"
1892 " errors will appear on stderr\n"
1893 " -G[ver] create SPIR-V binary, under OpenGL semantics; turns on -l;\n"
1894 " default file name is <stage>.spv (-o overrides this);\n"
1895 " 'ver', when present, is the version of the input semantics,\n"
1896 " which will appear in #define GL_SPIRV ver;\n"
1897 " '--client opengl100' is the same as -G100;\n"
1898 " a '--target-env' for OpenGL will also imply '-G';\n"
1899 " currently only supports GLSL\n"
1900 " -H print human readable form of SPIR-V; turns on -V\n"
1901 " -I<dir> add dir to the include search path; includer's directory\n"
1902 " is searched first, followed by left-to-right order of -I\n"
1903 " -Od disables optimization; may cause illegal SPIR-V for HLSL\n"
1904 " -Os optimizes SPIR-V to minimize size\n"
1905 " -R use relaxed verification rules for generating Vulkan SPIR-V,\n"
1906 " allowing the use of default uniforms, atomic_uints, and\n"
1907 " gl_VertexID and gl_InstanceID keywords.\n"
1908 " -S <stage> uses specified stage rather than parsing the file extension\n"
1909 " choices for <stage> are vert, tesc, tese, geom, frag, or comp\n"
1910 " -U<name> | --undef-macro <name> | --U <name>\n"
1911 " undefine a pre-processor macro\n"
1912 " -V[ver] create SPIR-V binary, under Vulkan semantics; turns on -l;\n"
1913 " default file name is <stage>.spv (-o overrides this)\n"
1914 " 'ver', when present, is the version of the input semantics,\n"
1915 " which will appear in #define VULKAN ver\n"
1916 " '--client vulkan100' is the same as -V100\n"
1917 " a '--target-env' for Vulkan will also imply '-V'\n"
1918 " -c configuration dump;\n"
1919 " creates the default configuration file (redirect to a .conf file)\n"
1920 " -d default to desktop (#version 110) when there is no shader #version\n"
1921 " (default is ES version 100)\n"
1922 " -e <name> | --entry-point <name>\n"
1923 " specify <name> as the entry-point function name\n"
1924 " -f{hlsl_functionality1}\n"
1925 " 'hlsl_functionality1' enables use of the\n"
1926 " SPV_GOOGLE_hlsl_functionality1 extension\n"
1927 " -g generate debug information\n"
1928 " -g0 strip debug information\n"
1929 " -gV generate nonsemantic shader debug information\n"
1930 " -gVS generate nonsemantic shader debug information with source\n"
1931 " -h print this usage message\n"
1932 " -i intermediate tree (glslang AST) is printed out\n"
1933 " -l link all input files together to form a single module\n"
1934 " -m memory leak mode\n"
1935 " -o <file> save binary to <file>, requires a binary option (e.g., -V)\n"
1936 " -q dump reflection query database; requires -l for linking\n"
1937 " -r | --relaxed-errors"
1938 " relaxed GLSL semantic error-checking mode\n"
1939 " -s silence syntax and semantic error reporting\n"
1940 " -t multi-threaded mode\n"
1942 " print version strings\n"
1943 " -w | --suppress-warnings\n"
1944 " suppress GLSL warnings, except as required by \"#extension : warn\"\n"
1945 " -x save binary output as text-based 32-bit hexadecimal numbers\n"
1946 " -u<name>:<loc> specify a uniform location override for --aml\n"
1947 " --uniform-base <base> set a base to use for generated uniform locations\n"
1948 " --auto-map-bindings | --amb automatically bind uniform variables\n"
1949 " without explicit bindings\n"
1950 " --auto-map-locations | --aml automatically locate input/output lacking\n"
1951 " 'location' (fragile, not cross stage)\n"
1952 " --auto-sampled-textures Removes sampler variables and converts\n"
1953 " existing textures to sampled textures\n"
1954 " --client {vulkan<ver>|opengl<ver>} see -V and -G\n"
1955 " --depfile <file> writes depfile for build systems\n"
1956 " --dump-builtin-symbols prints builtin symbol table prior each compile\n"
1957 " -dumpfullversion | -dumpversion print bare major.minor.patchlevel\n"
1958 " --flatten-uniform-arrays | --fua flatten uniform texture/sampler arrays to\n"
1960 " --glsl-version {100 | 110 | 120 | 130 | 140 | 150 |\n"
1961 " 300es | 310es | 320es | 330\n"
1962 " 400 | 410 | 420 | 430 | 440 | 450 | 460}\n"
1963 " set GLSL version, overrides #version\n"
1964 " in shader sourcen\n"
1965 " --hlsl-offsets allow block offsets to follow HLSL rules\n"
1966 " works independently of source language\n"
1967 " --hlsl-iomap perform IO mapping in HLSL register space\n"
1968 " --hlsl-enable-16bit-types allow 16-bit types in SPIR-V for HLSL\n"
1969 " --hlsl-dx9-compatible interprets sampler declarations as a\n"
1970 " texture/sampler combo like DirectX9 would,\n"
1971 " and recognizes DirectX9-specific semantics\n"
1972 " --hlsl-dx-position-w W component of SV_Position in HLSL fragment\n"
1973 " shaders compatible with DirectX\n"
1974 " --invert-y | --iy invert position.Y output in vertex shader\n"
1975 " --enhanced-msgs print more readable error messages (GLSL only)\n"
1976 " --keep-uncalled | --ku don't eliminate uncalled functions\n"
1977 " --nan-clamp favor non-NaN operand in min, max, and clamp\n"
1978 " --no-storage-format | --nsf use Unknown image format\n"
1979 " --quiet do not print anything to stdout, unless\n"
1980 " requested by another option\n"
1981 " --reflect-strict-array-suffix use strict array suffix rules when\n"
1983 " --reflect-basic-array-suffix arrays of basic types will have trailing [0]\n"
1984 " --reflect-intermediate-io reflection includes inputs/outputs of linked\n"
1985 " shaders rather than just vertex/fragment\n"
1986 " --reflect-separate-buffers reflect buffer variables and blocks\n"
1987 " separately to uniforms\n"
1988 " --reflect-all-block-variables reflect all variables in blocks, whether\n"
1989 " inactive or active\n"
1990 " --reflect-unwrap-io-blocks unwrap input/output blocks the same as\n"
1992 " --resource-set-binding [stage] name set binding\n"
1993 " set descriptor set and binding for\n"
1994 " individual resources\n"
1995 " --resource-set-binding [stage] set\n"
1996 " set descriptor set for all resources\n"
1997 " --rsb synonym for --resource-set-binding\n"
1998 " --set-block-backing name {uniform|buffer|push_constant}\n"
1999 " changes the backing type of a uniform, buffer,\n"
2000 " or push_constant block declared in\n"
2001 " in the program, when using -R option.\n"
2002 " This can be used to change the backing\n"
2003 " for existing blocks as well as implicit ones\n"
2004 " such as 'gl_DefaultUniformBlock'.\n"
2005 " --sbs synonym for set-block-storage\n"
2006 " --set-atomic-counter-block name set\n"
2007 " set name, and descriptor set for\n"
2008 " atomic counter blocks, with -R opt\n"
2009 " --sacb synonym for set-atomic-counter-block\n"
2010 " --set-default-uniform-block name set binding\n"
2011 " set name, descriptor set, and binding for\n"
2012 " global default-uniform-block, with -R opt\n"
2013 " --sdub synonym for set-default-uniform-block\n"
2014 " --shift-image-binding [stage] num\n"
2015 " base binding number for images (uav)\n"
2016 " --shift-image-binding [stage] [num set]...\n"
2017 " per-descriptor-set shift values\n"
2018 " --sib synonym for --shift-image-binding\n"
2019 " --shift-sampler-binding [stage] num\n"
2020 " base binding number for samplers\n"
2021 " --shift-sampler-binding [stage] [num set]...\n"
2022 " per-descriptor-set shift values\n"
2023 " --ssb synonym for --shift-sampler-binding\n"
2024 " --shift-ssbo-binding [stage] num base binding number for SSBOs\n"
2025 " --shift-ssbo-binding [stage] [num set]...\n"
2026 " per-descriptor-set shift values\n"
2027 " --sbb synonym for --shift-ssbo-binding\n"
2028 " --shift-texture-binding [stage] num\n"
2029 " base binding number for textures\n"
2030 " --shift-texture-binding [stage] [num set]...\n"
2031 " per-descriptor-set shift values\n"
2032 " --stb synonym for --shift-texture-binding\n"
2033 " --shift-uav-binding [stage] num base binding number for UAVs\n"
2034 " --shift-uav-binding [stage] [num set]...\n"
2035 " per-descriptor-set shift values\n"
2036 " --suavb synonym for --shift-uav-binding\n"
2037 " --shift-UBO-binding [stage] num base binding number for UBOs\n"
2038 " --shift-UBO-binding [stage] [num set]...\n"
2039 " per-descriptor-set shift values\n"
2040 " --sub synonym for --shift-UBO-binding\n"
2041 " --shift-cbuffer-binding | --scb synonyms for --shift-UBO-binding\n"
2042 " --spirv-dis output standard-form disassembly; works only\n"
2043 " when a SPIR-V generation option is also used\n"
2044 " --spirv-val execute the SPIRV-Tools validator\n"
2045 " --source-entrypoint <name> the given shader source function is\n"
2046 " renamed to be the <name> given in -e\n"
2047 " --sep synonym for --source-entrypoint\n"
2048 " --stdin read from stdin instead of from a file;\n"
2049 " requires providing the shader stage using -S\n"
2050 " --target-env {vulkan1.0 | vulkan1.1 | vulkan1.2 | vulkan1.3 | opengl |\n"
2051 " spirv1.0 | spirv1.1 | spirv1.2 | spirv1.3 | spirv1.4 |\n"
2052 " spirv1.5 | spirv1.6}\n"
2053 " Set the execution environment that the\n"
2054 " generated code will be executed in.\n"
2056 " * vulkan1.0 under --client vulkan<ver>\n"
2057 " * opengl under --client opengl<ver>\n"
2058 " * spirv1.0 under --target-env vulkan1.0\n"
2059 " * spirv1.3 under --target-env vulkan1.1\n"
2060 " * spirv1.5 under --target-env vulkan1.2\n"
2061 " * spirv1.6 under --target-env vulkan1.3\n"
2062 " Multiple --target-env can be specified.\n"
2063 " --variable-name <name>\n"
2064 " --vn <name> creates a C header file that contains a\n"
2065 " uint32_t array named <name>\n"
2066 " initialized with the shader binary code\n"
2072 #if !defined _MSC_VER && !defined MINGW_HAS_SECURE_API
2078 const char* filename,
2082 if (!pFile || !filename || !mode) {
2086 FILE* f = fopen(filename, mode);
2102 // Malloc a string of sufficient size and read a string into it.
2104 char* ReadFileData(const char* fileName)
2107 int errorCode = fopen_s(&in, fileName, "r");
2108 if (errorCode || in == nullptr)
2109 Error("unable to open input file");
2112 while (fgetc(in) != EOF)
2115 fseek(in, 0, SEEK_SET);
2117 char* return_data = (char*)malloc(count + 1); // freed in FreeFileData()
2118 if ((int)fread(return_data, 1, count, in) != count) {
2120 Error("can't read input file");
2123 return_data[count] = '\0';
2129 void FreeFileData(char* data)
2134 void InfoLogMsg(const char* msg, const char* name, const int num)
2137 printf("#### %s %s %d INFO LOG ####\n", msg, name, num);
2139 printf("#### %s %s INFO LOG ####\n", msg, name);