John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 2 | // Copyright (C) 2002-2005 3Dlabs Inc. Ltd. |
| 3 | // Copyright (C) 2013-2016 LunarG, Inc. |
John Kessenich | bd0747d | 2013-02-17 06:01:50 +0000 | [diff] [blame] | 4 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 5 | // All rights reserved. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 6 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 7 | // Redistribution and use in source and binary forms, with or without |
| 8 | // modification, are permitted provided that the following conditions |
| 9 | // are met: |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 10 | // |
| 11 | // Redistributions of source code must retain the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer. |
| 13 | // |
| 14 | // Redistributions in binary form must reproduce the above |
| 15 | // copyright notice, this list of conditions and the following |
| 16 | // disclaimer in the documentation and/or other materials provided |
| 17 | // with the distribution. |
| 18 | // |
| 19 | // Neither the name of 3Dlabs Inc. Ltd. nor the names of its |
| 20 | // contributors may be used to endorse or promote products derived |
| 21 | // from this software without specific prior written permission. |
| 22 | // |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 29 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 32 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 33 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 34 | // POSSIBILITY OF SUCH DAMAGE. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 35 | // |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 36 | |
| 37 | // this only applies to the standalone wrapper, not the front end in general |
| 38 | #define _CRT_SECURE_NO_WARNINGS |
| 39 | |
Lei Zhang | 8a9b1ee | 2016-05-19 13:31:43 -0400 | [diff] [blame] | 40 | #include "ResourceLimits.h" |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 41 | #include "Worklist.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 42 | #include "./../glslang/Include/ShHandle.h" |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 43 | #include "./../glslang/Include/revision.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 44 | #include "./../glslang/Public/ShaderLang.h" |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 45 | #include "../SPIRV/GlslangToSpv.h" |
John Kessenich | 5e4b124 | 2015-08-06 22:53:06 -0600 | [diff] [blame] | 46 | #include "../SPIRV/GLSL.std.450.h" |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 47 | #include "../SPIRV/doc.h" |
| 48 | #include "../SPIRV/disassemble.h" |
John Kessenich | 66ec80e | 2016-08-05 14:04:23 -0600 | [diff] [blame] | 49 | #include <cstring> |
| 50 | #include <cstdlib> |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 51 | #include <cctype> |
John Kessenich | 66ec80e | 2016-08-05 14:04:23 -0600 | [diff] [blame] | 52 | #include <cmath> |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 53 | #include <array> |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 54 | |
baldurk | 876a0e3 | 2015-11-16 18:03:28 +0100 | [diff] [blame] | 55 | #include "../glslang/OSDependent/osinclude.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 56 | |
| 57 | extern "C" { |
| 58 | SH_IMPORT_EXPORT void ShOutputHtml(); |
| 59 | } |
| 60 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 61 | // Command-line options |
| 62 | enum TOptions { |
John Kessenich | 906cc21 | 2016-12-09 19:22:20 -0700 | [diff] [blame] | 63 | EOptionNone = 0, |
| 64 | EOptionIntermediate = (1 << 0), |
| 65 | EOptionSuppressInfolog = (1 << 1), |
| 66 | EOptionMemoryLeakMode = (1 << 2), |
| 67 | EOptionRelaxedErrors = (1 << 3), |
| 68 | EOptionGiveWarnings = (1 << 4), |
| 69 | EOptionLinkProgram = (1 << 5), |
| 70 | EOptionMultiThreaded = (1 << 6), |
| 71 | EOptionDumpConfig = (1 << 7), |
| 72 | EOptionDumpReflection = (1 << 8), |
| 73 | EOptionSuppressWarnings = (1 << 9), |
| 74 | EOptionDumpVersions = (1 << 10), |
| 75 | EOptionSpv = (1 << 11), |
| 76 | EOptionHumanReadableSpv = (1 << 12), |
| 77 | EOptionVulkanRules = (1 << 13), |
| 78 | EOptionDefaultDesktop = (1 << 14), |
| 79 | EOptionOutputPreprocessed = (1 << 15), |
| 80 | EOptionOutputHexadecimal = (1 << 16), |
| 81 | EOptionReadHlsl = (1 << 17), |
| 82 | EOptionCascadingErrors = (1 << 18), |
| 83 | EOptionAutoMapBindings = (1 << 19), |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 84 | EOptionFlattenUniformArrays = (1 << 20), |
John Kessenich | 906cc21 | 2016-12-09 19:22:20 -0700 | [diff] [blame] | 85 | EOptionNoStorageFormat = (1 << 21), |
John Kessenich | 20f01e7 | 2016-12-12 11:41:43 -0700 | [diff] [blame] | 86 | EOptionKeepUncalled = (1 << 22), |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 89 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 90 | // Return codes from main/exit(). |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 91 | // |
| 92 | enum TFailCode { |
| 93 | ESuccess = 0, |
| 94 | EFailUsage, |
| 95 | EFailCompile, |
| 96 | EFailLink, |
| 97 | EFailCompilerCreate, |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 98 | EFailThreadCreate, |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 99 | EFailLinkerCreate |
| 100 | }; |
| 101 | |
| 102 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 103 | // Forward declarations. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 104 | // |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 105 | EShLanguage FindLanguage(const std::string& name, bool parseSuffix=true); |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 106 | void CompileFile(const char* fileName, ShHandle); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 107 | void usage(); |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 108 | void FreeFileData(char** data); |
| 109 | char** ReadFileData(const char* fileName); |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 110 | void InfoLogMsg(const char* msg, const char* name, const int num); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 111 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 112 | // Globally track if any compile or link failure. |
| 113 | bool CompileFailed = false; |
| 114 | bool LinkFailed = false; |
| 115 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 116 | // Use to test breaking up a single shader file into multiple strings. |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 117 | // Set in ReadFileData(). |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 118 | int NumShaderStrings; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 119 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 120 | TBuiltInResource Resources; |
| 121 | std::string ConfigFile; |
| 122 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 123 | // |
John Kessenich | f0bcb0a | 2016-04-02 13:09:14 -0600 | [diff] [blame] | 124 | // Parse either a .conf file provided by the user or the default from glslang::DefaultTBuiltInResource |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 125 | // |
| 126 | void ProcessConfigFile() |
John Kessenich | b51f62c | 2013-04-11 16:31:09 +0000 | [diff] [blame] | 127 | { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 128 | char** configStrings = 0; |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 129 | char* config = 0; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 130 | if (ConfigFile.size() > 0) { |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 131 | configStrings = ReadFileData(ConfigFile.c_str()); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 132 | if (configStrings) |
| 133 | config = *configStrings; |
| 134 | else { |
| 135 | printf("Error opening configuration file; will instead use the default configuration\n"); |
| 136 | usage(); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (config == 0) { |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 141 | Resources = glslang::DefaultTBuiltInResource; |
| 142 | return; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Lei Zhang | 1b14172 | 2016-05-19 13:50:49 -0400 | [diff] [blame] | 145 | glslang::DecodeResourceLimits(&Resources, config); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 146 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 147 | if (configStrings) |
| 148 | FreeFileData(configStrings); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 149 | else |
| 150 | delete[] config; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 151 | } |
| 152 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 153 | // thread-safe list of shaders to asynchronously grab and compile |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 154 | glslang::TWorklist Worklist; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 155 | |
| 156 | // array of unique places to leave the shader names and infologs for the asynchronous compiles |
John Kessenich | fd30542 | 2014-06-05 16:30:53 +0000 | [diff] [blame] | 157 | glslang::TWorkItem** Work = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 158 | int NumWorkItems = 0; |
| 159 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 160 | int Options = 0; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 161 | const char* ExecutableName = nullptr; |
| 162 | const char* binaryFileName = nullptr; |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 163 | const char* entryPointName = nullptr; |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 164 | const char* sourceEntryPointName = nullptr; |
Dan Baker | c6ede89 | 2016-08-11 14:06:06 -0400 | [diff] [blame] | 165 | const char* shaderStageName = nullptr; |
Flavio | aea3c89 | 2017-02-06 11:46:35 -0800 | [diff] [blame] | 166 | const char* variableName = nullptr; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 167 | |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 168 | std::array<unsigned int, EShLangCount> baseSamplerBinding; |
| 169 | std::array<unsigned int, EShLangCount> baseTextureBinding; |
steve-lunarg | 9088be4 | 2016-11-01 10:31:42 -0600 | [diff] [blame] | 170 | std::array<unsigned int, EShLangCount> baseImageBinding; |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 171 | std::array<unsigned int, EShLangCount> baseUboBinding; |
steve-lunarg | 932bb5c | 2017-02-21 17:19:08 -0700 | [diff] [blame] | 172 | std::array<unsigned int, EShLangCount> baseSsboBinding; |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 173 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 174 | // |
| 175 | // Create the default name for saving a binary if -o is not provided. |
| 176 | // |
| 177 | const char* GetBinaryName(EShLanguage stage) |
| 178 | { |
| 179 | const char* name; |
| 180 | if (binaryFileName == nullptr) { |
| 181 | switch (stage) { |
| 182 | case EShLangVertex: name = "vert.spv"; break; |
| 183 | case EShLangTessControl: name = "tesc.spv"; break; |
| 184 | case EShLangTessEvaluation: name = "tese.spv"; break; |
| 185 | case EShLangGeometry: name = "geom.spv"; break; |
| 186 | case EShLangFragment: name = "frag.spv"; break; |
| 187 | case EShLangCompute: name = "comp.spv"; break; |
| 188 | default: name = "unknown"; break; |
| 189 | } |
| 190 | } else |
| 191 | name = binaryFileName; |
| 192 | |
| 193 | return name; |
| 194 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 195 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 196 | // |
| 197 | // *.conf => this is a config file that can set limits/resources |
| 198 | // |
| 199 | bool SetConfigFile(const std::string& name) |
| 200 | { |
| 201 | if (name.size() < 5) |
| 202 | return false; |
| 203 | |
John Kessenich | 4c70685 | 2013-10-11 16:28:43 +0000 | [diff] [blame] | 204 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 205 | ConfigFile = name; |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | return false; |
| 210 | } |
| 211 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 212 | // |
| 213 | // Give error and exit with failure code. |
| 214 | // |
| 215 | void Error(const char* message) |
| 216 | { |
| 217 | printf("%s: Error %s (use -h for usage)\n", ExecutableName, message); |
| 218 | exit(EFailUsage); |
| 219 | } |
| 220 | |
| 221 | // |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 222 | // Process an optional binding base of the form: |
| 223 | // --argname [stage] base |
| 224 | // Where stage is one of the forms accepted by FindLanguage, and base is an integer |
| 225 | // |
| 226 | void ProcessBindingBase(int& argc, char**& argv, std::array<unsigned int, EShLangCount>& base) |
| 227 | { |
| 228 | if (argc < 2) |
| 229 | usage(); |
| 230 | |
| 231 | if (!isdigit(argv[1][0])) { |
| 232 | if (argc < 3) // this form needs one more argument |
| 233 | usage(); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 234 | |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 235 | // Parse form: --argname stage base |
| 236 | const EShLanguage lang = FindLanguage(argv[1], false); |
| 237 | base[lang] = atoi(argv[2]); |
| 238 | argc-= 2; |
| 239 | argv+= 2; |
| 240 | } else { |
| 241 | // Parse form: --argname base |
| 242 | for (int lang=0; lang<EShLangCount; ++lang) |
| 243 | base[lang] = atoi(argv[1]); |
| 244 | |
| 245 | argc--; |
| 246 | argv++; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 251 | // Do all command-line argument parsing. This includes building up the work-items |
| 252 | // to be processed later, and saving all the command-line options. |
| 253 | // |
| 254 | // Does not return (it exits) if command-line is fatally flawed. |
| 255 | // |
| 256 | void ProcessArguments(int argc, char* argv[]) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 257 | { |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 258 | baseSamplerBinding.fill(0); |
| 259 | baseTextureBinding.fill(0); |
steve-lunarg | 9088be4 | 2016-11-01 10:31:42 -0600 | [diff] [blame] | 260 | baseImageBinding.fill(0); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 261 | baseUboBinding.fill(0); |
steve-lunarg | 932bb5c | 2017-02-21 17:19:08 -0700 | [diff] [blame] | 262 | baseSsboBinding.fill(0); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 263 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 264 | ExecutableName = argv[0]; |
| 265 | NumWorkItems = argc; // will include some empties where the '-' options were, but it doesn't matter, they'll be 0 |
John Kessenich | fd30542 | 2014-06-05 16:30:53 +0000 | [diff] [blame] | 266 | Work = new glslang::TWorkItem*[NumWorkItems]; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 267 | for (int w = 0; w < NumWorkItems; ++w) |
| 268 | Work[w] = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 269 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 270 | argc--; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 271 | argv++; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 272 | for (; argc >= 1; argc--, argv++) { |
| 273 | if (argv[0][0] == '-') { |
John Kessenich | 2aa7f3a | 2015-05-15 16:02:07 +0000 | [diff] [blame] | 274 | switch (argv[0][1]) { |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 275 | case '-': |
| 276 | { |
| 277 | std::string lowerword(argv[0]+2); |
| 278 | std::transform(lowerword.begin(), lowerword.end(), lowerword.begin(), ::tolower); |
| 279 | |
| 280 | // handle --word style options |
| 281 | if (lowerword == "shift-sampler-bindings" || // synonyms |
| 282 | lowerword == "shift-sampler-binding" || |
| 283 | lowerword == "ssb") { |
| 284 | ProcessBindingBase(argc, argv, baseSamplerBinding); |
| 285 | } else if (lowerword == "shift-texture-bindings" || // synonyms |
| 286 | lowerword == "shift-texture-binding" || |
| 287 | lowerword == "stb") { |
| 288 | ProcessBindingBase(argc, argv, baseTextureBinding); |
steve-lunarg | 9088be4 | 2016-11-01 10:31:42 -0600 | [diff] [blame] | 289 | } else if (lowerword == "shift-image-bindings" || // synonyms |
| 290 | lowerword == "shift-image-binding" || |
| 291 | lowerword == "sib") { |
| 292 | ProcessBindingBase(argc, argv, baseImageBinding); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 293 | } else if (lowerword == "shift-ubo-bindings" || // synonyms |
| 294 | lowerword == "shift-ubo-binding" || |
| 295 | lowerword == "sub") { |
| 296 | ProcessBindingBase(argc, argv, baseUboBinding); |
steve-lunarg | 932bb5c | 2017-02-21 17:19:08 -0700 | [diff] [blame] | 297 | } else if (lowerword == "shift-ssbo-bindings" || // synonyms |
| 298 | lowerword == "shift-ssbo-binding" || |
| 299 | lowerword == "sbb") { |
| 300 | ProcessBindingBase(argc, argv, baseSsboBinding); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 301 | } else if (lowerword == "auto-map-bindings" || // synonyms |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 302 | lowerword == "auto-map-binding" || |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 303 | lowerword == "amb") { |
| 304 | Options |= EOptionAutoMapBindings; |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 305 | } else if (lowerword == "flatten-uniform-arrays" || // synonyms |
| 306 | lowerword == "flatten-uniform-array" || |
| 307 | lowerword == "fua") { |
| 308 | Options |= EOptionFlattenUniformArrays; |
steve-lunarg | cce8d48 | 2016-10-14 18:36:42 -0600 | [diff] [blame] | 309 | } else if (lowerword == "no-storage-format" || // synonyms |
| 310 | lowerword == "nsf") { |
| 311 | Options |= EOptionNoStorageFormat; |
Flavio | 15017db | 2017-02-15 14:29:33 -0800 | [diff] [blame] | 312 | } else if (lowerword == "variable-name" || // synonyms |
| 313 | lowerword == "vn") { |
| 314 | Options |= EOptionOutputHexadecimal; |
| 315 | variableName = argv[1]; |
| 316 | if (argc > 0) { |
| 317 | argc--; |
| 318 | argv++; |
| 319 | } else |
| 320 | Error("no <C-variable-name> provided for --variable-name"); |
| 321 | break; |
| 322 | } |
| 323 | else if (lowerword == "source-entrypoint" || // synonyms |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 324 | lowerword == "sep") { |
| 325 | sourceEntryPointName = argv[1]; |
| 326 | if (argc > 0) { |
| 327 | argc--; |
| 328 | argv++; |
| 329 | } else |
| 330 | Error("no <entry-point> provided for --source-entrypoint"); |
| 331 | break; |
John Kessenich | 906cc21 | 2016-12-09 19:22:20 -0700 | [diff] [blame] | 332 | } else if (lowerword == "keep-uncalled" || // synonyms |
| 333 | lowerword == "ku") { |
| 334 | Options |= EOptionKeepUncalled; |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 335 | } else { |
| 336 | usage(); |
| 337 | } |
| 338 | } |
| 339 | break; |
John Kessenich | 2aa7f3a | 2015-05-15 16:02:07 +0000 | [diff] [blame] | 340 | case 'H': |
| 341 | Options |= EOptionHumanReadableSpv; |
John Kessenich | 91e4aa5 | 2016-07-07 17:46:42 -0600 | [diff] [blame] | 342 | if ((Options & EOptionSpv) == 0) { |
| 343 | // default to Vulkan |
| 344 | Options |= EOptionSpv; |
| 345 | Options |= EOptionVulkanRules; |
| 346 | Options |= EOptionLinkProgram; |
| 347 | } |
| 348 | break; |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 349 | case 'V': |
| 350 | Options |= EOptionSpv; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 351 | Options |= EOptionVulkanRules; |
| 352 | Options |= EOptionLinkProgram; |
| 353 | break; |
Dan Baker | 5afdd78 | 2016-08-11 17:53:57 -0400 | [diff] [blame] | 354 | case 'S': |
Dan Baker | c6ede89 | 2016-08-11 14:06:06 -0400 | [diff] [blame] | 355 | shaderStageName = argv[1]; |
dankbaker | 45d49bc | 2016-08-08 21:43:07 -0400 | [diff] [blame] | 356 | if (argc > 0) { |
| 357 | argc--; |
| 358 | argv++; |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 359 | } else |
Dan Baker | 5afdd78 | 2016-08-11 17:53:57 -0400 | [diff] [blame] | 360 | Error("no <stage> specified for -S"); |
dankbaker | 45d49bc | 2016-08-08 21:43:07 -0400 | [diff] [blame] | 361 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 362 | case 'G': |
| 363 | Options |= EOptionSpv; |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 364 | Options |= EOptionLinkProgram; |
John Kessenich | 91e4aa5 | 2016-07-07 17:46:42 -0600 | [diff] [blame] | 365 | // undo a -H default to Vulkan |
| 366 | Options &= ~EOptionVulkanRules; |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 367 | break; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 368 | case 'E': |
| 369 | Options |= EOptionOutputPreprocessed; |
| 370 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 371 | case 'c': |
| 372 | Options |= EOptionDumpConfig; |
| 373 | break; |
John Kessenich | a86836e | 2016-07-09 14:50:57 -0600 | [diff] [blame] | 374 | case 'C': |
| 375 | Options |= EOptionCascadingErrors; |
| 376 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 377 | case 'd': |
John Kessenich | 26ad268 | 2014-08-13 20:17:19 +0000 | [diff] [blame] | 378 | Options |= EOptionDefaultDesktop; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 379 | break; |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 380 | case 'D': |
| 381 | Options |= EOptionReadHlsl; |
| 382 | break; |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 383 | case 'e': |
| 384 | // HLSL todo: entry point handle needs much more sophistication. |
| 385 | // This is okay for one compilation unit with one entry point. |
| 386 | entryPointName = argv[1]; |
| 387 | if (argc > 0) { |
| 388 | argc--; |
| 389 | argv++; |
| 390 | } else |
| 391 | Error("no <entry-point> provided for -e"); |
| 392 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 393 | case 'h': |
| 394 | usage(); |
| 395 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 396 | case 'i': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 397 | Options |= EOptionIntermediate; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 398 | break; |
| 399 | case 'l': |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 400 | Options |= EOptionLinkProgram; |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 401 | break; |
| 402 | case 'm': |
| 403 | Options |= EOptionMemoryLeakMode; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 404 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 405 | case 'o': |
| 406 | binaryFileName = argv[1]; |
| 407 | if (argc > 0) { |
| 408 | argc--; |
| 409 | argv++; |
| 410 | } else |
| 411 | Error("no <file> provided for -o"); |
| 412 | break; |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 413 | case 'q': |
| 414 | Options |= EOptionDumpReflection; |
| 415 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 416 | case 'r': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 417 | Options |= EOptionRelaxedErrors; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 418 | break; |
| 419 | case 's': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 420 | Options |= EOptionSuppressInfolog; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 421 | break; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 422 | case 't': |
| 423 | #ifdef _WIN32 |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 424 | Options |= EOptionMultiThreaded; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 425 | #endif |
| 426 | break; |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 427 | case 'v': |
| 428 | Options |= EOptionDumpVersions; |
| 429 | break; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 430 | case 'w': |
| 431 | Options |= EOptionSuppressWarnings; |
| 432 | break; |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 433 | case 'x': |
| 434 | Options |= EOptionOutputHexadecimal; |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 435 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 436 | default: |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 437 | usage(); |
| 438 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 439 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 440 | } else { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 441 | std::string name(argv[0]); |
| 442 | if (! SetConfigFile(name)) { |
| 443 | Work[argc] = new glslang::TWorkItem(name); |
| 444 | Worklist.add(Work[argc]); |
| 445 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 446 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 447 | } |
| 448 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 449 | // Make sure that -E is not specified alongside linking (which includes SPV generation) |
| 450 | if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram)) |
| 451 | Error("can't use -E when linking is selected"); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 452 | |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 453 | // -o or -x makes no sense if there is no target binary |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 454 | if (binaryFileName && (Options & EOptionSpv) == 0) |
| 455 | Error("no binary generation requested (e.g., -V)"); |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 456 | |
| 457 | if ((Options & EOptionFlattenUniformArrays) != 0 && |
| 458 | (Options & EOptionReadHlsl) == 0) |
| 459 | Error("uniform array flattening only valid when compiling HLSL source."); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 460 | } |
| 461 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 462 | // |
| 463 | // Translate the meaningful subset of command-line options to parser-behavior options. |
| 464 | // |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 465 | void SetMessageOptions(EShMessages& messages) |
| 466 | { |
| 467 | if (Options & EOptionRelaxedErrors) |
| 468 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 469 | if (Options & EOptionIntermediate) |
| 470 | messages = (EShMessages)(messages | EShMsgAST); |
| 471 | if (Options & EOptionSuppressWarnings) |
| 472 | messages = (EShMessages)(messages | EShMsgSuppressWarnings); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 473 | if (Options & EOptionSpv) |
| 474 | messages = (EShMessages)(messages | EShMsgSpvRules); |
| 475 | if (Options & EOptionVulkanRules) |
| 476 | messages = (EShMessages)(messages | EShMsgVulkanRules); |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 477 | if (Options & EOptionOutputPreprocessed) |
| 478 | messages = (EShMessages)(messages | EShMsgOnlyPreprocessor); |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 479 | if (Options & EOptionReadHlsl) |
| 480 | messages = (EShMessages)(messages | EShMsgReadHlsl); |
John Kessenich | a86836e | 2016-07-09 14:50:57 -0600 | [diff] [blame] | 481 | if (Options & EOptionCascadingErrors) |
| 482 | messages = (EShMessages)(messages | EShMsgCascadingErrors); |
John Kessenich | 906cc21 | 2016-12-09 19:22:20 -0700 | [diff] [blame] | 483 | if (Options & EOptionKeepUncalled) |
| 484 | messages = (EShMessages)(messages | EShMsgKeepUncalled); |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 485 | } |
| 486 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 487 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 488 | // Thread entry point, for non-linking asynchronous mode. |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 489 | // |
| 490 | // Return 0 for failure, 1 for success. |
| 491 | // |
Pyry Haulos | 5f6892e | 2015-12-01 12:59:53 -0800 | [diff] [blame] | 492 | unsigned int CompileShaders(void*) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 493 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 494 | glslang::TWorkItem* workItem; |
| 495 | while (Worklist.remove(workItem)) { |
| 496 | ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 497 | if (compiler == 0) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 498 | return 0; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 499 | |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 500 | CompileFile(workItem->name.c_str(), compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 501 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 502 | if (! (Options & EOptionSuppressInfolog)) |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 503 | workItem->results = ShGetInfoLog(compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 504 | |
| 505 | ShDestruct(compiler); |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 511 | // Outputs the given string, but only if it is non-null and non-empty. |
| 512 | // This prevents erroneous newlines from appearing. |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 513 | void PutsIfNonEmpty(const char* str) |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 514 | { |
| 515 | if (str && str[0]) { |
| 516 | puts(str); |
| 517 | } |
| 518 | } |
| 519 | |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 520 | // Outputs the given string to stderr, but only if it is non-null and non-empty. |
| 521 | // This prevents erroneous newlines from appearing. |
| 522 | void StderrIfNonEmpty(const char* str) |
| 523 | { |
| 524 | if (str && str[0]) { |
| 525 | fprintf(stderr, "%s\n", str); |
| 526 | } |
| 527 | } |
| 528 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 529 | // Simple bundling of what makes a compilation unit for ease in passing around, |
| 530 | // and separation of handling file IO versus API (programmatic) compilation. |
| 531 | struct ShaderCompUnit { |
| 532 | EShLanguage stage; |
| 533 | std::string fileName; |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 534 | char** text; // memory owned/managed externally |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 535 | const char* fileNameList[1]; |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 536 | |
John Kessenich | 219b025 | 2016-08-23 17:51:13 -0600 | [diff] [blame] | 537 | // Need to have a special constructors to adjust the fileNameList, since back end needs a list of ptrs |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 538 | ShaderCompUnit(EShLanguage istage, std::string &ifileName, char** itext) |
| 539 | { |
| 540 | stage = istage; |
| 541 | fileName = ifileName; |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 542 | text = itext; |
John Kessenich | 219b025 | 2016-08-23 17:51:13 -0600 | [diff] [blame] | 543 | fileNameList[0] = fileName.c_str(); |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | ShaderCompUnit(const ShaderCompUnit &rhs) |
| 547 | { |
| 548 | stage = rhs.stage; |
| 549 | fileName = rhs.fileName; |
| 550 | text = rhs.text; |
John Kessenich | 219b025 | 2016-08-23 17:51:13 -0600 | [diff] [blame] | 551 | fileNameList[0] = fileName.c_str(); |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 552 | } |
| 553 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 554 | }; |
| 555 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 556 | // |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 557 | // For linking mode: Will independently parse each compilation unit, but then put them |
| 558 | // in the same program and link them together, making at most one linked module per |
| 559 | // pipeline stage. |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 560 | // |
| 561 | // Uses the new C++ interface instead of the old handle-based interface. |
| 562 | // |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 563 | |
| 564 | void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 565 | { |
| 566 | // keep track of what to free |
| 567 | std::list<glslang::TShader*> shaders; |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 568 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 569 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 570 | SetMessageOptions(messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 571 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 572 | // |
| 573 | // Per-shader processing... |
| 574 | // |
| 575 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 576 | glslang::TProgram& program = *new glslang::TProgram; |
rdb | 32084e8 | 2016-02-23 22:17:38 +0100 | [diff] [blame] | 577 | for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) { |
| 578 | const auto &compUnit = *it; |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 579 | glslang::TShader* shader = new glslang::TShader(compUnit.stage); |
dankbaker | afe6e9c | 2016-08-21 12:29:08 -0400 | [diff] [blame] | 580 | shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, 1); |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 581 | if (entryPointName) // HLSL todo: this needs to be tracked per compUnits |
| 582 | shader->setEntryPoint(entryPointName); |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 583 | if (sourceEntryPointName) |
| 584 | shader->setSourceEntryPoint(sourceEntryPointName); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 585 | |
| 586 | shader->setShiftSamplerBinding(baseSamplerBinding[compUnit.stage]); |
| 587 | shader->setShiftTextureBinding(baseTextureBinding[compUnit.stage]); |
steve-lunarg | 9088be4 | 2016-11-01 10:31:42 -0600 | [diff] [blame] | 588 | shader->setShiftImageBinding(baseImageBinding[compUnit.stage]); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 589 | shader->setShiftUboBinding(baseUboBinding[compUnit.stage]); |
steve-lunarg | 932bb5c | 2017-02-21 17:19:08 -0700 | [diff] [blame] | 590 | shader->setShiftSsboBinding(baseSsboBinding[compUnit.stage]); |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 591 | shader->setFlattenUniformArrays((Options & EOptionFlattenUniformArrays) != 0); |
steve-lunarg | cce8d48 | 2016-10-14 18:36:42 -0600 | [diff] [blame] | 592 | shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0); |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 593 | |
| 594 | if (Options & EOptionAutoMapBindings) |
| 595 | shader->setAutoMapBindings(true); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 596 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 597 | shaders.push_back(shader); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 598 | |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 599 | const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 600 | |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 601 | if (Options & EOptionOutputPreprocessed) { |
| 602 | std::string str; |
John Kessenich | facde2c | 2017-01-06 16:48:18 -0700 | [diff] [blame] | 603 | glslang::TShader::ForbidIncluder includer; |
Dejan Mircevski | 7be4b82 | 2015-06-17 11:40:33 -0400 | [diff] [blame] | 604 | if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, |
Andrew Woloszyn | a132af5 | 2016-03-07 13:23:09 -0500 | [diff] [blame] | 605 | messages, &str, includer)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 606 | PutsIfNonEmpty(str.c_str()); |
| 607 | } else { |
| 608 | CompileFailed = true; |
| 609 | } |
| 610 | StderrIfNonEmpty(shader->getInfoLog()); |
| 611 | StderrIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 612 | continue; |
| 613 | } |
| 614 | if (! shader->parse(&Resources, defaultVersion, false, messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 615 | CompileFailed = true; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 616 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 617 | program.addShader(shader); |
| 618 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 619 | if (! (Options & EOptionSuppressInfolog) && |
| 620 | ! (Options & EOptionMemoryLeakMode)) { |
| 621 | PutsIfNonEmpty(compUnit.fileName.c_str()); |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 622 | PutsIfNonEmpty(shader->getInfoLog()); |
| 623 | PutsIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 624 | } |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | // |
| 628 | // Program-level processing... |
| 629 | // |
| 630 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 631 | // Link |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 632 | if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 633 | LinkFailed = true; |
| 634 | |
steve-lunarg | 9ae3474 | 2016-10-05 13:40:13 -0600 | [diff] [blame] | 635 | // Map IO |
| 636 | if (Options & EOptionSpv) { |
| 637 | if (!program.mapIO()) |
| 638 | LinkFailed = true; |
| 639 | } |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 640 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 641 | // Report |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 642 | if (! (Options & EOptionSuppressInfolog) && |
| 643 | ! (Options & EOptionMemoryLeakMode)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 644 | PutsIfNonEmpty(program.getInfoLog()); |
| 645 | PutsIfNonEmpty(program.getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 646 | } |
| 647 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 648 | // Reflect |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 649 | if (Options & EOptionDumpReflection) { |
| 650 | program.buildReflection(); |
| 651 | program.dumpReflection(); |
| 652 | } |
| 653 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 654 | // Dump SPIR-V |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 655 | if (Options & EOptionSpv) { |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 656 | if (CompileFailed || LinkFailed) |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 657 | printf("SPIR-V is not generated for failed compile or link\n"); |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 658 | else { |
| 659 | for (int stage = 0; stage < EShLangCount; ++stage) { |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 660 | if (program.getIntermediate((EShLanguage)stage)) { |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 661 | std::vector<unsigned int> spirv; |
Lei Zhang | 09caf12 | 2016-05-02 18:11:54 -0400 | [diff] [blame] | 662 | std::string warningsErrors; |
Lei Zhang | 17535f7 | 2016-05-04 15:55:59 -0400 | [diff] [blame] | 663 | spv::SpvBuildLogger logger; |
| 664 | glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 665 | |
| 666 | // Dump the spv to a file or stdout, etc., but only if not doing |
| 667 | // memory/perf testing, as it's not internal to programmatic use. |
| 668 | if (! (Options & EOptionMemoryLeakMode)) { |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 669 | printf("%s", logger.getAllMessages().c_str()); |
| 670 | if (Options & EOptionOutputHexadecimal) { |
John Kessenich | 8f674e8 | 2017-02-18 09:45:40 -0700 | [diff] [blame] | 671 | glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage), variableName); |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 672 | } else { |
| 673 | glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); |
| 674 | } |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 675 | if (Options & EOptionHumanReadableSpv) { |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 676 | spv::Disassemble(std::cout, spirv); |
| 677 | } |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 678 | } |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 679 | } |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 684 | // Free everything up, program has to go before the shaders |
| 685 | // because it might have merged stuff from the shaders, and |
| 686 | // the stuff from the shaders has to have its destructors called |
| 687 | // before the pools holding the memory in the shaders is freed. |
| 688 | delete &program; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 689 | while (shaders.size() > 0) { |
| 690 | delete shaders.back(); |
| 691 | shaders.pop_back(); |
| 692 | } |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 693 | } |
| 694 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 695 | // |
| 696 | // Do file IO part of compile and link, handing off the pure |
| 697 | // API/programmatic mode to CompileAndLinkShaderUnits(), which can |
| 698 | // be put in a loop for testing memory footprint and performance. |
| 699 | // |
| 700 | // This is just for linking mode: meaning all the shaders will be put into the |
| 701 | // the same program linked together. |
| 702 | // |
| 703 | // This means there are a limited number of work items (not multi-threading mode) |
| 704 | // and that the point is testing at the linking level. Hence, to enable |
| 705 | // performance and memory testing, the actual compile/link can be put in |
| 706 | // a loop, independent of processing the work items and file IO. |
| 707 | // |
| 708 | void CompileAndLinkShaderFiles() |
| 709 | { |
| 710 | std::vector<ShaderCompUnit> compUnits; |
| 711 | |
| 712 | // Transfer all the work items from to a simple list of |
| 713 | // of compilation units. (We don't care about the thread |
| 714 | // work-item distribution properties in this path, which |
| 715 | // is okay due to the limited number of shaders, know since |
| 716 | // they are all getting linked together.) |
| 717 | glslang::TWorkItem* workItem; |
| 718 | while (Worklist.remove(workItem)) { |
baldurk | 31d5d48 | 2016-10-13 19:25:52 +0200 | [diff] [blame] | 719 | ShaderCompUnit compUnit( |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 720 | FindLanguage(workItem->name), |
| 721 | workItem->name, |
| 722 | ReadFileData(workItem->name.c_str()) |
baldurk | 31d5d48 | 2016-10-13 19:25:52 +0200 | [diff] [blame] | 723 | ); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 724 | |
| 725 | if (! compUnit.text) { |
| 726 | usage(); |
| 727 | return; |
| 728 | } |
| 729 | |
| 730 | compUnits.push_back(compUnit); |
| 731 | } |
| 732 | |
| 733 | // Actual call to programmatic processing of compile and link, |
| 734 | // in a loop for testing memory and performance. This part contains |
| 735 | // all the perf/memory that a programmatic consumer will care about. |
| 736 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 737 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) |
| 738 | CompileAndLinkShaderUnits(compUnits); |
| 739 | |
| 740 | if (Options & EOptionMemoryLeakMode) |
| 741 | glslang::OS_DumpMemoryCounters(); |
| 742 | } |
| 743 | |
rdb | 32084e8 | 2016-02-23 22:17:38 +0100 | [diff] [blame] | 744 | for (auto it = compUnits.begin(); it != compUnits.end(); ++it) |
| 745 | FreeFileData(it->text); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 746 | } |
| 747 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 748 | int C_DECL main(int argc, char* argv[]) |
| 749 | { |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 750 | ProcessArguments(argc, argv); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 751 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 752 | if (Options & EOptionDumpConfig) { |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 753 | printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str()); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 754 | if (Worklist.empty()) |
| 755 | return ESuccess; |
| 756 | } |
| 757 | |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 758 | if (Options & EOptionDumpVersions) { |
| 759 | printf("Glslang Version: %s %s\n", GLSLANG_REVISION, GLSLANG_DATE); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 760 | printf("ESSL Version: %s\n", glslang::GetEsslVersionString()); |
| 761 | printf("GLSL Version: %s\n", glslang::GetGlslVersionString()); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 762 | std::string spirvVersion; |
| 763 | glslang::GetSpirvVersion(spirvVersion); |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 764 | printf("SPIR-V Version %s\n", spirvVersion.c_str()); |
John Kessenich | 5e4b124 | 2015-08-06 22:53:06 -0600 | [diff] [blame] | 765 | printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision); |
John Kessenich | 55e7d11 | 2015-11-15 21:33:39 -0700 | [diff] [blame] | 766 | printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId()); |
John Kessenich | b84313d | 2016-07-20 16:03:29 -0600 | [diff] [blame] | 767 | printf("GL_KHR_vulkan_glsl version %d\n", 100); |
| 768 | printf("ARB_GL_gl_spirv version %d\n", 100); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 769 | if (Worklist.empty()) |
| 770 | return ESuccess; |
| 771 | } |
| 772 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 773 | if (Worklist.empty()) { |
| 774 | usage(); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | ProcessConfigFile(); |
| 778 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 779 | // |
| 780 | // Two modes: |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 781 | // 1) linking all arguments together, single-threaded, new C++ interface |
| 782 | // 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 783 | // |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 784 | if (Options & EOptionLinkProgram || |
| 785 | Options & EOptionOutputPreprocessed) { |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 786 | glslang::InitializeProcess(); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 787 | CompileAndLinkShaderFiles(); |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 788 | glslang::FinalizeProcess(); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 789 | for (int w = 0; w < NumWorkItems; ++w) { |
| 790 | if (Work[w]) { |
| 791 | delete Work[w]; |
| 792 | } |
| 793 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 794 | } else { |
| 795 | ShInitialize(); |
| 796 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 797 | bool printShaderNames = Worklist.size() > 1; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 798 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 799 | if (Options & EOptionMultiThreaded) { |
| 800 | const int NumThreads = 16; |
| 801 | void* threads[NumThreads]; |
| 802 | for (int t = 0; t < NumThreads; ++t) { |
| 803 | threads[t] = glslang::OS_CreateThread(&CompileShaders); |
| 804 | if (! threads[t]) { |
| 805 | printf("Failed to create thread\n"); |
| 806 | return EFailThreadCreate; |
| 807 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 808 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 809 | glslang::OS_WaitForAllThreads(threads, NumThreads); |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 810 | } else |
| 811 | CompileShaders(0); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 812 | |
| 813 | // Print out all the resulting infologs |
| 814 | for (int w = 0; w < NumWorkItems; ++w) { |
| 815 | if (Work[w]) { |
Kenneth Perry | b07e6be | 2015-12-15 10:52:34 -0600 | [diff] [blame] | 816 | if (printShaderNames || Work[w]->results.size() > 0) |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 817 | PutsIfNonEmpty(Work[w]->name.c_str()); |
| 818 | PutsIfNonEmpty(Work[w]->results.c_str()); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 819 | delete Work[w]; |
| 820 | } |
| 821 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 822 | |
| 823 | ShFinalize(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 824 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 825 | |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 826 | delete[] Work; |
| 827 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 828 | if (CompileFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 829 | return EFailCompile; |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 830 | if (LinkFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 831 | return EFailLink; |
| 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | // |
| 837 | // Deduce the language from the filename. Files must end in one of the |
| 838 | // following extensions: |
| 839 | // |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 840 | // .vert = vertex |
| 841 | // .tesc = tessellation control |
| 842 | // .tese = tessellation evaluation |
| 843 | // .geom = geometry |
| 844 | // .frag = fragment |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 845 | // .comp = compute |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 846 | // |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 847 | EShLanguage FindLanguage(const std::string& name, bool parseSuffix) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 848 | { |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 849 | size_t ext = 0; |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 850 | std::string suffix; |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 851 | |
Dan Baker | c6ede89 | 2016-08-11 14:06:06 -0400 | [diff] [blame] | 852 | if (shaderStageName) |
| 853 | suffix = shaderStageName; |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 854 | else { |
| 855 | // Search for a suffix on a filename: e.g, "myfile.frag". If given |
| 856 | // the suffix directly, we skip looking for the '.' |
| 857 | if (parseSuffix) { |
| 858 | ext = name.rfind('.'); |
| 859 | if (ext == std::string::npos) { |
| 860 | usage(); |
| 861 | return EShLangVertex; |
| 862 | } |
| 863 | ++ext; |
| 864 | } |
| 865 | suffix = name.substr(ext, std::string::npos); |
| 866 | } |
dankbaker | 45d49bc | 2016-08-08 21:43:07 -0400 | [diff] [blame] | 867 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 868 | if (suffix == "vert") |
| 869 | return EShLangVertex; |
| 870 | else if (suffix == "tesc") |
| 871 | return EShLangTessControl; |
| 872 | else if (suffix == "tese") |
| 873 | return EShLangTessEvaluation; |
| 874 | else if (suffix == "geom") |
| 875 | return EShLangGeometry; |
| 876 | else if (suffix == "frag") |
| 877 | return EShLangFragment; |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 878 | else if (suffix == "comp") |
| 879 | return EShLangCompute; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 880 | |
| 881 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 882 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 883 | } |
| 884 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 885 | // |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 886 | // Read a file's data into a string, and compile it using the old interface ShCompile, |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 887 | // for non-linkable results. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 888 | // |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 889 | void CompileFile(const char* fileName, ShHandle compiler) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 890 | { |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 891 | int ret = 0; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 892 | char** shaderStrings = ReadFileData(fileName); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 893 | if (! shaderStrings) { |
| 894 | usage(); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 895 | } |
| 896 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 897 | int* lengths = new int[NumShaderStrings]; |
| 898 | |
| 899 | // move to length-based strings, rather than null-terminated strings |
| 900 | for (int s = 0; s < NumShaderStrings; ++s) |
John Kessenich | 35f04bd | 2014-02-19 02:47:20 +0000 | [diff] [blame] | 901 | lengths[s] = (int)strlen(shaderStrings[s]); |
John Kessenich | 09da79e | 2013-04-17 19:34:23 +0000 | [diff] [blame] | 902 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 903 | if (! shaderStrings) { |
| 904 | CompileFailed = true; |
| 905 | return; |
| 906 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 907 | |
John Kessenich | 52ac67e | 2013-05-05 23:46:22 +0000 | [diff] [blame] | 908 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 909 | SetMessageOptions(messages); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 910 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 911 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 912 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) { |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 913 | // ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 914 | ret = ShCompile(compiler, shaderStrings, NumShaderStrings, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 915 | // const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err", |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 916 | // "or should be l", "ine 1", "string 5\n", "float glo", "bal", |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 917 | // ";\n#error should be line 2\n void main() {", "global = 2.3;}" }; |
John Kessenich | 927608b | 2017-01-06 12:34:14 -0700 | [diff] [blame] | 918 | // const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; |
| 919 | // ret = ShCompile(compiler, multi, 7, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 920 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 921 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 922 | if (Options & EOptionMemoryLeakMode) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 923 | glslang::OS_DumpMemoryCounters(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 924 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 925 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 926 | delete [] lengths; |
| 927 | FreeFileData(shaderStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 928 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 929 | if (ret == 0) |
| 930 | CompileFailed = true; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 931 | } |
| 932 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 933 | // |
| 934 | // print usage to stdout |
| 935 | // |
| 936 | void usage() |
| 937 | { |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 938 | printf("Usage: glslangValidator [option]... [file]...\n" |
| 939 | "\n" |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 940 | "Where: each 'file' ends in .<stage>, where <stage> is one of\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 941 | " .conf to provide an optional config file that replaces the default configuration\n" |
| 942 | " (see -c option below for generating a template)\n" |
| 943 | " .vert for a vertex shader\n" |
| 944 | " .tesc for a tessellation control shader\n" |
| 945 | " .tese for a tessellation evaluation shader\n" |
| 946 | " .geom for a geometry shader\n" |
| 947 | " .frag for a fragment shader\n" |
| 948 | " .comp for a compute shader\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 949 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 950 | "Compilation warnings and errors will be printed to stdout.\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 951 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 952 | "To get other information, use one of the following options:\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 953 | "Each option must be specified separately.\n" |
| 954 | " -V create SPIR-V binary, under Vulkan semantics; turns on -l;\n" |
| 955 | " default file name is <stage>.spv (-o overrides this)\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 956 | " -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n" |
| 957 | " default file name is <stage>.spv (-o overrides this)\n" |
| 958 | " -H print human readable form of SPIR-V; turns on -V\n" |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 959 | " -E print pre-processed GLSL; cannot be used with -l;\n" |
| 960 | " errors will appear on stderr.\n" |
John Kessenich | e751bca | 2017-03-16 11:20:38 -0600 | [diff] [blame] | 961 | " -S <stage> uses specified stage rather than parsing the file extension\n" |
| 962 | " valid choices for <stage> are vert, tesc, tese, geom, frag, or comp\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 963 | " -c configuration dump;\n" |
| 964 | " creates the default configuration file (redirect to a .conf file)\n" |
John Kessenich | a86836e | 2016-07-09 14:50:57 -0600 | [diff] [blame] | 965 | " -C cascading errors; risks crashes from accumulation of error recoveries\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 966 | " -d default to desktop (#version 110) when there is no shader #version\n" |
| 967 | " (default is ES version 100)\n" |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 968 | " -D input is HLSL\n" |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 969 | " -e specify entry-point name\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 970 | " -h print this usage message\n" |
| 971 | " -i intermediate tree (glslang AST) is printed out\n" |
| 972 | " -l link all input files together to form a single module\n" |
| 973 | " -m memory leak mode\n" |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 974 | " -o <file> save binary to <file>, requires a binary option (e.g., -V)\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 975 | " -q dump reflection query database\n" |
| 976 | " -r relaxed semantic error-checking mode\n" |
| 977 | " -s silent mode\n" |
| 978 | " -t multi-threaded mode\n" |
| 979 | " -v print version strings\n" |
| 980 | " -w suppress warnings (except as required by #extension : warn)\n" |
Johannes van Waveren | 1fd0175 | 2016-05-31 08:39:41 -0500 | [diff] [blame] | 981 | " -x save 32-bit hexadecimal numbers as text, requires a binary option (e.g., -V)\n" |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 982 | "\n" |
| 983 | " --shift-sampler-binding [stage] num set base binding number for samplers\n" |
| 984 | " --ssb [stage] num synonym for --shift-sampler-binding\n" |
| 985 | "\n" |
| 986 | " --shift-texture-binding [stage] num set base binding number for textures\n" |
| 987 | " --stb [stage] num synonym for --shift-texture-binding\n" |
| 988 | "\n" |
steve-lunarg | 9088be4 | 2016-11-01 10:31:42 -0600 | [diff] [blame] | 989 | " --shift-image-binding [stage] num set base binding number for images (uav)\n" |
| 990 | " --sib [stage] num synonym for --shift-image-binding\n" |
| 991 | "\n" |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 992 | " --shift-UBO-binding [stage] num set base binding number for UBOs\n" |
| 993 | " --sub [stage] num synonym for --shift-UBO-binding\n" |
| 994 | "\n" |
steve-lunarg | 932bb5c | 2017-02-21 17:19:08 -0700 | [diff] [blame] | 995 | " --shift-ssbo-binding [stage] num set base binding number for SSBOs\n" |
| 996 | " --sbb [stage] num synonym for --shift-ssbo-binding\n" |
| 997 | "\n" |
steve-lunarg | 7f7c2ed | 2016-09-07 15:20:19 -0600 | [diff] [blame] | 998 | " --auto-map-bindings automatically bind uniform variables without\n" |
| 999 | " explicit bindings.\n" |
| 1000 | " --amb synonym for --auto-map-bindings\n" |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 1001 | "\n" |
steve-lunarg | bc9b765 | 2016-09-29 08:43:22 -0600 | [diff] [blame] | 1002 | " --flatten-uniform-arrays flatten uniform texture & sampler arrays to scalars\n" |
steve-lunarg | e0b9deb | 2016-09-16 13:26:37 -0600 | [diff] [blame] | 1003 | " --fua synonym for --flatten-uniform-arrays\n" |
steve-lunarg | cce8d48 | 2016-10-14 18:36:42 -0600 | [diff] [blame] | 1004 | "\n" |
| 1005 | " --no-storage-format use Unknown image format\n" |
| 1006 | " --nsf synonym for --no-storage-format\n" |
steve-lunarg | f1e0c87 | 2016-10-31 15:13:43 -0600 | [diff] [blame] | 1007 | "\n" |
| 1008 | " --source-entrypoint name the given shader source function is renamed to be the entry point given in -e\n" |
| 1009 | " --sep synonym for --source-entrypoint\n" |
John Kessenich | 906cc21 | 2016-12-09 19:22:20 -0700 | [diff] [blame] | 1010 | "\n" |
| 1011 | " --keep-uncalled don't eliminate uncalled functions when linking\n" |
| 1012 | " --ku synonym for --keep-uncalled\n" |
John Kessenich | 8f674e8 | 2017-02-18 09:45:40 -0700 | [diff] [blame] | 1013 | " --variable-name <name> Creates a C header file that contains a uint32_t array named <name> initialized with the shader binary code.\n" |
| 1014 | " --vn <name> synonym for --variable-name <name>.\n" |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 1015 | ); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1016 | |
| 1017 | exit(EFailUsage); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 1020 | #if !defined _MSC_VER && !defined MINGW_HAS_SECURE_API |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 1021 | |
| 1022 | #include <errno.h> |
| 1023 | |
| 1024 | int fopen_s( |
| 1025 | FILE** pFile, |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 1026 | const char* filename, |
| 1027 | const char* mode |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 1028 | ) |
| 1029 | { |
| 1030 | if (!pFile || !filename || !mode) { |
| 1031 | return EINVAL; |
| 1032 | } |
| 1033 | |
| 1034 | FILE* f = fopen(filename, mode); |
| 1035 | if (! f) { |
| 1036 | if (errno != 0) { |
| 1037 | return errno; |
| 1038 | } else { |
| 1039 | return ENOENT; |
| 1040 | } |
| 1041 | } |
| 1042 | *pFile = f; |
| 1043 | |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
| 1047 | #endif |
| 1048 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1049 | // |
| 1050 | // Malloc a string of sufficient size and read a string into it. |
| 1051 | // |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1052 | char** ReadFileData(const char* fileName) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1053 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1054 | FILE *in = nullptr; |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 1055 | int errorCode = fopen_s(&in, fileName, "r"); |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1056 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1057 | int count = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1058 | const int maxSourceStrings = 5; // for testing splitting shader/tokens across multiple strings |
| 1059 | char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1060 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1061 | if (errorCode || in == nullptr) |
| 1062 | Error("unable to open input file"); |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1063 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1064 | while (fgetc(in) != EOF) |
| 1065 | count++; |
| 1066 | |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1067 | fseek(in, 0, SEEK_SET); |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 1068 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1069 | char *fdata = (char*)malloc(count+2); // freed before return of this function |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1070 | if (! fdata) |
| 1071 | Error("can't allocate memory"); |
| 1072 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1073 | if ((int)fread(fdata, 1, count, in) != count) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1074 | free(fdata); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1075 | Error("can't read input file"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1076 | } |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1077 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1078 | fdata[count] = '\0'; |
| 1079 | fclose(in); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1080 | |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 1081 | if (count == 0) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1082 | // recover from empty file |
| 1083 | return_data[0] = (char*)malloc(count+2); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1084 | return_data[0][0]='\0'; |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 1085 | NumShaderStrings = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1086 | free(fdata); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1087 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1088 | return return_data; |
| 1089 | } else |
| 1090 | NumShaderStrings = 1; // Set to larger than 1 for testing multiple strings |
| 1091 | |
| 1092 | // compute how to split up the file into multiple strings, for testing multiple strings |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1093 | int len = (int)(ceil)((float)count/(float)NumShaderStrings); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1094 | int ptr_len = 0; |
| 1095 | int i = 0; |
| 1096 | while (count > 0) { |
| 1097 | return_data[i] = (char*)malloc(len + 2); // freed in FreeFileData() |
| 1098 | memcpy(return_data[i], fdata + ptr_len, len); |
| 1099 | return_data[i][len] = '\0'; |
| 1100 | count -= len; |
| 1101 | ptr_len += len; |
| 1102 | if (count < len) { |
| 1103 | if (count == 0) { |
| 1104 | NumShaderStrings = i + 1; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1107 | len = count; |
John Kessenich | ecba76f | 2017-01-06 00:34:48 -0700 | [diff] [blame] | 1108 | } |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1109 | ++i; |
| 1110 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1111 | |
| 1112 | free(fdata); |
| 1113 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1114 | return return_data; |
| 1115 | } |
| 1116 | |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 1117 | void FreeFileData(char** data) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1118 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1119 | for(int i = 0; i < NumShaderStrings; i++) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1120 | free(data[i]); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1121 | |
| 1122 | free(data); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 1125 | void InfoLogMsg(const char* msg, const char* name, const int num) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1126 | { |
John Kessenich | fae38ee | 2015-06-10 23:23:12 +0000 | [diff] [blame] | 1127 | if (num >= 0 ) |
| 1128 | printf("#### %s %s %d INFO LOG ####\n", msg, name, num); |
| 1129 | else |
| 1130 | printf("#### %s %s INFO LOG ####\n", msg, name); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1131 | } |