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 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 40 | #include "Worklist.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 41 | #include "./../glslang/Include/ShHandle.h" |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 42 | #include "./../glslang/Include/revision.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 43 | #include "./../glslang/Public/ShaderLang.h" |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 44 | #include "../SPIRV/GlslangToSpv.h" |
John Kessenich | 5e4b124 | 2015-08-06 22:53:06 -0600 | [diff] [blame] | 45 | #include "../SPIRV/GLSL.std.450.h" |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 46 | #include "../SPIRV/doc.h" |
| 47 | #include "../SPIRV/disassemble.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 48 | #include <string.h> |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 49 | #include <stdlib.h> |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 50 | #include <math.h> |
| 51 | |
baldurk | 876a0e3 | 2015-11-16 18:03:28 +0100 | [diff] [blame] | 52 | #include "../glslang/OSDependent/osinclude.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 53 | |
| 54 | extern "C" { |
| 55 | SH_IMPORT_EXPORT void ShOutputHtml(); |
| 56 | } |
| 57 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 58 | // Command-line options |
| 59 | enum TOptions { |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 60 | EOptionNone = 0x0000, |
| 61 | EOptionIntermediate = 0x0001, |
| 62 | EOptionSuppressInfolog = 0x0002, |
| 63 | EOptionMemoryLeakMode = 0x0004, |
| 64 | EOptionRelaxedErrors = 0x0008, |
| 65 | EOptionGiveWarnings = 0x0010, |
| 66 | EOptionLinkProgram = 0x0020, |
| 67 | EOptionMultiThreaded = 0x0040, |
| 68 | EOptionDumpConfig = 0x0080, |
| 69 | EOptionDumpReflection = 0x0100, |
| 70 | EOptionSuppressWarnings = 0x0200, |
| 71 | EOptionDumpVersions = 0x0400, |
| 72 | EOptionSpv = 0x0800, |
| 73 | EOptionHumanReadableSpv = 0x1000, |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 74 | EOptionVulkanRules = 0x2000, |
| 75 | EOptionDefaultDesktop = 0x4000, |
| 76 | EOptionOutputPreprocessed = 0x8000, |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 79 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 80 | // Return codes from main/exit(). |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 81 | // |
| 82 | enum TFailCode { |
| 83 | ESuccess = 0, |
| 84 | EFailUsage, |
| 85 | EFailCompile, |
| 86 | EFailLink, |
| 87 | EFailCompilerCreate, |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 88 | EFailThreadCreate, |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 89 | EFailLinkerCreate |
| 90 | }; |
| 91 | |
| 92 | // |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 93 | // Forward declarations. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 94 | // |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 95 | EShLanguage FindLanguage(const std::string& name); |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 96 | void CompileFile(const char* fileName, ShHandle); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 97 | void usage(); |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 98 | void FreeFileData(char** data); |
| 99 | char** ReadFileData(const char* fileName); |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 100 | void InfoLogMsg(const char* msg, const char* name, const int num); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 101 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 102 | // Globally track if any compile or link failure. |
| 103 | bool CompileFailed = false; |
| 104 | bool LinkFailed = false; |
| 105 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 106 | // Use to test breaking up a single shader file into multiple strings. |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 107 | // Set in ReadFileData(). |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 108 | int NumShaderStrings; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 109 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 110 | TBuiltInResource Resources; |
| 111 | std::string ConfigFile; |
| 112 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 113 | // |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 114 | // These are the default resources for TBuiltInResources, used for both |
| 115 | // - parsing this string for the case where the user didn't supply one |
| 116 | // - dumping out a template for user construction of a config file |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 117 | // |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 118 | const char* DefaultConfig = |
| 119 | "MaxLights 32\n" |
| 120 | "MaxClipPlanes 6\n" |
| 121 | "MaxTextureUnits 32\n" |
| 122 | "MaxTextureCoords 32\n" |
| 123 | "MaxVertexAttribs 64\n" |
| 124 | "MaxVertexUniformComponents 4096\n" |
| 125 | "MaxVaryingFloats 64\n" |
| 126 | "MaxVertexTextureImageUnits 32\n" |
John Kessenich | 623833f | 2013-12-11 18:57:40 +0000 | [diff] [blame] | 127 | "MaxCombinedTextureImageUnits 80\n" |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 128 | "MaxTextureImageUnits 32\n" |
| 129 | "MaxFragmentUniformComponents 4096\n" |
| 130 | "MaxDrawBuffers 32\n" |
| 131 | "MaxVertexUniformVectors 128\n" |
| 132 | "MaxVaryingVectors 8\n" |
| 133 | "MaxFragmentUniformVectors 16\n" |
| 134 | "MaxVertexOutputVectors 16\n" |
| 135 | "MaxFragmentInputVectors 15\n" |
| 136 | "MinProgramTexelOffset -8\n" |
| 137 | "MaxProgramTexelOffset 7\n" |
| 138 | "MaxClipDistances 8\n" |
| 139 | "MaxComputeWorkGroupCountX 65535\n" |
| 140 | "MaxComputeWorkGroupCountY 65535\n" |
| 141 | "MaxComputeWorkGroupCountZ 65535\n" |
| 142 | "MaxComputeWorkGroupSizeX 1024\n" |
John Kessenich | da66bc7 | 2014-08-19 20:32:48 +0000 | [diff] [blame] | 143 | "MaxComputeWorkGroupSizeY 1024\n" |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 144 | "MaxComputeWorkGroupSizeZ 64\n" |
| 145 | "MaxComputeUniformComponents 1024\n" |
| 146 | "MaxComputeTextureImageUnits 16\n" |
| 147 | "MaxComputeImageUniforms 8\n" |
| 148 | "MaxComputeAtomicCounters 8\n" |
| 149 | "MaxComputeAtomicCounterBuffers 1\n" |
| 150 | "MaxVaryingComponents 60\n" |
| 151 | "MaxVertexOutputComponents 64\n" |
| 152 | "MaxGeometryInputComponents 64\n" |
| 153 | "MaxGeometryOutputComponents 128\n" |
| 154 | "MaxFragmentInputComponents 128\n" |
| 155 | "MaxImageUnits 8\n" |
| 156 | "MaxCombinedImageUnitsAndFragmentOutputs 8\n" |
John Kessenich | ddea678 | 2014-08-10 18:19:36 +0000 | [diff] [blame] | 157 | "MaxCombinedShaderOutputResources 8\n" |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 158 | "MaxImageSamples 0\n" |
| 159 | "MaxVertexImageUniforms 0\n" |
| 160 | "MaxTessControlImageUniforms 0\n" |
| 161 | "MaxTessEvaluationImageUniforms 0\n" |
| 162 | "MaxGeometryImageUniforms 0\n" |
| 163 | "MaxFragmentImageUniforms 8\n" |
| 164 | "MaxCombinedImageUniforms 8\n" |
| 165 | "MaxGeometryTextureImageUnits 16\n" |
| 166 | "MaxGeometryOutputVertices 256\n" |
| 167 | "MaxGeometryTotalOutputComponents 1024\n" |
| 168 | "MaxGeometryUniformComponents 1024\n" |
| 169 | "MaxGeometryVaryingComponents 64\n" |
| 170 | "MaxTessControlInputComponents 128\n" |
| 171 | "MaxTessControlOutputComponents 128\n" |
| 172 | "MaxTessControlTextureImageUnits 16\n" |
| 173 | "MaxTessControlUniformComponents 1024\n" |
| 174 | "MaxTessControlTotalOutputComponents 4096\n" |
| 175 | "MaxTessEvaluationInputComponents 128\n" |
| 176 | "MaxTessEvaluationOutputComponents 128\n" |
| 177 | "MaxTessEvaluationTextureImageUnits 16\n" |
| 178 | "MaxTessEvaluationUniformComponents 1024\n" |
| 179 | "MaxTessPatchComponents 120\n" |
| 180 | "MaxPatchVertices 32\n" |
| 181 | "MaxTessGenLevel 64\n" |
| 182 | "MaxViewports 16\n" |
| 183 | "MaxVertexAtomicCounters 0\n" |
| 184 | "MaxTessControlAtomicCounters 0\n" |
| 185 | "MaxTessEvaluationAtomicCounters 0\n" |
| 186 | "MaxGeometryAtomicCounters 0\n" |
| 187 | "MaxFragmentAtomicCounters 8\n" |
| 188 | "MaxCombinedAtomicCounters 8\n" |
| 189 | "MaxAtomicCounterBindings 1\n" |
| 190 | "MaxVertexAtomicCounterBuffers 0\n" |
| 191 | "MaxTessControlAtomicCounterBuffers 0\n" |
| 192 | "MaxTessEvaluationAtomicCounterBuffers 0\n" |
| 193 | "MaxGeometryAtomicCounterBuffers 0\n" |
| 194 | "MaxFragmentAtomicCounterBuffers 1\n" |
| 195 | "MaxCombinedAtomicCounterBuffers 1\n" |
| 196 | "MaxAtomicCounterBufferSize 16384\n" |
John Kessenich | c7776ec | 2014-01-26 01:37:13 +0000 | [diff] [blame] | 197 | "MaxTransformFeedbackBuffers 4\n" |
| 198 | "MaxTransformFeedbackInterleavedComponents 64\n" |
John Kessenich | 6996841 | 2014-08-13 06:37:59 +0000 | [diff] [blame] | 199 | "MaxCullDistances 8\n" |
| 200 | "MaxCombinedClipAndCullDistances 8\n" |
John Kessenich | cd77f8e | 2014-08-13 16:54:02 +0000 | [diff] [blame] | 201 | "MaxSamples 4\n" |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 202 | |
| 203 | "nonInductiveForLoops 1\n" |
| 204 | "whileLoops 1\n" |
| 205 | "doWhileLoops 1\n" |
| 206 | "generalUniformIndexing 1\n" |
| 207 | "generalAttributeMatrixVectorIndexing 1\n" |
| 208 | "generalVaryingIndexing 1\n" |
| 209 | "generalSamplerIndexing 1\n" |
| 210 | "generalVariableIndexing 1\n" |
| 211 | "generalConstantMatrixVectorIndexing 1\n" |
| 212 | ; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 213 | |
| 214 | // |
| 215 | // Parse either a .conf file provided by the user or the default string above. |
| 216 | // |
| 217 | void ProcessConfigFile() |
John Kessenich | b51f62c | 2013-04-11 16:31:09 +0000 | [diff] [blame] | 218 | { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 219 | char** configStrings = 0; |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 220 | char* config = 0; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 221 | if (ConfigFile.size() > 0) { |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 222 | configStrings = ReadFileData(ConfigFile.c_str()); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 223 | if (configStrings) |
| 224 | config = *configStrings; |
| 225 | else { |
| 226 | printf("Error opening configuration file; will instead use the default configuration\n"); |
| 227 | usage(); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if (config == 0) { |
John Kessenich | 6494baf | 2014-02-19 00:08:59 +0000 | [diff] [blame] | 232 | config = new char[strlen(DefaultConfig) + 1]; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 233 | strcpy(config, DefaultConfig); |
| 234 | } |
| 235 | |
| 236 | const char* delims = " \t\n\r"; |
| 237 | const char* token = strtok(config, delims); |
| 238 | while (token) { |
| 239 | const char* valueStr = strtok(0, delims); |
| 240 | if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) { |
| 241 | printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : ""); |
| 242 | return; |
| 243 | } |
| 244 | int value = atoi(valueStr); |
| 245 | |
| 246 | if (strcmp(token, "MaxLights") == 0) |
| 247 | Resources.maxLights = value; |
| 248 | else if (strcmp(token, "MaxClipPlanes") == 0) |
| 249 | Resources.maxClipPlanes = value; |
| 250 | else if (strcmp(token, "MaxTextureUnits") == 0) |
| 251 | Resources.maxTextureUnits = value; |
| 252 | else if (strcmp(token, "MaxTextureCoords") == 0) |
| 253 | Resources.maxTextureCoords = value; |
| 254 | else if (strcmp(token, "MaxVertexAttribs") == 0) |
| 255 | Resources.maxVertexAttribs = value; |
| 256 | else if (strcmp(token, "MaxVertexUniformComponents") == 0) |
| 257 | Resources.maxVertexUniformComponents = value; |
| 258 | else if (strcmp(token, "MaxVaryingFloats") == 0) |
| 259 | Resources.maxVaryingFloats = value; |
| 260 | else if (strcmp(token, "MaxVertexTextureImageUnits") == 0) |
| 261 | Resources.maxVertexTextureImageUnits = value; |
| 262 | else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0) |
| 263 | Resources.maxCombinedTextureImageUnits = value; |
| 264 | else if (strcmp(token, "MaxTextureImageUnits") == 0) |
| 265 | Resources.maxTextureImageUnits = value; |
| 266 | else if (strcmp(token, "MaxFragmentUniformComponents") == 0) |
| 267 | Resources.maxFragmentUniformComponents = value; |
| 268 | else if (strcmp(token, "MaxDrawBuffers") == 0) |
| 269 | Resources.maxDrawBuffers = value; |
| 270 | else if (strcmp(token, "MaxVertexUniformVectors") == 0) |
| 271 | Resources.maxVertexUniformVectors = value; |
| 272 | else if (strcmp(token, "MaxVaryingVectors") == 0) |
| 273 | Resources.maxVaryingVectors = value; |
| 274 | else if (strcmp(token, "MaxFragmentUniformVectors") == 0) |
| 275 | Resources.maxFragmentUniformVectors = value; |
| 276 | else if (strcmp(token, "MaxVertexOutputVectors") == 0) |
| 277 | Resources.maxVertexOutputVectors = value; |
| 278 | else if (strcmp(token, "MaxFragmentInputVectors") == 0) |
| 279 | Resources.maxFragmentInputVectors = value; |
| 280 | else if (strcmp(token, "MinProgramTexelOffset") == 0) |
| 281 | Resources.minProgramTexelOffset = value; |
| 282 | else if (strcmp(token, "MaxProgramTexelOffset") == 0) |
| 283 | Resources.maxProgramTexelOffset = value; |
John Kessenich | e7c59c1 | 2013-10-16 22:28:35 +0000 | [diff] [blame] | 284 | else if (strcmp(token, "MaxClipDistances") == 0) |
| 285 | Resources.maxClipDistances = value; |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 286 | else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0) |
| 287 | Resources.maxComputeWorkGroupCountX = value; |
| 288 | else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0) |
| 289 | Resources.maxComputeWorkGroupCountY = value; |
| 290 | else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0) |
| 291 | Resources.maxComputeWorkGroupCountZ = value; |
| 292 | else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0) |
| 293 | Resources.maxComputeWorkGroupSizeX = value; |
| 294 | else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0) |
| 295 | Resources.maxComputeWorkGroupSizeY = value; |
| 296 | else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0) |
| 297 | Resources.maxComputeWorkGroupSizeZ = value; |
| 298 | else if (strcmp(token, "MaxComputeUniformComponents") == 0) |
| 299 | Resources.maxComputeUniformComponents = value; |
| 300 | else if (strcmp(token, "MaxComputeTextureImageUnits") == 0) |
| 301 | Resources.maxComputeTextureImageUnits = value; |
| 302 | else if (strcmp(token, "MaxComputeImageUniforms") == 0) |
| 303 | Resources.maxComputeImageUniforms = value; |
| 304 | else if (strcmp(token, "MaxComputeAtomicCounters") == 0) |
| 305 | Resources.maxComputeAtomicCounters = value; |
| 306 | else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0) |
| 307 | Resources.maxComputeAtomicCounterBuffers = value; |
| 308 | else if (strcmp(token, "MaxVaryingComponents") == 0) |
| 309 | Resources.maxVaryingComponents = value; |
| 310 | else if (strcmp(token, "MaxVertexOutputComponents") == 0) |
| 311 | Resources.maxVertexOutputComponents = value; |
| 312 | else if (strcmp(token, "MaxGeometryInputComponents") == 0) |
| 313 | Resources.maxGeometryInputComponents = value; |
| 314 | else if (strcmp(token, "MaxGeometryOutputComponents") == 0) |
| 315 | Resources.maxGeometryOutputComponents = value; |
| 316 | else if (strcmp(token, "MaxFragmentInputComponents") == 0) |
| 317 | Resources.maxFragmentInputComponents = value; |
| 318 | else if (strcmp(token, "MaxImageUnits") == 0) |
| 319 | Resources.maxImageUnits = value; |
| 320 | else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0) |
| 321 | Resources.maxCombinedImageUnitsAndFragmentOutputs = value; |
John Kessenich | ddea678 | 2014-08-10 18:19:36 +0000 | [diff] [blame] | 322 | else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0) |
| 323 | Resources.maxCombinedShaderOutputResources = value; |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 324 | else if (strcmp(token, "MaxImageSamples") == 0) |
| 325 | Resources.maxImageSamples = value; |
| 326 | else if (strcmp(token, "MaxVertexImageUniforms") == 0) |
| 327 | Resources.maxVertexImageUniforms = value; |
| 328 | else if (strcmp(token, "MaxTessControlImageUniforms") == 0) |
| 329 | Resources.maxTessControlImageUniforms = value; |
| 330 | else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0) |
| 331 | Resources.maxTessEvaluationImageUniforms = value; |
| 332 | else if (strcmp(token, "MaxGeometryImageUniforms") == 0) |
| 333 | Resources.maxGeometryImageUniforms = value; |
| 334 | else if (strcmp(token, "MaxFragmentImageUniforms") == 0) |
| 335 | Resources.maxFragmentImageUniforms = value; |
| 336 | else if (strcmp(token, "MaxCombinedImageUniforms") == 0) |
| 337 | Resources.maxCombinedImageUniforms = value; |
| 338 | else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0) |
| 339 | Resources.maxGeometryTextureImageUnits = value; |
| 340 | else if (strcmp(token, "MaxGeometryOutputVertices") == 0) |
| 341 | Resources.maxGeometryOutputVertices = value; |
| 342 | else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0) |
| 343 | Resources.maxGeometryTotalOutputComponents = value; |
| 344 | else if (strcmp(token, "MaxGeometryUniformComponents") == 0) |
| 345 | Resources.maxGeometryUniformComponents = value; |
| 346 | else if (strcmp(token, "MaxGeometryVaryingComponents") == 0) |
| 347 | Resources.maxGeometryVaryingComponents = value; |
| 348 | else if (strcmp(token, "MaxTessControlInputComponents") == 0) |
| 349 | Resources.maxTessControlInputComponents = value; |
| 350 | else if (strcmp(token, "MaxTessControlOutputComponents") == 0) |
| 351 | Resources.maxTessControlOutputComponents = value; |
| 352 | else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0) |
| 353 | Resources.maxTessControlTextureImageUnits = value; |
| 354 | else if (strcmp(token, "MaxTessControlUniformComponents") == 0) |
| 355 | Resources.maxTessControlUniformComponents = value; |
| 356 | else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0) |
| 357 | Resources.maxTessControlTotalOutputComponents = value; |
| 358 | else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0) |
| 359 | Resources.maxTessEvaluationInputComponents = value; |
| 360 | else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0) |
| 361 | Resources.maxTessEvaluationOutputComponents = value; |
| 362 | else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0) |
| 363 | Resources.maxTessEvaluationTextureImageUnits = value; |
| 364 | else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0) |
| 365 | Resources.maxTessEvaluationUniformComponents = value; |
| 366 | else if (strcmp(token, "MaxTessPatchComponents") == 0) |
| 367 | Resources.maxTessPatchComponents = value; |
| 368 | else if (strcmp(token, "MaxPatchVertices") == 0) |
| 369 | Resources.maxPatchVertices = value; |
| 370 | else if (strcmp(token, "MaxTessGenLevel") == 0) |
| 371 | Resources.maxTessGenLevel = value; |
| 372 | else if (strcmp(token, "MaxViewports") == 0) |
| 373 | Resources.maxViewports = value; |
| 374 | else if (strcmp(token, "MaxVertexAtomicCounters") == 0) |
| 375 | Resources.maxVertexAtomicCounters = value; |
| 376 | else if (strcmp(token, "MaxTessControlAtomicCounters") == 0) |
| 377 | Resources.maxTessControlAtomicCounters = value; |
| 378 | else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0) |
| 379 | Resources.maxTessEvaluationAtomicCounters = value; |
| 380 | else if (strcmp(token, "MaxGeometryAtomicCounters") == 0) |
| 381 | Resources.maxGeometryAtomicCounters = value; |
| 382 | else if (strcmp(token, "MaxFragmentAtomicCounters") == 0) |
| 383 | Resources.maxFragmentAtomicCounters = value; |
| 384 | else if (strcmp(token, "MaxCombinedAtomicCounters") == 0) |
| 385 | Resources.maxCombinedAtomicCounters = value; |
| 386 | else if (strcmp(token, "MaxAtomicCounterBindings") == 0) |
| 387 | Resources.maxAtomicCounterBindings = value; |
| 388 | else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0) |
| 389 | Resources.maxVertexAtomicCounterBuffers = value; |
| 390 | else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0) |
| 391 | Resources.maxTessControlAtomicCounterBuffers = value; |
| 392 | else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0) |
| 393 | Resources.maxTessEvaluationAtomicCounterBuffers = value; |
| 394 | else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0) |
| 395 | Resources.maxGeometryAtomicCounterBuffers = value; |
| 396 | else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0) |
| 397 | Resources.maxFragmentAtomicCounterBuffers = value; |
| 398 | else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0) |
| 399 | Resources.maxCombinedAtomicCounterBuffers = value; |
| 400 | else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0) |
| 401 | Resources.maxAtomicCounterBufferSize = value; |
John Kessenich | c7776ec | 2014-01-26 01:37:13 +0000 | [diff] [blame] | 402 | else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0) |
| 403 | Resources.maxTransformFeedbackBuffers = value; |
| 404 | else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0) |
| 405 | Resources.maxTransformFeedbackInterleavedComponents = value; |
John Kessenich | 6996841 | 2014-08-13 06:37:59 +0000 | [diff] [blame] | 406 | else if (strcmp(token, "MaxCullDistances") == 0) |
| 407 | Resources.maxCullDistances = value; |
| 408 | else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0) |
| 409 | Resources.maxCombinedClipAndCullDistances = value; |
John Kessenich | cd77f8e | 2014-08-13 16:54:02 +0000 | [diff] [blame] | 410 | else if (strcmp(token, "MaxSamples") == 0) |
| 411 | Resources.maxSamples = value; |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame] | 412 | |
John Kessenich | a5830df | 2013-10-02 05:10:48 +0000 | [diff] [blame] | 413 | else if (strcmp(token, "nonInductiveForLoops") == 0) |
| 414 | Resources.limits.nonInductiveForLoops = (value != 0); |
| 415 | else if (strcmp(token, "whileLoops") == 0) |
| 416 | Resources.limits.whileLoops = (value != 0); |
| 417 | else if (strcmp(token, "doWhileLoops") == 0) |
| 418 | Resources.limits.doWhileLoops = (value != 0); |
| 419 | else if (strcmp(token, "generalUniformIndexing") == 0) |
| 420 | Resources.limits.generalUniformIndexing = (value != 0); |
| 421 | else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0) |
| 422 | Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0); |
| 423 | else if (strcmp(token, "generalVaryingIndexing") == 0) |
| 424 | Resources.limits.generalVaryingIndexing = (value != 0); |
| 425 | else if (strcmp(token, "generalSamplerIndexing") == 0) |
| 426 | Resources.limits.generalSamplerIndexing = (value != 0); |
| 427 | else if (strcmp(token, "generalVariableIndexing") == 0) |
| 428 | Resources.limits.generalVariableIndexing = (value != 0); |
| 429 | else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0) |
| 430 | Resources.limits.generalConstantMatrixVectorIndexing = (value != 0); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 431 | else |
| 432 | printf("Warning: unrecognized limit (%s) in configuration file.\n", token); |
| 433 | |
| 434 | token = strtok(0, delims); |
| 435 | } |
| 436 | if (configStrings) |
| 437 | FreeFileData(configStrings); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame^] | 438 | else |
| 439 | delete[] config; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 440 | } |
| 441 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 442 | // thread-safe list of shaders to asynchronously grab and compile |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 443 | glslang::TWorklist Worklist; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 444 | |
| 445 | // 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] | 446 | glslang::TWorkItem** Work = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 447 | int NumWorkItems = 0; |
| 448 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 449 | int Options = 0; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 450 | const char* ExecutableName = nullptr; |
| 451 | const char* binaryFileName = nullptr; |
| 452 | |
| 453 | // |
| 454 | // Create the default name for saving a binary if -o is not provided. |
| 455 | // |
| 456 | const char* GetBinaryName(EShLanguage stage) |
| 457 | { |
| 458 | const char* name; |
| 459 | if (binaryFileName == nullptr) { |
| 460 | switch (stage) { |
| 461 | case EShLangVertex: name = "vert.spv"; break; |
| 462 | case EShLangTessControl: name = "tesc.spv"; break; |
| 463 | case EShLangTessEvaluation: name = "tese.spv"; break; |
| 464 | case EShLangGeometry: name = "geom.spv"; break; |
| 465 | case EShLangFragment: name = "frag.spv"; break; |
| 466 | case EShLangCompute: name = "comp.spv"; break; |
| 467 | default: name = "unknown"; break; |
| 468 | } |
| 469 | } else |
| 470 | name = binaryFileName; |
| 471 | |
| 472 | return name; |
| 473 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 474 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 475 | // |
| 476 | // *.conf => this is a config file that can set limits/resources |
| 477 | // |
| 478 | bool SetConfigFile(const std::string& name) |
| 479 | { |
| 480 | if (name.size() < 5) |
| 481 | return false; |
| 482 | |
John Kessenich | 4c70685 | 2013-10-11 16:28:43 +0000 | [diff] [blame] | 483 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 484 | ConfigFile = name; |
| 485 | return true; |
| 486 | } |
| 487 | |
| 488 | return false; |
| 489 | } |
| 490 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 491 | // |
| 492 | // Give error and exit with failure code. |
| 493 | // |
| 494 | void Error(const char* message) |
| 495 | { |
| 496 | printf("%s: Error %s (use -h for usage)\n", ExecutableName, message); |
| 497 | exit(EFailUsage); |
| 498 | } |
| 499 | |
| 500 | // |
| 501 | // Do all command-line argument parsing. This includes building up the work-items |
| 502 | // to be processed later, and saving all the command-line options. |
| 503 | // |
| 504 | // Does not return (it exits) if command-line is fatally flawed. |
| 505 | // |
| 506 | void ProcessArguments(int argc, char* argv[]) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 507 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 508 | ExecutableName = argv[0]; |
| 509 | 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] | 510 | Work = new glslang::TWorkItem*[NumWorkItems]; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 511 | for (int w = 0; w < NumWorkItems; ++w) |
| 512 | Work[w] = 0; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 513 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 514 | argc--; |
| 515 | argv++; |
| 516 | for (; argc >= 1; argc--, argv++) { |
| 517 | if (argv[0][0] == '-') { |
John Kessenich | 2aa7f3a | 2015-05-15 16:02:07 +0000 | [diff] [blame] | 518 | switch (argv[0][1]) { |
| 519 | case 'H': |
| 520 | Options |= EOptionHumanReadableSpv; |
| 521 | // fall through to -V |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 522 | case 'V': |
| 523 | Options |= EOptionSpv; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 524 | Options |= EOptionVulkanRules; |
| 525 | Options |= EOptionLinkProgram; |
| 526 | break; |
| 527 | case 'G': |
| 528 | Options |= EOptionSpv; |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 529 | Options |= EOptionLinkProgram; |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 530 | break; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 531 | case 'E': |
| 532 | Options |= EOptionOutputPreprocessed; |
| 533 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 534 | case 'c': |
| 535 | Options |= EOptionDumpConfig; |
| 536 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 537 | case 'd': |
John Kessenich | 26ad268 | 2014-08-13 20:17:19 +0000 | [diff] [blame] | 538 | Options |= EOptionDefaultDesktop; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 539 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 540 | case 'h': |
| 541 | usage(); |
| 542 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 543 | case 'i': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 544 | Options |= EOptionIntermediate; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 545 | break; |
| 546 | case 'l': |
John Kessenich | d78e351 | 2014-08-25 20:07:55 +0000 | [diff] [blame] | 547 | Options |= EOptionLinkProgram; |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 548 | break; |
| 549 | case 'm': |
| 550 | Options |= EOptionMemoryLeakMode; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 551 | break; |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 552 | case 'o': |
| 553 | binaryFileName = argv[1]; |
| 554 | if (argc > 0) { |
| 555 | argc--; |
| 556 | argv++; |
| 557 | } else |
| 558 | Error("no <file> provided for -o"); |
| 559 | break; |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 560 | case 'q': |
| 561 | Options |= EOptionDumpReflection; |
| 562 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 563 | case 'r': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 564 | Options |= EOptionRelaxedErrors; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 565 | break; |
| 566 | case 's': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 567 | Options |= EOptionSuppressInfolog; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 568 | break; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 569 | case 't': |
| 570 | #ifdef _WIN32 |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 571 | Options |= EOptionMultiThreaded; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 572 | #endif |
| 573 | break; |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 574 | case 'v': |
| 575 | Options |= EOptionDumpVersions; |
| 576 | break; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 577 | case 'w': |
| 578 | Options |= EOptionSuppressWarnings; |
| 579 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 580 | default: |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 581 | usage(); |
| 582 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 583 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 584 | } else { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 585 | std::string name(argv[0]); |
| 586 | if (! SetConfigFile(name)) { |
| 587 | Work[argc] = new glslang::TWorkItem(name); |
| 588 | Worklist.add(Work[argc]); |
| 589 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 590 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 591 | } |
| 592 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 593 | // Make sure that -E is not specified alongside linking (which includes SPV generation) |
| 594 | if ((Options & EOptionOutputPreprocessed) && (Options & EOptionLinkProgram)) |
| 595 | Error("can't use -E when linking is selected"); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 596 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 597 | // -o makes no sense if there is no target binary |
| 598 | if (binaryFileName && (Options & EOptionSpv) == 0) |
| 599 | Error("no binary generation requested (e.g., -V)"); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 600 | } |
| 601 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 602 | // |
| 603 | // Translate the meaningful subset of command-line options to parser-behavior options. |
| 604 | // |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 605 | void SetMessageOptions(EShMessages& messages) |
| 606 | { |
| 607 | if (Options & EOptionRelaxedErrors) |
| 608 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 609 | if (Options & EOptionIntermediate) |
| 610 | messages = (EShMessages)(messages | EShMsgAST); |
| 611 | if (Options & EOptionSuppressWarnings) |
| 612 | messages = (EShMessages)(messages | EShMsgSuppressWarnings); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 613 | if (Options & EOptionSpv) |
| 614 | messages = (EShMessages)(messages | EShMsgSpvRules); |
| 615 | if (Options & EOptionVulkanRules) |
| 616 | messages = (EShMessages)(messages | EShMsgVulkanRules); |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 617 | if (Options & EOptionOutputPreprocessed) |
| 618 | messages = (EShMessages)(messages | EShMsgOnlyPreprocessor); |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 619 | } |
| 620 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 621 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 622 | // Thread entry point, for non-linking asynchronous mode. |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 623 | // |
| 624 | // Return 0 for failure, 1 for success. |
| 625 | // |
Pyry Haulos | 5f6892e | 2015-12-01 12:59:53 -0800 | [diff] [blame] | 626 | unsigned int CompileShaders(void*) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 627 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 628 | glslang::TWorkItem* workItem; |
| 629 | while (Worklist.remove(workItem)) { |
| 630 | ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 631 | if (compiler == 0) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 632 | return 0; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 633 | |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 634 | CompileFile(workItem->name.c_str(), compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 635 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 636 | if (! (Options & EOptionSuppressInfolog)) |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 637 | workItem->results = ShGetInfoLog(compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 638 | |
| 639 | ShDestruct(compiler); |
| 640 | } |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 645 | // Outputs the given string, but only if it is non-null and non-empty. |
| 646 | // This prevents erroneous newlines from appearing. |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 647 | void PutsIfNonEmpty(const char* str) |
John Kessenich | 6626cad | 2015-06-19 05:14:19 +0000 | [diff] [blame] | 648 | { |
| 649 | if (str && str[0]) { |
| 650 | puts(str); |
| 651 | } |
| 652 | } |
| 653 | |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 654 | // Outputs the given string to stderr, but only if it is non-null and non-empty. |
| 655 | // This prevents erroneous newlines from appearing. |
| 656 | void StderrIfNonEmpty(const char* str) |
| 657 | { |
| 658 | if (str && str[0]) { |
| 659 | fprintf(stderr, "%s\n", str); |
| 660 | } |
| 661 | } |
| 662 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 663 | // |
| 664 | // For linking mode: Will independently parse each item in the worklist, but then put them |
| 665 | // in the same program and link them together. |
| 666 | // |
| 667 | // Uses the new C++ interface instead of the old handle-based interface. |
| 668 | // |
| 669 | void CompileAndLinkShaders() |
| 670 | { |
| 671 | // keep track of what to free |
| 672 | std::list<glslang::TShader*> shaders; |
John Kessenich | bf63ef0 | 2013-11-14 00:16:43 +0000 | [diff] [blame] | 673 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 674 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 675 | SetMessageOptions(messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 676 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 677 | // |
| 678 | // Per-shader processing... |
| 679 | // |
| 680 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 681 | glslang::TProgram& program = *new glslang::TProgram; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 682 | glslang::TWorkItem* workItem; |
| 683 | while (Worklist.remove(workItem)) { |
| 684 | EShLanguage stage = FindLanguage(workItem->name); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 685 | glslang::TShader* shader = new glslang::TShader(stage); |
| 686 | shaders.push_back(shader); |
| 687 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 688 | char** shaderStrings = ReadFileData(workItem->name.c_str()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 689 | if (! shaderStrings) { |
| 690 | usage(); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 691 | delete &program; |
| 692 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 693 | return; |
| 694 | } |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 695 | const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 696 | |
| 697 | shader->setStrings(shaderStrings, 1); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 698 | if (Options & EOptionOutputPreprocessed) { |
| 699 | std::string str; |
Dejan Mircevski | 7be4b82 | 2015-06-17 11:40:33 -0400 | [diff] [blame] | 700 | if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, |
| 701 | messages, &str, glslang::TShader::ForbidInclude())) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 702 | PutsIfNonEmpty(str.c_str()); |
| 703 | } else { |
| 704 | CompileFailed = true; |
| 705 | } |
| 706 | StderrIfNonEmpty(shader->getInfoLog()); |
| 707 | StderrIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 708 | FreeFileData(shaderStrings); |
| 709 | continue; |
| 710 | } |
| 711 | if (! shader->parse(&Resources, defaultVersion, false, messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 712 | CompileFailed = true; |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 713 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 714 | program.addShader(shader); |
| 715 | |
| 716 | if (! (Options & EOptionSuppressInfolog)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 717 | PutsIfNonEmpty(workItem->name.c_str()); |
| 718 | PutsIfNonEmpty(shader->getInfoLog()); |
| 719 | PutsIfNonEmpty(shader->getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | FreeFileData(shaderStrings); |
| 723 | } |
| 724 | |
| 725 | // |
| 726 | // Program-level processing... |
| 727 | // |
| 728 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 729 | if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages)) |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 730 | LinkFailed = true; |
| 731 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 732 | if (! (Options & EOptionSuppressInfolog)) { |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 733 | PutsIfNonEmpty(program.getInfoLog()); |
| 734 | PutsIfNonEmpty(program.getInfoDebugLog()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 735 | } |
| 736 | |
John Kessenich | 11f9fc7 | 2013-11-07 01:06:34 +0000 | [diff] [blame] | 737 | if (Options & EOptionDumpReflection) { |
| 738 | program.buildReflection(); |
| 739 | program.dumpReflection(); |
| 740 | } |
| 741 | |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 742 | if (Options & EOptionSpv) { |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 743 | if (CompileFailed || LinkFailed) |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 744 | printf("SPIR-V is not generated for failed compile or link\n"); |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 745 | else { |
| 746 | for (int stage = 0; stage < EShLangCount; ++stage) { |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 747 | if (program.getIntermediate((EShLanguage)stage)) { |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 748 | std::vector<unsigned int> spirv; |
| 749 | glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 750 | glslang::OutputSpv(spirv, GetBinaryName((EShLanguage)stage)); |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 751 | if (Options & EOptionHumanReadableSpv) { |
| 752 | spv::Parameterize(); |
John Kessenich | acba772 | 2015-03-04 03:48:38 +0000 | [diff] [blame] | 753 | spv::Disassemble(std::cout, spirv); |
| 754 | } |
John Kessenich | a7a68a9 | 2014-08-24 18:21:00 +0000 | [diff] [blame] | 755 | } |
John Kessenich | 92f9038 | 2014-07-28 04:21:04 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
John Kessenich | 5b0f13a | 2013-11-01 03:08:40 +0000 | [diff] [blame] | 760 | // Free everything up, program has to go before the shaders |
| 761 | // because it might have merged stuff from the shaders, and |
| 762 | // the stuff from the shaders has to have its destructors called |
| 763 | // before the pools holding the memory in the shaders is freed. |
| 764 | delete &program; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 765 | while (shaders.size() > 0) { |
| 766 | delete shaders.back(); |
| 767 | shaders.pop_back(); |
| 768 | } |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 769 | } |
| 770 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 771 | int C_DECL main(int argc, char* argv[]) |
| 772 | { |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 773 | ProcessArguments(argc, argv); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 774 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 775 | if (Options & EOptionDumpConfig) { |
| 776 | printf("%s", DefaultConfig); |
| 777 | if (Worklist.empty()) |
| 778 | return ESuccess; |
| 779 | } |
| 780 | |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 781 | if (Options & EOptionDumpVersions) { |
| 782 | printf("Glslang Version: %s %s\n", GLSLANG_REVISION, GLSLANG_DATE); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 783 | printf("ESSL Version: %s\n", glslang::GetEsslVersionString()); |
| 784 | printf("GLSL Version: %s\n", glslang::GetGlslVersionString()); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 785 | std::string spirvVersion; |
| 786 | glslang::GetSpirvVersion(spirvVersion); |
John Kessenich | 0da9eaa | 2015-08-01 17:10:02 -0600 | [diff] [blame] | 787 | printf("SPIR-V Version %s\n", spirvVersion.c_str()); |
John Kessenich | 5e4b124 | 2015-08-06 22:53:06 -0600 | [diff] [blame] | 788 | printf("GLSL.std.450 Version %d, Revision %d\n", GLSLstd450Version, GLSLstd450Revision); |
John Kessenich | 55e7d11 | 2015-11-15 21:33:39 -0700 | [diff] [blame] | 789 | printf("Khronos Tool ID %d\n", glslang::GetKhronosToolId()); |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 790 | if (Worklist.empty()) |
| 791 | return ESuccess; |
| 792 | } |
| 793 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 794 | if (Worklist.empty()) { |
| 795 | usage(); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | ProcessConfigFile(); |
| 799 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 800 | // |
| 801 | // Two modes: |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 802 | // 1) linking all arguments together, single-threaded, new C++ interface |
| 803 | // 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] | 804 | // |
John Kessenich | c555ddd | 2015-06-17 02:38:44 +0000 | [diff] [blame] | 805 | if (Options & EOptionLinkProgram || |
| 806 | Options & EOptionOutputPreprocessed) { |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 807 | glslang::InitializeProcess(); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 808 | CompileAndLinkShaders(); |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 809 | glslang::FinalizeProcess(); |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame^] | 810 | for (int w = 0; w < NumWorkItems; ++w) { |
| 811 | if (Work[w]) { |
| 812 | delete Work[w]; |
| 813 | } |
| 814 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 815 | } else { |
| 816 | ShInitialize(); |
| 817 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 818 | bool printShaderNames = Worklist.size() > 1; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 819 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 820 | if (Options & EOptionMultiThreaded) { |
| 821 | const int NumThreads = 16; |
| 822 | void* threads[NumThreads]; |
| 823 | for (int t = 0; t < NumThreads; ++t) { |
| 824 | threads[t] = glslang::OS_CreateThread(&CompileShaders); |
| 825 | if (! threads[t]) { |
| 826 | printf("Failed to create thread\n"); |
| 827 | return EFailThreadCreate; |
| 828 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 829 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 830 | glslang::OS_WaitForAllThreads(threads, NumThreads); |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 831 | } else |
| 832 | CompileShaders(0); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 833 | |
| 834 | // Print out all the resulting infologs |
| 835 | for (int w = 0; w < NumWorkItems; ++w) { |
| 836 | if (Work[w]) { |
Kenneth Perry | b07e6be | 2015-12-15 10:52:34 -0600 | [diff] [blame] | 837 | if (printShaderNames || Work[w]->results.size() > 0) |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 838 | PutsIfNonEmpty(Work[w]->name.c_str()); |
| 839 | PutsIfNonEmpty(Work[w]->results.c_str()); |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 840 | delete Work[w]; |
| 841 | } |
| 842 | } |
John Kessenich | c36e1d8 | 2013-11-01 17:41:52 +0000 | [diff] [blame] | 843 | |
| 844 | ShFinalize(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 845 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 846 | |
Andrew Woloszyn | b891c2b | 2016-01-18 09:26:25 -0500 | [diff] [blame^] | 847 | delete[] Work; |
| 848 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 849 | if (CompileFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 850 | return EFailCompile; |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 851 | if (LinkFailed) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 852 | return EFailLink; |
| 853 | |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | // |
| 858 | // Deduce the language from the filename. Files must end in one of the |
| 859 | // following extensions: |
| 860 | // |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 861 | // .vert = vertex |
| 862 | // .tesc = tessellation control |
| 863 | // .tese = tessellation evaluation |
| 864 | // .geom = geometry |
| 865 | // .frag = fragment |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 866 | // .comp = compute |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 867 | // |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 868 | EShLanguage FindLanguage(const std::string& name) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 869 | { |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 870 | size_t ext = name.rfind('.'); |
| 871 | if (ext == std::string::npos) { |
| 872 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 873 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 874 | } |
| 875 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 876 | std::string suffix = name.substr(ext + 1, std::string::npos); |
| 877 | if (suffix == "vert") |
| 878 | return EShLangVertex; |
| 879 | else if (suffix == "tesc") |
| 880 | return EShLangTessControl; |
| 881 | else if (suffix == "tese") |
| 882 | return EShLangTessEvaluation; |
| 883 | else if (suffix == "geom") |
| 884 | return EShLangGeometry; |
| 885 | else if (suffix == "frag") |
| 886 | return EShLangFragment; |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 887 | else if (suffix == "comp") |
| 888 | return EShLangCompute; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 889 | |
| 890 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 891 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 892 | } |
| 893 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 894 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 895 | // Read a file's data into a string, and compile it using the old interface ShCompile, |
| 896 | // for non-linkable results. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 897 | // |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 898 | void CompileFile(const char* fileName, ShHandle compiler) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 899 | { |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 900 | int ret = 0; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 901 | char** shaderStrings = ReadFileData(fileName); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 902 | if (! shaderStrings) { |
| 903 | usage(); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 904 | } |
| 905 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 906 | int* lengths = new int[NumShaderStrings]; |
| 907 | |
| 908 | // move to length-based strings, rather than null-terminated strings |
| 909 | for (int s = 0; s < NumShaderStrings; ++s) |
John Kessenich | 35f04bd | 2014-02-19 02:47:20 +0000 | [diff] [blame] | 910 | lengths[s] = (int)strlen(shaderStrings[s]); |
John Kessenich | 09da79e | 2013-04-17 19:34:23 +0000 | [diff] [blame] | 911 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 912 | if (! shaderStrings) { |
| 913 | CompileFailed = true; |
| 914 | return; |
| 915 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 916 | |
John Kessenich | 52ac67e | 2013-05-05 23:46:22 +0000 | [diff] [blame] | 917 | EShMessages messages = EShMsgDefault; |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 918 | SetMessageOptions(messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 919 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 920 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 921 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) { |
John Kessenich | 26ad268 | 2014-08-13 20:17:19 +0000 | [diff] [blame] | 922 | //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] | 923 | 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] | 924 | //const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err", |
| 925 | // "or should be l", "ine 1", "string 5\n", "float glo", "bal", |
| 926 | // ";\n#error should be line 2\n void main() {", "global = 2.3;}" }; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 927 | //const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 928 | //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] | 929 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 930 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 931 | if (Options & EOptionMemoryLeakMode) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 932 | glslang::OS_DumpMemoryCounters(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 933 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 934 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 935 | delete [] lengths; |
| 936 | FreeFileData(shaderStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 937 | |
John Kessenich | c999ba2 | 2013-11-07 23:33:24 +0000 | [diff] [blame] | 938 | if (ret == 0) |
| 939 | CompileFailed = true; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 940 | } |
| 941 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 942 | // |
| 943 | // print usage to stdout |
| 944 | // |
| 945 | void usage() |
| 946 | { |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 947 | printf("Usage: glslangValidator [option]... [file]...\n" |
| 948 | "\n" |
John Kessenich | 0df0cde | 2015-03-03 17:09:43 +0000 | [diff] [blame] | 949 | "Where: each 'file' ends in .<stage>, where <stage> is one of\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 950 | " .conf to provide an optional config file that replaces the default configuration\n" |
| 951 | " (see -c option below for generating a template)\n" |
| 952 | " .vert for a vertex shader\n" |
| 953 | " .tesc for a tessellation control shader\n" |
| 954 | " .tese for a tessellation evaluation shader\n" |
| 955 | " .geom for a geometry shader\n" |
| 956 | " .frag for a fragment shader\n" |
| 957 | " .comp for a compute shader\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 958 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 959 | "Compilation warnings and errors will be printed to stdout.\n" |
John Kessenich | 319de23 | 2013-12-04 04:43:40 +0000 | [diff] [blame] | 960 | "\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 961 | "To get other information, use one of the following options:\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 962 | "Each option must be specified separately.\n" |
| 963 | " -V create SPIR-V binary, under Vulkan semantics; turns on -l;\n" |
| 964 | " default file name is <stage>.spv (-o overrides this)\n" |
| 965 | " (unless -o is specified, which overrides the default file name)\n" |
| 966 | " -G create SPIR-V binary, under OpenGL semantics; turns on -l;\n" |
| 967 | " default file name is <stage>.spv (-o overrides this)\n" |
| 968 | " -H print human readable form of SPIR-V; turns on -V\n" |
Andrew Woloszyn | aae1ad8 | 2015-06-24 17:00:46 -0400 | [diff] [blame] | 969 | " -E print pre-processed GLSL; cannot be used with -l;\n" |
| 970 | " errors will appear on stderr.\n" |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 971 | " -c configuration dump;\n" |
| 972 | " creates the default configuration file (redirect to a .conf file)\n" |
| 973 | " -d default to desktop (#version 110) when there is no shader #version\n" |
| 974 | " (default is ES version 100)\n" |
| 975 | " -h print this usage message\n" |
| 976 | " -i intermediate tree (glslang AST) is printed out\n" |
| 977 | " -l link all input files together to form a single module\n" |
| 978 | " -m memory leak mode\n" |
| 979 | " -o <file> save binary into <file>, requires a binary option (e.g., -V)\n" |
| 980 | " -q dump reflection query database\n" |
| 981 | " -r relaxed semantic error-checking mode\n" |
| 982 | " -s silent mode\n" |
| 983 | " -t multi-threaded mode\n" |
| 984 | " -v print version strings\n" |
| 985 | " -w suppress warnings (except as required by #extension : warn)\n" |
John Kessenich | b0a7eb5 | 2013-11-07 17:44:20 +0000 | [diff] [blame] | 986 | ); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 987 | |
| 988 | exit(EFailUsage); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 989 | } |
| 990 | |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 991 | #if !defined _MSC_VER && !defined MINGW_HAS_SECURE_API |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 992 | |
| 993 | #include <errno.h> |
| 994 | |
| 995 | int fopen_s( |
| 996 | FILE** pFile, |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 997 | const char* filename, |
| 998 | const char* mode |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 999 | ) |
| 1000 | { |
| 1001 | if (!pFile || !filename || !mode) { |
| 1002 | return EINVAL; |
| 1003 | } |
| 1004 | |
| 1005 | FILE* f = fopen(filename, mode); |
| 1006 | if (! f) { |
| 1007 | if (errno != 0) { |
| 1008 | return errno; |
| 1009 | } else { |
| 1010 | return ENOENT; |
| 1011 | } |
| 1012 | } |
| 1013 | *pFile = f; |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
| 1018 | #endif |
| 1019 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1020 | // |
| 1021 | // Malloc a string of sufficient size and read a string into it. |
| 1022 | // |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 1023 | char** ReadFileData(const char* fileName) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1024 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1025 | FILE *in = nullptr; |
John Kessenich | 3ce4e59 | 2014-10-06 19:57:34 +0000 | [diff] [blame] | 1026 | int errorCode = fopen_s(&in, fileName, "r"); |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1027 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1028 | int count = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1029 | const int maxSourceStrings = 5; // for testing splitting shader/tokens across multiple strings |
| 1030 | char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1031 | |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1032 | if (errorCode || in == nullptr) |
| 1033 | Error("unable to open input file"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1034 | |
| 1035 | while (fgetc(in) != EOF) |
| 1036 | count++; |
| 1037 | |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1038 | fseek(in, 0, SEEK_SET); |
John Kessenich | ca3457f | 2015-05-18 01:59:45 +0000 | [diff] [blame] | 1039 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1040 | char *fdata = (char*)malloc(count+2); // freed before return of this function |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1041 | if (! fdata) |
| 1042 | Error("can't allocate memory"); |
| 1043 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1044 | if ((int)fread(fdata, 1, count, in) != count) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1045 | free(fdata); |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1046 | Error("can't read input file"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1047 | } |
John Kessenich | 68d78fd | 2015-07-12 19:28:10 -0600 | [diff] [blame] | 1048 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1049 | fdata[count] = '\0'; |
| 1050 | fclose(in); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1051 | |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 1052 | if (count == 0) { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1053 | // recover from empty file |
| 1054 | return_data[0] = (char*)malloc(count+2); // freed in FreeFileData() |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1055 | return_data[0][0]='\0'; |
John Kessenich | ea869fb | 2013-10-28 18:12:06 +0000 | [diff] [blame] | 1056 | NumShaderStrings = 0; |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1057 | free(fdata); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1058 | |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1059 | return return_data; |
| 1060 | } else |
| 1061 | NumShaderStrings = 1; // Set to larger than 1 for testing multiple strings |
| 1062 | |
| 1063 | // 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] | 1064 | int len = (int)(ceil)((float)count/(float)NumShaderStrings); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1065 | int ptr_len = 0; |
| 1066 | int i = 0; |
| 1067 | while (count > 0) { |
| 1068 | return_data[i] = (char*)malloc(len + 2); // freed in FreeFileData() |
| 1069 | memcpy(return_data[i], fdata + ptr_len, len); |
| 1070 | return_data[i][len] = '\0'; |
| 1071 | count -= len; |
| 1072 | ptr_len += len; |
| 1073 | if (count < len) { |
| 1074 | if (count == 0) { |
| 1075 | NumShaderStrings = i + 1; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1076 | break; |
| 1077 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1078 | len = count; |
John Kessenich | d6c72a4 | 2014-08-18 19:42:35 +0000 | [diff] [blame] | 1079 | } |
| 1080 | ++i; |
| 1081 | } |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1082 | |
| 1083 | free(fdata); |
| 1084 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1085 | return return_data; |
| 1086 | } |
| 1087 | |
John Kessenich | 51cdd90 | 2014-02-18 23:37:57 +0000 | [diff] [blame] | 1088 | void FreeFileData(char** data) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1089 | { |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1090 | for(int i = 0; i < NumShaderStrings; i++) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1091 | free(data[i]); |
John Kessenich | b329715 | 2015-07-11 18:01:03 -0600 | [diff] [blame] | 1092 | |
| 1093 | free(data); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 1096 | void InfoLogMsg(const char* msg, const char* name, const int num) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1097 | { |
John Kessenich | fae38ee | 2015-06-10 23:23:12 +0000 | [diff] [blame] | 1098 | if (num >= 0 ) |
| 1099 | printf("#### %s %s %d INFO LOG ####\n", msg, name, num); |
| 1100 | else |
| 1101 | printf("#### %s %s INFO LOG ####\n", msg, name); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 1102 | } |