Patch 14 in the glslang-elimination series. Second slice of the
batch FS conversion: the textured + Nearest-filter path
(texture_mode != Disabled AND m_texture_filter == Nearest). The
runtime decision in GetBatchFragmentShader now routes both the
untextured slice (patch 13) and this slice through the embedded
blob set; only textured non-Nearest still goes through
shadergen + glslang.
Five SPIR-V-structural axes (48 blobs total = 3 x 2 x 2 x 2 x 2):
- Input interpolation qualifier (none / centroid / sample). 3.
- Color input perspective (standard / noperspective). 2.
- Dual-source output (1 vs 2 outputs). 2.
- PGXP depth output (writes gl_FragDepth or omits it). 2.
- UV limits (without / with v_uv_limits flat input). 2.
The UV_LIMITS axis is new vs the untextured slice - it controls
whether v_uv_limits is declared as a per-vertex flat input on the
FS, matching the per-session m_using_uv_limits choice that already
drives the matching batch VS structural pick. Without UV limits the
FS skips the per-sample clamp.
Three new per-call specialisation constants relative to the
untextured slice cover the textured texture_mode encoding:
id = 107 PALETTE_4_BIT (bool, actual_texture_mode == 0)
id = 108 PALETTE_8_BIT (bool, actual_texture_mode == 1)
id = 109 RAW_TEXTURE (bool, RawTextureBit set in texture_mode)
PALETTE = PALETTE_4_BIT || PALETTE_8_BIT is derived inside the
shader. The texture_mode bit layout is described in
src/core/gpu_types.h; the C++ side derives the three boolean spec
const values from the per-call texture_mode in GetBatchPipeline.
Untextured blobs do not declare 107-109; passing them is harmless
per the Vulkan spec (unrecognised spec const IDs in the supplied
VkSpecializationInfo are silently dropped).
The shader body covers the helpers the shadergen path inlines:
ApplyTextureWindow, ApplyUpscaledTextureWindow, FloatToIntegerCoords,
RGBA8ToRGBA5551, and SampleFromVRAM. SampleFromVRAM splits on the
derived PALETTE flag and, within the palette branch, on
PALETTE_4_BIT vs PALETTE_8_BIT to do the correct sub-texel address
arithmetic. fixYCoord on Vulkan is the identity function so we use
the coord directly. The Vulkan-only API_VULKAN-y-flip in the VS
already accounts for sample-space orientation.
Output and discard logic mirrors the shadergen TEXTURED branches:
the no-TRANSPARENCY case writes o_col0 (and o_col1 when DUAL_SOURCE)
unconditionally; the TRANSPARENCY case branches on the texel's
semitransparency bit and applies the TRANSPARENCY_ONLY_OPAQUE /
TRANSPARENCY_ONLY_TRANSPARENT per-texel discard the way the
shadergen does.
Helper-side index encoding for the 48-blob array, matching
GetBatchTexturedNearestFragmentShaderBlob in embedded_shaders.cpp:
interp = per_sample_shading ? 2 : (msaa ? 1 : 0) (0..2)
persp = noperspective_color ? 1 : 0 (0..1)
dual = dual_source ? 1 : 0 (0..1)
pgxp = pgxp_depth ? 1 : 0 (0..1)
uv = uv_limits ? 1 : 0 (0..1)
index = interp*16 + persp*8 + dual*4 + pgxp*2 + uv (0..47)
The use_dual_source derivation in GetBatchFragmentShader matches
the shadergen-side check exactly: supports_dual_source_blend &&
((render_mode is transparent) || filter != Nearest). For the two
embedded branches (untextured and textured Nearest) the filter-half
of the OR evaluates false, so both branches fall through to the
render_mode test.
Smoke tests:
- g++ -fsyntax-only on the touched common TU.
- spirv-val --target-env vulkan1.0 on all 48 blobs - 48/48 valid.
- Total .inc size: ~2.2 MiB across all 48 blobs (~46 KiB each in
text form, which is the 0xNNNNNNNNu, packed layout from the regen
tool; binary contribution to the linked output is roughly 1/4 of
that, so ~550 KiB. Acceptable for a renderer that previously
pulled in glslang at runtime).
- --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
identical for every variant.
Test priority:
- Routine smoke under Enabled / Lazy / Disabled with Nearest
filter (the default). Any textured polygon in any game now
exercises the embedded path: dialogue portraits, sprite layers,
background textures - the vast majority of pixels in most
games.
- Toggle PGXP UV correction (drives m_using_uv_limits) to flip
the UV_LIMITS structural axis. Games that benefit most from
PGXP corrections - Final Fantasy series, Tekken 3, Soul Blade -
are good exercise targets.
- Antialiasing toggle round-trip under Disabled mode per the
patch-5-fix protocol (flips interpolation axis).
- Each texture mode is exercised by different draws: palette
textures dominate (most game art is 4-bit indexed), with
direct-16bpp showing up for render-to-texture effects. Raw
textures appear in framebuffer effects and some UI passes.
- Cross-check with shadergen path by switching texture filter to
Bilinear (still on the shadergen path) and back to Nearest -
rendering should remain consistent across the switch.
After this lands, the only remaining glslang consumers in the
Vulkan backend are the texture-filter slices (Bilinear /
BilinearBinAlpha, JINC2 / JINC2BinAlpha, xBR / xBRBinAlpha). Each
of those filter families has its own FilteredSampleFromVRAM body
and will get its own template in subsequent patches.
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.
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.
This is the probe patch in a series that eliminates dep/glslang from the
libretro core build. It establishes the infrastructure - the GLSL source
tree, the embedded-SPIR-V loader, the regeneration tool, and the build
wiring - by converting exactly one call site so the pattern can be
smoke-tested in isolation before the rest of Bucket A and then Bucket B
follow in subsequent patches. glslang stays in the tree until the final
patch in the series, which removes dep/glslang and the surrounding
shader_compiler.cpp.
What this patch does:
- Adds data/shaders/vulkan/screen_quad.vert.glsl - the GLSL source for
the screen-quad VS, kept in the tree for human readability. The build
does NOT see this file; it is consumed only by the offline regen tool.
- Adds src/common/vulkan/embedded_spirv/screen_quad_vs.inc - the
pre-compiled SPIR-V blob as a 'const uint32_t[]' (367 words, 1.4 KiB),
generated offline from the .glsl by glslangValidator targeting
vulkan1.0. The .inc is checked in and #include'd by embedded_shaders.cpp
inside namespace Vulkan::EmbeddedShaders. spirv-val confirms the blob
is valid Vulkan 1.0 SPIR-V (magic 0x07230203, version 1.0).
- Adds src/common/vulkan/embedded_shaders.{h,cpp}. The header exposes a
pair of extern declarations per blob and a single
CreateShaderModule(const uint32_t*, size_t) loader. The loader
intentionally bypasses Vulkan::ShaderCache - pre-baked SPIR-V is
already final, so there is nothing to compile and nothing worth
caching on disk. Just a sized-and-checked vkCreateShaderModule call.
- Adds tools/regen_vulkan_spirv.py - the offline workflow for
contributors who edit shader .glsl sources. It invokes
glslangValidator on each .glsl under data/shaders/vulkan/ and rewrites
the matching .inc. CRITICAL: this tool is NEVER invoked by Make or
CMake. The build sees only .h/.cpp/.inc files and has no shader-
compiler dependency. Contributors run the script manually after
editing .glsl, commit both files together.
- Adds data/shaders/vulkan/README.md documenting the workflow and the
invariant that the build must never invoke an external shader
compiler.
- Switches GPU_HW_Vulkan::GetFullscreenQuadVertexShader() (in
src/core/gpu_hw_vulkan.cpp) from
g_vulkan_shader_cache->GetVertexShader(m_shadergen->Generate...)
to
Vulkan::EmbeddedShaders::CreateShaderModule(k_screen_quad_vs, ...).
The m_shadergen null-check is removed since the embedded path has no
such ordering dependency. The function's contract (lazy creation,
stored in m_fullscreen_quad_vertex_shader, returned to multiple
pipeline builders) is unchanged.
- Registers src/common/vulkan/embedded_shaders.cpp in both
Makefile.libretro (alphabetical order in the vulkan/ SOURCES_CXX
block) and src/common/CMakeLists.txt (alphabetical order in the
common target's source list). Neither change adds any build-tool
dependency; the new .cpp compiles like any other.
What this patch does NOT do:
- It does not remove dep/glslang or the SOURCES_CXX entries that pull
in its 99 translation units. glslang is still needed for every shader
generator that has not yet been converted - in particular all of
GPU_HW_ShaderGen, plus the remaining utility shaders (UV quad VS,
VRAM read/copy/write/fill/update-depth FS, display FS, adaptive
downsample mip/blur/composite FS, box-sample downsample FS).
Subsequent patches in this series convert those one bucket at a time.
The final patch removes dep/glslang, src/common/vulkan/shader_compiler.{h,cpp},
the glslang link line in CMake, and the Makefile entries.
- It does not touch the disk-backed Vulkan::ShaderCache. That cache
still serves the runtime-glslang path for remaining shaders.
Smoke tests performed in isolation:
- glslangValidator --target-env vulkan1.0 succeeds on the .glsl source,
producing 367 32-bit words of SPIR-V.
- spirv-val --target-env vulkan1.0 reports VALID on the blob.
- spirv-dis confirms the entry point, VertexData block, and Position/
VertexIndex built-ins are correctly emitted.
- A standalone harness including the .inc inside the
Vulkan::EmbeddedShaders namespace and calling CreateShaderModule
through a stubbed vkCreateShaderModule reads back the correct magic
word and size.
- g++ -fsyntax-only on embedded_shaders.cpp against the real headers
in the tree (excluding only the platform-specific X11 surface define
not used by this TU) is clean.
Smoke tests that require the user's setup:
- Real build on Windows (RTX 5090) and macOS.
- Vulkan core boots, RetroArch's pipeline cache populates, and at
least one game renders past the first frame using the screen-quad
pipeline (VRAM ops, display, downsample - all of which call
GetFullscreenQuadVertexShader internally).