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