src/common/utilities/spirv_opt.c holds the passes every layer's SPIR-V shares: spirv-opt's algorithms, each written
again over a finished module's words. spirv-opt itself stays out of the runtime's path: it builds the whole module's
representation for each run, and a shader is translated while a draw waits for it.
A layer translates a program, runs its own pass (what the layer knows before the program runs, which no general optimizer can know), and then these:
#include "common/utilities/spirv_opt.h"
uint32_t* module = spv_emit_finish(&emitter, &words);
words = spv_opt_values(module, words);
words = spv_opt_dead_code(module, words);
Dead code goes last: what only fed an instruction another pass took out is dead then.
The Switch layer does it in vk_translate_spirv (src/nx/gpu/vk/pipeline.c), for the Maxwell and the SM86
translators alike. The translators' own entry points (shader_to_spirv, sm86_to_spirv) give the module as it was
written, which is what their tests read.
Made from docs/layers/gpu/spirv-opt.md at 69237645142c. GPL-3.0-or-later.