Commit graph

194 commits

Author SHA1 Message Date
LibretroAdmin
9dcfea435a common/vulkan, core: pre-bake batch FS textured Nearest slice (48 blobs)
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.
2026-05-18 01:43:15 +02:00
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
LibretroAdmin
890211d080 common/vulkan, core: pre-bake batch VS (18-blob template, 2 spec consts)
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.
2026-05-18 00:56:03 +02:00
LibretroAdmin
74bebf8908 common/vulkan, core: pre-bake VRAM update-depth FS (MSAA blob pair, no spec consts)
Patch 11 in the glslang-elimination series, and the last non-batch
shader on the runtime shadergen path. This was the original patch 5
culprit - lazy-building this pipeline inside UpdateSettings tripped an
NVIDIA driver quirk that produced corrupted rendering on the next
frame. The preceding fix patch (pre-build hot-path utility pipelines
in shader_precompile=Disabled) sidestepped the failure mode by
ensuring m_vram_update_depth_pipeline is always built before any
cmdbuf that could need it, regardless of precompile mode, so this
conversion is now safe to land.

Shader converted:

  VRAMUpdateDepthFragmentShader. Rebuilds the depth attachment of the
  upscaled VRAM render pass from the colour attachment's alpha after a
  framebuffer recreation (resolution scale change, antialiasing toggle,
  true colour toggle). Trivial body - one texelFetch, one assignment
  to gl_FragDepth.

  Blobs:
    vram_update_depth_fs      - sampler2D, texelFetch(samp0, coord, 0).
    vram_update_depth_msaa_fs - sampler2DMS, texelFetch(samp0, coord,
                                gl_SampleID). The gl_SampleID reference
                                forces per-sample shading per the
                                Vulkan spec, regardless of the
                                SetMultisamples per_sample_shading
                                flag the C++ side leaves at false (the
                                original shadergen relies on the same
                                implicit-per-sample behaviour).

  No spec constants on either blob - there is nothing to specialise.
  The pipeline-state knobs the C++ side cares about (sample count,
  depth state, blend state) are pipeline-creation-time choices, not
  shader-source knobs.

Bindings unchanged: set=0 binding=1 sampler from
m_single_sampler_descriptor_set_layout, no UBO at binding 0 (the
descriptor set layout only declares binding 1; the pipeline layout's
push constants are declared for ABI symmetry with other consumers but
are not read by this shader, and the C++ caller does not push any).

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on both blobs (219 / 242 words,
    0.9 KiB each - the smallest blobs in the project).
  - --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
    identical SPIR-V for both.

m_vram_update_depth_pipeline is on the antialiasing-toggle hot path
(UpdateSettings -> UpdateDepthBufferFromMaskBit at gpu_hw_vulkan.cpp
line ~817). With the preceding fix patch in place, the Disabled-mode
pre-build in CompilePipelines ensures the pipeline is always ready
before UpdateSettings' second cmdbuf starts recording, so the bug
that broke the original patch 5 (lazy build of MSAA depth blob in
the second SSAA toggle cycle, NVIDIA driver producing corrupt next
frame) is structurally impossible here.

Test priority:
  - shader_precompile=Disabled: same SSAA / MSAA round-trip protocol
    Lib used to surface the original patch 5 bug. Toggle SSAA None
    -> 8x -> None -> 8x, MSAA 1 -> 4 -> 1 -> 4, resolution scale
    1 -> 2 -> 1 -> 2, true colour off -> on -> off. Each toggle
    should produce a clean frame.
  - shader_precompile=Enabled / Lazy: routine smoke (any game).

After this lands, every non-batch shader in the Vulkan backend is
pre-baked SPIR-V; the only remaining runtime glslang consumers are
the two batch shaders (GenerateBatchVertexShader and
GenerateBatchFragmentShader at gpu_hw_vulkan.cpp lines ~1462 and
~1799). Those are Bucket B and a separate refactoring effort -
their state space is wide enough to warrant a different conversion
strategy from the per-shader spec-const collapses used here.
2026-05-18 00:38:31 +02:00
LibretroAdmin
cc69fc08e5 common/vulkan, core: pre-bake VRAM readback FS (MSAA blob pair, 1-2 spec consts)
Patch 10 in the glslang-elimination series. The shadergen helper is
named GenerateVRAMReadFragmentShader, but the pipeline it lives in
(m_vram_readback_pipeline) is the CPU readback path: it samples the
upscaled m_vram_texture, runs a box filter to downsample blocks back
to PSX-native 16bpp, and packs two adjacent 16-bit pixels into one
RGBA8 output texel for the host to pick up via staging.

Shader converted:

  VRAMReadFragmentShader. Single output slot, no per-frame variance
  - the existing C++ side already caches it as a single
  m_vram_readback_pipeline VkPipeline. Two blobs only because of the
  source texture's MSAA structural split (sampler2D vs sampler2DMS).

  Blobs:
    vram_readback_fs      - sampler2D, no per-pixel sample averaging.
    vram_readback_msaa_fs - sampler2DMS, LoadVRAM averages
                            MULTISAMPLES texelFetch results before
                            the box filter runs.

  Common spec constant:
    id = 0 RESOLUTION_SCALE (uint) - drives both the base_coords stride
                                     and the box-filter inner-loop
                                     bounds.
  MSAA blob adds:
    id = 1 MULTISAMPLES     (uint) - LoadVRAM averaging loop bound.

The OpenGL lower-left-origin Y-flip branch in the shadergen source is
omitted: Vulkan VRAM Y matches scanout Y directly, so the conditional
fold-up never fires on this backend. The single output pipeline keeps
its single C++ slot - no per-mode array needed.

