TsundereStation/data/shaders/vulkan
LibretroAdmin cde9da3c4b common/vulkan, core: pre-bake batch FS untextured slice (24 blobs)
Patch 13 in the glslang-elimination series. First slice of the batch
FS conversion (Bucket B's bigger half) - the untextured path
(texture_mode == GPUTextureMode::Disabled). Solid-shaded polygons
with no VRAM sampling, no palette logic, no texture filter
machinery, no UV limit logic; the shader is comparatively simple
and a good first cut into the FS state space.

Four SPIR-V-structural axes (24 blobs total = 3 x 2 x 2 x 2):

  - Input interpolation qualifier on v_col0, matching the batch VS
    this FS is bound with. None / centroid / sample. (3)
  - Color input perspective. Standard / noperspective. (2)
  - Dual-source colour output. With dual-source-blend hardware the
    TransparentAndOpaque and OnlyTransparent render modes write a
    second colour at (location 0 index 1) that drives SRC1_COLOR /
    SRC1_ALPHA. The pipeline blend state references SRC1_* or it
    does not - the output declaration count must match. (2)
  - PGXP depth output. With PGXP Depth Buffer enabled the FS omits
    gl_FragDepth so the rasterizer-interpolated VS depth (a_pos.w
    under PGXP) is used directly and early-Z stays available.
    Splitting this structurally preserves the early-Z optimisation
    that the original shadergen also relies on. (2)

Per-call knobs (TRANSPARENCY tri-state from BatchRenderMode,
DITHERING, INTERLACING) and the remaining per-session knobs
(TRUE_COLOR, DITHERING_SCALED, RESOLUTION_SCALE) collapse into
specialisation constants applied at pipeline-create time:

  id =   0  RESOLUTION_SCALE              (uint, per-session)
  id = 100  TRANSPARENCY                  (bool, per-call)
  id = 101  TRANSPARENCY_ONLY_OPAQUE      (bool, per-call)
  id = 102  TRANSPARENCY_ONLY_TRANSPARENT (bool, per-call)
  id = 103  DITHERING                     (bool, per-call)
  id = 104  INTERLACING                   (bool, per-call)
  id = 105  DITHERING_SCALED              (bool, per-session)
  id = 106  TRUE_COLOR                    (bool, per-session)

The TRANSPARENCY trio encodes the BatchRenderMode enum:
  TransparencyDisabled  -> (false, *, *)
  TransparentAndOpaque  -> (true,  false, false)
  OnlyOpaque            -> (true,  true,  false)
  OnlyTransparent       -> (true,  false, true)

These are spec consts applied to the FS in GetBatchPipeline.
The same constant_id values are passed to the runtime shadergen-
compiled textured FS as well, where they are silently dropped per
the Vulkan spec (unrecognised spec const IDs in the supplied
VkSpecializationInfo are ignored).

GetBatchFragmentShader now branches on lookup_mode at the slot-
miss path: GPUTextureMode::Disabled goes to the embedded blob set,
everything else continues through GenerateBatchFragmentShader +
g_vulkan_shader_cache->GetFragmentShader. The textured slices land
in subsequent patches, one or two texture filter values at a time
(Nearest first, then Bilinear / BilinearBinAlpha / JINC2 / xBRZ).

The regen tool's TEMPLATE_VARIANTS manifest grows a second entry
covering the 24 untextured FS variants alongside the 18 batch VS
variants that were already there. Same -D-flag-driven template
mechanism as patch 12. The unused 'fs' local at the bottom of
GetBatchPipeline before the SetFragmentShader call now collects
the FS spec constant info; both batch VS and FS spec constants
are independent VkSpecializationInfo blobs per Vulkan rules.

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on all 24 blobs - 24/24 valid.
  - Total .inc size: ~127 KiB across all 24 blobs (~5 KiB each).
  - --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
    identical for every variant.

Untextured batch draws are extremely common - solid-shaded
polygons in 2D HUDs, fills, debug overlays, the framebuffer clear
quads at the top of every frame on many games. If the embedded
untextured FS is wrong it will be IMMEDIATELY obvious on the first
frame of any game (HUD bars / lifebars / dialogue boxes will be
visibly broken).

Test priority:
  - Routine smoke under Enabled / Lazy / Disabled. Boot any game
    and watch the HUD: solid-shaded health/mana bars (most JRPGs),
    fade-in/fade-out solid alpha overlays (cutscenes), and 2D menu
    backgrounds are direct exercises of this path.
  - Antialiasing toggle round-trip under Disabled mode per the
    patch-5-fix protocol, confirming the structural blob-pick
    flips cleanly across interpolation axes as m_multisamples /
    m_per_sample_shading change.
  - Toggle PGXP Depth Buffer at runtime to flip the PGXP_DEPTH
    structural axis. Behaviour should be unchanged from the
    shadergen baseline.
  - Toggle 'disable color perspective' (under Texture Correction)
    to flip the perspective axis.
2026-05-18 01:15:55 +02:00
..
adaptive_downsample_blur.frag.glsl common/vulkan, core: spec-constant infrastructure + adaptive downsample mip/blur pre-bake 2026-05-17 20:39:19 +02:00
adaptive_downsample_composite.frag.glsl common/vulkan, core: pre-bake adaptive composite + box-sample downsample FS 2026-05-17 20:49:05 +02:00
adaptive_downsample_mip.frag.glsl common/vulkan, core: spec-constant infrastructure + adaptive downsample mip/blur pre-bake 2026-05-17 20:39:19 +02:00
batch.vert.glsl common/vulkan, core: pre-bake batch VS (18-blob template, 2 spec consts) 2026-05-18 00:56:03 +02:00
batch_untextured.frag.glsl common/vulkan, core: pre-bake batch FS untextured slice (24 blobs) 2026-05-18 01:15:55 +02:00
box_sample_downsample.frag.glsl common/vulkan, core: pre-bake adaptive composite + box-sample downsample FS 2026-05-17 20:49:05 +02:00
display.frag.glsl common/vulkan, core: pre-bake display FS (MSAA blob pair, 5-6 spec consts) 2026-05-18 00:02:50 +02:00
display_msaa.frag.glsl common/vulkan, core: pre-bake display FS (MSAA blob pair, 5-6 spec consts) 2026-05-18 00:02:50 +02:00
present_cursor.frag.glsl common/vulkan, core: pre-bake UV-quad VS and three presentation-stage shaders 2026-05-17 20:23:11 +02:00
present_display.frag.glsl common/vulkan, core: pre-bake UV-quad VS and three presentation-stage shaders 2026-05-17 20:23:11 +02:00
present_fullscreen.vert.glsl common/vulkan, core: pre-bake UV-quad VS and three presentation-stage shaders 2026-05-17 20:23:11 +02:00
README.md common/vulkan, core: pre-bake screen-quad VS, no glslang at runtime 2026-05-17 20:09:57 +02:00
screen_quad.vert.glsl common/vulkan, core: pre-bake screen-quad VS, no glslang at runtime 2026-05-17 20:09:57 +02:00
uv_quad.vert.glsl common/vulkan, core: pre-bake UV-quad VS and three presentation-stage shaders 2026-05-17 20:23:11 +02:00
vram_copy.frag.glsl common/vulkan, core: pre-bake VRAM copy FS (single blob, 2 spec consts) 2026-05-17 22:57:44 +02:00
vram_fill.frag.glsl common/vulkan, core: pre-bake VRAM fill FS (single blob, 8 specialisations) 2026-05-17 22:51:37 +02:00
vram_readback.frag.glsl common/vulkan, core: pre-bake VRAM readback FS (MSAA blob pair, 1-2 spec consts) 2026-05-18 00:16:58 +02:00
vram_readback_msaa.frag.glsl common/vulkan, core: pre-bake VRAM readback FS (MSAA blob pair, 1-2 spec consts) 2026-05-18 00:16:58 +02:00
vram_update_depth.frag.glsl common/vulkan, core: pre-bake VRAM update-depth FS (MSAA blob pair, no spec consts) 2026-05-18 00:38:31 +02:00
vram_update_depth_msaa.frag.glsl common/vulkan, core: pre-bake VRAM update-depth FS (MSAA blob pair, no spec consts) 2026-05-18 00:38:31 +02:00
vram_write_ssbo.frag.glsl common/vulkan, core: pre-bake VRAM write FS (SSBO + texbuf blob pair) 2026-05-17 23:46:01 +02:00
vram_write_texbuf.frag.glsl common/vulkan, core: pre-bake VRAM write FS (SSBO + texbuf blob pair) 2026-05-17 23:46:01 +02:00

Vulkan shader sources (pre-baked SPIR-V)

This directory holds the GLSL sources for shaders used by the Vulkan backend that have been moved off the runtime ShaderGen path. Each .glsl file here has a matching pre-compiled SPIR-V blob checked in to src/common/vulkan/embedded_spirv/.

Why this exists

Historically the Vulkan backend generated GLSL at runtime via src/core/shadergen.cpp and src/core/gpu_hw_shadergen.cpp, then handed the text to glslang inside src/common/vulkan/shader_compiler.cpp to produce SPIR-V. Both dep/glslang/ (4.4 MB of vendored source, 99 translation units) and the disk-backed runtime shader cache exist solely to support that path.

Pre-baking the SPIR-V removes:

  • the glslang dependency from the libretro core build,
  • the per-launch shader compilation stall, and
  • a class of "stale cache after glslang version bump" runtime failures.

The OpenGL / OpenGL ES / D3D11 / D3D12 backends still use the runtime ShaderGen path; only the Vulkan backend reads from the embedded SPIR-V.

Build-time constraint

The core build (Makefile.libretro and src/common/CMakeLists.txt) must never invoke an external shader compiler. The .inc files under src/common/vulkan/embedded_spirv/ are checked into the repository and compiled like any other C++ source. The tools/regen_vulkan_spirv.py helper exists for contributors who edit the .glsl sources in this directory; it is not part of the build.

Regenerating the SPIR-V blobs

After editing a .glsl file here, run:

python3 tools/regen_vulkan_spirv.py

This invokes glslangValidator --target-env vulkan1.0 on each .glsl file and rewrites the matching .inc under src/common/vulkan/embedded_spirv/. Both the .glsl and the regenerated .inc must be committed together so the two stay in sync.

glslangValidator is part of the Vulkan SDK (or the glslang-tools package on Debian / Ubuntu). It is not invoked by the core build.