Improve ResourceLimits interface to be more forward compatible
[platform/upstream/glslang.git] / StandAlone / ResourceLimits.cpp
1 //
2 // Copyright (C) 2016 Google, Inc.
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 //    Redistributions of source code must retain the above copyright
11 //    notice, this list of conditions and the following disclaimer.
12 //
13 //    Redistributions in binary form must reproduce the above
14 //    copyright notice, this list of conditions and the following
15 //    disclaimer in the documentation and/or other materials provided
16 //    with the distribution.
17 //
18 //    Neither the name of Google Inc. nor the names of its
19 //    contributors may be used to endorse or promote products derived
20 //    from this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
34
35 #include <cstdlib>
36 #include <cstring>
37 #include <sstream>
38 #include <cctype>
39
40 #include "glslang/Public/ResourceLimits.h"
41
42 TBuiltInResource Resources;
43
44 const TBuiltInResource DefaultTBuiltInResource = {
45     /* .MaxLights = */ 32,
46     /* .MaxClipPlanes = */ 6,
47     /* .MaxTextureUnits = */ 32,
48     /* .MaxTextureCoords = */ 32,
49     /* .MaxVertexAttribs = */ 64,
50     /* .MaxVertexUniformComponents = */ 4096,
51     /* .MaxVaryingFloats = */ 64,
52     /* .MaxVertexTextureImageUnits = */ 32,
53     /* .MaxCombinedTextureImageUnits = */ 80,
54     /* .MaxTextureImageUnits = */ 32,
55     /* .MaxFragmentUniformComponents = */ 4096,
56     /* .MaxDrawBuffers = */ 32,
57     /* .MaxVertexUniformVectors = */ 128,
58     /* .MaxVaryingVectors = */ 8,
59     /* .MaxFragmentUniformVectors = */ 16,
60     /* .MaxVertexOutputVectors = */ 16,
61     /* .MaxFragmentInputVectors = */ 15,
62     /* .MinProgramTexelOffset = */ -8,
63     /* .MaxProgramTexelOffset = */ 7,
64     /* .MaxClipDistances = */ 8,
65     /* .MaxComputeWorkGroupCountX = */ 65535,
66     /* .MaxComputeWorkGroupCountY = */ 65535,
67     /* .MaxComputeWorkGroupCountZ = */ 65535,
68     /* .MaxComputeWorkGroupSizeX = */ 1024,
69     /* .MaxComputeWorkGroupSizeY = */ 1024,
70     /* .MaxComputeWorkGroupSizeZ = */ 64,
71     /* .MaxComputeUniformComponents = */ 1024,
72     /* .MaxComputeTextureImageUnits = */ 16,
73     /* .MaxComputeImageUniforms = */ 8,
74     /* .MaxComputeAtomicCounters = */ 8,
75     /* .MaxComputeAtomicCounterBuffers = */ 1,
76     /* .MaxVaryingComponents = */ 60,
77     /* .MaxVertexOutputComponents = */ 64,
78     /* .MaxGeometryInputComponents = */ 64,
79     /* .MaxGeometryOutputComponents = */ 128,
80     /* .MaxFragmentInputComponents = */ 128,
81     /* .MaxImageUnits = */ 8,
82     /* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8,
83     /* .MaxCombinedShaderOutputResources = */ 8,
84     /* .MaxImageSamples = */ 0,
85     /* .MaxVertexImageUniforms = */ 0,
86     /* .MaxTessControlImageUniforms = */ 0,
87     /* .MaxTessEvaluationImageUniforms = */ 0,
88     /* .MaxGeometryImageUniforms = */ 0,
89     /* .MaxFragmentImageUniforms = */ 8,
90     /* .MaxCombinedImageUniforms = */ 8,
91     /* .MaxGeometryTextureImageUnits = */ 16,
92     /* .MaxGeometryOutputVertices = */ 256,
93     /* .MaxGeometryTotalOutputComponents = */ 1024,
94     /* .MaxGeometryUniformComponents = */ 1024,
95     /* .MaxGeometryVaryingComponents = */ 64,
96     /* .MaxTessControlInputComponents = */ 128,
97     /* .MaxTessControlOutputComponents = */ 128,
98     /* .MaxTessControlTextureImageUnits = */ 16,
99     /* .MaxTessControlUniformComponents = */ 1024,
100     /* .MaxTessControlTotalOutputComponents = */ 4096,
101     /* .MaxTessEvaluationInputComponents = */ 128,
102     /* .MaxTessEvaluationOutputComponents = */ 128,
103     /* .MaxTessEvaluationTextureImageUnits = */ 16,
104     /* .MaxTessEvaluationUniformComponents = */ 1024,
105     /* .MaxTessPatchComponents = */ 120,
106     /* .MaxPatchVertices = */ 32,
107     /* .MaxTessGenLevel = */ 64,
108     /* .MaxViewports = */ 16,
109     /* .MaxVertexAtomicCounters = */ 0,
110     /* .MaxTessControlAtomicCounters = */ 0,
111     /* .MaxTessEvaluationAtomicCounters = */ 0,
112     /* .MaxGeometryAtomicCounters = */ 0,
113     /* .MaxFragmentAtomicCounters = */ 8,
114     /* .MaxCombinedAtomicCounters = */ 8,
115     /* .MaxAtomicCounterBindings = */ 1,
116     /* .MaxVertexAtomicCounterBuffers = */ 0,
117     /* .MaxTessControlAtomicCounterBuffers = */ 0,
118     /* .MaxTessEvaluationAtomicCounterBuffers = */ 0,
119     /* .MaxGeometryAtomicCounterBuffers = */ 0,
120     /* .MaxFragmentAtomicCounterBuffers = */ 1,
121     /* .MaxCombinedAtomicCounterBuffers = */ 1,
122     /* .MaxAtomicCounterBufferSize = */ 16384,
123     /* .MaxTransformFeedbackBuffers = */ 4,
124     /* .MaxTransformFeedbackInterleavedComponents = */ 64,
125     /* .MaxCullDistances = */ 8,
126     /* .MaxCombinedClipAndCullDistances = */ 8,
127     /* .MaxSamples = */ 4,
128     /* .maxMeshOutputVerticesNV = */ 256,
129     /* .maxMeshOutputPrimitivesNV = */ 512,
130     /* .maxMeshWorkGroupSizeX_NV = */ 32,
131     /* .maxMeshWorkGroupSizeY_NV = */ 1,
132     /* .maxMeshWorkGroupSizeZ_NV = */ 1,
133     /* .maxTaskWorkGroupSizeX_NV = */ 32,
134     /* .maxTaskWorkGroupSizeY_NV = */ 1,
135     /* .maxTaskWorkGroupSizeZ_NV = */ 1,
136     /* .maxMeshViewCountNV = */ 4,
137     /* .maxMeshOutputVerticesEXT = */ 256,
138     /* .maxMeshOutputPrimitivesEXT = */ 256,
139     /* .maxMeshWorkGroupSizeX_EXT = */ 128,
140     /* .maxMeshWorkGroupSizeY_EXT = */ 128,
141     /* .maxMeshWorkGroupSizeZ_EXT = */ 128,
142     /* .maxTaskWorkGroupSizeX_EXT = */ 128,
143     /* .maxTaskWorkGroupSizeY_EXT = */ 128,
144     /* .maxTaskWorkGroupSizeZ_EXT = */ 128,
145     /* .maxMeshViewCountEXT = */ 4,
146     /* .maxDualSourceDrawBuffersEXT = */ 1,
147
148     /* .limits = */ {
149         /* .nonInductiveForLoops = */ 1,
150         /* .whileLoops = */ 1,
151         /* .doWhileLoops = */ 1,
152         /* .generalUniformIndexing = */ 1,
153         /* .generalAttributeMatrixVectorIndexing = */ 1,
154         /* .generalVaryingIndexing = */ 1,
155         /* .generalSamplerIndexing = */ 1,
156         /* .generalVariableIndexing = */ 1,
157         /* .generalConstantMatrixVectorIndexing = */ 1,
158     }};
159
160 std::string GetDefaultTBuiltInResourceString()
161 {
162     std::ostringstream ostream;
163
164     ostream << "MaxLights "                                 << DefaultTBuiltInResource.maxLights << "\n"
165             << "MaxClipPlanes "                             << DefaultTBuiltInResource.maxClipPlanes << "\n"
166             << "MaxTextureUnits "                           << DefaultTBuiltInResource.maxTextureUnits << "\n"
167             << "MaxTextureCoords "                          << DefaultTBuiltInResource.maxTextureCoords << "\n"
168             << "MaxVertexAttribs "                          << DefaultTBuiltInResource.maxVertexAttribs << "\n"
169             << "MaxVertexUniformComponents "                << DefaultTBuiltInResource.maxVertexUniformComponents << "\n"
170             << "MaxVaryingFloats "                          << DefaultTBuiltInResource.maxVaryingFloats << "\n"
171             << "MaxVertexTextureImageUnits "                << DefaultTBuiltInResource.maxVertexTextureImageUnits << "\n"
172             << "MaxCombinedTextureImageUnits "              << DefaultTBuiltInResource.maxCombinedTextureImageUnits << "\n"
173             << "MaxTextureImageUnits "                      << DefaultTBuiltInResource.maxTextureImageUnits << "\n"
174             << "MaxFragmentUniformComponents "              << DefaultTBuiltInResource.maxFragmentUniformComponents << "\n"
175             << "MaxDrawBuffers "                            << DefaultTBuiltInResource.maxDrawBuffers << "\n"
176             << "MaxVertexUniformVectors "                   << DefaultTBuiltInResource.maxVertexUniformVectors << "\n"
177             << "MaxVaryingVectors "                         << DefaultTBuiltInResource.maxVaryingVectors << "\n"
178             << "MaxFragmentUniformVectors "                 << DefaultTBuiltInResource.maxFragmentUniformVectors << "\n"
179             << "MaxVertexOutputVectors "                    << DefaultTBuiltInResource.maxVertexOutputVectors << "\n"
180             << "MaxFragmentInputVectors "                   << DefaultTBuiltInResource.maxFragmentInputVectors << "\n"
181             << "MinProgramTexelOffset "                     << DefaultTBuiltInResource.minProgramTexelOffset << "\n"
182             << "MaxProgramTexelOffset "                     << DefaultTBuiltInResource.maxProgramTexelOffset << "\n"
183             << "MaxClipDistances "                          << DefaultTBuiltInResource.maxClipDistances << "\n"
184             << "MaxComputeWorkGroupCountX "                 << DefaultTBuiltInResource.maxComputeWorkGroupCountX << "\n"
185             << "MaxComputeWorkGroupCountY "                 << DefaultTBuiltInResource.maxComputeWorkGroupCountY << "\n"
186             << "MaxComputeWorkGroupCountZ "                 << DefaultTBuiltInResource.maxComputeWorkGroupCountZ << "\n"
187             << "MaxComputeWorkGroupSizeX "                  << DefaultTBuiltInResource.maxComputeWorkGroupSizeX << "\n"
188             << "MaxComputeWorkGroupSizeY "                  << DefaultTBuiltInResource.maxComputeWorkGroupSizeY << "\n"
189             << "MaxComputeWorkGroupSizeZ "                  << DefaultTBuiltInResource.maxComputeWorkGroupSizeZ << "\n"
190             << "MaxComputeUniformComponents "               << DefaultTBuiltInResource.maxComputeUniformComponents << "\n"
191             << "MaxComputeTextureImageUnits "               << DefaultTBuiltInResource.maxComputeTextureImageUnits << "\n"
192             << "MaxComputeImageUniforms "                   << DefaultTBuiltInResource.maxComputeImageUniforms << "\n"
193             << "MaxComputeAtomicCounters "                  << DefaultTBuiltInResource.maxComputeAtomicCounters << "\n"
194             << "MaxComputeAtomicCounterBuffers "            << DefaultTBuiltInResource.maxComputeAtomicCounterBuffers << "\n"
195             << "MaxVaryingComponents "                      << DefaultTBuiltInResource.maxVaryingComponents << "\n"
196             << "MaxVertexOutputComponents "                 << DefaultTBuiltInResource.maxVertexOutputComponents << "\n"
197             << "MaxGeometryInputComponents "                << DefaultTBuiltInResource.maxGeometryInputComponents << "\n"
198             << "MaxGeometryOutputComponents "               << DefaultTBuiltInResource.maxGeometryOutputComponents << "\n"
199             << "MaxFragmentInputComponents "                << DefaultTBuiltInResource.maxFragmentInputComponents << "\n"
200             << "MaxImageUnits "                             << DefaultTBuiltInResource.maxImageUnits << "\n"
201             << "MaxCombinedImageUnitsAndFragmentOutputs "   << DefaultTBuiltInResource.maxCombinedImageUnitsAndFragmentOutputs << "\n"
202             << "MaxCombinedShaderOutputResources "          << DefaultTBuiltInResource.maxCombinedShaderOutputResources << "\n"
203             << "MaxImageSamples "                           << DefaultTBuiltInResource.maxImageSamples << "\n"
204             << "MaxVertexImageUniforms "                    << DefaultTBuiltInResource.maxVertexImageUniforms << "\n"
205             << "MaxTessControlImageUniforms "               << DefaultTBuiltInResource.maxTessControlImageUniforms << "\n"
206             << "MaxTessEvaluationImageUniforms "            << DefaultTBuiltInResource.maxTessEvaluationImageUniforms << "\n"
207             << "MaxGeometryImageUniforms "                  << DefaultTBuiltInResource.maxGeometryImageUniforms << "\n"
208             << "MaxFragmentImageUniforms "                  << DefaultTBuiltInResource.maxFragmentImageUniforms << "\n"
209             << "MaxCombinedImageUniforms "                  << DefaultTBuiltInResource.maxCombinedImageUniforms << "\n"
210             << "MaxGeometryTextureImageUnits "              << DefaultTBuiltInResource.maxGeometryTextureImageUnits << "\n"
211             << "MaxGeometryOutputVertices "                 << DefaultTBuiltInResource.maxGeometryOutputVertices << "\n"
212             << "MaxGeometryTotalOutputComponents "          << DefaultTBuiltInResource.maxGeometryTotalOutputComponents << "\n"
213             << "MaxGeometryUniformComponents "              << DefaultTBuiltInResource.maxGeometryUniformComponents << "\n"
214             << "MaxGeometryVaryingComponents "              << DefaultTBuiltInResource.maxGeometryVaryingComponents << "\n"
215             << "MaxTessControlInputComponents "             << DefaultTBuiltInResource.maxTessControlInputComponents << "\n"
216             << "MaxTessControlOutputComponents "            << DefaultTBuiltInResource.maxTessControlOutputComponents << "\n"
217             << "MaxTessControlTextureImageUnits "           << DefaultTBuiltInResource.maxTessControlTextureImageUnits << "\n"
218             << "MaxTessControlUniformComponents "           << DefaultTBuiltInResource.maxTessControlUniformComponents << "\n"
219             << "MaxTessControlTotalOutputComponents "       << DefaultTBuiltInResource.maxTessControlTotalOutputComponents << "\n"
220             << "MaxTessEvaluationInputComponents "          << DefaultTBuiltInResource.maxTessEvaluationInputComponents << "\n"
221             << "MaxTessEvaluationOutputComponents "         << DefaultTBuiltInResource.maxTessEvaluationOutputComponents << "\n"
222             << "MaxTessEvaluationTextureImageUnits "        << DefaultTBuiltInResource.maxTessEvaluationTextureImageUnits << "\n"
223             << "MaxTessEvaluationUniformComponents "        << DefaultTBuiltInResource.maxTessEvaluationUniformComponents << "\n"
224             << "MaxTessPatchComponents "                    << DefaultTBuiltInResource.maxTessPatchComponents << "\n"
225             << "MaxPatchVertices "                          << DefaultTBuiltInResource.maxPatchVertices << "\n"
226             << "MaxTessGenLevel "                           << DefaultTBuiltInResource.maxTessGenLevel << "\n"
227             << "MaxViewports "                              << DefaultTBuiltInResource.maxViewports << "\n"
228             << "MaxVertexAtomicCounters "                   << DefaultTBuiltInResource.maxVertexAtomicCounters << "\n"
229             << "MaxTessControlAtomicCounters "              << DefaultTBuiltInResource.maxTessControlAtomicCounters << "\n"
230             << "MaxTessEvaluationAtomicCounters "           << DefaultTBuiltInResource.maxTessEvaluationAtomicCounters << "\n"
231             << "MaxGeometryAtomicCounters "                 << DefaultTBuiltInResource.maxGeometryAtomicCounters << "\n"
232             << "MaxFragmentAtomicCounters "                 << DefaultTBuiltInResource.maxFragmentAtomicCounters << "\n"
233             << "MaxCombinedAtomicCounters "                 << DefaultTBuiltInResource.maxCombinedAtomicCounters << "\n"
234             << "MaxAtomicCounterBindings "                  << DefaultTBuiltInResource.maxAtomicCounterBindings << "\n"
235             << "MaxVertexAtomicCounterBuffers "             << DefaultTBuiltInResource.maxVertexAtomicCounterBuffers << "\n"
236             << "MaxTessControlAtomicCounterBuffers "        << DefaultTBuiltInResource.maxTessControlAtomicCounterBuffers << "\n"
237             << "MaxTessEvaluationAtomicCounterBuffers "     << DefaultTBuiltInResource.maxTessEvaluationAtomicCounterBuffers << "\n"
238             << "MaxGeometryAtomicCounterBuffers "           << DefaultTBuiltInResource.maxGeometryAtomicCounterBuffers << "\n"
239             << "MaxFragmentAtomicCounterBuffers "           << DefaultTBuiltInResource.maxFragmentAtomicCounterBuffers << "\n"
240             << "MaxCombinedAtomicCounterBuffers "           << DefaultTBuiltInResource.maxCombinedAtomicCounterBuffers << "\n"
241             << "MaxAtomicCounterBufferSize "                << DefaultTBuiltInResource.maxAtomicCounterBufferSize << "\n"
242             << "MaxTransformFeedbackBuffers "               << DefaultTBuiltInResource.maxTransformFeedbackBuffers << "\n"
243             << "MaxTransformFeedbackInterleavedComponents " << DefaultTBuiltInResource.maxTransformFeedbackInterleavedComponents << "\n"
244             << "MaxCullDistances "                          << DefaultTBuiltInResource.maxCullDistances << "\n"
245             << "MaxCombinedClipAndCullDistances "           << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n"
246             << "MaxSamples "                                << DefaultTBuiltInResource.maxSamples << "\n"
247             << "MaxMeshOutputVerticesNV "                   << DefaultTBuiltInResource.maxMeshOutputVerticesNV << "\n"
248             << "MaxMeshOutputPrimitivesNV "                 << DefaultTBuiltInResource.maxMeshOutputPrimitivesNV << "\n"
249             << "MaxMeshWorkGroupSizeX_NV "                  << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_NV << "\n"
250             << "MaxMeshWorkGroupSizeY_NV "                  << DefaultTBuiltInResource.maxMeshWorkGroupSizeY_NV << "\n"
251             << "MaxMeshWorkGroupSizeZ_NV "                  << DefaultTBuiltInResource.maxMeshWorkGroupSizeZ_NV << "\n"
252             << "MaxTaskWorkGroupSizeX_NV "                  << DefaultTBuiltInResource.maxTaskWorkGroupSizeX_NV << "\n"
253             << "MaxTaskWorkGroupSizeY_NV "                  << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_NV << "\n"
254             << "MaxTaskWorkGroupSizeZ_NV "                  << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_NV << "\n"
255             << "MaxMeshViewCountNV "                        << DefaultTBuiltInResource.maxMeshViewCountNV << "\n"
256             << "MaxMeshOutputVerticesEXT "                  << DefaultTBuiltInResource.maxMeshOutputVerticesEXT << "\n"
257             << "MaxMeshOutputPrimitivesEXT "                << DefaultTBuiltInResource.maxMeshOutputPrimitivesEXT << "\n"
258             << "MaxMeshWorkGroupSizeX_EXT "                 << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_EXT << "\n"
259             << "MaxMeshWorkGroupSizeY_EXT "                 << DefaultTBuiltInResource.maxMeshWorkGroupSizeY_EXT << "\n"
260             << "MaxMeshWorkGroupSizeZ_EXT "                 << DefaultTBuiltInResource.maxMeshWorkGroupSizeZ_EXT << "\n"
261             << "MaxTaskWorkGroupSizeX_EXT "                 << DefaultTBuiltInResource.maxTaskWorkGroupSizeX_EXT << "\n"
262             << "MaxTaskWorkGroupSizeY_EXT "                 << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_EXT << "\n"
263             << "MaxTaskWorkGroupSizeZ_EXT "                 << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_EXT << "\n"
264             << "MaxMeshViewCountEXT "                       << DefaultTBuiltInResource.maxMeshViewCountEXT << "\n"
265             << "MaxDualSourceDrawBuffersEXT "               << DefaultTBuiltInResource.maxDualSourceDrawBuffersEXT << "\n"
266             << "nonInductiveForLoops "                      << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n"
267             << "whileLoops "                                << DefaultTBuiltInResource.limits.whileLoops << "\n"
268             << "doWhileLoops "                              << DefaultTBuiltInResource.limits.doWhileLoops << "\n"
269             << "generalUniformIndexing "                    << DefaultTBuiltInResource.limits.generalUniformIndexing << "\n"
270             << "generalAttributeMatrixVectorIndexing "      << DefaultTBuiltInResource.limits.generalAttributeMatrixVectorIndexing << "\n"
271             << "generalVaryingIndexing "                    << DefaultTBuiltInResource.limits.generalVaryingIndexing << "\n"
272             << "generalSamplerIndexing "                    << DefaultTBuiltInResource.limits.generalSamplerIndexing << "\n"
273             << "generalVariableIndexing "                   << DefaultTBuiltInResource.limits.generalVariableIndexing << "\n"
274             << "generalConstantMatrixVectorIndexing "       << DefaultTBuiltInResource.limits.generalConstantMatrixVectorIndexing << "\n"
275       ;
276
277     return ostream.str();
278 }
279
280 void DecodeResourceLimits(TBuiltInResource* resources, char* config)
281 {
282     static const char* delims = " \t\n\r";
283
284     size_t pos     = 0;
285     std::string configStr(config);
286
287     while ((pos = configStr.find_first_not_of(delims, pos)) != std::string::npos) {
288         const size_t token_s = pos;
289         const size_t token_e = configStr.find_first_of(delims, token_s);
290         const size_t value_s = configStr.find_first_not_of(delims, token_e);
291         const size_t value_e = configStr.find_first_of(delims, value_s);
292         pos = value_e;
293
294         // Faster to use compare(), but prefering readability.
295         const std::string tokenStr = configStr.substr(token_s, token_e-token_s);
296         const std::string valueStr = configStr.substr(value_s, value_e-value_s);
297
298         if (value_s == std::string::npos || ! (valueStr[0] == '-' || isdigit(valueStr[0]))) {
299             printf("Error: '%s' bad .conf file.  Each name must be followed by one number.\n",
300                    valueStr.c_str());
301             return;
302         }
303
304         const int value = std::atoi(valueStr.c_str());
305
306         if (tokenStr == "MaxLights")
307             resources->maxLights = value;
308         else if (tokenStr == "MaxClipPlanes")
309             resources->maxClipPlanes = value;
310         else if (tokenStr == "MaxTextureUnits")
311             resources->maxTextureUnits = value;
312         else if (tokenStr == "MaxTextureCoords")
313             resources->maxTextureCoords = value;
314         else if (tokenStr == "MaxVertexAttribs")
315             resources->maxVertexAttribs = value;
316         else if (tokenStr == "MaxVertexUniformComponents")
317             resources->maxVertexUniformComponents = value;
318         else if (tokenStr == "MaxVaryingFloats")
319             resources->maxVaryingFloats = value;
320         else if (tokenStr == "MaxVertexTextureImageUnits")
321             resources->maxVertexTextureImageUnits = value;
322         else if (tokenStr == "MaxCombinedTextureImageUnits")
323             resources->maxCombinedTextureImageUnits = value;
324         else if (tokenStr == "MaxTextureImageUnits")
325             resources->maxTextureImageUnits = value;
326         else if (tokenStr == "MaxFragmentUniformComponents")
327             resources->maxFragmentUniformComponents = value;
328         else if (tokenStr == "MaxDrawBuffers")
329             resources->maxDrawBuffers = value;
330         else if (tokenStr == "MaxVertexUniformVectors")
331             resources->maxVertexUniformVectors = value;
332         else if (tokenStr == "MaxVaryingVectors")
333             resources->maxVaryingVectors = value;
334         else if (tokenStr == "MaxFragmentUniformVectors")
335             resources->maxFragmentUniformVectors = value;
336         else if (tokenStr == "MaxVertexOutputVectors")
337             resources->maxVertexOutputVectors = value;
338         else if (tokenStr == "MaxFragmentInputVectors")
339             resources->maxFragmentInputVectors = value;
340         else if (tokenStr == "MinProgramTexelOffset")
341             resources->minProgramTexelOffset = value;
342         else if (tokenStr == "MaxProgramTexelOffset")
343             resources->maxProgramTexelOffset = value;
344         else if (tokenStr == "MaxClipDistances")
345             resources->maxClipDistances = value;
346         else if (tokenStr == "MaxComputeWorkGroupCountX")
347             resources->maxComputeWorkGroupCountX = value;
348         else if (tokenStr == "MaxComputeWorkGroupCountY")
349             resources->maxComputeWorkGroupCountY = value;
350         else if (tokenStr == "MaxComputeWorkGroupCountZ")
351             resources->maxComputeWorkGroupCountZ = value;
352         else if (tokenStr == "MaxComputeWorkGroupSizeX")
353             resources->maxComputeWorkGroupSizeX = value;
354         else if (tokenStr == "MaxComputeWorkGroupSizeY")
355             resources->maxComputeWorkGroupSizeY = value;
356         else if (tokenStr == "MaxComputeWorkGroupSizeZ")
357             resources->maxComputeWorkGroupSizeZ = value;
358         else if (tokenStr == "MaxComputeUniformComponents")
359             resources->maxComputeUniformComponents = value;
360         else if (tokenStr == "MaxComputeTextureImageUnits")
361             resources->maxComputeTextureImageUnits = value;
362         else if (tokenStr == "MaxComputeImageUniforms")
363             resources->maxComputeImageUniforms = value;
364         else if (tokenStr == "MaxComputeAtomicCounters")
365             resources->maxComputeAtomicCounters = value;
366         else if (tokenStr == "MaxComputeAtomicCounterBuffers")
367             resources->maxComputeAtomicCounterBuffers = value;
368         else if (tokenStr == "MaxVaryingComponents")
369             resources->maxVaryingComponents = value;
370         else if (tokenStr == "MaxVertexOutputComponents")
371             resources->maxVertexOutputComponents = value;
372         else if (tokenStr == "MaxGeometryInputComponents")
373             resources->maxGeometryInputComponents = value;
374         else if (tokenStr == "MaxGeometryOutputComponents")
375             resources->maxGeometryOutputComponents = value;
376         else if (tokenStr == "MaxFragmentInputComponents")
377             resources->maxFragmentInputComponents = value;
378         else if (tokenStr == "MaxImageUnits")
379             resources->maxImageUnits = value;
380         else if (tokenStr == "MaxCombinedImageUnitsAndFragmentOutputs")
381             resources->maxCombinedImageUnitsAndFragmentOutputs = value;
382         else if (tokenStr == "MaxCombinedShaderOutputResources")
383             resources->maxCombinedShaderOutputResources = value;
384         else if (tokenStr == "MaxImageSamples")
385             resources->maxImageSamples = value;
386         else if (tokenStr == "MaxVertexImageUniforms")
387             resources->maxVertexImageUniforms = value;
388         else if (tokenStr == "MaxTessControlImageUniforms")
389             resources->maxTessControlImageUniforms = value;
390         else if (tokenStr == "MaxTessEvaluationImageUniforms")
391             resources->maxTessEvaluationImageUniforms = value;
392         else if (tokenStr == "MaxGeometryImageUniforms")
393             resources->maxGeometryImageUniforms = value;
394         else if (tokenStr == "MaxFragmentImageUniforms")
395             resources->maxFragmentImageUniforms = value;
396         else if (tokenStr == "MaxCombinedImageUniforms")
397             resources->maxCombinedImageUniforms = value;
398         else if (tokenStr == "MaxGeometryTextureImageUnits")
399             resources->maxGeometryTextureImageUnits = value;
400         else if (tokenStr == "MaxGeometryOutputVertices")
401             resources->maxGeometryOutputVertices = value;
402         else if (tokenStr == "MaxGeometryTotalOutputComponents")
403             resources->maxGeometryTotalOutputComponents = value;
404         else if (tokenStr == "MaxGeometryUniformComponents")
405             resources->maxGeometryUniformComponents = value;
406         else if (tokenStr == "MaxGeometryVaryingComponents")
407             resources->maxGeometryVaryingComponents = value;
408         else if (tokenStr == "MaxTessControlInputComponents")
409             resources->maxTessControlInputComponents = value;
410         else if (tokenStr == "MaxTessControlOutputComponents")
411             resources->maxTessControlOutputComponents = value;
412         else if (tokenStr == "MaxTessControlTextureImageUnits")
413             resources->maxTessControlTextureImageUnits = value;
414         else if (tokenStr == "MaxTessControlUniformComponents")
415             resources->maxTessControlUniformComponents = value;
416         else if (tokenStr == "MaxTessControlTotalOutputComponents")
417             resources->maxTessControlTotalOutputComponents = value;
418         else if (tokenStr == "MaxTessEvaluationInputComponents")
419             resources->maxTessEvaluationInputComponents = value;
420         else if (tokenStr == "MaxTessEvaluationOutputComponents")
421             resources->maxTessEvaluationOutputComponents = value;
422         else if (tokenStr == "MaxTessEvaluationTextureImageUnits")
423             resources->maxTessEvaluationTextureImageUnits = value;
424         else if (tokenStr == "MaxTessEvaluationUniformComponents")
425             resources->maxTessEvaluationUniformComponents = value;
426         else if (tokenStr == "MaxTessPatchComponents")
427             resources->maxTessPatchComponents = value;
428         else if (tokenStr == "MaxPatchVertices")
429             resources->maxPatchVertices = value;
430         else if (tokenStr == "MaxTessGenLevel")
431             resources->maxTessGenLevel = value;
432         else if (tokenStr == "MaxViewports")
433             resources->maxViewports = value;
434         else if (tokenStr == "MaxVertexAtomicCounters")
435             resources->maxVertexAtomicCounters = value;
436         else if (tokenStr == "MaxTessControlAtomicCounters")
437             resources->maxTessControlAtomicCounters = value;
438         else if (tokenStr == "MaxTessEvaluationAtomicCounters")
439             resources->maxTessEvaluationAtomicCounters = value;
440         else if (tokenStr == "MaxGeometryAtomicCounters")
441             resources->maxGeometryAtomicCounters = value;
442         else if (tokenStr == "MaxFragmentAtomicCounters")
443             resources->maxFragmentAtomicCounters = value;
444         else if (tokenStr == "MaxCombinedAtomicCounters")
445             resources->maxCombinedAtomicCounters = value;
446         else if (tokenStr == "MaxAtomicCounterBindings")
447             resources->maxAtomicCounterBindings = value;
448         else if (tokenStr == "MaxVertexAtomicCounterBuffers")
449             resources->maxVertexAtomicCounterBuffers = value;
450         else if (tokenStr == "MaxTessControlAtomicCounterBuffers")
451             resources->maxTessControlAtomicCounterBuffers = value;
452         else if (tokenStr == "MaxTessEvaluationAtomicCounterBuffers")
453             resources->maxTessEvaluationAtomicCounterBuffers = value;
454         else if (tokenStr == "MaxGeometryAtomicCounterBuffers")
455             resources->maxGeometryAtomicCounterBuffers = value;
456         else if (tokenStr == "MaxFragmentAtomicCounterBuffers")
457             resources->maxFragmentAtomicCounterBuffers = value;
458         else if (tokenStr == "MaxCombinedAtomicCounterBuffers")
459             resources->maxCombinedAtomicCounterBuffers = value;
460         else if (tokenStr == "MaxAtomicCounterBufferSize")
461             resources->maxAtomicCounterBufferSize = value;
462         else if (tokenStr == "MaxTransformFeedbackBuffers")
463             resources->maxTransformFeedbackBuffers = value;
464         else if (tokenStr == "MaxTransformFeedbackInterleavedComponents")
465             resources->maxTransformFeedbackInterleavedComponents = value;
466         else if (tokenStr == "MaxCullDistances")
467             resources->maxCullDistances = value;
468         else if (tokenStr == "MaxCombinedClipAndCullDistances")
469             resources->maxCombinedClipAndCullDistances = value;
470         else if (tokenStr == "MaxSamples")
471             resources->maxSamples = value;
472         else if (tokenStr == "MaxMeshOutputVerticesNV")
473             resources->maxMeshOutputVerticesNV = value;
474         else if (tokenStr == "MaxMeshOutputPrimitivesNV")
475             resources->maxMeshOutputPrimitivesNV = value;
476         else if (tokenStr == "MaxMeshWorkGroupSizeX_NV")
477             resources->maxMeshWorkGroupSizeX_NV = value;
478         else if (tokenStr == "MaxMeshWorkGroupSizeY_NV")
479             resources->maxMeshWorkGroupSizeY_NV = value;
480         else if (tokenStr == "MaxMeshWorkGroupSizeZ_NV")
481             resources->maxMeshWorkGroupSizeZ_NV = value;
482         else if (tokenStr == "MaxTaskWorkGroupSizeX_NV")
483             resources->maxTaskWorkGroupSizeX_NV = value;
484         else if (tokenStr == "MaxTaskWorkGroupSizeY_NV")
485             resources->maxTaskWorkGroupSizeY_NV = value;
486         else if (tokenStr == "MaxTaskWorkGroupSizeZ_NV")
487             resources->maxTaskWorkGroupSizeZ_NV = value;
488         else if (tokenStr == "MaxMeshViewCountNV")
489             resources->maxMeshViewCountNV = value;
490         else if (tokenStr == "MaxMeshOutputVerticesEXT")
491             resources->maxMeshOutputVerticesEXT = value;
492         else if (tokenStr == "MaxMeshOutputPrimitivesEXT")
493             resources->maxMeshOutputPrimitivesEXT = value;
494         else if (tokenStr == "MaxMeshWorkGroupSizeX_EXT")
495             resources->maxMeshWorkGroupSizeX_EXT = value;
496         else if (tokenStr == "MaxMeshWorkGroupSizeY_EXT")
497             resources->maxMeshWorkGroupSizeY_EXT = value;
498         else if (tokenStr == "MaxMeshWorkGroupSizeZ_EXT")
499             resources->maxMeshWorkGroupSizeZ_EXT = value;
500         else if (tokenStr == "MaxTaskWorkGroupSizeX_EXT")
501             resources->maxTaskWorkGroupSizeX_EXT = value;
502         else if (tokenStr == "MaxTaskWorkGroupSizeY_EXT")
503             resources->maxTaskWorkGroupSizeY_EXT = value;
504         else if (tokenStr == "MaxTaskWorkGroupSizeZ_EXT")
505             resources->maxTaskWorkGroupSizeZ_EXT = value;
506         else if (tokenStr == "MaxMeshViewCountEXT")
507             resources->maxMeshViewCountEXT = value;
508         else if (tokenStr == "nonInductiveForLoops")
509             resources->limits.nonInductiveForLoops = (value != 0);
510         else if (tokenStr == "whileLoops")
511             resources->limits.whileLoops = (value != 0);
512         else if (tokenStr == "doWhileLoops")
513             resources->limits.doWhileLoops = (value != 0);
514         else if (tokenStr == "generalUniformIndexing")
515             resources->limits.generalUniformIndexing = (value != 0);
516         else if (tokenStr == "generalAttributeMatrixVectorIndexing")
517             resources->limits.generalAttributeMatrixVectorIndexing = (value != 0);
518         else if (tokenStr == "generalVaryingIndexing")
519             resources->limits.generalVaryingIndexing = (value != 0);
520         else if (tokenStr == "generalSamplerIndexing")
521             resources->limits.generalSamplerIndexing = (value != 0);
522         else if (tokenStr == "generalVariableIndexing")
523             resources->limits.generalVariableIndexing = (value != 0);
524         else if (tokenStr == "generalConstantMatrixVectorIndexing")
525             resources->limits.generalConstantMatrixVectorIndexing = (value != 0);
526         else
527             printf("Warning: unrecognized limit (%s) in configuration file.\n", tokenStr.c_str());
528
529     }
530 }
531
532 TBuiltInResource* GetResources()
533 {
534    return &Resources;
535 }
536
537 const TBuiltInResource* GetDefaultResources()
538 {
539     return &DefaultTBuiltInResource;
540 }