Render target (m_vram_readback_texture) is always single-sample at
line 1118, so the pipeline's multisample state stays at the default
single-sample on both blobs. As with display, the MSAA-ness lives
entirely in the input sampler type.

Bindings unchanged: push_constant for the UBO, set=0 binding=1 for
the source sampler, matching m_single_sampler_pipeline_layout.

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on both blobs (1158 / 1302
    words, 4.5K / 5.1K).
  - --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
    identical SPIR-V for both.

VRAM readback is the rarest of the utility pipelines - it's exercised
only when something reads from upscaled VRAM through the host (save-
state capture, debugger introspection, certain games that read back
their own framebuffer for special effects). Not on the SSAA-toggle
hot-build path; shader_precompile=Disabled is expected to behave
identically to Enabled / Lazy.

Test priority:
  - shader_precompile=Enabled / Lazy: routine smoke.
  - shader_precompile=Disabled: any savestate save + load round-trip
    (forces a readback). A few games also self-read for visual
    effects - Silent Hill's fog overlay and the Castlevania:
    Symphony of the Night transition flashes are known triggers.
    SSAA round-trip is incidental but quick.

After this lands, the only non-batch shaders still on the runtime
shadergen + glslang path are the VRAM update depth pair, which is on
the SSAA-toggle hot-build path and broke patch 5. Plan for those is
to introduce a targeted pre-build at CompilePipelines time even in
Disabled mode, separately from the SPIR-V conversion itself.
2026-05-18 00:16:58 +02:00
LibretroAdmin
59b6fac749 common/vulkan, core: pre-bake display FS (MSAA blob pair, 5-6 spec consts)
Patch 9 in the glslang-elimination series. The display FS is the
densest shader in the project - shadergen takes depth_24bit (bool) x
interlace_mode (None/InterleavedFields/SeparateFields) x smooth_chroma
(bool) source variants, and the source m_vram_texture's sample count
varies with MSAA on top of that. The depth_24bit / interlace_mode pair
is the only knob set that varies at runtime within a session
(GPUSTAT.display_area_color_depth_24 and the CRTC interlace mode flip
during normal gameplay); smooth_chroma, MSAA, and RESOLUTION_SCALE are
all session-constant (toggling any of them goes through UpdateSettings
-> DestroyPipelines).

Shader converted:

  DisplayFragmentShader. Reads the upscaled m_vram_texture, applies
  field-discard for interlaced output, and writes the visible scanout
  rectangle to m_display_texture - either as direct 16bpp samples or as
  reconstructed 24bpp YUV-smoothed colour depending on the GPUSTAT bit.

  Blobs:
    display_fs       - source sampler is sampler2D       (non-MSAA path).
    display_msaa_fs  - source sampler is sampler2DMS, plus an extra
                       MULTISAMPLES spec constant for the LoadVRAM
                       averaging loop bound.

  Common spec constants on both blobs:
    id =   0 RESOLUTION_SCALE (uint) - common-knob convention.
    id = 100 DEPTH_24BIT      (bool) - 16bpp vs 24bpp reconstruction.
    id = 101 INTERLACED       (bool) - field-discard logic gate.
    id = 102 INTERLEAVED      (bool) - only meaningful when INTERLACED.
                                       Selects interleaved-both-fields
                                       coord folding vs separate-field.
    id = 103 SMOOTH_CHROMA    (bool) - only meaningful when DEPTH_24BIT.
                                       Enables bilinear UV smoothing.

  MSAA blob adds:
    id =   1 MULTISAMPLES     (uint) - common-knob convention.

The m_display_pipelines[depth_24][interlace_mode] 2x3 slot table is
preserved; each entry gets its own spec-const-specialised pipeline at
first-touch, like the VRAM fill pattern. interlace_mode is folded into
INTERLACED / INTERLEAVED at the call site:
  None              -> INTERLACED=false, INTERLEAVED=*  (INTERLEAVED
                                                         irrelevant when
                                                         INTERLACED is
                                                         false)
  InterleavedFields -> INTERLACED=true,  INTERLEAVED=true
  SeparateFields    -> INTERLACED=true,  INTERLEAVED=false

The render target (m_display_texture) is always single-sample at this
stage (line 1114 hardcodes VK_SAMPLE_COUNT_1_BIT regardless of MSAA);
the pipeline's multisample state is therefore single-sample on both
blobs, matching the original which did not call SetMultisamples either.
The MSAA-ness lives entirely in the input sampler type and the LoadVRAM
loop on the MSAA blob.

Bindings unchanged: push_constant for the UBO, set=0 binding=1 for the
source sampler, matching m_single_sampler_pipeline_layout.

The fixYCoord call from the original shadergen is dropped because the
Vulkan-side fixYCoord is the identity function (PSX VRAM Y matches
Vulkan Y); removing it spares a redundant function definition. The
GLSL-side helper macros (float4 / uint2 / etc) from WriteHeader are
also dropped since the .glsl files only need to work for Vulkan and
GLSL-native types are clearer than HLSL-style aliases.

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on both blobs (2391 / 2535
    words, 9.5K / 9.9K).
  - --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
    identical SPIR-V for both blobs.

Like VRAM fill / copy / write, the display pipeline is built on its
own first-touch path and is not on the UpdateSettings SSAA-toggle
hot-build path. shader_precompile=Disabled is expected to behave
identically to Enabled / Lazy.

