core, common/vulkan: add true_color and scaled_dithering as batch pipeline cache dimensions

Option B added texture filter as the outermost dimension of
m_batch_pipelines, making filter swaps instant on revisit. The same
problem still bit the user on toggling 'scaled dithering' and 'true
colour' in the core options menu: both are pure per-session spec
constants (DITHERING_SCALED = id 105, TRUE_COLOR = id 106) applied
at vkCreateGraphicsPipelines time, so the driver bakes them into
each cached PSO. With no cache dimension over them, the existing
non_filter_diff comparison in UpdateHWSettings would set
*only_filter_changed = false on a toggle, routing UpdateSettings
into the full DestroyPipelines + CompilePipelines path - the same
5-10 second pause Option B got rid of for filter.

Extend the same trick to both:

  m_batch_pipelines: 7D -> 9D
    was [filter][depth_test][render_mode][texture_mode]
        [transparency_mode][dithering][interlacing]
    now [filter][true_color][scaled_dithering][depth_test]
        [render_mode][texture_mode][transparency_mode]
        [dithering][interlacing]

m_batch_fragment_shaders stays 5D - true_color and scaled_dithering
do NOT affect SPIR-V blob choice, only the spec const value at PSO
bake time, so the same VkShaderModule backs both values. The PSO
cache doubles for each new dimension (atomic slots only - driver-
side memory grows only when a slot is populated).

API changes:

  - GPU_HW::UpdateHWSettings out-parameter renamed
    only_filter_changed -> only_dim_changed, with the semantics
    broadened: the flag is true iff the only shader-affecting
    changes are in dimensioned settings (filter, true_color,
    scaled_dithering). Default-nullptr param so the D3D11 / D3D12
    callers stay untouched - they continue doing a full destroy +
    recompile on any shaders_changed event because their batch
    caches are not yet dimensioned over anything.

  - GetBatchPipeline gains two leading parameters:
        GetBatchPipeline(filter, true_color, scaled_dithering, ...)
    The internal m_true_color / m_scaled_dithering reads (slot
    indexing context and the AddBool(105/106, ...) lines in the
    spec const setup) are replaced with the passed parameters.
    The same param-snapshot pattern Option C introduced for
    filter now covers all three dimensioned settings, so the
    helper has no implicit dependency on class-member state for
    any of its cache axes.

Call site updates:

  - DrawBatchVertices: passes (m_texture_filtering, m_true_color,
    m_scaled_dithering).
  - precompile_sync PSO loop in CompilePipelines: same.
  - ShaderCompileThreadEntryPoint: snapshots m_true_color and
    m_scaled_dithering at worker entry alongside the existing
    filter loop. The worker is responsible only for the CURRENT
    (true_color, scaled_dithering) combo's seven filter sub-
    cubes - walking all 7 x 2 x 2 = 28 sub-cubes in the
    background would balloon cold-cache warm-up to several
    minutes, well past 'useful' into 'annoying'.

Behaviour after this patch:

  - Cycling back to a previously-visited (filter, true_color,
    scaled_dithering) tuple: instant. The slot is already filled,
    GetBatchPipeline returns it from a single atomic load.
  - First time toggling true_color or scaled_dithering in a
    session: 5-10s sync compile in Enabled mode for the current
    filter's sub-cube under the new value, then the worker warms
    the other six filter sub-cubes in the background. Lazy mode
    fault-ins on first draws as before.
  - Toggling filter under the new (true_color, scaled_dithering):
    same as Option C - instant on revisit, sync compile + back-
    ground warm-up on first visit.

After enough cycling through the three settings (typically a few
back-and-forth toggles of each), all reachable combinations end up
cached and every toggle becomes instant for the rest of the
session.

Memory cost during warm-up:
  - PSO cache atomic-slot count grows by 4x relative to pre-B,
    7x already happened in Option B for filter, this patch makes
    it 14x (true_color) and 28x (scaled_dithering). Slot array
    size: ~480 KiB total. Driver-side PSO storage only grows when
    slots are populated; a typical session touches maybe 10-20%
    of one (filter, true_color, scaled_dithering) combo's
    reachable cells.
  - On hardware lacking dual-source blend the *BinAlpha and other
    non-Nearest filters are clamped to Nearest by UpdateHWSettings
    and the worker skips them via TextureFilterRequiresDualSource-
    Blend, so the actual populated count is lower.

Smoke tests:
  - Tree-wide grep for m_true_color / m_scaled_dithering /
    only_filter_changed inside the helpers and their callers:
    every remaining hit is either a comment, a callsite that
    correctly snapshots the class member to pass downward, or
    elsewhere in the file outside the batch pipeline path
    (m_true_color / m_scaled_dithering still drive other Vulkan
    structural choices like resolution scale).
  - The two GetBatchPipeline helper signatures match in header
    and impl; no stale 7D declaration of m_batch_pipelines
    survives in the header.

