Skip to content

Commit 78a69cd

Browse files
committed
PostProcessing: Set unscaled input based on first enabled shader
Only way to get correct sizing when combining reshade and slang.
1 parent 3066a38 commit 78a69cd

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/util/postprocessing.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
472472
progress.SetProgressRange(stage_count);
473473

474474
u32 enabled_stage_count = 0;
475+
u32 first_enabled_stage = std::numeric_limits<u32>::max();
475476
u32 last_enabled_stage = std::numeric_limits<u32>::max();
476477
for (u32 i = 0; i < stage_count; i++)
477478
{
@@ -503,7 +504,10 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
503504
shader->SetFinalStage(false);
504505
enabled_stage_count += BoolToUInt32(stage_enabled);
505506
if (stage_enabled)
507+
{
508+
first_enabled_stage = std::min(first_enabled_stage, i);
506509
last_enabled_stage = i;
510+
}
507511

508512
m_stages.push_back(std::move(shader));
509513
}
@@ -532,14 +536,16 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
532536

533537
// must be down here, because we need to compile first, triggered by CheckTargets()
534538
for (std::unique_ptr<Shader>& shader : m_stages)
535-
{
536539
m_wants_depth_buffer |= (shader->IsEnabled() && shader->WantsDepthBuffer());
537-
m_wants_unscaled_input |= (shader->IsEnabled() && shader->WantsUnscaledInput());
538-
}
539540
m_needs_depth_buffer = m_enabled && m_wants_depth_buffer;
540541
if (m_wants_depth_buffer)
541542
DEV_COLOR_LOG(StrongOrange, "Depth buffer is needed.");
542543

544+
m_wants_unscaled_input =
545+
(first_enabled_stage < m_stages.size() && m_stages[first_enabled_stage]->WantsUnscaledInput());
546+
if (m_wants_unscaled_input)
547+
DEV_COLOR_LOG(StrongOrange, "Shader chain wants unscaled input.");
548+
543549
// can't close/redraw with settings lock held because big picture
544550
settings_lock.unlock();
545551
progress.Close();
@@ -572,6 +578,7 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
572578
const u32 prev_enabled_stage_count = static_cast<u32>(std::ranges::count_if(
573579
m_stages, [](const std::unique_ptr<Shader>& shader) { return (shader && shader->IsEnabled()); }));
574580
u32 enabled_stage_count = 0;
581+
u32 first_enabled_stage = std::numeric_limits<u32>::max();
575582
u32 last_enabled_stage = 0;
576583
for (u32 i = 0; i < stage_count; i++)
577584
{
@@ -615,7 +622,10 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
615622
m_stages[i]->SetFinalStage(false);
616623
enabled_stage_count += BoolToUInt32(stage_enabled);
617624
if (stage_enabled)
625+
{
626+
first_enabled_stage = std::min(first_enabled_stage, i);
618627
last_enabled_stage = i;
628+
}
619629
}
620630

621631
if (prev_format != GPUTextureFormat::Unknown)
@@ -647,15 +657,16 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
647657

648658
// must be down here, because we need to compile first, triggered by CheckTargets()
649659
for (std::unique_ptr<Shader>& shader : m_stages)
650-
{
651660
m_wants_depth_buffer |= (shader->IsEnabled() && shader->WantsDepthBuffer());
652-
m_wants_unscaled_input |= (shader->IsEnabled() && shader->WantsUnscaledInput());
653-
}
654-
655661
m_needs_depth_buffer = m_enabled && m_wants_depth_buffer;
656662
if (m_wants_depth_buffer)
657663
DEV_LOG("Depth buffer is needed.");
658664

665+
m_wants_unscaled_input =
666+
(first_enabled_stage < m_stages.size() && m_stages[first_enabled_stage]->WantsUnscaledInput());
667+
if (m_wants_unscaled_input)
668+
DEV_COLOR_LOG(StrongOrange, "Shader chain wants unscaled input.");
669+
659670
// can't close/redraw with settings lock held because big picture
660671
settings_lock.unlock();
661672
progress.Close();
@@ -727,6 +738,9 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
727738
m_viewport_height = viewport_height;
728739

729740
// shortcut if only the source size changed
741+
u32 first_enabled_stage = std::numeric_limits<u32>::max();
742+
m_wants_depth_buffer = false;
743+
m_wants_unscaled_input = false;
730744
if (m_target_width != target_width || m_target_height != target_height || m_target_format != target_format)
731745
{
732746
if (!progress)
@@ -735,9 +749,6 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
735749
progress->SetProgressRange(static_cast<u32>(m_stages.size()));
736750
progress->SetProgressValue(0);
737751

738-
m_wants_depth_buffer = false;
739-
m_wants_unscaled_input = false;
740-
741752
for (size_t i = 0; i < m_stages.size(); i++)
742753
{
743754
Shader* const shader = m_stages[i].get();
@@ -764,8 +775,8 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
764775
if (!shader->IsEnabled())
765776
continue;
766777

778+
first_enabled_stage = std::min(first_enabled_stage, static_cast<u32>(i));
767779
m_wants_depth_buffer |= shader->WantsDepthBuffer();
768-
m_wants_unscaled_input |= shader->WantsUnscaledInput();
769780

770781
// First shader outputs at target size, so the input is now target size.
771782
source_width = target_width;
@@ -778,8 +789,10 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
778789
{
779790
m_wants_depth_buffer = false;
780791

781-
for (std::unique_ptr<Shader>& shader : m_stages)
792+
for (size_t i = 0; i < m_stages.size(); i++)
782793
{
794+
const std::unique_ptr<Shader>& shader = m_stages[i];
795+
783796
// Don't allocate targets until first enabled shader.
784797
if (!shader->IsEnabled())
785798
continue;
@@ -798,7 +811,8 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
798811
return false;
799812
}
800813

801-
m_wants_depth_buffer |= shader->IsEnabled() && shader->WantsDepthBuffer();
814+
first_enabled_stage = std::min(first_enabled_stage, static_cast<u32>(i));
815+
m_wants_depth_buffer |= shader->WantsDepthBuffer();
802816

803817
// First shader outputs at target size, so the input is now target size.
804818
source_width = target_width;
@@ -808,6 +822,9 @@ bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GP
808822
}
809823
}
810824

825+
m_wants_unscaled_input =
826+
(first_enabled_stage < m_stages.size() && m_stages[first_enabled_stage]->WantsUnscaledInput());
827+
811828
m_target_width = target_width;
812829
m_target_height = target_height;
813830
m_target_format = target_format;

0 commit comments

Comments
 (0)