mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-14 02:14:35 +00:00
PostProcessing: Ensure input buffer matches present format
This commit is contained in:
@@ -4072,9 +4072,9 @@ void GPU_HW::UpdateDisplay(const GPUBackendUpdateDisplayCommand* cmd)
|
||||
|
||||
// Apply internal postfx if enabled.
|
||||
if (m_internal_postfx && m_internal_postfx->IsActive() &&
|
||||
m_internal_postfx->CheckTargets(m_vram_texture->GetFormat(), scaled_display_width, scaled_display_height,
|
||||
m_vram_texture->GetFormat(), scaled_display_width, scaled_display_height,
|
||||
scaled_display_width, scaled_display_height))
|
||||
m_internal_postfx->CheckTargets(scaled_display_width, scaled_display_height, m_vram_texture->GetFormat(),
|
||||
scaled_display_width, scaled_display_height, scaled_display_width,
|
||||
scaled_display_height))
|
||||
{
|
||||
GPUTexture* const postfx_output = m_internal_postfx->GetOutputTexture();
|
||||
m_internal_postfx->Apply(
|
||||
|
||||
@@ -508,10 +508,9 @@ GPUDevice::PresentResult GPUPresenter::RenderDisplay(GPUTexture* target, const G
|
||||
}
|
||||
|
||||
// This could fail if we run out of VRAM.
|
||||
if ((postfx_active = m_display_postfx->CheckTargets(
|
||||
m_display_texture ? m_display_texture->GetFormat() : GPUTexture::Format::Unknown, postfx_source_size.x,
|
||||
postfx_source_size.y, m_present_format, postfx_target_size.x, postfx_target_size.y, postfx_viewport_size.x,
|
||||
postfx_viewport_size.y)))
|
||||
if ((postfx_active = m_display_postfx->CheckTargets(postfx_source_size.x, postfx_source_size.y, m_present_format,
|
||||
postfx_target_size.x, postfx_target_size.y,
|
||||
postfx_viewport_size.x, postfx_viewport_size.y)))
|
||||
{
|
||||
GL_INS("Post-processing is ACTIVE this frame");
|
||||
GL_INS_FMT("Post-processing source size: {}x{}", postfx_source_size.x, postfx_source_size.y);
|
||||
@@ -895,11 +894,11 @@ GPUTexture* GPUPresenter::GetDisplayPostProcessInputTexture(const GSVector4i dra
|
||||
{
|
||||
postfx_input = m_display_texture;
|
||||
|
||||
// OpenGL needs to flip the correct way around. If the source is exactly the same size without
|
||||
// any correction, we can pass it through to the chain directly.
|
||||
// OpenGL needs to flip the correct way around. If the source is exactly the same size without any correction we can
|
||||
// pass it through to the chain directly. Except if the swap chain isn't using BGRA8, then we need to blit too.
|
||||
if (g_gpu_device->UsesLowerLeftOrigin() || rotation != DisplayRotation::Normal || m_display_origin_left != 0 ||
|
||||
m_display_origin_top != 0 || m_display_vram_width != m_display_texture_view_width ||
|
||||
m_display_vram_height != m_display_texture_view_height)
|
||||
m_display_vram_height != m_display_texture_view_height || m_display_texture->GetFormat() != m_present_format)
|
||||
{
|
||||
GL_SCOPE_FMT("Pre-process postfx source");
|
||||
|
||||
|
||||
@@ -485,9 +485,8 @@ void PostProcessing::Chain::LoadStages(std::unique_lock<std::mutex>& settings_lo
|
||||
if (preload_swap_chain_size && g_gpu_device && g_gpu_device->HasMainSwapChain())
|
||||
{
|
||||
const GPUSwapChain* swap_chain = g_gpu_device->GetMainSwapChain();
|
||||
CheckTargets(swap_chain->GetFormat(), swap_chain->GetWidth(), swap_chain->GetHeight(), swap_chain->GetFormat(),
|
||||
swap_chain->GetWidth(), swap_chain->GetHeight(), swap_chain->GetWidth(), swap_chain->GetHeight(),
|
||||
&progress);
|
||||
CheckTargets(swap_chain->GetWidth(), swap_chain->GetHeight(), swap_chain->GetFormat(), swap_chain->GetWidth(),
|
||||
swap_chain->GetHeight(), swap_chain->GetWidth(), swap_chain->GetHeight(), &progress);
|
||||
}
|
||||
|
||||
// must be down here, because we need to compile first, triggered by CheckTargets()
|
||||
@@ -568,8 +567,8 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
|
||||
|
||||
if (prev_format != GPUTexture::Format::Unknown)
|
||||
{
|
||||
CheckTargets(prev_format, m_target_width, m_target_height, m_source_format, m_source_width, m_source_height,
|
||||
m_viewport_width, m_viewport_height, &progress);
|
||||
CheckTargets(m_target_width, m_target_height, prev_format, m_source_width, m_source_height, m_viewport_width,
|
||||
m_viewport_height, &progress);
|
||||
}
|
||||
|
||||
if (stage_count > 0)
|
||||
@@ -612,15 +611,13 @@ void PostProcessing::Chain::Toggle()
|
||||
s_start_time = Timer::GetCurrentValue();
|
||||
}
|
||||
|
||||
bool PostProcessing::Chain::CheckTargets(GPUTexture::Format source_format, u32 source_width, u32 source_height,
|
||||
GPUTexture::Format target_format, u32 target_width, u32 target_height,
|
||||
u32 viewport_width, u32 viewport_height,
|
||||
bool PostProcessing::Chain::CheckTargets(u32 source_width, u32 source_height, GPUTexture::Format target_format,
|
||||
u32 target_width, u32 target_height, u32 viewport_width, u32 viewport_height,
|
||||
ProgressCallback* progress /* = nullptr */)
|
||||
{
|
||||
// might not have a source, this is okay
|
||||
if (!m_wants_unscaled_input || source_width == 0 || source_height == 0)
|
||||
{
|
||||
source_format = target_format;
|
||||
source_width = target_width;
|
||||
source_height = target_height;
|
||||
viewport_width = target_width;
|
||||
@@ -629,7 +626,7 @@ bool PostProcessing::Chain::CheckTargets(GPUTexture::Format source_format, u32 s
|
||||
|
||||
if (m_target_width == target_width && m_target_height == target_height && m_source_width == source_width &&
|
||||
m_source_height == source_height && m_viewport_width == viewport_width && m_viewport_height == viewport_height &&
|
||||
m_source_format == source_format && m_target_format == target_format)
|
||||
m_target_format == target_format)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -637,7 +634,7 @@ bool PostProcessing::Chain::CheckTargets(GPUTexture::Format source_format, u32 s
|
||||
Error error;
|
||||
|
||||
if (!g_gpu_device->ResizeTexture(&m_input_texture, source_width, source_height, GPUTexture::Type::RenderTarget,
|
||||
source_format, GPUTexture::Flags::None, false, &error) ||
|
||||
target_format, GPUTexture::Flags::None, false, &error) ||
|
||||
!g_gpu_device->ResizeTexture(&m_output_texture, target_width, target_height, GPUTexture::Type::RenderTarget,
|
||||
target_format, GPUTexture::Flags::None, false, &error))
|
||||
{
|
||||
@@ -649,7 +646,6 @@ bool PostProcessing::Chain::CheckTargets(GPUTexture::Format source_format, u32 s
|
||||
// we change source after the first pass, so save the original values here
|
||||
m_source_width = source_width;
|
||||
m_source_height = source_height;
|
||||
m_source_format = source_format;
|
||||
m_viewport_width = viewport_width;
|
||||
m_viewport_height = viewport_height;
|
||||
|
||||
|
||||
@@ -136,9 +136,8 @@ public:
|
||||
/// Temporarily toggles post-processing on/off.
|
||||
void Toggle();
|
||||
|
||||
bool CheckTargets(GPUTexture::Format source_format, u32 source_width, u32 source_height,
|
||||
GPUTexture::Format target_format, u32 target_width, u32 target_height, u32 viewport_width,
|
||||
u32 viewport_height, ProgressCallback* progress = nullptr);
|
||||
bool CheckTargets(u32 source_width, u32 source_height, GPUTexture::Format target_format, u32 target_width,
|
||||
u32 target_height, u32 viewport_width, u32 viewport_height, ProgressCallback* progress = nullptr);
|
||||
|
||||
GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
|
||||
const GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width,
|
||||
@@ -156,7 +155,6 @@ private:
|
||||
u32 m_target_height = 0;
|
||||
u32 m_viewport_width = 0;
|
||||
u32 m_viewport_height = 0;
|
||||
GPUTexture::Format m_source_format = GPUTexture::Format::Unknown;
|
||||
GPUTexture::Format m_target_format = GPUTexture::Format::Unknown;
|
||||
bool m_enabled = false;
|
||||
bool m_wants_depth_buffer = false;
|
||||
|
||||
Reference in New Issue
Block a user