Patch 15 in the glslang-elimination series. Final batch FS conversion
covering all three remaining texture filter families:
- Bilinear / BilinearBinAlpha (24 blobs)
- JINC2 / JINC2BinAlpha (24 blobs)
- xBR / xBRBinAlpha (24 blobs)
After this lands, every batch FS slot in m_batch_fragment_shaders is
filled from a pre-baked SPIR-V blob; the runtime shadergen path for
batch shaders is gone. The m_shadergen unique_ptr and its
construction in CompilePipelines are removed since they have no
consumers left.
Each filter family shares the same 4-axis structural cube as the
patch-15-Bilinear-prep work that immediately preceded this commit:
- 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.
3 x 2 x 2 x 2 = 24 blobs per filter family. UV_LIMITS is implicit
for all non-Nearest filter families because ShouldUseUVLimits() in
gpu_hw.cpp forces m_using_uv_limits = true whenever
m_texture_filtering != Nearest. The *BinAlpha variant of each
family collapses into the BINALPHA per-call specialisation constant
(id=110) rather than a structural axis - the only SPIR-V difference
is a single ialpha-quantisation step at the end of
FilteredSampleFromVRAM.
Filter bodies are lifted from gpu_hw_shadergen.cpp WriteBatchTexture-
Filter:
- Bilinear lines ~188-224 (4-tap weighted average)
- JINC2 lines ~229-374 (4x4-tap sinc-windowed with anti-ring)
- xBR lines ~381-661 (5x5 neighbourhood, YCbCr edge
detection with BLEND_NONE / NORMAL /
DOMINANT directions per quadrant)
The xBR template is the largest of the three (~17 KiB per blob in
binary, the body is ~280 lines of GLSL). The translation from the
shadergen DSL is mechanical: float4 -> vec4, lerp -> mix, frac ->
fract, sign -> sign, VECTOR_EQ -> all(equal(...)), VECTOR_NEQ ->
any(notEqual(...)). The P() helper macro on xBR closes over coords
and uv_limits the same way the shadergen original does.
One xBR quirk is preserved verbatim: the Iw flag computation in
shadergen uses VECTOR_NEQ(H, ...) instead of VECTOR_NEQ(I, ...)
which is almost certainly a bug, but the alternative output would
differ visually from the released shadergen path. Preserving it
keeps the embedded-vs-shadergen output byte-identical for compat;
fixing it can be a follow-up patch with its own visual-test cycle.
GetBatchFragmentShader is now a switch on m_texture_filtering with
no fallback: every filter resolves to one of the embedded helpers.
The 'dual_source = ... || filter != Nearest' branch is preserved
verbatim from the shadergen-side derivation.
GenerateBatchFragmentShader and the m_shadergen unique_ptr are no
longer referenced. The construction at CompilePipelines is removed
along with the reset in DestroyPipelines and the declaration in
the header. The 'gpu_hw_shadergen.h' include is dropped from both
gpu_hw_vulkan.cpp and gpu_hw_vulkan.h. shader_compiler.{h,cpp},
dep/glslang/, and the Makefile / CMake glslang references are NOT
removed in this patch - that final cleanup will land separately
once this patch has been confirmed working in the wild, on the
theory that backing it out is easier with the runtime path's
support files still present.
Smoke tests:
- g++ -fsyntax-only on the touched common TU.
- spirv-val --target-env vulkan1.0 on all 72 new blobs: 72/72 valid.
- Total .inc text size for the three filter families: ~9.2 MiB
(Bilinear ~1.4 MiB, JINC2 ~2.6 MiB, xBR ~4.7 MiB). Binary
contribution is ~25% of those numbers, so adding ~2.3 MiB to
the .so. xBR alone is ~1.2 MiB binary contribution; this is the
largest single chunk of pre-baked SPIR-V in the project.
Test priority - this patch covers the actively-rendered path for
users who enable any non-Nearest filter, so:
- **Bilinear / BilinearBinAlpha**: smooth edges on textured
surfaces, slight softening of palette textures. Test by setting
the texture filter core option to Bilinear / Bilinear (BinAlpha).
- **JINC2 / JINC2BinAlpha**: sharper sampling than Bilinear with
visible anti-ringing on textured polygons. Heavier per-pixel
cost; testing on FF8/9 backgrounds, MGS textured screens, etc.
- **xBR / xBRBinAlpha**: pixel-art upscaler, very visible smooth
edges on 2D sprites. Best exercise targets are 2D-heavy games -
Castlevania SOTN, Symphony of the Night, Mega Man X4-6, the
Suikoden series. xBR is the most complex shader in the project
and produces visually-distinctive output that immediately
reveals miscompilation.
- All three families x every precompile mode (Disabled / Lazy /
Enabled) x antialiasing toggle round-trips.
- Cross-check: switch m_texture_filtering at runtime between all
six filter values plus Nearest. Each transition should produce
visibly-correct rendering without intermediate corruption.
After this lands and is confirmed working, the final patch in the
series will remove dep/glslang/, src/common/vulkan/shader_compiler
.{h,cpp}, and the Makefile.libretro / CMakeLists.txt entries that
pull glslang into the link.
|
||
|---|---|---|
| .. | ||
| adaptive_downsample_blur.frag.glsl | ||
| adaptive_downsample_composite.frag.glsl | ||
| adaptive_downsample_mip.frag.glsl | ||
| batch.vert.glsl | ||
| batch_textured_bilinear.frag.glsl | ||
| batch_textured_jinc2.frag.glsl | ||
| batch_textured_nearest.frag.glsl | ||
| batch_textured_xbr.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.