@@ -276,11 +276,29 @@ bool PostProcessing::Config::IsEnabled(const SettingsInterface& si, const char*
276276 return si.GetBoolValue (section, " Enabled" , false );
277277}
278278
279+ bool PostProcessing::Config::IsStageEnabled (const SettingsInterface& si, const char * section, u32 index)
280+ {
281+ return si.GetBoolValue (GetStageConfigSection (section, index), " Enabled" , true );
282+ }
283+
279284u32 PostProcessing::Config::GetStageCount (const SettingsInterface& si, const char * section)
280285{
281286 return si.GetUIntValue (section, " StageCount" , 0u );
282287}
283288
289+ u32 PostProcessing::Config::GetEnabledStageCount (const SettingsInterface& si, const char * section)
290+ {
291+ const int stage_count = GetStageCount (si, section);
292+ int enabled_count = 0 ;
293+ for (int i = 0 ; i < stage_count; i++)
294+ {
295+ if (IsStageEnabled (si, section, i))
296+ enabled_count++;
297+ }
298+
299+ return enabled_count;
300+ }
301+
284302std::string PostProcessing::Config::GetStageShaderName (const SettingsInterface& si, const char * section, u32 index)
285303{
286304 return si.GetStringValue (GetStageConfigSection (section, index), " ShaderName" );
@@ -317,6 +335,11 @@ std::vector<PostProcessing::ShaderOption> PostProcessing::Config::GetShaderOptio
317335 return ret;
318336}
319337
338+ void PostProcessing::Config::SetStageEnabled (SettingsInterface& si, const char * section, u32 index, bool enabled)
339+ {
340+ si.SetBoolValue (GetStageConfigSection (section, index), " Enabled" , enabled);
341+ }
342+
320343bool PostProcessing::Config::AddStage (SettingsInterface& si, const char * section, const std::string& shader_name,
321344 Error* error)
322345{
@@ -329,6 +352,7 @@ bool PostProcessing::Config::AddStage(SettingsInterface& si, const char* section
329352
330353 const TinyString stage_section = GetStageConfigSection (section, index);
331354 si.SetStringValue (stage_section, " ShaderName" , shader->GetName ().c_str ());
355+ SetStageEnabled (si, section, index, true );
332356
333357#if 0
334358 // Leave options unset for now.
@@ -448,16 +472,23 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
448472 m_wants_unscaled_input = false ;
449473
450474 const u32 stage_count = Config::GetStageCount (si, m_section);
451- if (stage_count == 0 )
475+ const u32 enabled_stage_count = Config::GetEnabledStageCount (si, m_section);
476+ if (stage_count == 0 || enabled_stage_count == 0 )
452477 return ;
453478
454479 Error error;
455480 FullscreenUI::LoadingScreenProgressCallback progress;
456481 progress.SetTitle (" Loading Post-Processing Shaders..." );
457- progress.SetProgressRange (stage_count );
482+ progress.SetProgressRange (enabled_stage_count );
458483
459484 for (u32 i = 0 ; i < stage_count; i++)
460485 {
486+ bool stage_enabled = Config::IsStageEnabled (si, m_section, i);
487+ if (!stage_enabled)
488+ {
489+ continue ;
490+ }
491+
461492 std::string stage_name = Config::GetStageShaderName (si, m_section, i);
462493 if (stage_name.empty ())
463494 {
@@ -483,8 +514,8 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
483514 m_stages.push_back (std::move (shader));
484515 }
485516
486- if (stage_count > 0 )
487- DEV_LOG (" Loaded {} post-processing stages." , stage_count );
517+ if (enabled_stage_count > 0 )
518+ DEV_LOG (" Loaded {} post-processing stages." , enabled_stage_count );
488519
489520 // precompile shaders
490521 if (preload_swap_chain_size && g_gpu_device && g_gpu_device->HasMainSwapChain ())
@@ -515,7 +546,8 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
515546 m_enabled = si.GetBoolValue (m_section, " Enabled" , false );
516547
517548 const u32 stage_count = Config::GetStageCount (si, m_section);
518- if (stage_count == 0 )
549+ const u32 enabled_stage_count = Config::GetEnabledStageCount (si, m_section);
550+ if (stage_count == 0 || enabled_stage_count == 0 )
519551 {
520552 m_stages.clear ();
521553 return ;
@@ -527,12 +559,12 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
527559
528560 FullscreenUI::LoadingScreenProgressCallback progress;
529561 progress.SetTitle (" Loading Post-Processing Shaders..." );
530- progress.SetProgressRange (stage_count );
562+ progress.SetProgressRange (enabled_stage_count );
531563
532564 const GPUTexture::Format prev_format = m_target_format;
533565 m_wants_depth_buffer = false ;
534566
535- for (u32 i = 0 ; i < stage_count; i++)
567+ for (u32 i = 0 , j = 0 ; i < stage_count; i++)
536568 {
537569 std::string stage_name = Config::GetStageShaderName (si, m_section, i);
538570 if (stage_name.empty ())
@@ -542,10 +574,18 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
542574 return ;
543575 }
544576
545- if (!m_stages[i] || stage_name != m_stages[i]->GetName ())
577+ bool stage_enabled = Config::IsStageEnabled (si, m_section, i);
578+ if (!stage_enabled)
546579 {
547- if (i < m_stages.size ())
548- m_stages[i].reset ();
580+ if (m_stages[j] && stage_name == m_stages[j]->GetName ())
581+ m_stages[j].reset ();
582+ continue ;
583+ }
584+
585+ if (!m_stages[j] || stage_name != m_stages[j]->GetName ())
586+ {
587+ if (j < m_stages.size ())
588+ m_stages[j].reset ();
549589
550590 // Force recompile.
551591 m_target_format = GPUTexture::Format::Unknown;
@@ -559,27 +599,30 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
559599 return ;
560600 }
561601
562- if (i < m_stages.size ())
563- m_stages[i ] = std::move (shader);
602+ if (j < m_stages.size ())
603+ m_stages[j ] = std::move (shader);
564604 else
565605 m_stages.push_back (std::move (shader));
566606
567607 settings_lock.lock ();
568608 }
569609
570- m_stages[i]->LoadOptions (si, GetStageConfigSection (m_section, i));
610+ m_stages[j]->LoadOptions (si, GetStageConfigSection (m_section, i));
611+ j++;
571612 }
572613
614+ m_stages.resize (enabled_stage_count);
615+
573616 if (prev_format != GPUTexture::Format::Unknown)
574617 {
575618 CheckTargets (m_target_width, m_target_height, prev_format, m_source_width, m_source_height, m_viewport_width,
576619 m_viewport_height, &progress);
577620 }
578621
579- if (stage_count > 0 )
622+ if (enabled_stage_count > 0 )
580623 {
581624 s_start_time = Timer::GetCurrentValue ();
582- DEV_LOG (" Loaded {} post-processing stages." , stage_count );
625+ DEV_LOG (" Loaded {} post-processing stages." , enabled_stage_count );
583626 }
584627
585628 // must be down here, because we need to compile first, triggered by CheckTargets()
0 commit comments