Test priority:
  - shader_precompile=Enabled / Lazy: routine smoke (any game).
  - shader_precompile=Disabled: any game that flips interlace_mode
    during gameplay (interlaced cutscenes -> progressive gameplay
    transitions) or that toggles 24bpp display mode (FMV intros in
    most JRPGs). Smooth-chroma path is exercised by enabling the
    Chroma Smoothing 24-bit option in the core options and watching
    an FMV. Worth doing a coarse SSAA round-trip too even though the
    display pipeline shouldn't be sensitive to it.
2026-05-18 00:02:50 +02:00
LibretroAdmin
30793791f8 common/vulkan, core: pre-bake VRAM write FS (SSBO + texbuf blob pair)
Patch 8 in the glslang-elimination series. VRAM write has a structural
variant the rest of Bucket A has not had to deal with: the descriptor
type at set=0 binding=0 differs depending on
m_use_ssbos_for_vram_writes (storage buffer vs uniform texel buffer),
so a single SPIR-V blob with a spec constant cannot collapse it. Two
blobs, otherwise sharing the same spec-constant interface.

Shader converted:

  VRAMWriteFragmentShader. Writes one upscaled PSX pixel per fragment
  from a host-staged 16-bit-per-pixel VRAM tile.

  Blobs:
    vram_write_ssbo_fs   - readonly restrict std430 SSBO ssbo_data[],
                           two PSX pixels packed per uint32 element.
    vram_write_texbuf_fs - uniform usamplerBuffer samp0 with R16_UINT
                           buffer view, one PSX pixel per element.

  Spec constants (identical between the two blobs):
    id = 0  RESOLUTION_SCALE (uint) - common-knob convention. Drives
                                      both the upscale-aware coord
                                      conversion (gl_FragCoord.xy
                                      divided by RESOLUTION_SCALE) and
                                      the VRAM_SIZE wrap-around math.
    id = 3  PGXP_DEPTH       (bool) - common-knob convention. Selects
                                      between sampled-alpha-derived
                                      depth and a fixed 1.0.

The depth_test pipeline knob remains a SetDepthState toggle, not a
spec constant; the C++ side keeps the 2-entry slot lookup in
m_vram_write_pipelines and selects the SSBO-vs-texbuf blob inside the
slot miss path. m_use_ssbos_for_vram_writes is a per-session decision
(set in CompilePipelines based on device features), so in any given
session only one of the two blobs will ever be touched at
vkCreateShaderModule time.

Inlined the RGBA5551ToRGBA8 helper directly into both .glsl files
rather than relying on what WriteCommonFunctions would have emitted -
keeps each blob self-contained and avoids dragging in the other
WriteCommonFunctions helpers (fixYCoord, RGBA8ToRGBA5551) that are not
used here. The Vulkan-side fixYCoord is the identity function in any
case.

Bindings unchanged from the shadergen path - both blobs target
m_vram_write_pipeline_layout, which is constructed with the matching
descriptor type at CreateLayouts time.

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on both blobs (1433 / 1356 words).
  - --target-env vulkan1.0 vs un-flagged glslangValidator: byte-
    identical SPIR-V for both.

Like patches 6 and 7, VRAM write is exercised by game-driven VRAM
uploads, not by UpdateSettings, so this pipeline does not see the
SSAA-toggle lazy-build path. shader_precompile=Disabled is expected to
match Enabled / Lazy behaviour.

Test priority:
  - shader_precompile=Enabled / Lazy: routine smoke (any game).
  - shader_precompile=Disabled: any game with heavy texture streaming
    over CPU-side DMA - JRPG cutscenes, pre-rendered backgrounds,
    movie-frame VRAM uploads. The SSBO blob is the common one on
    desktop GPUs; the texbuf blob may be exercised by retesting on
    something with the SSBO path disabled.
2026-05-17 23:46:01 +02:00
LibretroAdmin
34cda08c7a common/vulkan, core: pre-bake VRAM copy FS (single blob, 2 spec consts)
Patch 7 in the glslang-elimination series. VRAM copy is the simplest
remaining shader from the original shadergen-driven set: the source-side
has no MSAA variant (the shadergen hard-codes msaa=false at the top of
GenerateVRAMCopyFragmentShader because Vulkan won't let us bind the
source texture to both an input sampler and a colour attachment), so
unlike VRAM read / update-depth we collapse to a single SPIR-V blob with
just two spec constants.

Shader converted:

  VRAMCopyFragmentShader. Copies a rectangular region from one part of
  upscaled VRAM to another, with PSX-style modulo-1024x512-VRAM wrap-
  around at the destination and optional mask-bit writeback.

  Spec constants used (documented in the .glsl):
    id = 0  RESOLUTION_SCALE (uint) - common-knob convention.
    id = 3  PGXP_DEPTH       (bool) - common-knob convention.

  No MSAA spec const; no shader-specific spec consts. The depth_test
  state knob the C++ side cares about is a SetDepthState pipeline-state
  toggle, not a shader knob, so it stays as a 2-entry slot lookup in
  m_vram_copy_pipelines and does not factor into spec constants.

Bindings unchanged: push_constant block for the UBO, set=0 binding=1 for
the source sampler2D, matching m_single_sampler_pipeline_layout.

Smoke tests:
  - g++ -fsyntax-only on the touched common TU.
  - spirv-val --target-env vulkan1.0 on the regenerated blob (1203
    words, 4.7 KiB).
  - Verified --target-env vulkan1.0 produces byte-identical SPIR-V to
    the un-flagged glslangValidator default (relevant since the runtime
    glslang path does not call setEnvTarget; both paths emit the same
    bytes for our shaders).

Like patch 6, this pipeline is not on the SSAA-toggle hot path - VRAM
copy is exercised by game-driven VRAM-to-VRAM blits, not by
UpdateSettings. shader_precompile=Disabled is therefore expected to
behave identically to Enabled / Lazy for this pipeline.