Test priority:
  - With shader cache nuked, in Enabled mode, toggle the
    'scaled dithering' core option on then off then on. First
    toggle pays the usual 5-10s pause for the current filter
    sub-cube under the new dithering value. Second toggle back
    to the original should be INSTANT - the slot is already
    filled.
  - Same test with 'true colour'. Same behaviour expected.
  - Toggle both: scaled dithering off, true colour off, then
    scaled dithering on, true colour off, ... cycle through all
    four (true_color, scaled_dithering) combos. After one cycle,
    every transition is instant for the rest of the session.
  - Confirm non-dimensioned changes (resolution scale, MSAA,
    PGXP depth, etc.) still trigger the full
    DestroyPipelines + CompilePipelines pause - that path is
    unchanged and required for those settings to be applied
    correctly.
  - On hardware without dual-source blend: confirm the worker
    still walks only Nearest's sub-cube across the current
    (true_color, scaled_dithering) snapshot.
  - Long session (10+ minutes) of toggling the three dimensioned
    settings: no driver-side OOM. Watch GPU memory in nvidia-smi
    or Task Manager.

The set of dimensioned settings could be extended further to
pgxp_depth_buffer or other 2-value spec consts, but those toggle
much less frequently in practice and would only add another 2x
slot cost each. Defer until requested.

After this lands the Vulkan filter / dithering / true-colour
trio is functionally complete: every common user-toggled batch
shader setting is dimensioned, with current-combo background
warm-up keeping cold-cache cost bounded.
This commit is contained in:
LibretroAdmin 2026-05-18 01:38:34 +00:00 • committed by U-DESKTOP-SPFP6AQ\twistedtechre
commit dbdd273622
4 changed files with 146 additions and 89 deletions

View file

@ -129,7 +129,7 @@ bool GPU_HW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool u
}
void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed,
bool* only_filter_changed)
bool* only_dim_changed)
{
const uint32_t resolution_scale = CalculateResolutionScale();
const uint32_t multisamples = std::min(m_max_multisamples, g_settings.gpu_multisamples);
@ -141,29 +141,39 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed,
*framebuffer_changed =
(m_resolution_scale != resolution_scale || m_multisamples != multisamples || m_downsample_mode != downsample_mode);
// Split the shader-affecting setting comparison into "filter
// changed" and "anything else changed". A filter-only change can
// be served by a backend that keeps a per-filter sub-cube of
// batch pipelines populated across swaps - the previous filter's
// PSOs are still valid and reachable, so DestroyPipelines can be
// skipped and CompilePipelines just lazy-populates the new
// filter's sub-cube on top of whatever was already there. Any
// non-filter change (resolution, MSAA, true colour, PGXP depth,
// dithering, precompile mode, ...) flips the per-session spec
// constants or the structural SPIR-V blob choice applied to
// EVERY filter sub-cube and therefore requires a full flush.
const bool filter_diff = (m_texture_filtering != g_settings.gpu_texture_filter);
const bool non_filter_diff =
// Split the shader-affecting setting comparison into "cache-
// dimensioned settings changed" and "non-dimensioned settings
// changed". A change confined to dimensioned settings can be
// served by a backend that keeps a per-(filter, true_color,
// scaled_dithering) sub-cube of batch pipelines populated across
// toggles - the previous sub-cube's PSOs are still valid and
// reachable, so DestroyPipelines can be skipped and
// CompilePipelines just lazy-populates the new sub-cube on top of
// whatever was already there. Any non-dimensioned change
// (resolution scale, MSAA, per-sample shading, UV limits, chroma
// smoothing, downsample mode, PGXP depth, colour perspective,
// precompile mode) flips per-session spec constants or structural
// SPIR-V blob choice applied to EVERY sub-cube and therefore
// requires a full flush.
//
// GPUTextureFilter, m_true_color and m_scaled_dithering are the
// three settings the Vulkan backend currently dimensions over.
// The set may extend to other 2-value spec consts in the future
// without changing this API.
const bool filter_diff = (m_texture_filtering != g_settings.gpu_texture_filter);
const bool true_color_diff = (m_true_color != g_settings.gpu_true_color);
const bool scaled_dithering_diff = (m_scaled_dithering != g_settings.gpu_scaled_dithering);
const bool dim_diff = filter_diff || true_color_diff || scaled_dithering_diff;
const bool non_dim_diff =
(m_resolution_scale != resolution_scale || m_multisamples != multisamples ||
m_true_color != g_settings.gpu_true_color || m_per_sample_shading != per_sample_shading ||
m_scaled_dithering != g_settings.gpu_scaled_dithering ||
m_per_sample_shading != per_sample_shading ||
m_using_uv_limits != use_uv_limits || m_chroma_smoothing != g_settings.gpu_24bit_chroma_smoothing ||
m_downsample_mode != downsample_mode || m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer() ||
m_disable_color_perspective != disable_color_perspective ||
m_shader_precompile_mode != g_settings.gpu_shader_precompile_mode);
*shaders_changed = filter_diff || non_filter_diff;
if (only_filter_changed)
*only_filter_changed = filter_diff && !non_filter_diff;
*shaders_changed = dim_diff || non_dim_diff;
if (only_dim_changed)
*only_dim_changed = dim_diff && !non_dim_diff;
m_resolution_scale = resolution_scale;
m_multisamples = multisamples;