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