Test priority:
  - shader_precompile=Enabled / Lazy: routine smoke (any game).
  - shader_precompile=Disabled: any game that performs frequent VRAM
    copies (Final Fantasy series, anything with prerendered backgrounds
    streamed into VRAM). SSAA toggle round-trip should be fine.
2026-05-17 22:57:44 +02:00
LibretroAdmin
af9c287efb common/vulkan, core: pre-bake VRAM fill FS (single blob, 8 specialisations)
Patch 6 in the glslang-elimination series. Demonstrates the
'multiple-spec-constants-collapse-source-variants' pattern: the original
shadergen produced four GLSL source strings (wrapped x interlaced) and
a per-session constructor-level PGXP_DEPTH bake, for up to eight cached
SPIR-V blobs on the disk-backed cache. This patch collapses all of that
into a single SPIR-V blob with three boolean specialisation constants.

Shader converted:

  VRAMFillFragmentShader. Writes u_fill_color to a destination rectangle
  in upscaled VRAM, optionally discarding pixels for interlace masking
  or out-of-bounds-wrapped fills.

  Spec constants used (documented in the .glsl):
    id =   3 PGXP_DEPTH  (bool, common-knob convention).
    id = 100 INTERLACED  (bool, shader-specific).
    id = 101 WRAPPED     (bool, shader-specific).

  Cross-shader id reuse note: id=100 is also FIRST_PASS in
  adaptive_downsample_mip.frag.glsl. SPIR-V spec scopes spec-constant
  ids per-stage, so reuse across different shaders is harmless. Each
  shader file documents its own ids at the top.

Call site changes in src/core/gpu_hw_vulkan.cpp:

- GetVRAMFillPipeline: switched to embedded path. The 'wrapped' and
  'interlaced' uint8 inputs (each 0 or 1) now drive AddBool calls into
  the SpecConstants helper rather than picking a GLSL source string.
  PGXP_DEPTH is sourced from GPU_HW::m_pgxp_depth_buffer. m_shadergen
  null-check removed.

  Pipeline cache shape unchanged: m_vram_fill_pipelines[wrapped][interlaced]
  still gives a 2x2 grid of distinct VkPipeline handles, since
  specialisation is per-pipeline. (A future patch could fold this into
  one VkPipeline per visible PGXP_DEPTH state if pipeline-create cost
  becomes a measurable burden, but that's a different optimisation;
  current state matches the pre-patch pipeline count.)

Notes on spec-const evaluation:

- The dst_coords uvec2 conversion at the top of main() is always
  computed in the SPIR-V even when neither INTERLACED nor WRAPPED is
  taken. The driver's optimiser is expected to dead-code-eliminate it
  at vkCreateGraphicsPipelines time once both spec constants are bound
  to false; spirv-dis on the non-specialised blob shows the IR allows
  this. If a driver doesn't optimise it the cost is negligible (a few
  ALU ops per fragment).

- gl_FragDepth = PGXP_DEPTH ? 1.0 : u_fill_color.a translates to an
  OpSelect on a spec-constant condition. After specialisation the
  OpSelect collapses to one of its two operands; modern drivers do
  this fold during pipeline compile.

Cumulative state after this patch:

- 14 of ~25-30 Bucket A blob variants converted (counting this single
  blob with eight specialisations as one blob - the on-disk pipeline
  cache shape across the four wrapped x interlaced combos and two
  PGXP states is what matters operationally, and that remains 4-or-8
  distinct VkPipelines as before).
- Spec-constant infrastructure exercised with 3 booleans driving
  source-level variants - the densest specialisation use so far.
- First use of constant_id=3 (PGXP_DEPTH common knob).
- Remaining Bucket A: VRAM copy FS (MSAA pair + spec consts),
  VRAM write FS (SSBO vs uniform-buffer pair + spec consts),
  Display FS (the densest one).

Smoke tests in the sandbox:

- vram_fill_fs.inc reconstructs to SPIR-V that passes
  spirv-val --target-env vulkan1.0.
- spirv-dis confirms three SpecId decorations (3, 100, 101) on three
  separate OpSpecConstantFalse %bool entries.
- g++ -fsyntax-only on embedded_shaders.cpp is clean.

Smoke tests at user's end:

- VRAM fill is exercised heavily during VRAM-to-VRAM copies and
  initial framebuffer clears at game boot. Cold-boot with cache nuked
  at scales 1x and 4x, run any game past the first few frames.
  Wrong behaviour in the INTERLACED branch would show as missing
  every-other-line in interlaced video modes (most visible in some
  PSX RPG cutscenes). Wrong behaviour in the WRAPPED branch would
  cause incorrect VRAM-to-VRAM rectangles in games that DMA between
  overlapping regions.

- Toggle PGXP Depth Buffer on/off at runtime. This forces a
  pipeline destroy + rebuild with the new spec-constant value for
  PGXP_DEPTH (id=3). If the spec const isn't being re-applied on
  rebuild, the depth output stays at the old value across the
  toggle - visually that means correct-vs-broken depth ordering in
  PGXP-affected games (Tekken 3 is a known fixture for this).

- The four wrapped/interlaced combinations are exercised by
  oversized VRAM fills and by interlaced-video games respectively.
  At least one of each in normal gameplay should hit a code path
  that runs through every spec-const combination.
2026-05-17 22:51:37 +02:00
LibretroAdmin
bc2776687f common/vulkan, core: pre-bake adaptive composite + box-sample downsample FS
Patch 4 in the glslang-elimination series. Completes the downsample
subsystem: all four downsample pipeline build paths in
src/core/gpu_hw_vulkan.cpp now use embedded SPIR-V. This patch is the
first to plumb the common-knobs spec constant (RESOLUTION_SCALE at
constant_id=0), establishing the project-wide pattern for the
larger remaining utility shaders.

