Patch 12 in the glslang-elimination series, and the first step into
Bucket B (batch shaders). The batch VS state space has three SPIR-V-
structurally-distinct axes that specialisation constants cannot fold:
1. Vertex attribute layout. 2 inputs (untextured), 4 (textured
without UV limits) or 5 (textured with UV limits). The 'in <type>
<name>' declarations are part of the SPIR-V module interface.
2. Output interpolation qualifier on the v_col0 / v_tex0 outputs.
None / centroid / sample, selected per session by UsingMSAA() /
UsingPerSampleShading(). These compile to OpMemberDecorate
Centroid / Sample on the VertexData output block, which is not
a spec-constant-controllable property of the SPIR-V module.
3. Color output perspective. m_disable_color_perspective toggles a
'noperspective' qualifier on v_col0, compiling to
OpMemberDecorate NoPerspective.
3 x 3 x 2 = 18 structurally distinct blobs. Body-level knobs
(RESOLUTION_SCALE, PGXP_DEPTH) are common-knob specialisation
constants on every blob (constant_id = 0 and 3 per the project
convention).
To avoid maintaining 18 hand-edited .glsl files, the source is a
single template (data/shaders/vulkan/batch.vert.glsl) with #if
guards on TEXTURED, UV_LIMITS, INTERP_CENTROID / INTERP_SAMPLE, and
NOPERSP. The regen tool (tools/regen_vulkan_spirv.py) is extended
with a TEMPLATE_VARIANTS manifest that compiles the template once
per variant with the corresponding -D flags. Build-time impact is
zero - the script is still developer-only and the .inc files are
checked in.
The matching index encoding lives in src/common/vulkan/embedded_-
shaders.cpp next to the lookup helper:
attr = !textured ? 0 : (uv_limits ? 2 : 1) (0..2)
interp = per_sample_shading ? 2 : (msaa ? 1 : 0) (0..2)
persp = noperspective_color ? 1 : 0 (0..1)
index = attr * 6 + interp * 2 + persp (0..17)
The C++ side calls GetBatchVertexShaderBlob with the per-session
state (m_using_uv_limits, m_multisamples > 1, m_per_sample_shading,
m_disable_color_perspective) and the per-call 'textured' loop
variable to pick the right blob in CompilePipelines. The existing
m_batch_vertex_shaders[2] cache shape is preserved - the helper just
selects which two of the 18 blobs to instantiate this session.
Spec constants are applied at PIPELINE-create time inside
GetBatchPipeline rather than at module-create time, matching the
SpecConstants infrastructure laid down in patch 3. The values are
session-constant, so they are the same for every batch pipeline in
a session and the driver caches them keyed by (module + spec values)
in the pipeline cache.
Header-side ergonomics: instead of declaring 36 individual extern
arrays (18 SPIR-V + 18 size), the .h declares a small
EmbeddedShaderBlob struct and a single
k_batch_vs_blobs[18] array, plus the GetBatchVertexShaderBlob
helper. The same struct is intended to be reused for the eventual
batch FS conversion (likely many more blobs given the texture filter
state space).
Smoke tests:
- g++ -fsyntax-only on the touched common TU.
- spirv-val --target-env vulkan1.0 on all 18 blobs - 18/18 valid.
- Total .inc size: ~53 KiB across all 18 blobs.
- --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
identical for every variant.
The batch VS is filled in CompilePipelines for all three precompile
modes (Enabled, Lazy, Disabled), so this conversion does not change
the hot-path-pre-build pattern from the patch 10-fix. The two VS
modules are present before any batch draw on every code path.
Test priority:
- Routine smoke under Enabled / Lazy / Disabled. Any rendering at
all exercises both VS modules immediately, so visual regressions
show up on the first frame of the first game booted.
- SSAA / MSAA round-trip in Disabled mode (per the patch-5-fix
protocol), specifically to confirm the structural-blob-pick
flips through 'none' -> 'centroid' -> 'sample' interp variants
cleanly as m_multisamples changes.
- Toggle 'disable color perspective' core option (under Texture
Correction) to flip the perspective axis; visual difference is
subtle but the blob-pick change is real.
- Toggle PGXP Geometry Correction (drives UV_LIMITS via
m_using_uv_limits) and PGXP Depth Buffer (drives PGXP_DEPTH
spec const) to flip the body and attribute-layout axes.
After this lands, the only remaining runtime glslang consumer in
the Vulkan backend is the batch FS (GenerateBatchFragmentShader at
gpu_hw_shadergen.cpp line ~667). That is a far larger state space
- six texture filters x ~14 boolean macros plus the structural
USE_DUAL_SOURCE / PALETTE_* axes - and will need to land in
several patches, one or two texture filters at a time.