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.
|
||
|---|---|---|
| .. | ||
| adaptive_downsample_blur.frag.glsl | ||
| adaptive_downsample_composite.frag.glsl | ||
| adaptive_downsample_mip.frag.glsl | ||
| batch.vert.glsl | ||
| batch_textured_nearest.frag.glsl | ||
| batch_untextured.frag.glsl | ||
| box_sample_downsample.frag.glsl | ||
| display.frag.glsl | ||
| display_msaa.frag.glsl | ||
| present_cursor.frag.glsl | ||
| present_display.frag.glsl | ||
| present_fullscreen.vert.glsl | ||
| README.md | ||
| screen_quad.vert.glsl | ||
| uv_quad.vert.glsl | ||
| vram_copy.frag.glsl | ||
| vram_fill.frag.glsl | ||
| vram_readback.frag.glsl | ||
| vram_readback_msaa.frag.glsl | ||
| vram_update_depth.frag.glsl | ||
| vram_update_depth_msaa.frag.glsl | ||
| vram_write_ssbo.frag.glsl | ||
| vram_write_texbuf.frag.glsl | ||
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.