Shaders converted by this patch:

1. AdaptiveDownsampleCompositeFragmentShader. The runtime-baked
   RESOLUTION_SCALE used to derive RCP_VRAM_SIZE = 1/(VRAM_SIZE) and a
   mip-level multiplier '(RESOLUTION_SCALE - 1)'. Both are now SPIR-V
   OpSpecConstantOp arithmetic chained from the constant_id=0 input;
   the driver folds them to literals at vkCreateGraphicsPipelines time
   once GPU_HW_Vulkan::m_resolution_scale is bound. Reads two textures
   at bindings 1 and 2 (matching ShaderGen's 'index + 1' convention
   for Vulkan).

2. BoxSampleDownsampleFragmentShader. Same RESOLUTION_SCALE spec
   constant, used three ways: in 'base_coords = gl_FragCoord *
   uvec2(RESOLUTION_SCALE, RESOLUTION_SCALE)' (OpSpecConstantComposite),
   in the inner loop bounds 'offset < RESOLUTION_SCALE', and in the
   final divisor 'color /= RESOLUTION_SCALE * RESOLUTION_SCALE'
   (OpSpecConstantOp IMul). Whether the loop unrolls is left to the
   driver; this matches the original runtime path's behaviour where
   GLSL frontend often unrolled the bound-as-literal version. At
   extreme RESOLUTION_SCALE=16 the inner body runs 256 times either
   way.

GLSL constraint discovered (documented in the composite shader for
future contributors): glslangValidator rejects spec-const-derived
expressions at global 'const' scope - 'global const initializers must
be constant'. The workaround is to compute the derived value inside
main() as a regular vec2; the SPIR-V will then contain runtime
ALU ops chained from the OpSpecConstant rather than the cleaner
OpSpecConstantOp form, but the driver constant-folds either at
specialisation time.

Call site changes in src/core/gpu_hw_vulkan.cpp:

- GetDownsampleCompositePassPipeline: switched to embedded blob with
  RESOLUTION_SCALE spec const. m_shadergen null-check dropped (it
  was only there for the glslang path).

- GetDownsampleFirstPassPipeline (Box branch): switched to embedded
  blob with RESOLUTION_SCALE spec const. m_shadergen null-check that
  patch 3 had left inside this branch is now also removed - both
  branches of this function are fully pre-baked. The comment block
  at function entry is updated to reflect the new state.

Cumulative state after this patch:

- 9 of ~25-30 Bucket A variants converted. The entire downsample
  subsystem (4 pipelines: Adaptive first-pass, mid-pass, blur,
  composite, plus Box first-pass) is now glslang-free.
- Spec constant infrastructure exercised on its second-stage use
  case: a numeric uint (RESOLUTION_SCALE) rather than a bool
  (FIRST_PASS from patch 3). Confirms the
  OpSpecConstant/OpSpecConstantOp paths through the SpecConstants
  helper work for both flavours.
- Remaining Bucket A: VRAM read FS, VRAM update-depth FS (both
  trivial - just need MULTISAMPLES + possibly an MSAA-vs-not blob
  pair), VRAM copy FS (MSAA blob pair + RESOLUTION_SCALE +
  PGXP_DEPTH), VRAM write FS (SSBO vs uniform-buffer blob pair +
  RESOLUTION_SCALE), VRAM fill FS (RESOLUTION_SCALE + PGXP_DEPTH +
  WRAPPED + INTERLACED), Display FS (the multi-variant one).

Smoke tests in the sandbox:

- Both new .inc files reconstruct to SPIR-V that passes
  'spirv-val --target-env vulkan1.0'.
- spirv-dis on the composite FS confirms 'OpDecorate %RESOLUTION_SCALE
  SpecId 0' and 'OpSpecConstantOp %uint ISub %RESOLUTION_SCALE
  %uint_1' for the mip-level multiplier.
- spirv-dis on the box-sample FS confirms 'OpDecorate
  %RESOLUTION_SCALE SpecId 0', 'OpSpecConstantComposite %v2uint'
  for the base_coords scaling, and 'OpSpecConstantOp %uint IMul' for
  the final divisor.
- g++ -fsyntax-only on embedded_shaders.cpp against the real tree
  headers is clean.

Smoke tests at user's end:

- Cold-boot with shader cache nuked, downsample mode = Adaptive at
  several resolution scales (1x, 4x, 8x, ideally 16x). The composite
  pipeline now drives a spec-constant for RESOLUTION_SCALE; if the
  plumbing is wrong, the downsampled output will be either at the
  wrong scale (mip 0 used everywhere -> overly sharp) or at the
  maximum mip everywhere (overly blurry). Both modes should be
  visually unchanged from the patch-3 baseline.
- Cold-boot with cache nuked, downsample mode = Box, same scales.
  Box-sample now also takes the spec constant; if mis-plumbed at
  scale > 1 the output will be all-black (loop runs 0 times if
  RESOLUTION_SCALE = 0 in SPIR-V) or wildly wrong colors (if the
  averaging divisor is wrong).
- Toggle resolution scale at runtime (which triggers pipeline
  destroy + rebuild). Confirms the SpecConstants helper correctly
  re-specialises on each build with the new m_resolution_scale
  value. This is the test most likely to catch a 'spec value latched
  on first build and never updates' bug, if one exists.
