Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/src/resource_parse.cc
1560 views
1
// Copyright 2016 The Shaderc Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "resource_parse.h"
16
17
#include <algorithm>
18
#include <cstring>
19
#include <iterator>
20
#include <sstream>
21
#include <vector>
22
23
namespace {
24
25
// Converts a limit string to a limit enum. Returns true on successful
26
// conversion.
27
bool StringToLimit(const std::string& str, shaderc_limit* limit) {
28
const char* cstr = str.c_str();
29
#define RESOURCE(NAME, FIELD, ENUM) \
30
if (0 == std::strcmp(#NAME, cstr)) { \
31
*limit = shaderc_limit_##ENUM; \
32
return true; \
33
}
34
#include "libshaderc_util/resources.inc"
35
#undef RESOURCE
36
return false;
37
}
38
39
// Returns true if we should ignore the setting.
40
bool IgnoreSetting(const std::string& str) {
41
const std::string ignore_list[] = {
42
"nonInductiveForLoops",
43
"whileLoops",
44
"doWhileLoops",
45
"generalUniformIndexing",
46
"generalAttributeMatrixVectorIndexing",
47
"generalVaryingIndexing",
48
"generalSamplerIndexing",
49
"generalVariableIndexing",
50
"generalConstantMatrixVectorIndexing",
51
};
52
return std::find(std::begin(ignore_list), std::end(ignore_list), str) !=
53
std::end(ignore_list);
54
}
55
56
} // anonymous namespace
57
58
namespace glslc {
59
60
bool ParseResourceSettings(const std::string& input,
61
std::vector<ResourceSetting>* limits,
62
std::string* err) {
63
auto failure = [err, limits](std::string msg) {
64
*err = msg;
65
limits->clear();
66
return false;
67
};
68
std::istringstream input_stream(input);
69
std::istream_iterator<std::string> pos((input_stream));
70
limits->clear();
71
72
while (pos != std::istream_iterator<std::string>()) {
73
const std::string limit_name = *pos++;
74
shaderc_limit limit = static_cast<shaderc_limit>(0);
75
bool ignore = IgnoreSetting(limit_name);
76
if (!ignore) {
77
if (!StringToLimit(limit_name, &limit))
78
return failure(std::string("invalid resource limit: " + limit_name));
79
}
80
81
if (pos == std::istream_iterator<std::string>())
82
return failure(std::string("missing value after limit: ") + limit_name);
83
84
const std::string value_str = *pos;
85
int value;
86
std::istringstream value_stream(value_str);
87
value_stream >> value;
88
if (value_stream.bad() || !value_stream.eof() || value_stream.fail())
89
return failure(std::string("invalid integer: ") + value_str);
90
91
if (!ignore) limits->push_back({limit, value});
92
++pos;
93
}
94
95
return true;
96
}
97
} // anonymous namespace
98
99