#include "glslc/glslc.h"
static uint32_t words[SNX_GLSLC_MAX_WORDS];
static GlslcResult result;
/* once for each thread that compiles: glslc allocates nothing, the workspace is all the memory it uses */
GlslcWorkspace workspace;
size_t bytes = snx_glslc_workspace_size();
if (snx_glslc_workspace_init(&workspace, malloc(bytes), bytes, &result) != 0)
fprintf(stderr, "%s\n", result.error);
/* then for each shader; bind, a binding map, is optional */
GlslcOptions options = {SNX_GLSLC_FRAGMENT, bind, bind_user, 0, 0, 0};
if (snx_glslc_compile(&workspace, &options, source, size, words, SNX_GLSLC_MAX_WORDS, &result) != 0)
fprintf(stderr, "%u:%u: %s\n", result.line, result.column, result.error);
snx_glslc_workspace_size() bytes (4.1 MiB): one per
thread, reused by every compilation on it, one at a time. Each compilation carves its arrays from it anew, so
nothing of one reaches the next. A workspace too small or misaligned is refused with its size and the size needed.result.words is the module's size. With a buffer too small (or NULL) the call returns -1 and still says how
many words the module needs.#line applied. A warning (an extension glslc does not have, a name with
__) is counted, and the first is kept in result.warning with its place.result.reflect lists the interface the program binds by name: inputs and outputs with their locations, the loose
uniforms with their offsets in the default uniform block, samplers, images and blocks with their set and binding.
Each name is a view of the source, so the source must stay while the caller reads them.The library links as snx_glslc. tests/glslc/glslc_cli.c is a small command line around it.
Made from docs/layers/gpu/glslc.md at 69237645142c. GPL-3.0-or-later.