John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1 | // |
| 2 | //Copyright (C) 2002-2005 3Dlabs Inc. Ltd. |
John Kessenich | bd0747d | 2013-02-17 06:01:50 +0000 | [diff] [blame] | 3 | //Copyright (C) 2013 LunarG, Inc. |
| 4 | // |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 5 | //All rights reserved. |
| 6 | // |
| 7 | //Redistribution and use in source and binary forms, with or without |
| 8 | //modification, are permitted provided that the following conditions |
| 9 | //are met: |
| 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 | // |
| 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. |
| 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 | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 49 | #include <string.h> |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 50 | #include <stdlib.h> |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 51 | #include <math.h> |
| 52 | |
baldurk | 876a0e3 | 2015-11-16 18:03:28 +0100 | [diff] [blame] | 53 | #include "../glslang/OSDependent/osinclude.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 54 | |
| 55 | extern "C" { |
| 56 | SH_IMPORT_EXPORT void ShOutputHtml(); |
| 57 | } |
| 58 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 59 | // Command-line options |
| 60 | enum TOptions { |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 61 | EOptionNone = 0x0000, |
| 62 | EOptionIntermediate = 0x0001, |
| 63 | EOptionSuppressInfolog = 0x0002, |
| 64 | EOptionMemoryLeakMode = 0x0004, |
| 65 | EOptionRelaxedErrors = 0x0008, |
| 66 | EOptionGiveWarnings = 0x0010, |
| 67 | EOptionLinkProgram = 0x0020, |
| 68 | EOptionMultiThreaded = 0x0040, |
| 69 | EOptionDumpConfig = 0x0080, |
| 70 | EOptionDumpReflection = 0x0100, |
| 71 | EOptionSuppressWarnings = 0x0200, |
| 72 | EOptionDumpVersions = 0x0400, |
| 73 | EOptionSpv = 0x0800, |
| 74 | EOptionHumanReadableSpv = 0x1000, |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 75 | EOptionVulkanRules = 0x2000, |
| 76 | EOptionDefaultDesktop = 0x4000, |
| 77 | EOptionOutputPreprocessed = 0x8000, |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 78 | EOptionOutputHexadecimal = 0x10000, |
| 79 | EOptionReadHlsl = 0x20000, |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 82 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 83 | // Return codes from main/exit(). |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 84 | // |
| 85 | enum TFailCode { |
| 86 | ESuccess = 0, |
| 87 | EFailUsage, |
| 88 | EFailCompile, |
| 89 | EFailLink, |
| 90 | EFailCompilerCreate, |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 91 | EFailThreadCreate, |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 92 | EFailLinkerCreate |
| 93 | }; |
| 94 | |
| 95 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 96 | // Forward declarations. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 97 | // |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 98 | EShLanguage FindLanguage(const std::string& name); |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 99 | void CompileFile(const char* fileName, ShHandle); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 100 | void usage(); |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 101 | void FreeFileData(char** data); |
| 102 | char** ReadFileData(const char* fileName); |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 103 | void InfoLogMsg(const char* msg, const char* name, const int num); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 104 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 105 | // Globally track if any compile or link failure. |
| 106 | bool CompileFailed = false; |
| 107 | bool LinkFailed = false; |
| 108 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 109 | // Use to test breaking up a single shader file into multiple strings. |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 110 | // Set in ReadFileData(). |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 111 | int NumShaderStrings; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 112 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 113 | TBuiltInResource Resources; |
| 114 | std::string ConfigFile; |
| 115 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 116 | // |
John Kessenich | f0bcb0a | 2016-04-02 13:09:14 -0600 | [diff] [blame] | 117 | // 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] | 118 | // |
| 119 | void ProcessConfigFile() |
John Kessenich | b51f62c | 2013-04-11 16:31:09 +0000 | [diff] [blame] | 120 | { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 121 | char** configStrings = 0; |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 122 | char* config = 0; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 123 | if (ConfigFile.size() > 0) { |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 124 | configStrings = ReadFileData(ConfigFile.c_str()); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 125 | if (configStrings) |
| 126 | config = *configStrings; |
| 127 | else { |
| 128 | printf("Error opening configuration file; will instead use the default configuration\n"); |
| 129 | usage(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (config == 0) { |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 134 | Resources = glslang::DefaultTBuiltInResource; |
| 135 | return; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Lei Zhang | 1b14172 | 2016-05-19 13:50:49 -0400 | [diff] [blame] | 138 | glslang::DecodeResourceLimits(&Resources, config); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 139 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 140 | if (configStrings) |
| 141 | FreeFileData(configStrings); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 142 | else |
| 143 | delete[] config; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 144 | } |
| 145 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 146 | // thread-safe list of shaders to asynchronously grab and compile |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 147 | glslang::TWorklist Worklist; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 148 | |
| 149 | // 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] | 150 | glslang::TWorkItem** Work = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 151 | int NumWorkItems = 0; |
| 152 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 153 | int Options = 0; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 154 | const char* ExecutableName = nullptr; |
| 155 | const char* binaryFileName = nullptr; |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 156 | const char* entryPointName = nullptr; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 157 | |
| 158 | // |
| 159 | // Create the default name for saving a binary if -o is not provided. |
| 160 | // |
| 161 | const char* GetBinaryName(EShLanguage stage) |
| 162 | { |
| 163 | const char* name; |
| 164 | if (binaryFileName == nullptr) { |
| 165 | switch (stage) { |
| 166 | case EShLangVertex: name = "vert.spv"; break; |
| 167 | case EShLangTessControl: name = "tesc.spv"; break; |
| 168 | case EShLangTessEvaluation: name = "tese.spv"; break; |
| 169 | case EShLangGeometry: name = "geom.spv"; break; |
| 170 | case EShLangFragment: name = "frag.spv"; break; |
| 171 | case EShLangCompute: name = "comp.spv"; break; |
| 172 | default: name = "unknown"; break; |
| 173 | } |
| 174 | } else |
| 175 | name = binaryFileName; |
| 176 | |
| 177 | return name; |
| 178 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 179 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 180 | // |
| 181 | // *.conf => this is a config file that can set limits/resources |
| 182 | // |
| 183 | bool SetConfigFile(const std::string& name) |
| 184 | { |
| 185 | if (name.size() < 5) |
| 186 | return false; |
| 187 | |
John Kessenich | 4c70685 | 2013-10-11 16:28:43 +0000 | [diff] [blame] | 188 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 189 | ConfigFile = name; |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | return false; |
| 194 | } |
| 195 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 196 | // |
| 197 | // Give error and exit with failure code. |
| 198 | // |
| 199 | void Error(const char* message) |
| 200 | { |
| 201 | printf("%s: Error %s (use -h for usage)\n", ExecutableName, message); |
| 202 | exit(EFailUsage); |
| 203 | } |
| 204 | |
| 205 | // |
| 206 | // Do all command-line argument parsing. This includes building up the work-items |
| 207 | // to be processed later, and saving all the command-line options. |
| 208 | // |
| 209 | // Does not return (it exits) if command-line is fatally flawed. |
| 210 | // |
| 211 | void ProcessArguments(int argc, char* argv[]) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 212 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 213 | ExecutableName = argv[0]; |
| 214 | 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] | 215 | Work = new glslang::TWorkItem*[NumWorkItems]; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 216 | for (int w = 0; w < NumWorkItems; ++w) |
| 217 | Work[w] = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 218 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 219 | argc--; |
| 220 | argv++; |
| 221 | for (; argc >= 1; argc--, argv++) { |
| 222 | if (argv[0][0] == '-') { |
John Kessenich | 2aa7f3a | 2015-05-15 16:02:07 +0000 | [diff] [blame] | 223 | switch (argv[0][1]) { |
| 224 | case 'H': |
| 225 | Options |= EOptionHumanReadableSpv; |
| 226 | // fall through to -V |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 227 | case 'V': |
| 228 | Options |= EOptionSpv; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 229 | Options |= EOptionVulkanRules; |
| 230 | Options |= EOptionLinkProgram; |
| 231 | break; |
| 232 | case 'G': |
| 233 | Options |= EOptionSpv; |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 234 | Options |= EOptionLinkProgram; |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 235 | break; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 236 | case 'E': |
| 237 | Options |= EOptionOutputPreprocessed; |
| 238 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 239 | case 'c': |
| 240 | Options |= EOptionDumpConfig; |
| 241 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 242 | case 'd': |
John Kessenich | 26ad268 | 2014-08-13 20:17:19 +0000 | [diff] [blame] | 243 | Options |= EOptionDefaultDesktop; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 244 | break; |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 245 | case 'D': |
| 246 | Options |= EOptionReadHlsl; |
| 247 | break; |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 248 | case 'e': |
| 249 | // HLSL todo: entry point handle needs much more sophistication. |
| 250 | // This is okay for one compilation unit with one entry point. |
| 251 | entryPointName = argv[1]; |
| 252 | if (argc > 0) { |
| 253 | argc--; |
| 254 | argv++; |
| 255 | } else |
| 256 | Error("no <entry-point> provided for -e"); |
| 257 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 258 | case 'h': |
| 259 | usage(); |
| 260 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 261 | case 'i': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 262 | Options |= EOptionIntermediate; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 263 | break; |
| 264 | case 'l': |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 265 | Options |= EOptionLinkProgram; |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 266 | break; |
| 267 | case 'm': |
| 268 | Options |= EOptionMemoryLeakMode; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 269 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 270 | case 'o': |
| 271 | binaryFileName = argv[1]; |
| 272 | if (argc > 0) { |
| 273 | argc--; |
| 274 | argv++; |
| 275 | } else |
| 276 | Error("no <file> provided for -o"); |
| 277 | break; |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 278 | case 'q': |
| 279 | Options |= EOptionDumpReflection; |
| 280 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 281 | case 'r': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 282 | Options |= EOptionRelaxedErrors; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 283 | break; |
| 284 | case 's': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 285 | Options |= EOptionSuppressInfolog; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 286 | break; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 287 | case 't': |
| 288 | #ifdef _WIN32 |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 289 | Options |= EOptionMultiThreaded; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 290 | #endif |
| 291 | break; |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 292 | case 'v': |
| 293 | Options |= EOptionDumpVersions; |
| 294 | break; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 295 | case 'w': |
| 296 | Options |= EOptionSuppressWarnings; |
| 297 | break; |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 298 | case 'x': |
| 299 | Options |= EOptionOutputHexadecimal; |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 300 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 301 | default: |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 302 | usage(); |
| 303 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 304 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 305 | } else { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 306 | std::string name(argv[0]); |
| 307 | if (! SetConfigFile(name)) { |
| 308 | Work[argc] = new glslang::TWorkItem(name); |
| 309 | Worklist.add(Work[argc]); |
| 310 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 311 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 312 | } |
| 313 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 314 | // Make sure that -E is not specified alongside linking (which includes SPV generation) |
| 315 | if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram)) |
| 316 | Error("can't use -E when linking is selected"); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 317 | |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 318 | // -o or -x makes no sense if there is no target binary |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 319 | if (binaryFileName && (Options & EOptionSpv) == 0) |
| 320 | Error("no binary generation requested (e.g., -V)"); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 321 | } |
| 322 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 323 | // |
| 324 | // Translate the meaningful subset of command-line options to parser-behavior options. |
| 325 | // |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 326 | void SetMessageOptions(EShMessages& messages) |
| 327 | { |
| 328 | if (Options & EOptionRelaxedErrors) |
| 329 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 330 | if (Options & EOptionIntermediate) |
| 331 | messages = (EShMessages)(messages | EShMsgAST); |
| 332 | if (Options & EOptionSuppressWarnings) |
| 333 | messages = (EShMessages)(messages | EShMsgSuppressWarnings); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 334 | if (Options & EOptionSpv) |
| 335 | messages = (EShMessages)(messages | EShMsgSpvRules); |
| 336 | if (Options & EOptionVulkanRules) |
| 337 | messages = (EShMessages)(messages | EShMsgVulkanRules); |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 338 | if (Options & EOptionOutputPreprocessed) |
| 339 | messages = (EShMessages)(messages | EShMsgOnlyPreprocessor); |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 340 | if (Options & EOptionReadHlsl) |
| 341 | messages = (EShMessages)(messages | EShMsgReadHlsl); |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 342 | } |
| 343 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 344 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 345 | // Thread entry point, for non-linking asynchronous mode. |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 346 | // |
| 347 | // Return 0 for failure, 1 for success. |
| 348 | // |
Pyry Haulos | 5f6892e | 2015-12-01 12:59:53 -0800 | [diff] [blame] | 349 | unsigned int CompileShaders(void*) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 350 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 351 | glslang::TWorkItem* workItem; |
| 352 | while (Worklist.remove(workItem)) { |
| 353 | ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 354 | if (compiler == 0) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 355 | return 0; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 356 | |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 357 | CompileFile(workItem->name.c_str(), compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 358 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 359 | if (! (Options & EOptionSuppressInfolog)) |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 360 | workItem->results = ShGetInfoLog(compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 361 | |
| 362 | ShDestruct(compiler); |
| 363 | } |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 368 | // Outputs the given string, but only if it is non-null and non-empty. |
| 369 | // This prevents erroneous newlines from appearing. |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 370 | void PutsIfNonEmpty(const char* str) |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 371 | { |
| 372 | if (str && str[0]) { |
| 373 | puts(str); |
| 374 | } |
| 375 | } |
| 376 | |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 377 | // Outputs the given string to stderr, but only if it is non-null and non-empty. |
| 378 | // This prevents erroneous newlines from appearing. |
| 379 | void StderrIfNonEmpty(const char* str) |
| 380 | { |
| 381 | if (str && str[0]) { |
| 382 | fprintf(stderr, "%s\n", str); |
| 383 | } |
| 384 | } |
| 385 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 386 | // Simple bundling of what makes a compilation unit for ease in passing around, |
| 387 | // and separation of handling file IO versus API (programmatic) compilation. |
| 388 | struct ShaderCompUnit { |
| 389 | EShLanguage stage; |
| 390 | std::string fileName; |
| 391 | char** text; // memory owned/managed externally |
| 392 | }; |
| 393 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 394 | // |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 395 | // For linking mode: Will independently parse each compilation unit, but then put them |
| 396 | // in the same program and link them together, making at most one linked module per |
| 397 | // pipeline stage. |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 398 | // |
| 399 | // Uses the new C++ interface instead of the old handle-based interface. |
| 400 | // |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 401 | |
| 402 | void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits) |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 403 | { |
| 404 | // keep track of what to free |
| 405 | std::list<glslang::TShader*> shaders; |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 406 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 407 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 408 | SetMessageOptions(messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 409 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 410 | // |
| 411 | // Per-shader processing... |
| 412 | // |
| 413 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 414 | glslang::TProgram& program = *new glslang::TProgram; |
rdb | 32084e8 | 2016-02-23 22:17:38 +0100 | [diff] [blame] | 415 | for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) { |
| 416 | const auto &compUnit = *it; |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 417 | glslang::TShader* shader = new glslang::TShader(compUnit.stage); |
| 418 | shader->setStrings(compUnit.text, 1); |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 419 | if (entryPointName) // HLSL todo: this needs to be tracked per compUnits |
| 420 | shader->setEntryPoint(entryPointName); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 421 | shaders.push_back(shader); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 422 | |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 423 | const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 424 | |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 425 | if (Options & EOptionOutputPreprocessed) { |
| 426 | std::string str; |
Andrew Woloszyn | a132af5 | 2016-03-07 13:23:09 -0500 | [diff] [blame] | 427 | glslang::TShader::ForbidInclude includer; |
Dejan Mircevski | 7be4b82 | 2015-06-17 11:40:33 -0400 | [diff] [blame] | 428 | if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, |
Andrew Woloszyn | a132af5 | 2016-03-07 13:23:09 -0500 | [diff] [blame] | 429 | messages, &str, includer)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 430 | PutsIfNonEmpty(str.c_str()); |
| 431 | } else { |
| 432 | CompileFailed = true; |
| 433 | } |
| 434 | StderrIfNonEmpty(shader->getInfoLog()); |
| 435 | StderrIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 436 | continue; |
| 437 | } |
| 438 | if (! shader->parse(&Resources, defaultVersion, false, messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 439 | CompileFailed = true; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 440 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 441 | program.addShader(shader); |
| 442 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 443 | if (! (Options & EOptionSuppressInfolog) && |
| 444 | ! (Options & EOptionMemoryLeakMode)) { |
| 445 | PutsIfNonEmpty(compUnit.fileName.c_str()); |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 446 | PutsIfNonEmpty(shader->getInfoLog()); |
| 447 | PutsIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 448 | } |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // |
| 452 | // Program-level processing... |
| 453 | // |
| 454 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 455 | // Link |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 456 | if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 457 | LinkFailed = true; |
| 458 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 459 | // Report |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 460 | if (! (Options & EOptionSuppressInfolog) && |
| 461 | ! (Options & EOptionMemoryLeakMode)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 462 | PutsIfNonEmpty(program.getInfoLog()); |
| 463 | PutsIfNonEmpty(program.getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 464 | } |
| 465 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 466 | // Reflect |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 467 | if (Options & EOptionDumpReflection) { |
| 468 | program.buildReflection(); |
| 469 | program.dumpReflection(); |
| 470 | } |
| 471 | |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 472 | // Dump SPIR-V |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 473 | if (Options & EOptionSpv) { |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 474 | if (CompileFailed || LinkFailed) |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 475 | printf("SPIR-V is not generated for failed compile or link\n"); |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 476 | else { |
| 477 | for (int stage = 0; stage < EShLangCount; ++stage) { |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 478 | if (program.getIntermediate((EShLanguage)stage)) { |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 479 | std::vector<unsigned int> spirv; |
Lei Zhang | 09caf12 | 2016-05-02 18:11:54 -0400 | [diff] [blame] | 480 | std::string warningsErrors; |
Lei Zhang | 17535f7 | 2016-05-04 15:55:59 -0400 | [diff] [blame] | 481 | spv::SpvBuildLogger logger; |
| 482 | glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv, &logger); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 483 | |
| 484 | // Dump the spv to a file or stdout, etc., but only if not doing |
| 485 | // memory/perf testing, as it's not internal to programmatic use. |
| 486 | if (! (Options & EOptionMemoryLeakMode)) { |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 487 | printf("%s", logger.getAllMessages().c_str()); |
| 488 | if (Options & EOptionOutputHexadecimal) { |
| 489 | glslang::OutputSpvHex(spirv, GetBinaryName((EShLanguage)stage)); |
| 490 | } else { |
| 491 | glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); |
| 492 | } |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 493 | if (Options & EOptionHumanReadableSpv) { |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 494 | spv::Disassemble(std::cout, spirv); |
| 495 | } |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 496 | } |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 497 | } |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 502 | // Free everything up, program has to go before the shaders |
| 503 | // because it might have merged stuff from the shaders, and |
| 504 | // the stuff from the shaders has to have its destructors called |
| 505 | // before the pools holding the memory in the shaders is freed. |
| 506 | delete &program; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 507 | while (shaders.size() > 0) { |
| 508 | delete shaders.back(); |
| 509 | shaders.pop_back(); |
| 510 | } |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 511 | } |
| 512 | |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 513 | // |
| 514 | // Do file IO part of compile and link, handing off the pure |
| 515 | // API/programmatic mode to CompileAndLinkShaderUnits(), which can |
| 516 | // be put in a loop for testing memory footprint and performance. |
| 517 | // |
| 518 | // This is just for linking mode: meaning all the shaders will be put into the |
| 519 | // the same program linked together. |
| 520 | // |
| 521 | // This means there are a limited number of work items (not multi-threading mode) |
| 522 | // and that the point is testing at the linking level. Hence, to enable |
| 523 | // performance and memory testing, the actual compile/link can be put in |
| 524 | // a loop, independent of processing the work items and file IO. |
| 525 | // |
| 526 | void CompileAndLinkShaderFiles() |
| 527 | { |
| 528 | std::vector<ShaderCompUnit> compUnits; |
| 529 | |
| 530 | // Transfer all the work items from to a simple list of |
| 531 | // of compilation units. (We don't care about the thread |
| 532 | // work-item distribution properties in this path, which |
| 533 | // is okay due to the limited number of shaders, know since |
| 534 | // they are all getting linked together.) |
| 535 | glslang::TWorkItem* workItem; |
| 536 | while (Worklist.remove(workItem)) { |
| 537 | ShaderCompUnit compUnit = { |
| 538 | FindLanguage(workItem->name), |
| 539 | workItem->name, |
| 540 | ReadFileData(workItem->name.c_str()) |
| 541 | }; |
| 542 | |
| 543 | if (! compUnit.text) { |
| 544 | usage(); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | compUnits.push_back(compUnit); |
| 549 | } |
| 550 | |
| 551 | // Actual call to programmatic processing of compile and link, |
| 552 | // in a loop for testing memory and performance. This part contains |
| 553 | // all the perf/memory that a programmatic consumer will care about. |
| 554 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 555 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) |
| 556 | CompileAndLinkShaderUnits(compUnits); |
| 557 | |
| 558 | if (Options & EOptionMemoryLeakMode) |
| 559 | glslang::OS_DumpMemoryCounters(); |
| 560 | } |
| 561 | |
rdb | 32084e8 | 2016-02-23 22:17:38 +0100 | [diff] [blame] | 562 | for (auto it = compUnits.begin(); it != compUnits.end(); ++it) |
| 563 | FreeFileData(it->text); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 564 | } |
| 565 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 566 | int C_DECL main(int argc, char* argv[]) |
| 567 | { |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 568 | ProcessArguments(argc, argv); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 569 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 570 | if (Options & EOptionDumpConfig) { |
Lei Zhang | 414eb60 | 2016-03-04 16:22:34 -0500 | [diff] [blame] | 571 | printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str()); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 572 | if (Worklist.empty()) |
| 573 | return ESuccess; |
| 574 | } |
| 575 | |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 576 | if (Options & EOptionDumpVersions) { |
| 577 | printf("Glslang Version: %s %s\n", GLSLANG_REVISION, GLSLANG_DATE); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 578 | printf("ESSL Version: %s\n", glslang::GetEsslVersionString()); |
| 579 | printf("GLSL Version: %s\n", glslang::GetGlslVersionString()); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 580 | std::string spirvVersion; |
| 581 | glslang::GetSpirvVersion(spirvVersion); |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 582 | printf("SPIR-V Version %s\n", spirvVersion.c_str()); |
John Kessenich | 5e4b124 | 2015-08-06 22:53:06 -0600 | [diff] [blame] | 583 | printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision); |
John Kessenich | 55e7d11 | 2015-11-15 21:33:39 -0700 | [diff] [blame] | 584 | printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId()); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 585 | if (Worklist.empty()) |
| 586 | return ESuccess; |
| 587 | } |
| 588 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 589 | if (Worklist.empty()) { |
| 590 | usage(); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | ProcessConfigFile(); |
| 594 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 595 | // |
| 596 | // Two modes: |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 597 | // 1) linking all arguments together, single-threaded, new C++ interface |
| 598 | // 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] | 599 | // |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 600 | if (Options & EOptionLinkProgram || |
| 601 | Options & EOptionOutputPreprocessed) { |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 602 | glslang::InitializeProcess(); |
John Kessenich | c57b2a9 | 2016-01-16 15:30:03 -0700 | [diff] [blame] | 603 | CompileAndLinkShaderFiles(); |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 604 | glslang::FinalizeProcess(); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 605 | for (int w = 0; w < NumWorkItems; ++w) { |
| 606 | if (Work[w]) { |
| 607 | delete Work[w]; |
| 608 | } |
| 609 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 610 | } else { |
| 611 | ShInitialize(); |
| 612 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 613 | bool printShaderNames = Worklist.size() > 1; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 614 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 615 | if (Options & EOptionMultiThreaded) { |
| 616 | const int NumThreads = 16; |
| 617 | void* threads[NumThreads]; |
| 618 | for (int t = 0; t < NumThreads; ++t) { |
| 619 | threads[t] = glslang::OS_CreateThread(&CompileShaders); |
| 620 | if (! threads[t]) { |
| 621 | printf("Failed to create thread\n"); |
| 622 | return EFailThreadCreate; |
| 623 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 624 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 625 | glslang::OS_WaitForAllThreads(threads, NumThreads); |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 626 | } else |
| 627 | CompileShaders(0); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 628 | |
| 629 | // Print out all the resulting infologs |
| 630 | for (int w = 0; w < NumWorkItems; ++w) { |
| 631 | if (Work[w]) { |
Kenneth Perry | b07e6be | 2015-12-15 10:52:34 -0600 | [diff] [blame] | 632 | if (printShaderNames || Work[w]->results.size() > 0) |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 633 | PutsIfNonEmpty(Work[w]->name.c_str()); |
| 634 | PutsIfNonEmpty(Work[w]->results.c_str()); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 635 | delete Work[w]; |
| 636 | } |
| 637 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 638 | |
| 639 | ShFinalize(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 640 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 641 | |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame] | 642 | delete[] Work; |
| 643 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 644 | if (CompileFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 645 | return EFailCompile; |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 646 | if (LinkFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 647 | return EFailLink; |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | // |
| 653 | // Deduce the language from the filename. Files must end in one of the |
| 654 | // following extensions: |
| 655 | // |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 656 | // .vert = vertex |
| 657 | // .tesc = tessellation control |
| 658 | // .tese = tessellation evaluation |
| 659 | // .geom = geometry |
| 660 | // .frag = fragment |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 661 | // .comp = compute |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 662 | // |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 663 | EShLanguage FindLanguage(const std::string& name) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 664 | { |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 665 | size_t ext = name.rfind('.'); |
| 666 | if (ext == std::string::npos) { |
| 667 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 668 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 669 | } |
| 670 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 671 | std::string suffix = name.substr(ext + 1, std::string::npos); |
| 672 | if (suffix == "vert") |
| 673 | return EShLangVertex; |
| 674 | else if (suffix == "tesc") |
| 675 | return EShLangTessControl; |
| 676 | else if (suffix == "tese") |
| 677 | return EShLangTessEvaluation; |
| 678 | else if (suffix == "geom") |
| 679 | return EShLangGeometry; |
| 680 | else if (suffix == "frag") |
| 681 | return EShLangFragment; |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 682 | else if (suffix == "comp") |
| 683 | return EShLangCompute; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 684 | |
| 685 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 686 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 687 | } |
| 688 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 689 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 690 | // Read a file's data into a string, and compile it using the old interface ShCompile, |
| 691 | // for non-linkable results. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 692 | // |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 693 | void CompileFile(const char* fileName, ShHandle compiler) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 694 | { |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 695 | int ret = 0; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 696 | char** shaderStrings = ReadFileData(fileName); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 697 | if (! shaderStrings) { |
| 698 | usage(); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 699 | } |
| 700 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 701 | int* lengths = new int[NumShaderStrings]; |
| 702 | |
| 703 | // move to length-based strings, rather than null-terminated strings |
| 704 | for (int s = 0; s < NumShaderStrings; ++s) |
John Kessenich | 35f04bd | 2014-02-19 02:47:20 +0000 | [diff] [blame] | 705 | lengths[s] = (int)strlen(shaderStrings[s]); |
John Kessenich | 09da79e | 2013-04-17 19:34:23 +0000 | [diff] [blame] | 706 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 707 | if (! shaderStrings) { |
| 708 | CompileFailed = true; |
| 709 | return; |
| 710 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 711 | |
John Kessenich | 52ac67e | 2013-05-05 23:46:22 +0000 | [diff] [blame] | 712 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 713 | SetMessageOptions(messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 714 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 715 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 716 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) { |
John Kessenich | 26ad268 | 2014-08-13 20:17:19 +0000 | [diff] [blame] | 717 | //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] | 718 | ret = ShCompile(compiler, shaderStrings, NumShaderStrings, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 719 | //const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err", |
| 720 | // "or should be l", "ine 1", "string 5\n", "float glo", "bal", |
| 721 | // ";\n#error should be line 2\n void main() {", "global = 2.3;}" }; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 722 | //const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 723 | //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] | 724 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 725 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 726 | if (Options & EOptionMemoryLeakMode) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 727 | glslang::OS_DumpMemoryCounters(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 728 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 729 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 730 | delete [] lengths; |
| 731 | FreeFileData(shaderStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 732 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 733 | if (ret == 0) |
| 734 | CompileFailed = true; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 735 | } |
| 736 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 737 | // |
| 738 | // print usage to stdout |
| 739 | // |
| 740 | void usage() |
| 741 | { |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 742 | printf("Usage: glslangValidator [option]... [file]...\n" |
| 743 | "\n" |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 744 | "Where: each 'file' ends in .<stage>, where <stage> is one of\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 745 | " .conf to provide an optional config file that replaces the default configuration\n" |
| 746 | " (see -c option below for generating a template)\n" |
| 747 | " .vert for a vertex shader\n" |
| 748 | " .tesc for a tessellation control shader\n" |
| 749 | " .tese for a tessellation evaluation shader\n" |
| 750 | " .geom for a geometry shader\n" |
| 751 | " .frag for a fragment shader\n" |
| 752 | " .comp for a compute shader\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 753 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 754 | "Compilation warnings and errors will be printed to stdout.\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 755 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 756 | "To get other information, use one of the following options:\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 757 | "Each option must be specified separately.\n" |
| 758 | " -V create SPIR-V binary, under Vulkan semantics; turns on -l;\n" |
| 759 | " default file name is <stage>.spv (-o overrides this)\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 760 | " -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n" |
| 761 | " default file name is <stage>.spv (-o overrides this)\n" |
| 762 | " -H print human readable form of SPIR-V; turns on -V\n" |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 763 | " -E print pre-processed GLSL; cannot be used with -l;\n" |
| 764 | " errors will appear on stderr.\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 765 | " -c configuration dump;\n" |
| 766 | " creates the default configuration file (redirect to a .conf file)\n" |
| 767 | " -d default to desktop (#version 110) when there is no shader #version\n" |
| 768 | " (default is ES version 100)\n" |
John Kessenich | 66e2faf | 2016-03-12 18:34:36 -0700 | [diff] [blame] | 769 | " -D input is HLSL\n" |
John Kessenich | 4d65ee3 | 2016-03-12 18:17:47 -0700 | [diff] [blame] | 770 | " -e specify entry-point name\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 771 | " -h print this usage message\n" |
| 772 | " -i intermediate tree (glslang AST) is printed out\n" |
| 773 | " -l link all input files together to form a single module\n" |
| 774 | " -m memory leak mode\n" |
Johannes van Waveren | ecb0f3b | 2016-05-27 12:55:53 -0500 | [diff] [blame] | 775 | " -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] | 776 | " -q dump reflection query database\n" |
| 777 | " -r relaxed semantic error-checking mode\n" |
| 778 | " -s silent mode\n" |
| 779 | " -t multi-threaded mode\n" |
| 780 | " -v print version strings\n" |
| 781 | " -w suppress warnings (except as required by #extension : warn)\n" |
Johannes van Waveren | 1fd0175 | 2016-05-31 08:39:41 -0500 | [diff] [blame^] | 782 | " -x save 32-bit hexadecimal numbers as text, requires a binary option (e.g., -V)\n" |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 783 | ); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 784 | |
| 785 | exit(EFailUsage); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 786 | } |
| 787 | |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 788 | #if !defined _MSC_VER && !defined MINGW_HAS_SECURE_API |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 789 | |
| 790 | #include <errno.h> |
| 791 | |
| 792 | int fopen_s( |
| 793 | FILE** pFile, |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 794 | const char* filename, |
| 795 | const char* mode |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 796 | ) |
| 797 | { |
| 798 | if (!pFile || !filename || !mode) { |
| 799 | return EINVAL; |
| 800 | } |
| 801 | |
| 802 | FILE* f = fopen(filename, mode); |
| 803 | if (! f) { |
| 804 | if (errno != 0) { |
| 805 | return errno; |
| 806 | } else { |
| 807 | return ENOENT; |
| 808 | } |
| 809 | } |
| 810 | *pFile = f; |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | #endif |
| 816 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 817 | // |
| 818 | // Malloc a string of sufficient size and read a string into it. |
| 819 | // |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 820 | char** ReadFileData(const char* fileName) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 821 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 822 | FILE *in = nullptr; |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 823 | int errorCode = fopen_s(&in, fileName, "r"); |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 824 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 825 | int count = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 826 | const int maxSourceStrings = 5; // for testing splitting shader/tokens across multiple strings |
| 827 | char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 828 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 829 | if (errorCode || in == nullptr) |
| 830 | Error("unable to open input file"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 831 | |
| 832 | while (fgetc(in) != EOF) |
| 833 | count++; |
| 834 | |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 835 | fseek(in, 0, SEEK_SET); |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 836 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 837 | char *fdata = (char*)malloc(count+2); // freed before return of this function |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 838 | if (! fdata) |
| 839 | Error("can't allocate memory"); |
| 840 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 841 | if ((int)fread(fdata, 1, count, in) != count) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 842 | free(fdata); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 843 | Error("can't read input file"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 844 | } |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 845 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 846 | fdata[count] = '\0'; |
| 847 | fclose(in); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 848 | |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 849 | if (count == 0) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 850 | // recover from empty file |
| 851 | return_data[0] = (char*)malloc(count+2); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 852 | return_data[0][0]='\0'; |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 853 | NumShaderStrings = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 854 | free(fdata); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 855 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 856 | return return_data; |
| 857 | } else |
| 858 | NumShaderStrings = 1; // Set to larger than 1 for testing multiple strings |
| 859 | |
| 860 | // 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] | 861 | int len = (int)(ceil)((float)count/(float)NumShaderStrings); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 862 | int ptr_len = 0; |
| 863 | int i = 0; |
| 864 | while (count > 0) { |
| 865 | return_data[i] = (char*)malloc(len + 2); // freed in FreeFileData() |
| 866 | memcpy(return_data[i], fdata + ptr_len, len); |
| 867 | return_data[i][len] = '\0'; |
| 868 | count -= len; |
| 869 | ptr_len += len; |
| 870 | if (count < len) { |
| 871 | if (count == 0) { |
| 872 | NumShaderStrings = i + 1; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 873 | break; |
| 874 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 875 | len = count; |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 876 | } |
| 877 | ++i; |
| 878 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 879 | |
| 880 | free(fdata); |
| 881 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 882 | return return_data; |
| 883 | } |
| 884 | |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 885 | void FreeFileData(char** data) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 886 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 887 | for(int i = 0; i < NumShaderStrings; i++) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 888 | free(data[i]); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 889 | |
| 890 | free(data); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 891 | } |
| 892 | |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 893 | void InfoLogMsg(const char* msg, const char* name, const int num) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 894 | { |
John Kessenich | fae38ee | 2015-06-10 23:23:12 +0000 | [diff] [blame] | 895 | if (num >= 0 ) |
| 896 | printf("#### %s %s %d INFO LOG ####\n", msg, name, num); |
| 897 | else |
| 898 | printf("#### %s %s INFO LOG ####\n", msg, name); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 899 | } |