2026-05-17 20:49:05 +02:00
LibretroAdmin
6727587113 common/vulkan, core: spec-constant infrastructure + adaptive downsample mip/blur pre-bake
Patch 3 in the glslang-elimination series. Introduces the specialization-
constant plumbing that subsequent patches need, and applies it to two
adaptive-downsample shaders that demonstrate both the no-spec-const and
the with-spec-const paths through the new infrastructure.

Infrastructure additions:

- Vulkan::SpecConstants class in builders.{h,cpp}. A small builder that
  owns a VkSpecializationMapEntry array and a 4-byte-per-slot payload
  buffer, exposing AddBool/AddUInt/AddInt/AddFloat by constant_id. The
  consumer typically declares a SpecConstants on the same stack frame
  as the GraphicsPipelineBuilder, fills it, and passes GetInfo() to
  SetVertexShader / SetFragmentShader. GetInfo() returns nullptr if no
  entries have been added (equivalent to no specialization info), so
  the same code path can serve both spec-const and non-spec-const
  shaders without conditionals at the call site.

  Up to MAX_ENTRIES (16) constants per stage; AddBool stores the
  value as a 4-byte word (1 for true, 0 for false) per the Vulkan
  spec-constant ABI. Larger types (vec4, double) intentionally not
  supported - no current shader needs them; can be added later if
  the batch shaders end up needing wider values.

- GraphicsPipelineBuilder::SetVertexShader and ::SetFragmentShader now
  take an optional 'const VkSpecializationInfo*' that defaults to
  nullptr. All 36 existing call sites continue to compile unchanged
  via the default. SetShaderStage is also extended; in addition to
  threading spec_info through it now explicitly clears pNext, flags,
  and pSpecializationInfo on every call. The builder is sometimes
  reused across pipelines without an intervening Clear() (e.g. the
  display / cursor pair in LibretroVulkanHostDisplay::CreateResources),
  so a stale spec_info pointer or flags bit could previously leak from
  one pipeline build into the next. Latent issue pre-existing this
  patch; fixed defensively because the new code path exercises it.

Spec-constant ID allocation convention (documented in the SpecConstants
class header and adhered to project-wide):

    0-99    common knobs (RESOLUTION_SCALE, MULTISAMPLES,
            PER_SAMPLE_SHADING, PGXP_DEPTH) - to be plumbed by patch 4.
    100+    shader-specific; e.g. FIRST_PASS for the adaptive-downsample
            mip FS in this patch.

Shaders converted by this patch:

1. AdaptiveDownsampleBlurFragmentShader (no spec constants). One
   SPIR-V blob, replaces GetDownsampleBlurPassPipeline's runtime
   glslang call. Establishes that the embedded path works alongside
   the spec-constant path - the call site is identical to a patch-1
   or patch-2 conversion.

2. AdaptiveDownsampleMipFragmentShader. The 'first_pass' bool that
   previously produced two distinct GLSL source strings (and so two
   cached SPIR-V blobs) is now a single 'bool FIRST_PASS' spec
   constant at constant_id=100. ONE SPIR-V blob serves both
   GetDownsampleFirstPassPipeline (Adaptive branch) with
   FIRST_PASS=true, and GetDownsampleMidPassPipeline with
   FIRST_PASS=false. The branch is preserved as a runtime 'if'; the
   driver's SPIR-V optimizer drops the dead arm at vkCreateGraphics
   Pipelines time because the bool is a compile-time constant in
   that context.

   spirv-dis on the blob confirms 'OpDecorate %FIRST_PASS SpecId 100'
   and 'OpSpecConstantFalse %bool' are emitted as expected.

Other changes in gpu_hw_vulkan.cpp:

- GetDownsampleFirstPassPipeline: m_shadergen null-check moved from
  function entry into the Box branch (which still uses
  GenerateBoxSampleDownsampleFragmentShader at runtime). The Adaptive
  branch no longer needs the check - pre-baked SPIR-V doesn't depend
  on shadergen.
- GetDownsampleMidPassPipeline and GetDownsampleBlurPassPipeline:
  m_shadergen null-checks removed entirely - both are Adaptive-only
  (early-return on non-Adaptive) and now fully pre-baked.

Cumulative state after this patch:

- 7 of ~25-30 Bucket A variants converted (1 in patch 1, 4 in patch 2,
  2 in this patch; the mip FS is one source but two specializations).
- Spec-constant infrastructure ready for patches 4+ to plumb
  RESOLUTION_SCALE / MULTISAMPLES / PGXP_DEPTH into the remaining
  utility shaders.
- glslang and the runtime ShaderGen path still in the tree, still used
  by every Vulkan path not yet converted (batch shaders, remaining
  utility shaders, Box downsample, all GL/D3D backends).

Smoke tests in the sandbox:

- Both new .inc files reconstruct to SPIR-V that passes
  spirv-val --target-env vulkan1.0.
- spirv-dis on the mip FS confirms the OpDecorate SpecId 100 +
  OpSpecConstantFalse pair.
- g++ -fsyntax-only on both modified TUs (builders.cpp,
  embedded_shaders.cpp) is clean; the only warnings are two
  pre-existing unused-parameter warnings in SamplerBuilder::Create
  and BufferViewBuilder::Create, unchanged by this patch.

Smoke tests at user's end:

- Cold-boot with the shader cache nuked and the downsample mode set
  to Adaptive. All three Adaptive pipelines must succeed; the visual
  output should be byte-identical to the pre-patch baseline (same
  algorithm, same texture binds, just specialized SPIR-V instead of
  hand-rolled GLSL).
- Same cold-boot test with Box mode is also useful - it exercises
  that the Box branch in GetDownsampleFirstPassPipeline still works
  via the runtime-glslang path (regression check on the m_shadergen
  null-check relocation).
2026-05-17 20:39:19 +02:00
LibretroAdmin
64c9adaca8 common/vulkan, core: pre-bake UV-quad VS and three presentation-stage shaders
Patch 2 in the glslang-elimination series (probe was 2cbcefc). Converts
four more shaders to the pre-baked SPIR-V path established in the probe.
No new infrastructure - each blob just adds an extern pair to
embedded_shaders.h, a #include inside the namespace block in
embedded_shaders.cpp, and a call-site swap. The probe pattern handles
N=5 blobs as cleanly as it handled N=1.

Shaders converted by this patch:

1. UV-quad vertex shader (GPU_HW_Vulkan::GetUVQuadVertexShader, the
   variant of the screen-quad that maps the swept triangle into a
   [u_uv_min..u_uv_max] UV rect from a push constant). The runtime
   equivalent is ShaderGen::GenerateUVQuadVertexShader().

2. Presentation-stage fullscreen-quad VS - the one with the u_src_rect
   push constant, distinct from the GPU_HW screen quad. Used only by
   LibretroVulkanHostDisplay to blit the rendered frame and the
   software cursor into the libretro framebuffer.

3. Presentation-stage display FS - writes the source texture opaque.

4. Presentation-stage cursor FS - preserves source alpha for blending.

Shaders 2-4 previously lived as inline R"()" string literals at the
top of LibretroVulkanHostDisplay::CreateResources() in
src/core/gpu_hw_vulkan.cpp. They are now in data/shaders/vulkan/ with
matching pre-compiled SPIR-V under src/common/vulkan/embedded_spirv/.
The C++-side pipeline layout (16-byte u_src_rect push constant, single
combined image sampler at set 0 / binding 0) is unchanged, so no
descriptor or push-constant byte-layout coordination is needed.

Cumulative state after this patch:

- 5 of ~25-30 utility-shader variants in Bucket A converted.
- glslang is still in dep/ and still in the build - it is needed by
  every shader generator not yet converted, in particular all of
  GPU_HW_ShaderGen plus the remaining utility shaders that bake
  RESOLUTION_SCALE / MULTISAMPLES / PGXP_DEPTH into source via
  WriteCommonFunctions. The next patch in the series introduces
  specialization-constant infrastructure in GraphicsPipelineBuilder so
  those constants can be moved out of GLSL into SPIR-V OpSpecConstant,
  enabling the rest of Bucket A.

Smoke tests in the sandbox:

- All 5 .inc files reconstruct to SPIR-V that passes
  'spirv-val --target-env vulkan1.0'.
- spirv-dis confirms each blob's entry point, descriptor bindings, and
  push-constant block match the call-site expectations.
- g++ -fsyntax-only on embedded_shaders.cpp against the real tree
  headers is clean.

Smoke tests at user's end:

- Cold-boot the Vulkan backend with the disk shader cache nuked. The
  three presentation-stage pipelines build during
  LibretroVulkanHostDisplay::CreateResources(); the UV-quad VS is
  faulted in lazily by any of the three adaptive-downsample pipeline
  paths (line ~2284 in gpu_hw_vulkan.cpp post-patch). All four must
  succeed for the emulator to reach a first frame.
- A second cold boot (same nuke) verifies the embedded path is
  reproducibly correct, not relying on any leftover state.
