core/opengl: skip batch matrix rebuild on chroma_smoothing-only flip
OpenGL parity port of the chroma_smoothing partial-clear that landed for D3D12 in57ac62eand for D3D11 in93e5db5. Same motivation: chroma_smoothing is a DefineMacro inside GenerateDisplayFragmentShader only - it never reaches the batch program matrix or the VRAM ops programs. The previous OpenGL patches kept it in shader_source_changed but didn't split it out from the dim-cache branch, so on OpenGL a chroma toggle still called CompilePrograms with clear_existing_render_programs=true (only_dim_changed is false for chroma, since chroma sits in non_dim_diff), which wiped every filter sub-cube and walked the 144-cell batch program matrix synchronously when shader_precompile_mode = Enabled. Reuses the display_only_source_changed signal added by57ac62e(no API change). GPU_HW_OpenGL::UpdateSettings checks it first inside the shader_source_changed gate, before the CompilePrograms call that handles the dim-cache and full-flush paths. The display-only branch calls a new helper, RebuildDisplayPrograms, that recompiles the 2x3 m_display_programs matrix against the new m_chroma_smoothing value (which UpdateHWSettings has already written into the member). The 144-cell batch program matrix, the VRAM ops programs (vram_fill / vram_read / vram_write / vram_copy / vram_update_depth), and the downsample programs all stay valid because none of them carry chroma_smoothing as ctor or compile-time state. CompilePrograms is refactored to call the same helper for its initial display program build, so the 6-cell compile loop only lives in one place. Progress tracking is bumped six times inline after the helper returns to match the pre-patch progress bar units. chroma_smoothing only takes effect on the depth_24bit paths (see the SMOOTH_CHROMA DefineMacro guard in GenerateDisplayFragmentShader), so technically only three of the six programs actually depend on it. Rebuilding all six anyway keeps the path simple - on a chroma toggle the three depth_24bit=false programs re-resolve to cache hits on their existing GLSL hashes in m_shader_cache (instant GetProgram return - the cache reloads the linked binary from disk via glProgramBinary instead of recompiling and re-linking), and the three depth_24bit=true programs pick up the new SMOOTH_CHROMA value via a fresh GL_FRAGMENT_SHADER compile + glLinkProgram. Unlike the D3D11 / D3D12 ports, this patch has no worker-thread relaunch step - the libretro hardware-renderer protocol gives OpenGL a single GL context bound to the runloop thread, so there's no background compile worker to stop or restart. The precompile_mode contract on this path is simply 'RebuildDisplayPrograms is synchronous' in every mode (Enabled, Lazy, Disabled). The other rebuild branches (only_dim_changed via clear_existing_render_programs=false, full-flush via clear_existing_render_programs=true) are unchanged - they're hit only when something the batch matrix genuinely depends on changed, and the dim cache / full-flush paths fromf8b4a41already do the right thing there. Cost matrix after this patch (OpenGL, shader_precompile_mode = Enabled, 144 batch program cells): Toggle Before (f8b4a41) After this patch chroma_smoothing ~5-15 sec ~600 ms (full matrix walk) (6 display programs) texture_filter (warm) instant unchanged texture_filter (cold) ~5-15 sec unchanged (new sub-cube) resolution_scale zero unchanged true_color zero unchanged scaled_dithering zero unchanged multisamples ~5-15 sec unchanged (necessary) per_sample_shading ~5-15 sec unchanged (necessary) uv_limits ~5-15 sec unchanged (necessary) pgxp_depth ~5-15 sec unchanged (necessary) disable_color_persp. ~5-15 sec unchanged (necessary) shader_precompile_mode ~5-15 sec unchanged (intentional) Every remaining 'still pays' toggle in the matrix is one that genuinely invalidates batch GLSL across the board. The OpenGL backend's UpdateSettings path is now structurally on par with the D3D11 / D3D12 backends' post-57ac62e /93e5db5cost matrices. The only remaining backend without this optimisation is Vulkan - same pattern would apply (Vulkan's chroma toggle currently does a full DestroyPipelines + CompilePipelines and could clear just the 6-slot display VkPipeline cache). Test: - OpenGL, shader_precompile = Enabled. Toggle 24-bit chroma smoothing on / off: ~600 ms pause (6 display program rebuilds), no batch matrix progress OSD. Batch draw remains hot - no stutter on the next frame. - Same toggle under Lazy / Disabled: ~600 ms pause for the display rebuild, no worker behavior to verify (OpenGL has none). Batch matrix stays as it was - empty in Disabled mode, partially populated in Lazy if any draws have run. - Toggle chroma_smoothing AT THE SAME TIME as another setting (e.g. via batch settings reload): display_only_source_changed returns false (other_source_diff is true), the CompilePrograms branch fires with the right clear_existing_render_programs flag as before. - Cycle chroma on -> off -> on: first toggle pays the 600ms compile, second toggle hits all 6 entries as cache hits in m_shader_cache and returns instantly. Third toggle hits cache hits on the on-state programs too. Steady-state chroma cycling is effectively free.
This commit is contained in:
parent
f8b4a41bd9
commit
722e98aacb
2 changed files with 95 additions and 33 deletions
|
|
@ -807,8 +807,18 @@ void GPU_HW_OpenGL::UpdateSettings()
|
|||
// this path can call through without throwing away the previous
|
||||
// filter's compiled programs. Mirrors the D3D11 / D3D12 / Vulkan
|
||||
// dim-cache fast paths.
|
||||
bool framebuffer_changed, shaders_changed, only_dim_changed, shader_source_changed;
|
||||
UpdateHWSettings(&framebuffer_changed, &shaders_changed, &only_dim_changed, nullptr, &shader_source_changed);
|
||||
//
|
||||
// display_only_source_changed: chroma_smoothing flipped and
|
||||
// nothing else affecting shader source changed. The batch program
|
||||
// matrix, VRAM ops programs, and downsample programs all stay
|
||||
// valid; only the 6-slot m_display_programs cache needs to go.
|
||||
// Mirrors the D3D12 / D3D11 partial-clear from 57ac62e / 93e5db5.
|
||||
// OpenGL has no worker thread so there's no relaunch step on this
|
||||
// path - precompile_mode contract is simply "RebuildDisplayPrograms
|
||||
// is synchronous" in any mode.
|
||||
bool framebuffer_changed, shaders_changed, only_dim_changed, shader_source_changed, display_only_source_changed;
|
||||
UpdateHWSettings(&framebuffer_changed, &shaders_changed, &only_dim_changed, nullptr, &shader_source_changed,
|
||||
&display_only_source_changed);
|
||||
|
||||
if (framebuffer_changed)
|
||||
{
|
||||
|
|
@ -820,11 +830,30 @@ void GPU_HW_OpenGL::UpdateSettings()
|
|||
}
|
||||
if (shader_source_changed)
|
||||
{
|
||||
// only_dim_changed: filter (and/or cbuffer-only members) changed
|
||||
// but nothing in non_dim_diff. Preserve previously-visited
|
||||
// filter sub-cubes so the user can cycle filters without paying
|
||||
// the recompile cost more than once per filter.
|
||||
CompilePrograms(/*clear_existing_render_programs=*/!only_dim_changed);
|
||||
if (display_only_source_changed)
|
||||
{
|
||||
// chroma_smoothing flipped and nothing else - rebuild the six
|
||||
// display programs against the new m_chroma_smoothing value
|
||||
// (which UpdateHWSettings has already written into the member).
|
||||
// The 144-cell batch program matrix, the VRAM ops programs, and
|
||||
// the downsample programs all stay valid. Cost is 6 link calls
|
||||
// (mostly cache hits from m_shader_cache for previously-seen
|
||||
// GLSL hashes) instead of the full CompilePrograms pass walking
|
||||
// the entire batch matrix.
|
||||
(void)RebuildDisplayPrograms();
|
||||
}
|
||||
else
|
||||
{
|
||||
// only_dim_changed: filter (and/or cbuffer-only members) changed
|
||||
// but nothing in non_dim_diff. Preserve previously-visited
|
||||
// filter sub-cubes so the user can cycle filters without paying
|
||||
// the recompile cost more than once per filter.
|
||||
//
|
||||
// Otherwise (non-dim, non-display-only source change): wipe all
|
||||
// sub-cubes via clear_existing_render_programs=true, full
|
||||
// rebuild walks the current filter's sub-cube.
|
||||
CompilePrograms(/*clear_existing_render_programs=*/!only_dim_changed);
|
||||
}
|
||||
}
|
||||
|
||||
if (framebuffer_changed)
|
||||
|
|
@ -1182,32 +1211,10 @@ bool GPU_HW_OpenGL::CompilePrograms(bool clear_existing_render_programs)
|
|||
// constructed (program id 0); each cell is filled on first draw
|
||||
// by GetBatchProgram on the runloop thread.
|
||||
|
||||
for (uint8_t depth_24bit = 0; depth_24bit < 2; depth_24bit++)
|
||||
{
|
||||
for (uint8_t interlaced = 0; interlaced < 3; interlaced++)
|
||||
{
|
||||
const std::string vs = shadergen.GenerateScreenQuadVertexShader();
|
||||
const std::string fs = shadergen.GenerateDisplayFragmentShader(
|
||||
static_cast<bool>(depth_24bit), static_cast<InterlacedRenderMode>(interlaced), m_chroma_smoothing);
|
||||
|
||||
std::optional<GL::Program> prog =
|
||||
shader_cache.GetProgram(vs, {}, fs, [this, use_binding_layout](GL::Program& p) {
|
||||
if (!IsGLES() && !use_binding_layout)
|
||||
p.BindFragData(0, "o_col0");
|
||||
});
|
||||
if (!prog)
|
||||
return false;
|
||||
|
||||
if (!use_binding_layout)
|
||||
{
|
||||
prog->BindUniformBlock("UBOBlock", 1);
|
||||
prog->Bind();
|
||||
prog->Uniform1i("samp0", 0);
|
||||
}
|
||||
m_display_programs[depth_24bit][interlaced] = std::move(*prog);
|
||||
progress.Increment();
|
||||
}
|
||||
}
|
||||
if (!RebuildDisplayPrograms())
|
||||
return false;
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
progress.Increment();
|
||||
|
||||
for (uint8_t wrapped = 0; wrapped < 2; wrapped++)
|
||||
{
|
||||
|
|
@ -1325,6 +1332,60 @@ bool GPU_HW_OpenGL::CompilePrograms(bool clear_existing_render_programs)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GPU_HW_OpenGL::RebuildDisplayPrograms()
|
||||
{
|
||||
// (Re)compile the 2x3 m_display_programs matrix against the
|
||||
// current m_chroma_smoothing. Called from CompilePrograms during
|
||||
// the initial / full-rebuild pass and from UpdateSettings on a
|
||||
// chroma_smoothing-only flip - chroma_smoothing is a DefineMacro
|
||||
// inside GenerateDisplayFragmentShader only (see
|
||||
// gpu_hw_shadergen.cpp:1056), so the batch program matrix, the
|
||||
// VRAM ops programs, the VRAM read/write/copy/update-depth
|
||||
// programs, and the downsample programs all stay valid through
|
||||
// a chroma toggle and don't need rebuilding. Costs 6 link calls
|
||||
// (effectively cache hits via m_shader_cache when an HLSL/GLSL
|
||||
// hash has been seen before; cold builds otherwise) instead of
|
||||
// the full CompilePrograms pass.
|
||||
//
|
||||
// chroma_smoothing only takes effect on the depth_24bit paths
|
||||
// (see the SMOOTH_CHROMA DefineMacro in
|
||||
// GenerateDisplayFragmentShader), so technically only three of
|
||||
// the six display programs depend on it. Rebuilding all six
|
||||
// anyway keeps this path simple - on a chroma toggle the three
|
||||
// depth_24bit=false programs re-resolve to cache hits on their
|
||||
// existing GLSL hashes (instant), and the three depth_24bit=true
|
||||
// programs pick up the new SMOOTH_CHROMA value.
|
||||
if (!m_shadergen)
|
||||
return false;
|
||||
const bool use_binding_layout = m_use_binding_layout;
|
||||
for (uint8_t depth_24bit = 0; depth_24bit < 2; depth_24bit++)
|
||||
{
|
||||
for (uint8_t interlaced = 0; interlaced < 3; interlaced++)
|
||||
{
|
||||
const std::string vs = m_shadergen->GenerateScreenQuadVertexShader();
|
||||
const std::string fs = m_shadergen->GenerateDisplayFragmentShader(
|
||||
static_cast<bool>(depth_24bit), static_cast<InterlacedRenderMode>(interlaced), m_chroma_smoothing);
|
||||
|
||||
std::optional<GL::Program> prog =
|
||||
m_shader_cache.GetProgram(vs, {}, fs, [this, use_binding_layout](GL::Program& p) {
|
||||
if (!IsGLES() && !use_binding_layout)
|
||||
p.BindFragData(0, "o_col0");
|
||||
});
|
||||
if (!prog)
|
||||
return false;
|
||||
|
||||
if (!use_binding_layout)
|
||||
{
|
||||
prog->BindUniformBlock("UBOBlock", 1);
|
||||
prog->Bind();
|
||||
prog->Uniform1i("samp0", 0);
|
||||
}
|
||||
m_display_programs[depth_24bit][interlaced] = std::move(*prog);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const GL::Program* GPU_HW_OpenGL::GetBatchProgram(GPUTextureFilter filter, uint8_t render_mode, uint8_t texture_mode, bool dithering, bool interlacing)
|
||||
{
|
||||
// Reserved_*Direct16Bit dedup. The fragment shader source for
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ private:
|
|||
bool CreateTextureBuffer();
|
||||
|
||||
bool CompilePrograms(bool clear_existing_render_programs = true);
|
||||
bool RebuildDisplayPrograms();
|
||||
|
||||
// Lazy batch-program compile path. The libretro hardware-renderer
|
||||
// protocol gives us a single GL context bound to the runloop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue