45 if (!source)
return 0;
47 for (
const char* p = source; (p = std::strstr(p,
"@group(")) !=
nullptr;) {
50 const unsigned long g = std::strtoul(p, &end, 10);
51 if (end == p)
continue;
53 if (g != group)
continue;
54 const char* b = std::strstr(p,
"@binding(");
57 const unsigned long idx = std::strtoul(b, &end, 10);
58 if (end == b)
continue;
60 if (idx < 64) mask |= (
u64{1} << idx);
82 const auto isIdent = [](
char c) {
83 return (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9') || c ==
'_';
85 const auto isSpace = [](
char c) {
return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r'; };
87 const auto ownName = [&](
const char* p,
const char* end) ->
bool {
89 while (b != source && isSpace(b[-1])) --b;
90 const char* after = end;
91 while (isSpace(*after)) ++after;
92 if (b != source && (b[-1] ==
'(' || b[-1] ==
',' || b[-1] ==
'{') && *after ==
':')
return true;
94 while (w != source && isIdent(w[-1])) --w;
96 if (len == 3 && std::strncmp(w,
"let", 3) == 0)
return true;
97 if (len == 5 && std::strncmp(w,
"const", 5) == 0)
return true;
98 if (len != 3 || std::strncmp(w,
"var", 3) != 0)
return false;
99 while (w != source && isSpace(w[-1])) --w;
100 return w == source || w[-1] !=
')';
104 for (
const char* p = source; *p; ++p) {
105 if (*p !=
't' && *p !=
's')
continue;
106 if (p != source && isIdent(p[-1]))
continue;
108 const unsigned long unit = std::strtoul(p + 1, &end, 10);
109 if (end == p + 1 || isIdent(*end))
continue;
111 (*p ==
't' ? textures : samplers) |= (1u << unit);
112 if (ownName(p, end)) (*p ==
't' ? ownTextures : ownSamplers) |= (1u << unit);
116 textures &= ~ownTextures;
117 samplers &= ~ownSamplers;