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" |
| 42 | #include "./../glslang/Public/ShaderLang.h" |
| 43 | #include <string.h> |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 44 | #include <stdlib.h> |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 45 | #include <math.h> |
| 46 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 47 | #include "osinclude.h" |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 48 | |
| 49 | extern "C" { |
| 50 | SH_IMPORT_EXPORT void ShOutputHtml(); |
| 51 | } |
| 52 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 53 | // Command-line options |
| 54 | enum TOptions { |
| 55 | EOptionNone = 0x000, |
| 56 | EOptionIntermediate = 0x001, |
| 57 | EOptionSuppressInfolog = 0x002, |
| 58 | EOptionMemoryLeakMode = 0x004, |
| 59 | EOptionRelaxedErrors = 0x008, |
| 60 | EOptionGiveWarnings = 0x010, |
| 61 | EOptionsLinkProgram = 0x020, |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 62 | EOptionMultiThreaded = 0x040, |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 63 | EOptionDumpConfig = 0x080, |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 66 | // |
| 67 | // Return codes from main. |
| 68 | // |
| 69 | enum TFailCode { |
| 70 | ESuccess = 0, |
| 71 | EFailUsage, |
| 72 | EFailCompile, |
| 73 | EFailLink, |
| 74 | EFailCompilerCreate, |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 75 | EFailThreadCreate, |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 76 | EFailLinkerCreate |
| 77 | }; |
| 78 | |
| 79 | // |
| 80 | // Just placeholders for testing purposes. The stand-alone environment |
| 81 | // can't actually do a full link without something specifying real |
| 82 | // attribute bindings. |
| 83 | // |
| 84 | ShBinding FixedAttributeBindings[] = { |
| 85 | { "gl_Vertex", 15 }, |
| 86 | { "gl_Color", 10 }, |
| 87 | { "gl_Normal", 7 }, |
| 88 | }; |
| 89 | |
| 90 | ShBindingTable FixedAttributeTable = { 3, FixedAttributeBindings }; |
| 91 | |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 92 | EShLanguage FindLanguage(const std::string& name); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 93 | bool CompileFile(const char *fileName, ShHandle, int options); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 94 | void usage(); |
| 95 | void FreeFileData(char **data); |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 96 | char** ReadFileData(const char *fileName); |
| 97 | void InfoLogMsg(const char* msg, const char* name, const int num); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 98 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 99 | // Use to test breaking up a single shader file into multiple strings. |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 100 | int NumShaderStrings = 1; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 101 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 102 | TBuiltInResource Resources; |
| 103 | std::string ConfigFile; |
| 104 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 105 | // |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 106 | // These are the default resources for TBuiltInResources, used for both |
| 107 | // - parsing this string for the case where the user didn't supply one |
| 108 | // - dumping out a template for user construction of a config file |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 109 | // |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame^] | 110 | const char* DefaultConfig = |
| 111 | "MaxLights 32\n" |
| 112 | "MaxClipPlanes 6\n" |
| 113 | "MaxTextureUnits 32\n" |
| 114 | "MaxTextureCoords 32\n" |
| 115 | "MaxVertexAttribs 64\n" |
| 116 | "MaxVertexUniformComponents 4096\n" |
| 117 | "MaxVaryingFloats 64\n" |
| 118 | "MaxVertexTextureImageUnits 32\n" |
| 119 | "MaxCombinedTextureImageUnits 32\n" |
| 120 | "MaxTextureImageUnits 32\n" |
| 121 | "MaxFragmentUniformComponents 4096\n" |
| 122 | "MaxDrawBuffers 32\n" |
| 123 | "MaxVertexUniformVectors 128\n" |
| 124 | "MaxVaryingVectors 8\n" |
| 125 | "MaxFragmentUniformVectors 16\n" |
| 126 | "MaxVertexOutputVectors 16\n" |
| 127 | "MaxFragmentInputVectors 15\n" |
| 128 | "MinProgramTexelOffset -8\n" |
| 129 | "MaxProgramTexelOffset 7\n" |
| 130 | "MaxClipDistances 8\n" |
| 131 | "MaxComputeWorkGroupCountX 65535\n" |
| 132 | "MaxComputeWorkGroupCountY 65535\n" |
| 133 | "MaxComputeWorkGroupCountZ 65535\n" |
| 134 | "MaxComputeWorkGroupSizeX 1024\n" |
| 135 | "MaxComputeWorkGroupSizeX 1024\n" |
| 136 | "MaxComputeWorkGroupSizeZ 64\n" |
| 137 | "MaxComputeUniformComponents 1024\n" |
| 138 | "MaxComputeTextureImageUnits 16\n" |
| 139 | "MaxComputeImageUniforms 8\n" |
| 140 | "MaxComputeAtomicCounters 8\n" |
| 141 | "MaxComputeAtomicCounterBuffers 1\n" |
| 142 | "MaxVaryingComponents 60\n" |
| 143 | "MaxVertexOutputComponents 64\n" |
| 144 | "MaxGeometryInputComponents 64\n" |
| 145 | "MaxGeometryOutputComponents 128\n" |
| 146 | "MaxFragmentInputComponents 128\n" |
| 147 | "MaxImageUnits 8\n" |
| 148 | "MaxCombinedImageUnitsAndFragmentOutputs 8\n" |
| 149 | "MaxImageSamples 0\n" |
| 150 | "MaxVertexImageUniforms 0\n" |
| 151 | "MaxTessControlImageUniforms 0\n" |
| 152 | "MaxTessEvaluationImageUniforms 0\n" |
| 153 | "MaxGeometryImageUniforms 0\n" |
| 154 | "MaxFragmentImageUniforms 8\n" |
| 155 | "MaxCombinedImageUniforms 8\n" |
| 156 | "MaxGeometryTextureImageUnits 16\n" |
| 157 | "MaxGeometryOutputVertices 256\n" |
| 158 | "MaxGeometryTotalOutputComponents 1024\n" |
| 159 | "MaxGeometryUniformComponents 1024\n" |
| 160 | "MaxGeometryVaryingComponents 64\n" |
| 161 | "MaxTessControlInputComponents 128\n" |
| 162 | "MaxTessControlOutputComponents 128\n" |
| 163 | "MaxTessControlTextureImageUnits 16\n" |
| 164 | "MaxTessControlUniformComponents 1024\n" |
| 165 | "MaxTessControlTotalOutputComponents 4096\n" |
| 166 | "MaxTessEvaluationInputComponents 128\n" |
| 167 | "MaxTessEvaluationOutputComponents 128\n" |
| 168 | "MaxTessEvaluationTextureImageUnits 16\n" |
| 169 | "MaxTessEvaluationUniformComponents 1024\n" |
| 170 | "MaxTessPatchComponents 120\n" |
| 171 | "MaxPatchVertices 32\n" |
| 172 | "MaxTessGenLevel 64\n" |
| 173 | "MaxViewports 16\n" |
| 174 | "MaxVertexAtomicCounters 0\n" |
| 175 | "MaxTessControlAtomicCounters 0\n" |
| 176 | "MaxTessEvaluationAtomicCounters 0\n" |
| 177 | "MaxGeometryAtomicCounters 0\n" |
| 178 | "MaxFragmentAtomicCounters 8\n" |
| 179 | "MaxCombinedAtomicCounters 8\n" |
| 180 | "MaxAtomicCounterBindings 1\n" |
| 181 | "MaxVertexAtomicCounterBuffers 0\n" |
| 182 | "MaxTessControlAtomicCounterBuffers 0\n" |
| 183 | "MaxTessEvaluationAtomicCounterBuffers 0\n" |
| 184 | "MaxGeometryAtomicCounterBuffers 0\n" |
| 185 | "MaxFragmentAtomicCounterBuffers 1\n" |
| 186 | "MaxCombinedAtomicCounterBuffers 1\n" |
| 187 | "MaxAtomicCounterBufferSize 16384\n" |
| 188 | |
| 189 | "nonInductiveForLoops 1\n" |
| 190 | "whileLoops 1\n" |
| 191 | "doWhileLoops 1\n" |
| 192 | "generalUniformIndexing 1\n" |
| 193 | "generalAttributeMatrixVectorIndexing 1\n" |
| 194 | "generalVaryingIndexing 1\n" |
| 195 | "generalSamplerIndexing 1\n" |
| 196 | "generalVariableIndexing 1\n" |
| 197 | "generalConstantMatrixVectorIndexing 1\n" |
| 198 | ; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 199 | |
| 200 | // |
| 201 | // Parse either a .conf file provided by the user or the default string above. |
| 202 | // |
| 203 | void ProcessConfigFile() |
John Kessenich | b51f62c | 2013-04-11 16:31:09 +0000 | [diff] [blame] | 204 | { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 205 | char** configStrings = 0; |
| 206 | char *config = 0; |
| 207 | if (ConfigFile.size() > 0) { |
| 208 | char** configStrings = ReadFileData(ConfigFile.c_str()); |
| 209 | if (configStrings) |
| 210 | config = *configStrings; |
| 211 | else { |
| 212 | printf("Error opening configuration file; will instead use the default configuration\n"); |
| 213 | usage(); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if (config == 0) { |
| 218 | config = new char[strlen(DefaultConfig)]; |
| 219 | strcpy(config, DefaultConfig); |
| 220 | } |
| 221 | |
| 222 | const char* delims = " \t\n\r"; |
| 223 | const char* token = strtok(config, delims); |
| 224 | while (token) { |
| 225 | const char* valueStr = strtok(0, delims); |
| 226 | if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) { |
| 227 | printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : ""); |
| 228 | return; |
| 229 | } |
| 230 | int value = atoi(valueStr); |
| 231 | |
| 232 | if (strcmp(token, "MaxLights") == 0) |
| 233 | Resources.maxLights = value; |
| 234 | else if (strcmp(token, "MaxClipPlanes") == 0) |
| 235 | Resources.maxClipPlanes = value; |
| 236 | else if (strcmp(token, "MaxTextureUnits") == 0) |
| 237 | Resources.maxTextureUnits = value; |
| 238 | else if (strcmp(token, "MaxTextureCoords") == 0) |
| 239 | Resources.maxTextureCoords = value; |
| 240 | else if (strcmp(token, "MaxVertexAttribs") == 0) |
| 241 | Resources.maxVertexAttribs = value; |
| 242 | else if (strcmp(token, "MaxVertexUniformComponents") == 0) |
| 243 | Resources.maxVertexUniformComponents = value; |
| 244 | else if (strcmp(token, "MaxVaryingFloats") == 0) |
| 245 | Resources.maxVaryingFloats = value; |
| 246 | else if (strcmp(token, "MaxVertexTextureImageUnits") == 0) |
| 247 | Resources.maxVertexTextureImageUnits = value; |
| 248 | else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0) |
| 249 | Resources.maxCombinedTextureImageUnits = value; |
| 250 | else if (strcmp(token, "MaxTextureImageUnits") == 0) |
| 251 | Resources.maxTextureImageUnits = value; |
| 252 | else if (strcmp(token, "MaxFragmentUniformComponents") == 0) |
| 253 | Resources.maxFragmentUniformComponents = value; |
| 254 | else if (strcmp(token, "MaxDrawBuffers") == 0) |
| 255 | Resources.maxDrawBuffers = value; |
| 256 | else if (strcmp(token, "MaxVertexUniformVectors") == 0) |
| 257 | Resources.maxVertexUniformVectors = value; |
| 258 | else if (strcmp(token, "MaxVaryingVectors") == 0) |
| 259 | Resources.maxVaryingVectors = value; |
| 260 | else if (strcmp(token, "MaxFragmentUniformVectors") == 0) |
| 261 | Resources.maxFragmentUniformVectors = value; |
| 262 | else if (strcmp(token, "MaxVertexOutputVectors") == 0) |
| 263 | Resources.maxVertexOutputVectors = value; |
| 264 | else if (strcmp(token, "MaxFragmentInputVectors") == 0) |
| 265 | Resources.maxFragmentInputVectors = value; |
| 266 | else if (strcmp(token, "MinProgramTexelOffset") == 0) |
| 267 | Resources.minProgramTexelOffset = value; |
| 268 | else if (strcmp(token, "MaxProgramTexelOffset") == 0) |
| 269 | Resources.maxProgramTexelOffset = value; |
John Kessenich | e7c59c1 | 2013-10-16 22:28:35 +0000 | [diff] [blame] | 270 | else if (strcmp(token, "MaxClipDistances") == 0) |
| 271 | Resources.maxClipDistances = value; |
John Kessenich | 284231c | 2013-10-22 01:50:39 +0000 | [diff] [blame^] | 272 | else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0) |
| 273 | Resources.maxComputeWorkGroupCountX = value; |
| 274 | else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0) |
| 275 | Resources.maxComputeWorkGroupCountY = value; |
| 276 | else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0) |
| 277 | Resources.maxComputeWorkGroupCountZ = value; |
| 278 | else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0) |
| 279 | Resources.maxComputeWorkGroupSizeX = value; |
| 280 | else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0) |
| 281 | Resources.maxComputeWorkGroupSizeY = value; |
| 282 | else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0) |
| 283 | Resources.maxComputeWorkGroupSizeZ = value; |
| 284 | else if (strcmp(token, "MaxComputeUniformComponents") == 0) |
| 285 | Resources.maxComputeUniformComponents = value; |
| 286 | else if (strcmp(token, "MaxComputeTextureImageUnits") == 0) |
| 287 | Resources.maxComputeTextureImageUnits = value; |
| 288 | else if (strcmp(token, "MaxComputeImageUniforms") == 0) |
| 289 | Resources.maxComputeImageUniforms = value; |
| 290 | else if (strcmp(token, "MaxComputeAtomicCounters") == 0) |
| 291 | Resources.maxComputeAtomicCounters = value; |
| 292 | else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0) |
| 293 | Resources.maxComputeAtomicCounterBuffers = value; |
| 294 | else if (strcmp(token, "MaxVaryingComponents") == 0) |
| 295 | Resources.maxVaryingComponents = value; |
| 296 | else if (strcmp(token, "MaxVertexOutputComponents") == 0) |
| 297 | Resources.maxVertexOutputComponents = value; |
| 298 | else if (strcmp(token, "MaxGeometryInputComponents") == 0) |
| 299 | Resources.maxGeometryInputComponents = value; |
| 300 | else if (strcmp(token, "MaxGeometryOutputComponents") == 0) |
| 301 | Resources.maxGeometryOutputComponents = value; |
| 302 | else if (strcmp(token, "MaxFragmentInputComponents") == 0) |
| 303 | Resources.maxFragmentInputComponents = value; |
| 304 | else if (strcmp(token, "MaxImageUnits") == 0) |
| 305 | Resources.maxImageUnits = value; |
| 306 | else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0) |
| 307 | Resources.maxCombinedImageUnitsAndFragmentOutputs = value; |
| 308 | else if (strcmp(token, "MaxImageSamples") == 0) |
| 309 | Resources.maxImageSamples = value; |
| 310 | else if (strcmp(token, "MaxVertexImageUniforms") == 0) |
| 311 | Resources.maxVertexImageUniforms = value; |
| 312 | else if (strcmp(token, "MaxTessControlImageUniforms") == 0) |
| 313 | Resources.maxTessControlImageUniforms = value; |
| 314 | else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0) |
| 315 | Resources.maxTessEvaluationImageUniforms = value; |
| 316 | else if (strcmp(token, "MaxGeometryImageUniforms") == 0) |
| 317 | Resources.maxGeometryImageUniforms = value; |
| 318 | else if (strcmp(token, "MaxFragmentImageUniforms") == 0) |
| 319 | Resources.maxFragmentImageUniforms = value; |
| 320 | else if (strcmp(token, "MaxCombinedImageUniforms") == 0) |
| 321 | Resources.maxCombinedImageUniforms = value; |
| 322 | else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0) |
| 323 | Resources.maxGeometryTextureImageUnits = value; |
| 324 | else if (strcmp(token, "MaxGeometryOutputVertices") == 0) |
| 325 | Resources.maxGeometryOutputVertices = value; |
| 326 | else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0) |
| 327 | Resources.maxGeometryTotalOutputComponents = value; |
| 328 | else if (strcmp(token, "MaxGeometryUniformComponents") == 0) |
| 329 | Resources.maxGeometryUniformComponents = value; |
| 330 | else if (strcmp(token, "MaxGeometryVaryingComponents") == 0) |
| 331 | Resources.maxGeometryVaryingComponents = value; |
| 332 | else if (strcmp(token, "MaxTessControlInputComponents") == 0) |
| 333 | Resources.maxTessControlInputComponents = value; |
| 334 | else if (strcmp(token, "MaxTessControlOutputComponents") == 0) |
| 335 | Resources.maxTessControlOutputComponents = value; |
| 336 | else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0) |
| 337 | Resources.maxTessControlTextureImageUnits = value; |
| 338 | else if (strcmp(token, "MaxTessControlUniformComponents") == 0) |
| 339 | Resources.maxTessControlUniformComponents = value; |
| 340 | else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0) |
| 341 | Resources.maxTessControlTotalOutputComponents = value; |
| 342 | else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0) |
| 343 | Resources.maxTessEvaluationInputComponents = value; |
| 344 | else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0) |
| 345 | Resources.maxTessEvaluationOutputComponents = value; |
| 346 | else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0) |
| 347 | Resources.maxTessEvaluationTextureImageUnits = value; |
| 348 | else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0) |
| 349 | Resources.maxTessEvaluationUniformComponents = value; |
| 350 | else if (strcmp(token, "MaxTessPatchComponents") == 0) |
| 351 | Resources.maxTessPatchComponents = value; |
| 352 | else if (strcmp(token, "MaxPatchVertices") == 0) |
| 353 | Resources.maxPatchVertices = value; |
| 354 | else if (strcmp(token, "MaxTessGenLevel") == 0) |
| 355 | Resources.maxTessGenLevel = value; |
| 356 | else if (strcmp(token, "MaxViewports") == 0) |
| 357 | Resources.maxViewports = value; |
| 358 | else if (strcmp(token, "MaxVertexAtomicCounters") == 0) |
| 359 | Resources.maxVertexAtomicCounters = value; |
| 360 | else if (strcmp(token, "MaxTessControlAtomicCounters") == 0) |
| 361 | Resources.maxTessControlAtomicCounters = value; |
| 362 | else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0) |
| 363 | Resources.maxTessEvaluationAtomicCounters = value; |
| 364 | else if (strcmp(token, "MaxGeometryAtomicCounters") == 0) |
| 365 | Resources.maxGeometryAtomicCounters = value; |
| 366 | else if (strcmp(token, "MaxFragmentAtomicCounters") == 0) |
| 367 | Resources.maxFragmentAtomicCounters = value; |
| 368 | else if (strcmp(token, "MaxCombinedAtomicCounters") == 0) |
| 369 | Resources.maxCombinedAtomicCounters = value; |
| 370 | else if (strcmp(token, "MaxAtomicCounterBindings") == 0) |
| 371 | Resources.maxAtomicCounterBindings = value; |
| 372 | else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0) |
| 373 | Resources.maxVertexAtomicCounterBuffers = value; |
| 374 | else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0) |
| 375 | Resources.maxTessControlAtomicCounterBuffers = value; |
| 376 | else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0) |
| 377 | Resources.maxTessEvaluationAtomicCounterBuffers = value; |
| 378 | else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0) |
| 379 | Resources.maxGeometryAtomicCounterBuffers = value; |
| 380 | else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0) |
| 381 | Resources.maxFragmentAtomicCounterBuffers = value; |
| 382 | else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0) |
| 383 | Resources.maxCombinedAtomicCounterBuffers = value; |
| 384 | else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0) |
| 385 | Resources.maxAtomicCounterBufferSize = value; |
| 386 | |
John Kessenich | a5830df | 2013-10-02 05:10:48 +0000 | [diff] [blame] | 387 | else if (strcmp(token, "nonInductiveForLoops") == 0) |
| 388 | Resources.limits.nonInductiveForLoops = (value != 0); |
| 389 | else if (strcmp(token, "whileLoops") == 0) |
| 390 | Resources.limits.whileLoops = (value != 0); |
| 391 | else if (strcmp(token, "doWhileLoops") == 0) |
| 392 | Resources.limits.doWhileLoops = (value != 0); |
| 393 | else if (strcmp(token, "generalUniformIndexing") == 0) |
| 394 | Resources.limits.generalUniformIndexing = (value != 0); |
| 395 | else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0) |
| 396 | Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0); |
| 397 | else if (strcmp(token, "generalVaryingIndexing") == 0) |
| 398 | Resources.limits.generalVaryingIndexing = (value != 0); |
| 399 | else if (strcmp(token, "generalSamplerIndexing") == 0) |
| 400 | Resources.limits.generalSamplerIndexing = (value != 0); |
| 401 | else if (strcmp(token, "generalVariableIndexing") == 0) |
| 402 | Resources.limits.generalVariableIndexing = (value != 0); |
| 403 | else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0) |
| 404 | Resources.limits.generalConstantMatrixVectorIndexing = (value != 0); |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 405 | else |
| 406 | printf("Warning: unrecognized limit (%s) in configuration file.\n", token); |
| 407 | |
| 408 | token = strtok(0, delims); |
| 409 | } |
| 410 | if (configStrings) |
| 411 | FreeFileData(configStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 412 | } |
| 413 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 414 | // thread-safe list of shaders to asynchronously grab and compile |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 415 | glslang::TWorklist Worklist; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 416 | |
| 417 | // array of unique places to leave the shader names and infologs for the asynchronous compiles |
| 418 | glslang::TWorkItem **Work = 0; |
| 419 | int NumWorkItems = 0; |
| 420 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 421 | int Options = 0; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 422 | bool Delay = false; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 423 | const char* ExecutableName; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 424 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 425 | // |
| 426 | // *.conf => this is a config file that can set limits/resources |
| 427 | // |
| 428 | bool SetConfigFile(const std::string& name) |
| 429 | { |
| 430 | if (name.size() < 5) |
| 431 | return false; |
| 432 | |
John Kessenich | 4c70685 | 2013-10-11 16:28:43 +0000 | [diff] [blame] | 433 | if (name.compare(name.size() - 5, 5, ".conf") == 0) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 434 | ConfigFile = name; |
| 435 | return true; |
| 436 | } |
| 437 | |
| 438 | return false; |
| 439 | } |
| 440 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 441 | bool ProcessArguments(int argc, char* argv[]) |
| 442 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 443 | ExecutableName = argv[0]; |
| 444 | NumWorkItems = argc; // will include some empties where the '-' options were, but it doesn't matter, they'll be 0 |
| 445 | Work = new glslang::TWorkItem*[NumWorkItems]; |
| 446 | Work[0] = 0; |
| 447 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 448 | argc--; |
| 449 | argv++; |
| 450 | for (; argc >= 1; argc--, argv++) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 451 | Work[argc] = 0; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 452 | if (argv[0][0] == '-') { |
| 453 | switch (argv[0][1]) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 454 | case 'c': |
| 455 | Options |= EOptionDumpConfig; |
| 456 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 457 | case 'd': |
| 458 | Delay = true; |
| 459 | break; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 460 | case 'i': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 461 | Options |= EOptionIntermediate; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 462 | break; |
| 463 | case 'l': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 464 | Options |= EOptionsLinkProgram; |
| 465 | break; |
| 466 | case 'm': |
| 467 | Options |= EOptionMemoryLeakMode; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 468 | break; |
| 469 | case 'r': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 470 | Options |= EOptionRelaxedErrors; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 471 | break; |
| 472 | case 's': |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 473 | Options |= EOptionSuppressInfolog; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 474 | break; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 475 | case 't': |
| 476 | #ifdef _WIN32 |
| 477 | Options |= EOptionMultiThreaded; |
| 478 | #endif |
| 479 | break; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 480 | default: |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 481 | return false; |
| 482 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 483 | } else { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 484 | std::string name(argv[0]); |
| 485 | if (! SetConfigFile(name)) { |
| 486 | Work[argc] = new glslang::TWorkItem(name); |
| 487 | Worklist.add(Work[argc]); |
| 488 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 489 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | return true; |
| 493 | } |
| 494 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 495 | // Thread entry point, for non-linking asynchronous mode. |
John Kessenich | ee6a9c8 | 2013-07-31 23:19:17 +0000 | [diff] [blame] | 496 | unsigned int |
| 497 | #ifdef _WIN32 |
| 498 | __stdcall |
| 499 | #endif |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 500 | CompileShaders(void*) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 501 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 502 | glslang::TWorkItem* workItem; |
| 503 | while (Worklist.remove(workItem)) { |
| 504 | ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 505 | if (compiler == 0) |
| 506 | return false; |
| 507 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 508 | CompileFile(workItem->name.c_str(), compiler, Options); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 509 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 510 | if (! (Options & EOptionSuppressInfolog)) |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 511 | workItem->results = ShGetInfoLog(compiler); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 512 | |
| 513 | ShDestruct(compiler); |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 519 | // |
| 520 | // For linking mode: Will independently parse each item in the worklist, but then put them |
| 521 | // in the same program and link them together. |
| 522 | // |
| 523 | // Uses the new C++ interface instead of the old handle-based interface. |
| 524 | // |
| 525 | void CompileAndLinkShaders() |
| 526 | { |
| 527 | // keep track of what to free |
| 528 | std::list<glslang::TShader*> shaders; |
| 529 | |
| 530 | EShMessages messages = EShMsgDefault; |
| 531 | if (Options & EOptionRelaxedErrors) |
| 532 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
| 533 | if (Options & EOptionIntermediate) |
| 534 | messages = (EShMessages)(messages | EShMsgAST); |
| 535 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 536 | // |
| 537 | // Per-shader processing... |
| 538 | // |
| 539 | |
| 540 | glslang::TProgram program; |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 541 | glslang::TWorkItem* workItem; |
| 542 | while (Worklist.remove(workItem)) { |
| 543 | EShLanguage stage = FindLanguage(workItem->name); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 544 | glslang::TShader* shader = new glslang::TShader(stage); |
| 545 | shaders.push_back(shader); |
| 546 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 547 | char** shaderStrings = ReadFileData(workItem->name.c_str()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 548 | if (! shaderStrings) { |
| 549 | usage(); |
| 550 | return; |
| 551 | } |
| 552 | |
| 553 | shader->setStrings(shaderStrings, 1); |
| 554 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 555 | shader->parse(&Resources, 100, false, messages); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 556 | |
| 557 | program.addShader(shader); |
| 558 | |
| 559 | if (! (Options & EOptionSuppressInfolog)) { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 560 | puts(workItem->name.c_str()); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 561 | puts(shader->getInfoLog()); |
| 562 | puts(shader->getInfoDebugLog()); |
| 563 | } |
| 564 | |
| 565 | FreeFileData(shaderStrings); |
| 566 | } |
| 567 | |
| 568 | // |
| 569 | // Program-level processing... |
| 570 | // |
| 571 | |
| 572 | program.link(messages); |
| 573 | if (! (Options & EOptionSuppressInfolog)) { |
| 574 | puts(program.getInfoLog()); |
| 575 | puts(program.getInfoDebugLog()); |
| 576 | } |
| 577 | |
| 578 | // free everything up |
| 579 | while (shaders.size() > 0) { |
| 580 | delete shaders.back(); |
| 581 | shaders.pop_back(); |
| 582 | } |
| 583 | |
| 584 | // TODO: memory: for each compile, need a GetThreadPoolAllocator().pop(); |
| 585 | } |
| 586 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 587 | int C_DECL main(int argc, char* argv[]) |
| 588 | { |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 589 | bool compileFailed = false; |
| 590 | bool linkFailed = false; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 591 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 592 | // Init for front-end proper |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 593 | ShInitialize(); |
| 594 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 595 | // Init for standalone |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 596 | glslang::InitGlobalLock(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 597 | |
John Kessenich | 54f6e56 | 2013-08-03 00:04:10 +0000 | [diff] [blame] | 598 | if (! ProcessArguments(argc, argv)) { |
| 599 | usage(); |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 600 | return EFailUsage; |
John Kessenich | 54f6e56 | 2013-08-03 00:04:10 +0000 | [diff] [blame] | 601 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 602 | |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 603 | if (Options & EOptionDumpConfig) { |
| 604 | printf("%s", DefaultConfig); |
| 605 | if (Worklist.empty()) |
| 606 | return ESuccess; |
| 607 | } |
| 608 | |
| 609 | if (Worklist.empty()) { |
| 610 | usage(); |
| 611 | return EFailUsage; |
| 612 | } |
| 613 | |
| 614 | ProcessConfigFile(); |
| 615 | |
| 616 | |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 617 | // |
| 618 | // Two modes: |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 619 | // 1) linking all arguments together, single-threaded, new C++ interface |
| 620 | // 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] | 621 | // |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 622 | if (Options & EOptionsLinkProgram) |
| 623 | CompileAndLinkShaders(); |
| 624 | else { |
| 625 | bool printShaderNames = Worklist.size() > 1; |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 626 | |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 627 | if (Options & EOptionMultiThreaded) { |
| 628 | const int NumThreads = 16; |
| 629 | void* threads[NumThreads]; |
| 630 | for (int t = 0; t < NumThreads; ++t) { |
| 631 | threads[t] = glslang::OS_CreateThread(&CompileShaders); |
| 632 | if (! threads[t]) { |
| 633 | printf("Failed to create thread\n"); |
| 634 | return EFailThreadCreate; |
| 635 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 636 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 637 | glslang::OS_WaitForAllThreads(threads, NumThreads); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 638 | } else { |
| 639 | if (! CompileShaders(0)) |
| 640 | compileFailed = true; |
| 641 | } |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 642 | |
| 643 | // Print out all the resulting infologs |
| 644 | for (int w = 0; w < NumWorkItems; ++w) { |
| 645 | if (Work[w]) { |
| 646 | if (printShaderNames) |
| 647 | puts(Work[w]->name.c_str()); |
| 648 | puts(Work[w]->results.c_str()); |
| 649 | delete Work[w]; |
| 650 | } |
| 651 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 652 | } |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 653 | |
| 654 | if (Delay) |
| 655 | glslang::OS_Sleep(1000000); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 656 | |
| 657 | if (compileFailed) |
| 658 | return EFailCompile; |
| 659 | if (linkFailed) |
| 660 | return EFailLink; |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | // |
| 666 | // Deduce the language from the filename. Files must end in one of the |
| 667 | // following extensions: |
| 668 | // |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 669 | // .vert = vertex |
| 670 | // .tesc = tessellation control |
| 671 | // .tese = tessellation evaluation |
| 672 | // .geom = geometry |
| 673 | // .frag = fragment |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 674 | // .comp = compute |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 675 | // |
John Kessenich | b603f91 | 2013-08-29 00:39:25 +0000 | [diff] [blame] | 676 | EShLanguage FindLanguage(const std::string& name) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 677 | { |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 678 | size_t ext = name.rfind('.'); |
| 679 | if (ext == std::string::npos) { |
| 680 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 681 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 682 | } |
| 683 | |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 684 | std::string suffix = name.substr(ext + 1, std::string::npos); |
| 685 | if (suffix == "vert") |
| 686 | return EShLangVertex; |
| 687 | else if (suffix == "tesc") |
| 688 | return EShLangTessControl; |
| 689 | else if (suffix == "tese") |
| 690 | return EShLangTessEvaluation; |
| 691 | else if (suffix == "geom") |
| 692 | return EShLangGeometry; |
| 693 | else if (suffix == "frag") |
| 694 | return EShLangFragment; |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 695 | else if (suffix == "comp") |
| 696 | return EShLangCompute; |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 697 | |
| 698 | usage(); |
John Kessenich | e95ecc5 | 2012-12-12 21:34:14 +0000 | [diff] [blame] | 699 | return EShLangVertex; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 700 | } |
| 701 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 702 | // |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 703 | // Read a file's data into a string, and compile it using the old interface ShCompile, |
| 704 | // for non-linkable results. |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 705 | // |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 706 | bool CompileFile(const char *fileName, ShHandle compiler, int Options) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 707 | { |
| 708 | int ret; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 709 | char** shaderStrings = ReadFileData(fileName); |
John Kessenich | db4cd54 | 2013-06-26 22:42:55 +0000 | [diff] [blame] | 710 | if (! shaderStrings) { |
| 711 | usage(); |
| 712 | return false; |
| 713 | } |
| 714 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 715 | int* lengths = new int[NumShaderStrings]; |
| 716 | |
| 717 | // move to length-based strings, rather than null-terminated strings |
| 718 | for (int s = 0; s < NumShaderStrings; ++s) |
| 719 | lengths[s] = strlen(shaderStrings[s]); |
John Kessenich | 09da79e | 2013-04-17 19:34:23 +0000 | [diff] [blame] | 720 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 721 | if (! shaderStrings) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 722 | return false; |
| 723 | |
John Kessenich | 52ac67e | 2013-05-05 23:46:22 +0000 | [diff] [blame] | 724 | EShMessages messages = EShMsgDefault; |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 725 | if (Options & EOptionRelaxedErrors) |
John Kessenich | 52ac67e | 2013-05-05 23:46:22 +0000 | [diff] [blame] | 726 | messages = (EShMessages)(messages | EShMsgRelaxedErrors); |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 727 | if (Options & EOptionIntermediate) |
| 728 | messages = (EShMessages)(messages | EShMsgAST); |
John Kessenich | 69f4b51 | 2013-09-04 21:19:27 +0000 | [diff] [blame] | 729 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 730 | for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { |
| 731 | for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) { |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 732 | //ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, 100, false, messages); |
| 733 | ret = ShCompile(compiler, shaderStrings, NumShaderStrings, 0, EShOptNone, &Resources, Options, 100, false, messages); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 734 | //const char* multi[4] = { "# ve", "rsion", " 300 e", "s" }; |
| 735 | //const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 736 | //ret = ShCompile(compiler, multi, 4, 0, EShOptNone, &Resources, Options, 100, false, messages); |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 737 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 738 | |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 739 | if (Options & EOptionMemoryLeakMode) |
John Kessenich | 2b07c7e | 2013-07-31 18:44:13 +0000 | [diff] [blame] | 740 | glslang::OS_DumpMemoryCounters(); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 741 | } |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 742 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 743 | delete [] lengths; |
| 744 | FreeFileData(shaderStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 745 | |
| 746 | return ret ? true : false; |
| 747 | } |
| 748 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 749 | // |
| 750 | // print usage to stdout |
| 751 | // |
| 752 | void usage() |
| 753 | { |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 754 | printf("Usage: glslangValidator [ options ] filename\n" |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 755 | "Where: filename is a name ending in\n" |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 756 | " .conf provides an optional config file that replaces the default configuration\n" |
| 757 | " (see -c option below for generating a template)\n" |
John Kessenich | c027579 | 2013-08-09 17:14:49 +0000 | [diff] [blame] | 758 | " .vert for a vertex shader\n" |
| 759 | " .tesc for a tessellation control shader\n" |
| 760 | " .tese for a tessellation evaluation shader\n" |
| 761 | " .geom for a geometry shader\n" |
| 762 | " .frag for a fragment shader\n" |
| 763 | " .comp for a compute shader\n\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 764 | "Compilation warnings and errors will be printed to stdout.\n" |
| 765 | "To get other information, use one of the following options:\n" |
John Kessenich | 05a7063 | 2013-09-17 19:26:08 +0000 | [diff] [blame] | 766 | "-c: configuration dump; use to create default configuration file (redirect to a .conf file)\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 767 | "-i: intermediate tree (glslang AST) is printed out\n" |
| 768 | "-d: delay exit\n" |
John Kessenich | 94a81fb | 2013-08-31 02:41:30 +0000 | [diff] [blame] | 769 | "-l: link validation of all input files\n" |
| 770 | "-m: memory leak mode\n" |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 771 | "-r: relaxed semantic error-checking mode\n" |
John Kessenich | 4586dbd | 2013-08-05 15:52:03 +0000 | [diff] [blame] | 772 | "-s: silent mode\n" |
John Kessenich | 38f3b89 | 2013-09-06 19:52:57 +0000 | [diff] [blame] | 773 | "-t: multi-threaded mode\n"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 774 | } |
| 775 | |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 776 | #ifndef _WIN32 |
| 777 | |
| 778 | #include <errno.h> |
| 779 | |
| 780 | int fopen_s( |
| 781 | FILE** pFile, |
| 782 | const char *filename, |
| 783 | const char *mode |
| 784 | ) |
| 785 | { |
| 786 | if (!pFile || !filename || !mode) { |
| 787 | return EINVAL; |
| 788 | } |
| 789 | |
| 790 | FILE* f = fopen(filename, mode); |
| 791 | if (! f) { |
| 792 | if (errno != 0) { |
| 793 | return errno; |
| 794 | } else { |
| 795 | return ENOENT; |
| 796 | } |
| 797 | } |
| 798 | *pFile = f; |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | #endif |
| 804 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 805 | // |
| 806 | // Malloc a string of sufficient size and read a string into it. |
| 807 | // |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 808 | char** ReadFileData(const char *fileName) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 809 | { |
John Kessenich | 200b273 | 2012-12-12 21:21:23 +0000 | [diff] [blame] | 810 | FILE *in; |
| 811 | int errorCode = fopen_s(&in, fileName, "r"); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 812 | char *fdata; |
| 813 | int count = 0; |
John Kessenich | cfd643e | 2013-03-08 23:14:42 +0000 | [diff] [blame] | 814 | const int maxSourceStrings = 5; |
| 815 | char** return_data = (char**)malloc(maxSourceStrings+1); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 816 | |
| 817 | //return_data[MAX_SOURCE_STRINGS]=NULL; |
John Kessenich | 200b273 | 2012-12-12 21:21:23 +0000 | [diff] [blame] | 818 | if (errorCode) { |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 819 | printf("Error: unable to open input file: %s\n", fileName); |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | while (fgetc(in) != EOF) |
| 824 | count++; |
| 825 | |
| 826 | fseek(in, 0, SEEK_SET); |
| 827 | |
| 828 | |
| 829 | if (!(fdata = (char *)malloc(count+2))) { |
| 830 | printf("Error allocating memory\n"); |
| 831 | return 0; |
| 832 | } |
| 833 | if (fread(fdata,1,count, in)!=count) { |
| 834 | printf("Error reading input file: %s\n", fileName); |
| 835 | return 0; |
| 836 | } |
| 837 | fdata[count] = '\0'; |
| 838 | fclose(in); |
| 839 | if(count==0){ |
| 840 | return_data[0]=(char*)malloc(count+2); |
| 841 | return_data[0][0]='\0'; |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 842 | NumShaderStrings=0; |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 843 | return return_data; |
| 844 | } |
| 845 | |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 846 | int len = (int)(ceil)((float)count/(float)NumShaderStrings); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 847 | int ptr_len=0,i=0; |
| 848 | while(count>0){ |
| 849 | return_data[i]=(char*)malloc(len+2); |
| 850 | memcpy(return_data[i],fdata+ptr_len,len); |
| 851 | return_data[i][len]='\0'; |
| 852 | count-=(len); |
| 853 | ptr_len+=(len); |
| 854 | if(count<len){ |
| 855 | if(count==0){ |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 856 | NumShaderStrings=(i+1); |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 857 | break; |
| 858 | } |
| 859 | len = count; |
| 860 | } |
| 861 | ++i; |
| 862 | } |
| 863 | return return_data; |
| 864 | } |
| 865 | |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 866 | void FreeFileData(char **data) |
| 867 | { |
John Kessenich | 41cf6b5 | 2013-06-25 18:10:05 +0000 | [diff] [blame] | 868 | for(int i=0;i<NumShaderStrings;i++) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 869 | free(data[i]); |
| 870 | } |
| 871 | |
John Kessenich | 54d8cda | 2013-02-11 22:36:01 +0000 | [diff] [blame] | 872 | void InfoLogMsg(const char* msg, const char* name, const int num) |
John Kessenich | a0af473 | 2012-12-12 21:15:54 +0000 | [diff] [blame] | 873 | { |
| 874 | printf(num >= 0 ? "#### %s %s %d INFO LOG ####\n" : |
| 875 | "#### %s %s INFO LOG ####\n", msg, name, num); |
| 876 | } |