diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 98576539..b164ccef 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -159,7 +159,8 @@ bool GPU_HW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool u } void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed, - bool* only_dim_changed, bool* downsample_changed) + bool* only_dim_changed, bool* downsample_changed, + bool* shader_source_changed) { const uint32_t resolution_scale = CalculateResolutionScale(); const uint32_t multisamples = std::min(m_max_multisamples, g_settings.gpu_multisamples); @@ -224,6 +225,40 @@ void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed, if (downsample_changed) *downsample_changed = (m_downsample_mode != downsample_mode); + // shader_source_changed: the narrower "HLSL / GLSL source string + // actually changed" signal. Set true only when a setting that the + // shader generator bakes into the emitted source has flipped. + // Excludes the three per-session settings routed through the batch + // UBO by 7b575a3 (resolution_scale, true_color, scaled_dithering) - + // toggling those is a single 4-byte cbuffer write on the next + // FlushRender and costs zero shader compilation on D3D11 / D3D12 / + // OpenGL. Backends that don't carry the Vulkan-style per-spec-const + // pipeline dim cache check this signal to gate the + // DestroyPipelines + CompilePipelines round trip; the broader + // shaders_changed above remains for Vulkan's spec-const-aware path. + // + // chroma_smoothing stays in here because it does change the display + // FS source string on those backends (D3D12 passes it to + // GenerateDisplayFragmentShader at gpu_hw_d3d12.cpp:~1639, D3D11 at + // gpu_hw_d3d11.cpp:~1118, OpenGL at gpu_hw_opengl.cpp:~1145). + // shader_precompile_mode stays in here because flipping from + // Disabled to Enabled is the request to walk the whole matrix + // synchronously now - the work is in CompilePipelines, not in + // shader source, so the existing destroy-and-rebuild path is the + // right hook even though no source actually changed. + if (shader_source_changed) + { + *shader_source_changed = + (m_texture_filtering != g_settings.gpu_texture_filter) || + (m_multisamples != multisamples) || + (m_per_sample_shading != per_sample_shading) || + (m_using_uv_limits != use_uv_limits) || + (m_chroma_smoothing != g_settings.gpu_24bit_chroma_smoothing) || + (m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer()) || + (m_disable_color_perspective != disable_color_perspective) || + (m_shader_precompile_mode != g_settings.gpu_shader_precompile_mode); + } + m_resolution_scale = resolution_scale; m_multisamples = multisamples; m_per_sample_shading = per_sample_shading; diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h index 8af8a806..3081096d 100644 --- a/src/core/gpu_hw.h +++ b/src/core/gpu_hw.h @@ -219,7 +219,8 @@ protected: // round-trip. void UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed, bool* only_dim_changed = nullptr, - bool* downsample_changed = nullptr); + bool* downsample_changed = nullptr, + bool* shader_source_changed = nullptr); virtual void UpdateVRAMReadTexture(); virtual void UpdateDepthBufferFromMaskBit() = 0; diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp index 61bbbc52..ac8dc9b5 100644 --- a/src/core/gpu_hw_d3d11.cpp +++ b/src/core/gpu_hw_d3d11.cpp @@ -579,8 +579,18 @@ void GPU_HW_D3D11::UpdateSettings() { GPU_HW::UpdateSettings(); - bool framebuffer_changed, shaders_changed; - UpdateHWSettings(&framebuffer_changed, &shaders_changed); + // See GPU_HW_D3D12::UpdateSettings for the rationale on + // shader_source_changed vs shaders_changed: the cbuffer-refactor + // patch made true_color / scaled_dithering / resolution_scale + // invariant under HLSL source, so toggling them no longer requires + // DestroyShaders + CompileShaders. The DXBC blobs, state objects, + // and Direct3D11 shader handles all stay valid; the new values + // ride the per-batch UBO upload on the next FlushRender. State + // objects also stay valid through those toggles because their + // descriptions key on MSAA / dual-source / depth-test / blend + // mode - none of which are in the cbuffer-only set. + bool framebuffer_changed, shaders_changed, shader_source_changed; + UpdateHWSettings(&framebuffer_changed, &shaders_changed, nullptr, nullptr, &shader_source_changed); if (framebuffer_changed) { @@ -591,7 +601,7 @@ void GPU_HW_D3D11::UpdateSettings() CreateFramebuffer(); } - if (shaders_changed) + if (shader_source_changed) { DestroyShaders(); DestroyStateObjects(); diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp index a43fd7e9..8fc97fd0 100644 --- a/src/core/gpu_hw_d3d12.cpp +++ b/src/core/gpu_hw_d3d12.cpp @@ -396,8 +396,19 @@ void GPU_HW_D3D12::UpdateSettings() { GPU_HW::UpdateSettings(); - bool framebuffer_changed, shaders_changed; - UpdateHWSettings(&framebuffer_changed, &shaders_changed); + // shader_source_changed is the narrower signal added by the + // cbuffer-refactor follow-up - it fires only when a setting that + // the shader generator bakes into the HLSL string has flipped. + // Toggling resolution_scale / true_color / scaled_dithering now + // costs no DXBC compile and no PSO rebuild: the HLSL is invariant + // under those three, and the new values ride the per-batch UBO + // upload on the next FlushRender. Without checking this signal, + // every option toggle would still walk the whole 1164-PSO batch + // matrix synchronously when shader_precompile_mode = Enabled, + // exactly the multi-tens-of-seconds pause this patch series is + // meant to remove. + bool framebuffer_changed, shaders_changed, shader_source_changed; + UpdateHWSettings(&framebuffer_changed, &shaders_changed, nullptr, nullptr, &shader_source_changed); if (framebuffer_changed) { @@ -413,7 +424,7 @@ void GPU_HW_D3D12::UpdateSettings() if (framebuffer_changed) CreateFramebuffer(); - if (shaders_changed) + if (shader_source_changed) { // clear it since we draw a loading screen and it's not in the correct state DestroyPipelines(); diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index 00ae18ab..380e8fbe 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -791,8 +791,15 @@ void GPU_HW_OpenGL::UpdateSettings() { GPU_HW::UpdateSettings(); - bool framebuffer_changed, shaders_changed; - UpdateHWSettings(&framebuffer_changed, &shaders_changed); + // See GPU_HW_D3D12::UpdateSettings for the rationale on + // shader_source_changed vs shaders_changed: post-7b575a3 the + // batch GLSL is invariant under resolution_scale / true_color / + // scaled_dithering, so toggling them no longer requires + // CompilePrograms (which would otherwise relink every program in + // the batch matrix). The new values ride the per-batch UBO + // upload on the next FlushRender. + bool framebuffer_changed, shaders_changed, shader_source_changed; + UpdateHWSettings(&framebuffer_changed, &shaders_changed, nullptr, nullptr, &shader_source_changed); if (framebuffer_changed) { @@ -802,7 +809,7 @@ void GPU_HW_OpenGL::UpdateSettings() m_host_display->ClearDisplayTexture(); CreateFramebuffer(); } - if (shaders_changed) + if (shader_source_changed) CompilePrograms(); if (framebuffer_changed)