2026-05-17 20:23:11 +02:00
LibretroAdmin
2cbcefcff6 common/vulkan, core: pre-bake screen-quad VS, no glslang at runtime
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).
2026-05-17 20:09:57 +02:00
DarthMew
4335a2ad7e Reduce the amount of files in the repo & rename 'duckstation-libretro' to 'libretro' 2022-02-21 23:16:22 +01:00
Connor McLaughlin
30a53fbb3c GameSettings: Disable GPU runahead for Red Asphalt PAL 2022-01-06 22:47:10 +10:00
bslenul
1af69ff38e Database update for mouse compatible games 2021-11-29 12:29:05 +01:00
Connor McLaughlin
46f9da97d2
Merge pull request #2749 from bslenul/guncon-update
Update database for GunCon/Justifier games
2021-11-28 11:22:20 +10:00
Risae
ab831daa18
Update chtdb.txt (#2735)
* Update chtdb.txt

Adds the following cheats to Gran Turismo 1 & 2:

Gran Turismo 1:
- 60 FPS (NTSC-U 1.1, NTSC-U 1.0, PAL, JP NTSC-J)
- Simulation timescale in Arcade (NTSC-U 1.1, PAL)

Gran Turismo 2:
- 16:9 Widescreen Hack 2.0 (NTSC-U 1.2, NTSC-U 1.1, PAL, NTSC-J 1.1, NTSC-J 1.0)
- 21:9 Widescreen Hack 2.0 (NTSC-U 1.2, NTSC-U 1.1, PAL, NTSC-J 1.1, NTSC-J 1.0)
- 60 FPS (NTSC-U 1.2, NTSC-U 1.1, PAL, Arcade Disc: JP NTSC-J 1.0, Simulation Disc: JP NTSC-J 1.1, NTSC-J 1.0)
- Metric units code (NTSC-U 1.2, NTSC-U 1.1, PAL)
- Full detail AI cars (NTSC-U 1.1, NTSC-U 1.2, PAL, NTSC-J 1.1, NTSC-J 1.0)
- Slightly higher draw distance (NTSC-U 1.2, NTSC-U 1.1, PAL, NTSC-J 1.1, NTSC-J 1.0)
- Use 8MB RAM for polygon buffers (NTSC-U 1.1, NTSC-U 1.2, PAL, NTSC-J 1.1, JP NTSC-J 1.0)

Credits go to
https://cookieplmonster.github.io/
https://cookieplmonster.github.io/mods/gran-turismo/
https://cookieplmonster.github.io/mods/gran-turismo-2/

* Update chtdb.txt

Added:

";This game currently has no cheats" to some games that didn't have any cheats yet.

HUD & rear view mirror toggle (NTSC-U 1.2, NTSC-U 1.1, PAL, NTSC-J 1.1, NTSC-J 1.0)
Replay cameras in race (NTSC-U 1.1, NTSC-U 1.2, PAL, Arcade Disc: NTSC-J 1.0, Simulation Disc: NTSC-J 1.1, NTSC-J 1.0)
True Endurance ( NTSC-U 1.2, NTSC-U 1.1, PAL, NTSC-J 1.1)

Removed:

Gran Turismo 2 (USA, v1.1)
#Widescreen 16-9 option Better Graphics
#Widescreen 16-9

Gran Turismo 2 (Euro)
#Widescreen 16-9
#Widescreen 16-9 Better Graphics (Optional)

Gran Turismo 2 (Arcade + Gran Turismo Mode) (Japan, Asia)
#Widescreen 16-9 v1.0
#Widescreen 16-9 v1.0 - Better Graphics (Optional)
#Widescreen 16-9 V1.1
#Widescreen 16-9 v1.1 - Better Graphics (Optional)

* Update chtdb.txt

Removed unnecessary line break
2021-11-28 11:22:04 +10:00
bslenul
19f7516b5b Update database for GunCon/Justifier games 2021-11-27 14:26:57 +01:00
Chromaryu
23a34cb119
GameDB: Add missing definition 2021-11-25 15:11:12 +09:00
Connor McLaughlin
10cf8ef638 GameSettings: Force true color off for SLPS-00078 2021-11-14 23:47:15 +10:00
Connor McLaughlin
acace84bd1 GameDB: Use hash for SLPS-00078 2021-11-14 23:44:26 +10:00
Connor McLaughlin
f982a2a580 Update merged gamedb 2021-11-11 15:36:58 +10:00
Connor McLaughlin
c78047c28f Update gamedb with new hashes for colliding games 2021-11-10 12:53:41 +10:00
Connor McLaughlin
ae92ce8405 Update game database with NeGcon entries from PiperCalls 2021-11-02 11:25:54 +10:00
Connor McLaughlin
d7b913288d Update SDL game controller database 2021-11-02 11:25:54 +10:00
Connor McLaughlin
ccf5006bc8
Merge pull request #2668 from CookiePLMonster/dump-verification
Implement image verification
2021-10-25 17:30:20 +10:00
Connor McLaughlin
45a2e0df5c Update compatibility list 2021-10-25 17:15:56 +10:00
Silent
764c6e4a72
Rewrote gamedb with revisional hashes 2021-10-23 21:46:56 +02:00
Connor McLaughlin
1cc6ee4857 Update bundled SDL game controller database 2021-09-21 10:05:30 +10:00
Connor McLaughlin
f1d6e81751 Update compatibility list 2021-09-15 12:24:32 +10:00
Connor McLaughlin
396b4a48f2 Data: Update SDL game controller database 2021-09-08 10:49:54 +10:00
Connor McLaughlin
6c628bb89f Update compatibility list 2021-09-05 10:11:00 +10:00
Connor McLaughlin
8d57229bdc Update compatibility list 2021-09-01 15:01:39 +10:00
Connor McLaughlin
7f3f5ce1bd Update compatibility list 2021-09-01 14:57:21 +10:00
Connor McLaughlin
4848c72466 GameDB: Actually fix SLES-00107 2021-08-23 02:28:44 +10:00
Connor McLaughlin
95ccf82ff6 GameDB: Fix SLES-00107 2021-08-23 02:09:57 +10:00
Connor McLaughlin
4f190aa902 CommonHostInterface: Move fonts/logo to resources directory 2021-08-12 21:31:40 +10:00
Connor McLaughlin
0576cb6e3b Update compatibility list 2021-08-07 11:45:20 +10:00
Connor McLaughlin
75b69a6f7e GameSettings: Force icache for World Cup 98 2021-07-17 14:03:04 +10:00
Connor McLaughlin
2f2dc9cf72 GameSettings: Force software renderer for Addie no Okurimono - To Moze from Addie 2021-07-05 21:44:03 +10:00
Connor McLaughlin
1da39bdb0b GameDB: Add NeGcon for a few games 2021-07-03 14:37:28 +10:00
Connor McLaughlin
2fbfd53d51 GameSettings: Force CPU PGXP mode for a bunch of games 2021-06-24 17:04:52 +10:00
Connor McLaughlin
8ddc1d6016 GameSettings: Force icache for International Superstar Soccer Pro '98 2021-06-24 14:44:54 +10:00
Connor McLaughlin
e4fb028c8c GameDB: Add PlayStationMouse for Project - Horned Owl 2021-06-17 20:04:05 +10:00
Connor McLaughlin
22b2963bfe Update compatibility list 2021-06-12 18:22:58 +10:00
Connor McLaughlin
6b83bb0cfe GameSettings: Use icache for Chrono Cross 2021-06-11 20:47:46 +10:00
Connor McLaughlin
3a831c543d GameSettings: Force icache for NHL FaceOff 2001 2021-06-02 15:13:43 +10:00
Connor McLaughlin
4a13009af8 GameSettings: Force ICache for SLPM-86086 2021-05-29 18:35:41 +10:00
Connor McLaughlin
deb7f0741a GameSettings: Force LUT fastmem for Racing Lagoon
Slight performance boost.
2021-05-26 02:50:44 +10:00