The source stays where the caller keeps it. A token, an identifier or a member name is a view of it, a 16-bit position and length, so a source is 65535 bytes at most; the lexer scans a copy in the workspace with zero bytes after its end, so it reads ahead without asking where the source ends. Three passes write arrays of fixed records that refer to each other by 16-bit index, never by pointer, all carved from the caller's workspace by each compilation, which clears none of it: the emitter's hash of types and constants says which slots are taken with a sparse set, which nothing the workspace held can fake.
A token's kind is 32 bits. A punctuator's is its characters, packed from the first in the low byte ('(',
'+' | '=' << 8), made from the bytes one at a time, so the same number on a big-endian host; keywords and the
built-in types are past them. Every identifier is interned: one name for each text, by hash, and the token's kind is
the name's index with the top bit set, so two tokens name the same thing when their kinds are equal. A name holds what
the passes learn of it once: the macro it names, its keyword row (one slot of a perfect hash that tools/glslc_kwgen
makes of builtins.c's keyword table as glslc is built), its innermost symbol in scope (each symbol keeps the
one it hides), and its rows of the built-in functions and variables. The tables' names carry their lengths, known
when compiled (builtins.c's ROW), and no type's name is made unless an error shows it.
lexer.c: the preprocessor and the tokens. Macros expand on a stack of tokens: a use's arguments are expanded,
put into the body, and the result scanned again with the macro turned off, each step on top of the last.parser.c: typed syntax nodes, by recursive descent. GLSL declares every name before its use, so the same pass
resolves names, checks types and folds the scalar constant expressions that array sizes, case labels and layout
values need.emit.c: SPIR-V, section by section, put together at the end.builtins.c holds the tables: the built-in types, the words each version keeps (checked against glslangValidator
word by word), the built-in variables and constants, and the built-in functions with the SPIR-V each becomes.
Every array has an upper bound. A shader that needs more is refused, and the error names the bound and what the
shader needed (the shader has 32769 tokens after preprocessing, more than the 32768 glslc takes):
| Bound | Value | What it counts |
|---|---|---|
SNX_GLSLC_MAX_SOURCE | 65535 | bytes of source |
SNX_GLSLC_MAX_TOKENS | 32768 | tokens after preprocessing |
SNX_GLSLC_MAX_NODES | 32768 | syntax nodes; no construct makes more than it has tokens |
SNX_GLSLC_MAX_MACROS | 512 | macros, the predefined ones the shader reads included |
SNX_GLSLC_MAX_NAMES | 8192 | distinct names the preprocessor reads, the predefined macros' included |
SNX_GLSLC_MAX_MACRO_TOKENS | 8192 | tokens of every macro's parameters and body |
SNX_GLSLC_MAX_EXPANSION | 4096 | tokens one macro use expands to |
SNX_GLSLC_MAX_MACRO_DEPTH | 32 | macros expanding inside each other |
SNX_GLSLC_MAX_IF_DEPTH | 64 | #if nested |
SNX_GLSLC_MAX_DEPTH | 96 | expressions and statements nested |
SNX_GLSLC_MAX_SCOPES | 64 | scopes nested |
SNX_GLSLC_MAX_TYPES | 2048 | types, the built-in ones included |
SNX_GLSLC_MAX_SYMBOLS | 4096 | names declared |
SNX_GLSLC_MAX_WORDS | 262144 | words of SPIR-V |
glslc.h lists the others. The nesting bounds also bound the C stack each pass takes.
Made from docs/layers/gpu/glslc.md at 69237645142c. GPL-3.0-or-later.