2019-02-15 01:59:50 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
2019-12-22 18:40:40 +00:00
|
|
|
|
2021-12-09 22:00:08 +00:00
|
|
|
#include <fmt/format.h>
|
2019-02-15 01:59:50 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-06-29 11:05:30 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2019-07-23 19:19:13 +00:00
|
|
|
#include "Core/Config/GraphicsSettings.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "VideoCommon/AbstractFramebuffer.h"
|
|
|
|
#include "VideoCommon/AbstractPipeline.h"
|
|
|
|
#include "VideoCommon/AbstractShader.h"
|
|
|
|
#include "VideoCommon/AbstractStagingTexture.h"
|
|
|
|
#include "VideoCommon/AbstractTexture.h"
|
|
|
|
#include "VideoCommon/DriverDetails.h"
|
2019-12-22 18:40:40 +00:00
|
|
|
#include "VideoCommon/FramebufferShaderGen.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2019-12-22 18:40:40 +00:00
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
|
|
|
// Maximum number of pixels poked in one batch * 6
|
|
|
|
constexpr size_t MAX_POKE_VERTICES = 32768;
|
|
|
|
|
|
|
|
std::unique_ptr<FramebufferManager> g_framebuffer_manager;
|
|
|
|
|
|
|
|
FramebufferManager::FramebufferManager() = default;
|
|
|
|
|
|
|
|
FramebufferManager::~FramebufferManager()
|
|
|
|
{
|
|
|
|
DestroyClearPipelines();
|
|
|
|
DestroyPokePipelines();
|
|
|
|
DestroyConversionPipelines();
|
|
|
|
DestroyReadbackPipelines();
|
|
|
|
DestroyReadbackFramebuffer();
|
|
|
|
DestroyEFBFramebuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::Initialize()
|
|
|
|
{
|
|
|
|
if (!CreateEFBFramebuffer())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to create EFB framebuffer");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_cache_tile_size = static_cast<u32>(std::max(g_ActiveConfig.iEFBAccessTileSize, 0));
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!CreateReadbackFramebuffer())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to create EFB readback framebuffer");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CompileReadbackPipelines())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to compile EFB readback pipelines");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CompileConversionPipelines())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to compile EFB conversion pipelines");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CompileClearPipelines())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to compile EFB clear pipelines");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CompilePokePipelines())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to compile EFB poke pipelines");
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::RecreateEFBFramebuffer()
|
|
|
|
{
|
|
|
|
FlushEFBPokes();
|
2019-03-02 07:05:38 +00:00
|
|
|
InvalidatePeekCache(true);
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
DestroyReadbackFramebuffer();
|
|
|
|
DestroyEFBFramebuffer();
|
|
|
|
if (!CreateEFBFramebuffer() || !CreateReadbackFramebuffer())
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to recreate EFB framebuffer");
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::RecompileShaders()
|
|
|
|
{
|
|
|
|
DestroyPokePipelines();
|
|
|
|
DestroyClearPipelines();
|
|
|
|
DestroyConversionPipelines();
|
|
|
|
DestroyReadbackPipelines();
|
|
|
|
if (!CompileReadbackPipelines() || !CompileConversionPipelines() || !CompileClearPipelines() ||
|
|
|
|
!CompilePokePipelines())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to recompile EFB pipelines");
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractTextureFormat FramebufferManager::GetEFBColorFormat()
|
|
|
|
{
|
|
|
|
// The EFB can be set to different pixel formats by the game through the
|
|
|
|
// BPMEM_ZCOMPARE register (which should probably have a different name).
|
|
|
|
// They are:
|
|
|
|
// - 24-bit RGB (8-bit components) with 24-bit Z
|
|
|
|
// - 24-bit RGBA (6-bit components) with 24-bit Z
|
|
|
|
// - Multisampled 16-bit RGB (5-6-5 format) with 16-bit Z
|
|
|
|
// We only use one EFB format here: 32-bit ARGB with 32-bit Z.
|
|
|
|
// Multisampling depends on user settings.
|
|
|
|
// The distinction becomes important for certain operations, i.e. the
|
|
|
|
// alpha channel should be ignored if the EFB does not have one.
|
|
|
|
return AbstractTextureFormat::RGBA8;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractTextureFormat FramebufferManager::GetEFBDepthFormat()
|
|
|
|
{
|
|
|
|
// 32-bit depth clears are broken in the Adreno Vulkan driver, and have no effect.
|
|
|
|
// To work around this, we use a D24_S8 buffer instead, which results in a loss of accuracy.
|
|
|
|
// We still resolve this to a R32F texture, as there is no 24-bit format.
|
|
|
|
if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_D32F_CLEAR))
|
|
|
|
return AbstractTextureFormat::D24_S8;
|
|
|
|
else
|
|
|
|
return AbstractTextureFormat::D32F;
|
|
|
|
}
|
|
|
|
|
2019-07-31 05:33:27 +00:00
|
|
|
AbstractTextureFormat FramebufferManager::GetEFBDepthCopyFormat()
|
|
|
|
{
|
|
|
|
return AbstractTextureFormat::R32F;
|
|
|
|
}
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
static u32 CalculateEFBLayers()
|
|
|
|
{
|
|
|
|
return (g_ActiveConfig.stereo_mode != StereoMode::Off) ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureConfig FramebufferManager::GetEFBColorTextureConfig()
|
|
|
|
{
|
|
|
|
return TextureConfig(g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(), 1,
|
|
|
|
CalculateEFBLayers(), g_ActiveConfig.iMultisamples, GetEFBColorFormat(),
|
|
|
|
AbstractTextureFlag_RenderTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureConfig FramebufferManager::GetEFBDepthTextureConfig()
|
|
|
|
{
|
|
|
|
return TextureConfig(g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(), 1,
|
|
|
|
CalculateEFBLayers(), g_ActiveConfig.iMultisamples, GetEFBDepthFormat(),
|
|
|
|
AbstractTextureFlag_RenderTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
FramebufferState FramebufferManager::GetEFBFramebufferState() const
|
|
|
|
{
|
|
|
|
FramebufferState ret = {};
|
|
|
|
ret.color_texture_format = m_efb_color_texture->GetFormat();
|
|
|
|
ret.depth_texture_format = m_efb_depth_texture->GetFormat();
|
|
|
|
ret.per_sample_shading = IsEFBMultisampled() && g_ActiveConfig.bSSAA;
|
|
|
|
ret.samples = m_efb_color_texture->GetSamples();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::CreateEFBFramebuffer()
|
|
|
|
{
|
|
|
|
const TextureConfig efb_color_texture_config = GetEFBColorTextureConfig();
|
|
|
|
const TextureConfig efb_depth_texture_config = GetEFBDepthTextureConfig();
|
|
|
|
|
|
|
|
// We need a second texture to swap with for changing pixel formats
|
2021-12-09 22:00:08 +00:00
|
|
|
m_efb_color_texture = g_renderer->CreateTexture(efb_color_texture_config, "EFB color texture");
|
|
|
|
m_efb_depth_texture = g_renderer->CreateTexture(efb_depth_texture_config, "EFB depth texture");
|
|
|
|
m_efb_convert_color_texture =
|
|
|
|
g_renderer->CreateTexture(efb_color_texture_config, "EFB convert color texture");
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!m_efb_color_texture || !m_efb_depth_texture || !m_efb_convert_color_texture)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_efb_framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_color_texture.get(), m_efb_depth_texture.get());
|
|
|
|
m_efb_convert_framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_convert_color_texture.get(), m_efb_depth_texture.get());
|
|
|
|
if (!m_efb_framebuffer || !m_efb_convert_framebuffer)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Create resolved textures if MSAA is on
|
|
|
|
if (g_ActiveConfig.MultisamplingEnabled())
|
|
|
|
{
|
2022-06-21 07:07:35 +00:00
|
|
|
u32 flags = 0;
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsPartialMultisampleResolve)
|
|
|
|
flags |= AbstractTextureFlag_RenderTarget;
|
2019-02-15 01:59:50 +00:00
|
|
|
m_efb_resolve_color_texture = g_renderer->CreateTexture(
|
|
|
|
TextureConfig(efb_color_texture_config.width, efb_color_texture_config.height, 1,
|
2022-06-21 07:07:35 +00:00
|
|
|
efb_color_texture_config.layers, 1, efb_color_texture_config.format, flags),
|
2021-12-09 22:00:08 +00:00
|
|
|
"EFB color resolve texture");
|
2020-05-24 05:33:02 +00:00
|
|
|
if (!m_efb_resolve_color_texture)
|
|
|
|
return false;
|
2022-06-21 07:07:35 +00:00
|
|
|
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsPartialMultisampleResolve)
|
|
|
|
{
|
|
|
|
m_efb_color_resolve_framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_resolve_color_texture.get(), nullptr);
|
|
|
|
if (!m_efb_color_resolve_framebuffer)
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-24 05:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We also need one to convert the D24S8 to R32F if that is being used (Adreno).
|
|
|
|
if (g_ActiveConfig.MultisamplingEnabled() || GetEFBDepthFormat() != AbstractTextureFormat::R32F)
|
|
|
|
{
|
2019-07-31 05:33:27 +00:00
|
|
|
m_efb_depth_resolve_texture = g_renderer->CreateTexture(
|
|
|
|
TextureConfig(efb_depth_texture_config.width, efb_depth_texture_config.height, 1,
|
|
|
|
efb_depth_texture_config.layers, 1, GetEFBDepthCopyFormat(),
|
2021-12-09 22:00:08 +00:00
|
|
|
AbstractTextureFlag_RenderTarget),
|
|
|
|
"EFB depth resolve texture");
|
2020-05-24 05:33:02 +00:00
|
|
|
if (!m_efb_depth_resolve_texture)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
m_efb_depth_resolve_framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_depth_resolve_texture.get(), nullptr);
|
|
|
|
if (!m_efb_depth_resolve_framebuffer)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the renderable textures out.
|
|
|
|
g_renderer->SetAndClearFramebuffer(
|
|
|
|
m_efb_framebuffer.get(), {{0.0f, 0.0f, 0.0f, 0.0f}},
|
|
|
|
g_ActiveConfig.backend_info.bSupportsReversedDepthRange ? 1.0f : 0.0f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyEFBFramebuffer()
|
|
|
|
{
|
|
|
|
m_efb_framebuffer.reset();
|
|
|
|
m_efb_convert_framebuffer.reset();
|
|
|
|
m_efb_color_texture.reset();
|
|
|
|
m_efb_convert_color_texture.reset();
|
|
|
|
m_efb_depth_texture.reset();
|
|
|
|
m_efb_resolve_color_texture.reset();
|
|
|
|
m_efb_depth_resolve_framebuffer.reset();
|
|
|
|
m_efb_depth_resolve_texture.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::BindEFBFramebuffer()
|
|
|
|
{
|
|
|
|
g_renderer->SetFramebuffer(m_efb_framebuffer.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractTexture* FramebufferManager::ResolveEFBColorTexture(const MathUtil::Rectangle<int>& region)
|
|
|
|
{
|
|
|
|
// Return the normal EFB texture if multisampling is off.
|
|
|
|
if (!IsEFBMultisampled())
|
|
|
|
return m_efb_color_texture.get();
|
|
|
|
|
|
|
|
// It's not valid to resolve an out-of-range rectangle.
|
|
|
|
MathUtil::Rectangle<int> clamped_region = region;
|
|
|
|
clamped_region.ClampUL(0, 0, GetEFBWidth(), GetEFBHeight());
|
|
|
|
|
|
|
|
// Resolve to our already-created texture.
|
2022-06-21 07:07:35 +00:00
|
|
|
if (g_ActiveConfig.backend_info.bSupportsPartialMultisampleResolve)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2022-06-21 07:07:35 +00:00
|
|
|
for (u32 layer = 0; layer < GetEFBLayers(); layer++)
|
|
|
|
{
|
|
|
|
m_efb_resolve_color_texture->ResolveFromTexture(m_efb_color_texture.get(), clamped_region,
|
|
|
|
layer, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_efb_color_texture->FinishedRendering();
|
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
g_renderer->SetAndDiscardFramebuffer(m_efb_color_resolve_framebuffer.get());
|
|
|
|
g_renderer->SetPipeline(m_efb_color_resolve_pipeline.get());
|
|
|
|
g_renderer->SetTexture(0, m_efb_color_texture.get());
|
|
|
|
g_renderer->SetSamplerState(0, RenderState::GetPointSamplerState());
|
|
|
|
g_renderer->SetViewportAndScissor(clamped_region);
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
m_efb_resolve_color_texture->FinishedRendering();
|
|
|
|
g_renderer->EndUtilityDrawing();
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
m_efb_resolve_color_texture->FinishedRendering();
|
|
|
|
return m_efb_resolve_color_texture.get();
|
|
|
|
}
|
|
|
|
|
2020-05-24 05:33:02 +00:00
|
|
|
AbstractTexture* FramebufferManager::ResolveEFBDepthTexture(const MathUtil::Rectangle<int>& region,
|
|
|
|
bool force_r32f)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2020-09-24 00:25:48 +00:00
|
|
|
if (!IsEFBMultisampled() &&
|
|
|
|
(!force_r32f || m_efb_depth_texture->GetFormat() == AbstractTextureFormat::D32F))
|
2020-05-24 05:33:02 +00:00
|
|
|
{
|
2019-02-15 01:59:50 +00:00
|
|
|
return m_efb_depth_texture.get();
|
2020-05-24 05:33:02 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
// It's not valid to resolve an out-of-range rectangle.
|
|
|
|
MathUtil::Rectangle<int> clamped_region = region;
|
|
|
|
clamped_region.ClampUL(0, 0, GetEFBWidth(), GetEFBHeight());
|
|
|
|
|
|
|
|
m_efb_depth_texture->FinishedRendering();
|
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
g_renderer->SetAndDiscardFramebuffer(m_efb_depth_resolve_framebuffer.get());
|
2020-09-24 00:25:48 +00:00
|
|
|
g_renderer->SetPipeline(IsEFBMultisampled() ? m_efb_depth_resolve_pipeline.get() :
|
|
|
|
m_efb_depth_cache.copy_pipeline.get());
|
2019-02-15 01:59:50 +00:00
|
|
|
g_renderer->SetTexture(0, m_efb_depth_texture.get());
|
|
|
|
g_renderer->SetSamplerState(0, RenderState::GetPointSamplerState());
|
|
|
|
g_renderer->SetViewportAndScissor(clamped_region);
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
m_efb_depth_resolve_texture->FinishedRendering();
|
|
|
|
g_renderer->EndUtilityDrawing();
|
|
|
|
|
|
|
|
return m_efb_depth_resolve_texture.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::ReinterpretPixelData(EFBReinterpretType convtype)
|
|
|
|
{
|
|
|
|
if (!m_format_conversion_pipelines[static_cast<u32>(convtype)])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Draw to the secondary framebuffer.
|
2019-03-16 13:40:07 +00:00
|
|
|
// We don't discard here because discarding the framebuffer also throws away the depth
|
|
|
|
// buffer, which we want to preserve. If we find this to be hindering performance in the
|
|
|
|
// future (e.g. on mobile/tilers), it may be worth discarding only the color buffer.
|
2019-02-15 01:59:50 +00:00
|
|
|
m_efb_color_texture->FinishedRendering();
|
|
|
|
g_renderer->BeginUtilityDrawing();
|
2019-03-16 13:40:07 +00:00
|
|
|
g_renderer->SetFramebuffer(m_efb_convert_framebuffer.get());
|
2019-02-15 01:59:50 +00:00
|
|
|
g_renderer->SetViewportAndScissor(m_efb_framebuffer->GetRect());
|
|
|
|
g_renderer->SetPipeline(m_format_conversion_pipelines[static_cast<u32>(convtype)].get());
|
|
|
|
g_renderer->SetTexture(0, m_efb_color_texture.get());
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
|
|
|
|
// And swap the framebuffers around, so we do new drawing to the converted framebuffer.
|
|
|
|
std::swap(m_efb_color_texture, m_efb_convert_color_texture);
|
|
|
|
std::swap(m_efb_framebuffer, m_efb_convert_framebuffer);
|
|
|
|
g_renderer->EndUtilityDrawing();
|
2019-03-02 07:05:38 +00:00
|
|
|
InvalidatePeekCache(true);
|
2019-02-15 01:59:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::CompileConversionPipelines()
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < NUM_EFB_REINTERPRET_TYPES; i++)
|
|
|
|
{
|
2021-12-09 22:00:08 +00:00
|
|
|
EFBReinterpretType convtype = static_cast<EFBReinterpretType>(i);
|
2019-02-15 01:59:50 +00:00
|
|
|
std::unique_ptr<AbstractShader> pixel_shader = g_renderer->CreateShaderFromSource(
|
2021-12-09 22:00:08 +00:00
|
|
|
ShaderStage::Pixel,
|
|
|
|
FramebufferShaderGen::GenerateFormatConversionShader(convtype, GetEFBSamples()),
|
|
|
|
fmt::format("Framebuffer conversion pixel shader {}", convtype));
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!pixel_shader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractPipelineConfig config = {};
|
|
|
|
config.vertex_shader = g_shader_cache->GetScreenQuadVertexShader();
|
|
|
|
config.geometry_shader = IsEFBStereo() ? g_shader_cache->GetTexcoordGeometryShader() : nullptr;
|
|
|
|
config.pixel_shader = pixel_shader.get();
|
|
|
|
config.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles);
|
|
|
|
config.depth_state = RenderState::GetNoDepthTestingDepthState();
|
|
|
|
config.blending_state = RenderState::GetNoBlendingBlendState();
|
|
|
|
config.framebuffer_state = GetEFBFramebufferState();
|
|
|
|
config.usage = AbstractPipelineUsage::Utility;
|
|
|
|
m_format_conversion_pipelines[i] = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_format_conversion_pipelines[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyConversionPipelines()
|
|
|
|
{
|
|
|
|
for (auto& pipeline : m_format_conversion_pipelines)
|
|
|
|
pipeline.reset();
|
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
bool FramebufferManager::IsUsingTiledEFBCache() const
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
return m_efb_cache_tile_size > 0;
|
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
bool FramebufferManager::IsEFBCacheTilePresent(bool depth, u32 x, u32 y, u32* tile_index) const
|
|
|
|
{
|
|
|
|
const EFBCacheData& data = depth ? m_efb_depth_cache : m_efb_color_cache;
|
|
|
|
if (m_efb_cache_tile_size == 0)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
*tile_index = 0;
|
|
|
|
return data.valid;
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
*tile_index =
|
|
|
|
((y / m_efb_cache_tile_size) * m_efb_cache_tiles_wide) + (x / m_efb_cache_tile_size);
|
2022-09-26 21:41:56 +00:00
|
|
|
return data.valid && data.tiles[*tile_index].present;
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
2019-03-02 05:11:47 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
MathUtil::Rectangle<int> FramebufferManager::GetEFBCacheTileRect(u32 tile_index) const
|
|
|
|
{
|
|
|
|
if (m_efb_cache_tile_size == 0)
|
|
|
|
return MathUtil::Rectangle<int>(0, 0, EFB_WIDTH, EFB_HEIGHT);
|
|
|
|
|
|
|
|
const u32 tile_y = tile_index / m_efb_cache_tiles_wide;
|
|
|
|
const u32 tile_x = tile_index % m_efb_cache_tiles_wide;
|
|
|
|
const u32 start_y = tile_y * m_efb_cache_tile_size;
|
|
|
|
const u32 start_x = tile_x * m_efb_cache_tile_size;
|
|
|
|
return MathUtil::Rectangle<int>(
|
|
|
|
start_x, start_y, std::min(start_x + m_efb_cache_tile_size, static_cast<u32>(EFB_WIDTH)),
|
|
|
|
std::min(start_y + m_efb_cache_tile_size, static_cast<u32>(EFB_HEIGHT)));
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
u32 FramebufferManager::PeekEFBColor(u32 x, u32 y)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
// The y coordinate here assumes upper-left origin, but the readback texture is lower-left in GL.
|
|
|
|
if (g_ActiveConfig.backend_info.bUsesLowerLeftOrigin)
|
|
|
|
y = EFB_HEIGHT - 1 - y;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
u32 tile_index;
|
|
|
|
if (!IsEFBCacheTilePresent(false, x, y, &tile_index))
|
|
|
|
PopulateEFBCache(false, tile_index);
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2022-09-26 21:41:56 +00:00
|
|
|
if (IsUsingTiledEFBCache())
|
|
|
|
m_efb_color_cache.tiles[tile_index].frame_access_mask |= 1;
|
|
|
|
|
|
|
|
if (m_efb_color_cache.needs_flush)
|
|
|
|
{
|
|
|
|
m_efb_color_cache.readback_texture->Flush();
|
|
|
|
m_efb_color_cache.needs_flush = false;
|
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
u32 value;
|
|
|
|
m_efb_color_cache.readback_texture->ReadTexel(x, y, &value);
|
|
|
|
return value;
|
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
float FramebufferManager::PeekEFBDepth(u32 x, u32 y)
|
|
|
|
{
|
|
|
|
// The y coordinate here assumes upper-left origin, but the readback texture is lower-left in GL.
|
|
|
|
if (g_ActiveConfig.backend_info.bUsesLowerLeftOrigin)
|
|
|
|
y = EFB_HEIGHT - 1 - y;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
u32 tile_index;
|
|
|
|
if (!IsEFBCacheTilePresent(true, x, y, &tile_index))
|
|
|
|
PopulateEFBCache(true, tile_index);
|
|
|
|
|
2022-09-26 21:41:56 +00:00
|
|
|
if (IsUsingTiledEFBCache())
|
|
|
|
m_efb_depth_cache.tiles[tile_index].frame_access_mask |= 1;
|
|
|
|
|
|
|
|
if (m_efb_depth_cache.needs_flush)
|
|
|
|
{
|
|
|
|
m_efb_depth_cache.readback_texture->Flush();
|
|
|
|
m_efb_depth_cache.needs_flush = false;
|
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
float value;
|
|
|
|
m_efb_depth_cache.readback_texture->ReadTexel(x, y, &value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::SetEFBCacheTileSize(u32 size)
|
|
|
|
{
|
|
|
|
if (m_efb_cache_tile_size == size)
|
|
|
|
return;
|
|
|
|
|
2019-03-02 07:05:38 +00:00
|
|
|
InvalidatePeekCache(true);
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_cache_tile_size = size;
|
|
|
|
DestroyReadbackFramebuffer();
|
|
|
|
if (!CreateReadbackFramebuffer())
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("Failed to create EFB readback framebuffers");
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 21:41:56 +00:00
|
|
|
void FramebufferManager::RefreshPeekCache()
|
|
|
|
{
|
|
|
|
if (m_efb_color_cache.valid && m_efb_depth_cache.valid)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool flush_command_buffer = false;
|
|
|
|
|
|
|
|
if (IsUsingTiledEFBCache())
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < m_efb_color_cache.tiles.size(); i++)
|
|
|
|
{
|
|
|
|
if (m_efb_color_cache.tiles[i].frame_access_mask != 0 &&
|
|
|
|
(!m_efb_color_cache.valid || !m_efb_color_cache.tiles[i].present))
|
|
|
|
{
|
|
|
|
PopulateEFBCache(false, i, true);
|
|
|
|
flush_command_buffer = true;
|
|
|
|
}
|
|
|
|
if (m_efb_depth_cache.tiles[i].frame_access_mask != 0 &&
|
|
|
|
(!m_efb_depth_cache.valid || !m_efb_depth_cache.tiles[i].present))
|
|
|
|
{
|
|
|
|
PopulateEFBCache(true, i, true);
|
|
|
|
flush_command_buffer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!m_efb_color_cache.valid)
|
|
|
|
{
|
|
|
|
PopulateEFBCache(false, 0, true);
|
|
|
|
flush_command_buffer = true;
|
|
|
|
}
|
|
|
|
if (!m_efb_depth_cache.valid)
|
|
|
|
{
|
|
|
|
PopulateEFBCache(true, 0, true);
|
|
|
|
flush_command_buffer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flush_command_buffer)
|
|
|
|
{
|
|
|
|
g_renderer->Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 07:05:38 +00:00
|
|
|
void FramebufferManager::InvalidatePeekCache(bool forced)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2019-03-02 07:05:38 +00:00
|
|
|
if (forced || m_efb_color_cache.out_of_date)
|
2019-03-02 05:11:47 +00:00
|
|
|
{
|
2019-03-24 05:02:08 +00:00
|
|
|
if (m_efb_color_cache.valid)
|
2022-09-26 21:41:56 +00:00
|
|
|
{
|
|
|
|
for (u32 i = 0; i < m_efb_color_cache.tiles.size(); i++)
|
|
|
|
{
|
|
|
|
m_efb_color_cache.tiles[i].present = false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 05:02:08 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_color_cache.valid = false;
|
2019-03-02 07:05:38 +00:00
|
|
|
m_efb_color_cache.out_of_date = false;
|
2022-09-26 21:41:56 +00:00
|
|
|
m_efb_color_cache.needs_flush = true;
|
2019-03-02 05:11:47 +00:00
|
|
|
}
|
2019-03-02 07:05:38 +00:00
|
|
|
if (forced || m_efb_depth_cache.out_of_date)
|
2019-03-02 05:11:47 +00:00
|
|
|
{
|
2019-03-24 05:02:08 +00:00
|
|
|
if (m_efb_depth_cache.valid)
|
2022-09-26 21:41:56 +00:00
|
|
|
{
|
|
|
|
for (u32 i = 0; i < m_efb_depth_cache.tiles.size(); i++)
|
|
|
|
{
|
|
|
|
m_efb_depth_cache.tiles[i].present = false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 05:02:08 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_depth_cache.valid = false;
|
2019-03-02 07:05:38 +00:00
|
|
|
m_efb_depth_cache.out_of_date = false;
|
2022-09-26 21:41:56 +00:00
|
|
|
m_efb_depth_cache.needs_flush = true;
|
2019-03-02 05:11:47 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 07:05:38 +00:00
|
|
|
void FramebufferManager::FlagPeekCacheAsOutOfDate()
|
|
|
|
{
|
|
|
|
if (m_efb_color_cache.valid)
|
|
|
|
m_efb_color_cache.out_of_date = true;
|
|
|
|
if (m_efb_depth_cache.valid)
|
|
|
|
m_efb_depth_cache.out_of_date = true;
|
|
|
|
|
|
|
|
if (!g_ActiveConfig.bEFBAccessDeferInvalidation)
|
|
|
|
InvalidatePeekCache();
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:41:56 +00:00
|
|
|
void FramebufferManager::EndOfFrame()
|
|
|
|
{
|
|
|
|
if (!IsUsingTiledEFBCache())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (u32 i = 0; i < m_efb_color_cache.tiles.size(); i++)
|
|
|
|
{
|
|
|
|
m_efb_color_cache.tiles[i].frame_access_mask <<= 1;
|
|
|
|
m_efb_depth_cache.tiles[i].frame_access_mask <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
bool FramebufferManager::CompileReadbackPipelines()
|
|
|
|
{
|
|
|
|
AbstractPipelineConfig config = {};
|
2019-03-02 05:11:47 +00:00
|
|
|
config.vertex_shader = g_shader_cache->GetTextureCopyVertexShader();
|
2019-02-15 01:59:50 +00:00
|
|
|
config.geometry_shader = IsEFBStereo() ? g_shader_cache->GetTexcoordGeometryShader() : nullptr;
|
|
|
|
config.pixel_shader = g_shader_cache->GetTextureCopyPixelShader();
|
|
|
|
config.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles);
|
|
|
|
config.depth_state = RenderState::GetNoDepthTestingDepthState();
|
|
|
|
config.blending_state = RenderState::GetNoBlendingBlendState();
|
|
|
|
config.framebuffer_state = RenderState::GetColorFramebufferState(GetEFBColorFormat());
|
|
|
|
config.usage = AbstractPipelineUsage::Utility;
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_color_cache.copy_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_color_cache.copy_pipeline)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// same for depth, except different format
|
2019-07-31 05:33:27 +00:00
|
|
|
config.framebuffer_state.color_texture_format = GetEFBDepthCopyFormat();
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_depth_cache.copy_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_depth_cache.copy_pipeline)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (IsEFBMultisampled())
|
|
|
|
{
|
|
|
|
auto depth_resolve_shader = g_renderer->CreateShaderFromSource(
|
2021-12-09 22:00:08 +00:00
|
|
|
ShaderStage::Pixel, FramebufferShaderGen::GenerateResolveDepthPixelShader(GetEFBSamples()),
|
|
|
|
"Depth resolve pixel shader");
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!depth_resolve_shader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
config.pixel_shader = depth_resolve_shader.get();
|
|
|
|
m_efb_depth_resolve_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_depth_resolve_pipeline)
|
|
|
|
return false;
|
2022-06-21 07:07:35 +00:00
|
|
|
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsPartialMultisampleResolve)
|
|
|
|
{
|
|
|
|
config.framebuffer_state.color_texture_format = GetEFBColorFormat();
|
|
|
|
auto color_resolve_shader = g_renderer->CreateShaderFromSource(
|
|
|
|
ShaderStage::Pixel,
|
|
|
|
FramebufferShaderGen::GenerateResolveColorPixelShader(GetEFBSamples()),
|
|
|
|
"Color resolve pixel shader");
|
|
|
|
if (!color_resolve_shader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
config.pixel_shader = color_resolve_shader.get();
|
|
|
|
m_efb_color_resolve_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_color_resolve_pipeline)
|
|
|
|
return false;
|
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-29 11:05:30 +00:00
|
|
|
// EFB restore pipeline
|
|
|
|
auto restore_shader = g_renderer->CreateShaderFromSource(
|
2021-12-09 22:00:08 +00:00
|
|
|
ShaderStage::Pixel, FramebufferShaderGen::GenerateEFBRestorePixelShader(),
|
|
|
|
"EFB restore pixel shader");
|
2019-06-29 11:05:30 +00:00
|
|
|
if (!restore_shader)
|
|
|
|
return false;
|
|
|
|
|
2019-08-02 15:46:52 +00:00
|
|
|
config.depth_state = RenderState::GetAlwaysWriteDepthState();
|
2019-06-29 11:05:30 +00:00
|
|
|
config.framebuffer_state = GetEFBFramebufferState();
|
|
|
|
config.framebuffer_state.per_sample_shading = false;
|
|
|
|
config.vertex_shader = g_shader_cache->GetScreenQuadVertexShader();
|
|
|
|
config.pixel_shader = restore_shader.get();
|
|
|
|
m_efb_restore_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_restore_pipeline)
|
|
|
|
return false;
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyReadbackPipelines()
|
|
|
|
{
|
|
|
|
m_efb_depth_resolve_pipeline.reset();
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_depth_cache.copy_pipeline.reset();
|
|
|
|
m_efb_color_cache.copy_pipeline.reset();
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::CreateReadbackFramebuffer()
|
|
|
|
{
|
2019-07-31 05:33:27 +00:00
|
|
|
if (g_renderer->GetEFBScale() != 1)
|
2019-02-15 01:59:50 +00:00
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
const TextureConfig color_config(IsUsingTiledEFBCache() ? m_efb_cache_tile_size : EFB_WIDTH,
|
|
|
|
IsUsingTiledEFBCache() ? m_efb_cache_tile_size : EFB_HEIGHT, 1,
|
|
|
|
1, 1, GetEFBColorFormat(), AbstractTextureFlag_RenderTarget);
|
2021-12-09 22:00:08 +00:00
|
|
|
m_efb_color_cache.texture = g_renderer->CreateTexture(color_config, "EFB color cache");
|
2019-07-31 05:33:27 +00:00
|
|
|
if (!m_efb_color_cache.texture)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_color_cache.framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_color_cache.texture.get(), nullptr);
|
2019-07-31 05:33:27 +00:00
|
|
|
if (!m_efb_color_cache.framebuffer)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we can't partially copy from a depth buffer directly to the staging texture in D3D, we
|
|
|
|
// use an intermediate buffer to avoid copying the whole texture.
|
2020-05-24 06:11:10 +00:00
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsDepthReadback ||
|
|
|
|
(IsUsingTiledEFBCache() && !g_ActiveConfig.backend_info.bSupportsPartialDepthCopies) ||
|
2019-07-31 05:33:27 +00:00
|
|
|
!AbstractTexture::IsCompatibleDepthAndColorFormats(m_efb_depth_texture->GetFormat(),
|
|
|
|
GetEFBDepthCopyFormat()) ||
|
|
|
|
g_renderer->GetEFBScale() != 1)
|
|
|
|
{
|
|
|
|
const TextureConfig depth_config(IsUsingTiledEFBCache() ? m_efb_cache_tile_size : EFB_WIDTH,
|
|
|
|
IsUsingTiledEFBCache() ? m_efb_cache_tile_size : EFB_HEIGHT, 1,
|
|
|
|
1, 1, GetEFBDepthCopyFormat(),
|
|
|
|
AbstractTextureFlag_RenderTarget);
|
2021-12-09 22:00:08 +00:00
|
|
|
m_efb_depth_cache.texture = g_renderer->CreateTexture(depth_config, "EFB depth cache");
|
2019-07-31 05:33:27 +00:00
|
|
|
if (!m_efb_depth_cache.texture)
|
|
|
|
return false;
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_depth_cache.framebuffer =
|
|
|
|
g_renderer->CreateFramebuffer(m_efb_depth_cache.texture.get(), nullptr);
|
2019-07-31 05:33:27 +00:00
|
|
|
if (!m_efb_depth_cache.framebuffer)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
// Staging texture use the full EFB dimensions, as this is the buffer for the whole cache.
|
|
|
|
m_efb_color_cache.readback_texture = g_renderer->CreateStagingTexture(
|
|
|
|
StagingTextureType::Mutable,
|
|
|
|
TextureConfig(EFB_WIDTH, EFB_HEIGHT, 1, 1, 1, GetEFBColorFormat(), 0));
|
|
|
|
m_efb_depth_cache.readback_texture = g_renderer->CreateStagingTexture(
|
|
|
|
StagingTextureType::Mutable,
|
2019-07-31 05:33:27 +00:00
|
|
|
TextureConfig(EFB_WIDTH, EFB_HEIGHT, 1, 1, 1, GetEFBDepthCopyFormat(), 0));
|
2019-03-02 05:11:47 +00:00
|
|
|
if (!m_efb_color_cache.readback_texture || !m_efb_depth_cache.readback_texture)
|
2019-02-15 01:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
if (IsUsingTiledEFBCache())
|
|
|
|
{
|
|
|
|
const u32 tiles_wide = ((EFB_WIDTH + (m_efb_cache_tile_size - 1)) / m_efb_cache_tile_size);
|
|
|
|
const u32 tiles_high = ((EFB_HEIGHT + (m_efb_cache_tile_size - 1)) / m_efb_cache_tile_size);
|
|
|
|
const u32 total_tiles = tiles_wide * tiles_high;
|
|
|
|
m_efb_color_cache.tiles.resize(total_tiles);
|
2022-09-26 21:41:56 +00:00
|
|
|
std::fill(m_efb_color_cache.tiles.begin(), m_efb_color_cache.tiles.end(),
|
|
|
|
EFBCacheTile{false, 0});
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_depth_cache.tiles.resize(total_tiles);
|
2022-09-26 21:41:56 +00:00
|
|
|
std::fill(m_efb_depth_cache.tiles.begin(), m_efb_depth_cache.tiles.end(),
|
|
|
|
EFBCacheTile{false, 0});
|
2019-03-02 05:11:47 +00:00
|
|
|
m_efb_cache_tiles_wide = tiles_wide;
|
|
|
|
}
|
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyReadbackFramebuffer()
|
|
|
|
{
|
2019-03-02 05:11:47 +00:00
|
|
|
auto DestroyCache = [](EFBCacheData& data) {
|
|
|
|
data.readback_texture.reset();
|
|
|
|
data.framebuffer.reset();
|
|
|
|
data.texture.reset();
|
|
|
|
data.valid = false;
|
|
|
|
};
|
|
|
|
DestroyCache(m_efb_color_cache);
|
|
|
|
DestroyCache(m_efb_depth_cache);
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:41:56 +00:00
|
|
|
void FramebufferManager::PopulateEFBCache(bool depth, u32 tile_index, bool async)
|
2019-03-02 05:11:47 +00:00
|
|
|
{
|
2022-02-21 20:42:51 +00:00
|
|
|
FlushEFBPokes();
|
2019-03-02 05:11:47 +00:00
|
|
|
g_vertex_manager->OnCPUEFBAccess();
|
|
|
|
|
|
|
|
// Force the path through the intermediate texture, as we can't do an image copy from a depth
|
|
|
|
// buffer directly to a staging texture (must be the whole resource).
|
|
|
|
const bool force_intermediate_copy =
|
2019-07-31 05:33:27 +00:00
|
|
|
depth &&
|
2020-05-24 06:11:10 +00:00
|
|
|
(!g_ActiveConfig.backend_info.bSupportsDepthReadback ||
|
|
|
|
(!g_ActiveConfig.backend_info.bSupportsPartialDepthCopies && IsUsingTiledEFBCache()) ||
|
2019-07-31 05:33:27 +00:00
|
|
|
!AbstractTexture::IsCompatibleDepthAndColorFormats(m_efb_depth_texture->GetFormat(),
|
|
|
|
GetEFBDepthCopyFormat()));
|
2019-03-02 05:11:47 +00:00
|
|
|
|
|
|
|
// Issue a copy from framebuffer -> copy texture if we have >1xIR or MSAA on.
|
|
|
|
EFBCacheData& data = depth ? m_efb_depth_cache : m_efb_color_cache;
|
|
|
|
const MathUtil::Rectangle<int> rect = GetEFBCacheTileRect(tile_index);
|
|
|
|
const MathUtil::Rectangle<int> native_rect = g_renderer->ConvertEFBRectangle(rect);
|
|
|
|
AbstractTexture* src_texture =
|
|
|
|
depth ? ResolveEFBDepthTexture(native_rect) : ResolveEFBColorTexture(native_rect);
|
|
|
|
if (g_renderer->GetEFBScale() != 1 || force_intermediate_copy)
|
|
|
|
{
|
|
|
|
// Downsample from internal resolution to 1x.
|
|
|
|
// TODO: This won't produce correct results at IRs above 2x. More samples are required.
|
|
|
|
// This is the same issue as with EFB copies.
|
2019-04-28 06:13:49 +00:00
|
|
|
src_texture->FinishedRendering();
|
2019-03-02 05:11:47 +00:00
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
|
|
|
|
const float rcp_src_width = 1.0f / m_efb_framebuffer->GetWidth();
|
|
|
|
const float rcp_src_height = 1.0f / m_efb_framebuffer->GetHeight();
|
|
|
|
const std::array<float, 4> uniforms = {
|
|
|
|
{native_rect.left * rcp_src_width, native_rect.top * rcp_src_height,
|
|
|
|
native_rect.GetWidth() * rcp_src_width, native_rect.GetHeight() * rcp_src_height}};
|
|
|
|
g_vertex_manager->UploadUtilityUniforms(&uniforms, sizeof(uniforms));
|
2019-03-27 12:12:40 +00:00
|
|
|
|
|
|
|
// Viewport will not be TILE_SIZExTILE_SIZE for the last row of tiles, assuming a tile size of
|
|
|
|
// 64, because 528 is not evenly divisible by 64.
|
2019-03-02 05:11:47 +00:00
|
|
|
g_renderer->SetAndDiscardFramebuffer(data.framebuffer.get());
|
2019-03-27 12:12:40 +00:00
|
|
|
g_renderer->SetViewportAndScissor(
|
|
|
|
MathUtil::Rectangle<int>(0, 0, rect.GetWidth(), rect.GetHeight()));
|
2019-03-02 05:11:47 +00:00
|
|
|
g_renderer->SetPipeline(data.copy_pipeline.get());
|
|
|
|
g_renderer->SetTexture(0, src_texture);
|
|
|
|
g_renderer->SetSamplerState(0, depth ? RenderState::GetPointSamplerState() :
|
|
|
|
RenderState::GetLinearSamplerState());
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
|
|
|
|
// Copy from EFB or copy texture to staging texture.
|
|
|
|
// No need to call FinishedRendering() here because CopyFromTexture() transitions.
|
|
|
|
data.readback_texture->CopyFromTexture(
|
|
|
|
data.texture.get(), MathUtil::Rectangle<int>(0, 0, rect.GetWidth(), rect.GetHeight()), 0, 0,
|
|
|
|
rect);
|
|
|
|
|
|
|
|
g_renderer->EndUtilityDrawing();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data.readback_texture->CopyFromTexture(src_texture, rect, 0, 0, rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait until the copy is complete.
|
2022-09-26 21:41:56 +00:00
|
|
|
if (!async)
|
|
|
|
{
|
|
|
|
data.readback_texture->Flush();
|
|
|
|
data.needs_flush = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data.needs_flush = true;
|
|
|
|
}
|
2019-03-02 05:11:47 +00:00
|
|
|
data.valid = true;
|
2019-03-02 07:05:38 +00:00
|
|
|
data.out_of_date = false;
|
2019-03-02 05:11:47 +00:00
|
|
|
if (IsUsingTiledEFBCache())
|
2022-09-26 21:41:56 +00:00
|
|
|
data.tiles[tile_index].present = true;
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::ClearEFB(const MathUtil::Rectangle<int>& rc, bool clear_color,
|
|
|
|
bool clear_alpha, bool clear_z, u32 color, u32 z)
|
|
|
|
{
|
|
|
|
FlushEFBPokes();
|
2019-03-02 07:05:38 +00:00
|
|
|
FlagPeekCacheAsOutOfDate();
|
2019-02-15 01:59:50 +00:00
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
|
|
|
|
// Set up uniforms.
|
|
|
|
struct Uniforms
|
|
|
|
{
|
|
|
|
float clear_color[4];
|
|
|
|
float clear_depth;
|
|
|
|
float padding1, padding2, padding3;
|
|
|
|
};
|
|
|
|
static_assert(std::is_standard_layout<Uniforms>::value);
|
|
|
|
Uniforms uniforms = {{static_cast<float>((color >> 16) & 0xFF) / 255.0f,
|
|
|
|
static_cast<float>((color >> 8) & 0xFF) / 255.0f,
|
|
|
|
static_cast<float>((color >> 0) & 0xFF) / 255.0f,
|
|
|
|
static_cast<float>((color >> 24) & 0xFF) / 255.0f},
|
|
|
|
static_cast<float>(z & 0xFFFFFF) / 16777216.0f};
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsReversedDepthRange)
|
|
|
|
uniforms.clear_depth = 1.0f - uniforms.clear_depth;
|
|
|
|
g_vertex_manager->UploadUtilityUniforms(&uniforms, sizeof(uniforms));
|
|
|
|
|
|
|
|
const auto target_rc = g_renderer->ConvertFramebufferRectangle(
|
|
|
|
g_renderer->ConvertEFBRectangle(rc), m_efb_framebuffer.get());
|
|
|
|
g_renderer->SetPipeline(m_efb_clear_pipelines[clear_color][clear_alpha][clear_z].get());
|
|
|
|
g_renderer->SetViewportAndScissor(target_rc);
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
g_renderer->EndUtilityDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::CompileClearPipelines()
|
|
|
|
{
|
|
|
|
auto vertex_shader = g_renderer->CreateShaderFromSource(
|
2021-12-09 22:00:08 +00:00
|
|
|
ShaderStage::Vertex, FramebufferShaderGen::GenerateClearVertexShader(),
|
|
|
|
"Clear vertex shader");
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!vertex_shader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractPipelineConfig config;
|
|
|
|
config.vertex_format = nullptr;
|
|
|
|
config.vertex_shader = vertex_shader.get();
|
|
|
|
config.geometry_shader = IsEFBStereo() ? g_shader_cache->GetColorGeometryShader() : nullptr;
|
|
|
|
config.pixel_shader = g_shader_cache->GetColorPixelShader();
|
|
|
|
config.rasterization_state = RenderState::GetNoCullRasterizationState(PrimitiveType::Triangles);
|
|
|
|
config.depth_state = RenderState::GetAlwaysWriteDepthState();
|
|
|
|
config.blending_state = RenderState::GetNoBlendingBlendState();
|
|
|
|
config.framebuffer_state = GetEFBFramebufferState();
|
|
|
|
config.usage = AbstractPipelineUsage::Utility;
|
|
|
|
|
|
|
|
for (u32 color_enable = 0; color_enable < 2; color_enable++)
|
|
|
|
{
|
|
|
|
config.blending_state.colorupdate = color_enable != 0;
|
|
|
|
for (u32 alpha_enable = 0; alpha_enable < 2; alpha_enable++)
|
|
|
|
{
|
|
|
|
config.blending_state.alphaupdate = alpha_enable != 0;
|
|
|
|
for (u32 depth_enable = 0; depth_enable < 2; depth_enable++)
|
|
|
|
{
|
|
|
|
config.depth_state.testenable = depth_enable != 0;
|
|
|
|
config.depth_state.updateenable = depth_enable != 0;
|
|
|
|
|
|
|
|
m_efb_clear_pipelines[color_enable][alpha_enable][depth_enable] =
|
|
|
|
g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_efb_clear_pipelines[color_enable][alpha_enable][depth_enable])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyClearPipelines()
|
|
|
|
{
|
|
|
|
for (u32 color_enable = 0; color_enable < 2; color_enable++)
|
|
|
|
{
|
|
|
|
for (u32 alpha_enable = 0; alpha_enable < 2; alpha_enable++)
|
|
|
|
{
|
|
|
|
for (u32 depth_enable = 0; depth_enable < 2; depth_enable++)
|
|
|
|
{
|
|
|
|
m_efb_clear_pipelines[color_enable][alpha_enable][depth_enable].reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::PokeEFBColor(u32 x, u32 y, u32 color)
|
|
|
|
{
|
|
|
|
// Flush if we exceeded the number of vertices per batch.
|
|
|
|
if ((m_color_poke_vertices.size() + 6) > MAX_POKE_VERTICES)
|
|
|
|
FlushEFBPokes();
|
|
|
|
|
|
|
|
CreatePokeVertices(&m_color_poke_vertices, x, y, 0.0f, color);
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
// See comment above for reasoning for lower-left coordinates.
|
|
|
|
if (g_ActiveConfig.backend_info.bUsesLowerLeftOrigin)
|
|
|
|
y = EFB_HEIGHT - 1 - y;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
// Update the peek cache if it's valid, since we know the color of the pixel now.
|
|
|
|
u32 tile_index;
|
|
|
|
if (IsEFBCacheTilePresent(false, x, y, &tile_index))
|
|
|
|
m_efb_color_cache.readback_texture->WriteTexel(x, y, &color);
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::PokeEFBDepth(u32 x, u32 y, float depth)
|
|
|
|
{
|
|
|
|
// Flush if we exceeded the number of vertices per batch.
|
2019-03-12 08:25:25 +00:00
|
|
|
if ((m_depth_poke_vertices.size() + 6) > MAX_POKE_VERTICES)
|
2019-02-15 01:59:50 +00:00
|
|
|
FlushEFBPokes();
|
|
|
|
|
|
|
|
CreatePokeVertices(&m_depth_poke_vertices, x, y, depth, 0);
|
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
// See comment above for reasoning for lower-left coordinates.
|
|
|
|
if (g_ActiveConfig.backend_info.bUsesLowerLeftOrigin)
|
|
|
|
y = EFB_HEIGHT - 1 - y;
|
2019-02-15 01:59:50 +00:00
|
|
|
|
2019-03-02 05:11:47 +00:00
|
|
|
// Update the peek cache if it's valid, since we know the color of the pixel now.
|
|
|
|
u32 tile_index;
|
|
|
|
if (IsEFBCacheTilePresent(true, x, y, &tile_index))
|
|
|
|
m_efb_depth_cache.readback_texture->WriteTexel(x, y, &depth);
|
2019-02-15 01:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::CreatePokeVertices(std::vector<EFBPokeVertex>* destination_list, u32 x,
|
|
|
|
u32 y, float z, u32 color)
|
|
|
|
{
|
|
|
|
const float cs_pixel_width = 1.0f / EFB_WIDTH * 2.0f;
|
|
|
|
const float cs_pixel_height = 1.0f / EFB_HEIGHT * 2.0f;
|
|
|
|
if (g_ActiveConfig.backend_info.bSupportsLargePoints)
|
|
|
|
{
|
|
|
|
// GPU will expand the point to a quad.
|
|
|
|
const float cs_x = (static_cast<float>(x) + 0.5f) * cs_pixel_width - 1.0f;
|
|
|
|
const float cs_y = 1.0f - (static_cast<float>(y) + 0.5f) * cs_pixel_height;
|
|
|
|
const float point_size = static_cast<float>(g_renderer->GetEFBScale());
|
|
|
|
destination_list->push_back({{cs_x, cs_y, z, point_size}, color});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate quad from the single point (clip-space coordinates).
|
|
|
|
const float x1 = static_cast<float>(x) * cs_pixel_width - 1.0f;
|
|
|
|
const float y1 = 1.0f - static_cast<float>(y) * cs_pixel_height;
|
|
|
|
const float x2 = x1 + cs_pixel_width;
|
2019-03-27 13:28:34 +00:00
|
|
|
const float y2 = y1 - cs_pixel_height;
|
2019-02-15 01:59:50 +00:00
|
|
|
destination_list->push_back({{x1, y1, z, 1.0f}, color});
|
|
|
|
destination_list->push_back({{x2, y1, z, 1.0f}, color});
|
|
|
|
destination_list->push_back({{x1, y2, z, 1.0f}, color});
|
|
|
|
destination_list->push_back({{x1, y2, z, 1.0f}, color});
|
|
|
|
destination_list->push_back({{x2, y1, z, 1.0f}, color});
|
|
|
|
destination_list->push_back({{x2, y2, z, 1.0f}, color});
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::FlushEFBPokes()
|
|
|
|
{
|
|
|
|
if (!m_color_poke_vertices.empty())
|
|
|
|
{
|
|
|
|
DrawPokeVertices(m_color_poke_vertices.data(), static_cast<u32>(m_color_poke_vertices.size()),
|
|
|
|
m_color_poke_pipeline.get());
|
|
|
|
m_color_poke_vertices.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_depth_poke_vertices.empty())
|
|
|
|
{
|
|
|
|
DrawPokeVertices(m_depth_poke_vertices.data(), static_cast<u32>(m_depth_poke_vertices.size()),
|
|
|
|
m_depth_poke_pipeline.get());
|
|
|
|
m_depth_poke_vertices.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DrawPokeVertices(const EFBPokeVertex* vertices, u32 vertex_count,
|
|
|
|
const AbstractPipeline* pipeline)
|
|
|
|
{
|
|
|
|
// Copy to vertex buffer.
|
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
u32 base_vertex, base_index;
|
|
|
|
g_vertex_manager->UploadUtilityVertices(vertices, sizeof(EFBPokeVertex),
|
|
|
|
static_cast<u32>(vertex_count), nullptr, 0, &base_vertex,
|
|
|
|
&base_index);
|
|
|
|
|
|
|
|
// Now we can draw.
|
|
|
|
g_renderer->SetViewportAndScissor(m_efb_framebuffer->GetRect());
|
|
|
|
g_renderer->SetPipeline(pipeline);
|
|
|
|
g_renderer->Draw(base_vertex, vertex_count);
|
|
|
|
g_renderer->EndUtilityDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FramebufferManager::CompilePokePipelines()
|
|
|
|
{
|
|
|
|
PortableVertexDeclaration vtx_decl = {};
|
|
|
|
vtx_decl.position.enable = true;
|
2021-06-26 19:48:28 +00:00
|
|
|
vtx_decl.position.type = ComponentFormat::Float;
|
2019-02-15 01:59:50 +00:00
|
|
|
vtx_decl.position.components = 4;
|
|
|
|
vtx_decl.position.integer = false;
|
|
|
|
vtx_decl.position.offset = offsetof(EFBPokeVertex, position);
|
|
|
|
vtx_decl.colors[0].enable = true;
|
2021-06-26 19:48:28 +00:00
|
|
|
vtx_decl.colors[0].type = ComponentFormat::UByte;
|
2019-02-15 01:59:50 +00:00
|
|
|
vtx_decl.colors[0].components = 4;
|
|
|
|
vtx_decl.colors[0].integer = false;
|
|
|
|
vtx_decl.colors[0].offset = offsetof(EFBPokeVertex, color);
|
|
|
|
vtx_decl.stride = sizeof(EFBPokeVertex);
|
|
|
|
|
|
|
|
m_poke_vertex_format = g_renderer->CreateNativeVertexFormat(vtx_decl);
|
|
|
|
if (!m_poke_vertex_format)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto poke_vertex_shader = g_renderer->CreateShaderFromSource(
|
2021-12-09 22:00:08 +00:00
|
|
|
ShaderStage::Vertex, FramebufferShaderGen::GenerateEFBPokeVertexShader(),
|
|
|
|
"EFB poke vertex shader");
|
2019-02-15 01:59:50 +00:00
|
|
|
if (!poke_vertex_shader)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AbstractPipelineConfig config = {};
|
|
|
|
config.vertex_format = m_poke_vertex_format.get();
|
|
|
|
config.vertex_shader = poke_vertex_shader.get();
|
|
|
|
config.geometry_shader = IsEFBStereo() ? g_shader_cache->GetColorGeometryShader() : nullptr;
|
|
|
|
config.pixel_shader = g_shader_cache->GetColorPixelShader();
|
|
|
|
config.rasterization_state = RenderState::GetNoCullRasterizationState(
|
|
|
|
g_ActiveConfig.backend_info.bSupportsLargePoints ? PrimitiveType::Points :
|
|
|
|
PrimitiveType::Triangles);
|
|
|
|
config.depth_state = RenderState::GetNoDepthTestingDepthState();
|
|
|
|
config.blending_state = RenderState::GetNoBlendingBlendState();
|
|
|
|
config.framebuffer_state = GetEFBFramebufferState();
|
|
|
|
config.usage = AbstractPipelineUsage::Utility;
|
|
|
|
m_color_poke_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_color_poke_pipeline)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Turn off color writes, depth writes on for depth pokes.
|
|
|
|
config.depth_state = RenderState::GetAlwaysWriteDepthState();
|
|
|
|
config.blending_state = RenderState::GetNoColorWriteBlendState();
|
|
|
|
m_depth_poke_pipeline = g_renderer->CreatePipeline(config);
|
|
|
|
if (!m_depth_poke_pipeline)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DestroyPokePipelines()
|
|
|
|
{
|
|
|
|
m_depth_poke_pipeline.reset();
|
|
|
|
m_color_poke_pipeline.reset();
|
|
|
|
m_poke_vertex_format.reset();
|
|
|
|
}
|
2019-06-29 11:05:30 +00:00
|
|
|
|
|
|
|
void FramebufferManager::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
FlushEFBPokes();
|
|
|
|
|
2019-07-23 19:19:13 +00:00
|
|
|
bool save_efb_state = Config::Get(Config::GFX_SAVE_TEXTURE_CACHE_TO_STATE);
|
|
|
|
p.Do(save_efb_state);
|
|
|
|
if (!save_efb_state)
|
|
|
|
return;
|
|
|
|
|
2022-05-18 05:29:05 +00:00
|
|
|
if (p.IsWriteMode() || p.IsMeasureMode())
|
2019-06-29 11:05:30 +00:00
|
|
|
DoSaveState(p);
|
|
|
|
else
|
|
|
|
DoLoadState(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DoSaveState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
// For multisampling, we need to resolve first before we can save.
|
|
|
|
// This won't be bit-exact when loading, which could cause interesting rendering side-effects for
|
|
|
|
// a frame. But whatever, MSAA doesn't exactly behave that well anyway.
|
|
|
|
AbstractTexture* color_texture = ResolveEFBColorTexture(m_efb_color_texture->GetRect());
|
2020-05-24 05:33:02 +00:00
|
|
|
AbstractTexture* depth_texture = ResolveEFBDepthTexture(m_efb_depth_texture->GetRect(), true);
|
2019-06-29 11:05:30 +00:00
|
|
|
|
|
|
|
// We don't want to save these as rendertarget textures, just the data itself when deserializing.
|
|
|
|
const TextureConfig color_texture_config(color_texture->GetWidth(), color_texture->GetHeight(),
|
|
|
|
color_texture->GetLevels(), color_texture->GetLayers(),
|
|
|
|
1, GetEFBColorFormat(), 0);
|
|
|
|
g_texture_cache->SerializeTexture(color_texture, color_texture_config, p);
|
|
|
|
|
2020-05-24 05:33:02 +00:00
|
|
|
const TextureConfig depth_texture_config(depth_texture->GetWidth(), depth_texture->GetHeight(),
|
|
|
|
depth_texture->GetLevels(), depth_texture->GetLayers(),
|
|
|
|
1, GetEFBDepthCopyFormat(), 0);
|
|
|
|
g_texture_cache->SerializeTexture(depth_texture, depth_texture_config, p);
|
2019-06-29 11:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FramebufferManager::DoLoadState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
// Invalidate any peek cache tiles.
|
|
|
|
InvalidatePeekCache(true);
|
|
|
|
|
|
|
|
// Deserialize the color and depth textures. This could fail.
|
|
|
|
auto color_tex = g_texture_cache->DeserializeTexture(p);
|
|
|
|
auto depth_tex = g_texture_cache->DeserializeTexture(p);
|
|
|
|
|
|
|
|
// If the stereo mode is different in the save state, throw it away.
|
|
|
|
if (!color_tex || !depth_tex ||
|
|
|
|
color_tex->texture->GetLayers() != m_efb_color_texture->GetLayers())
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "Failed to deserialize EFB contents. Clearing instead.");
|
2019-06-29 11:05:30 +00:00
|
|
|
g_renderer->SetAndClearFramebuffer(
|
|
|
|
m_efb_framebuffer.get(), {{0.0f, 0.0f, 0.0f, 0.0f}},
|
|
|
|
g_ActiveConfig.backend_info.bSupportsReversedDepthRange ? 1.0f : 0.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size differences are okay here, since the linear filtering will downscale/upscale it.
|
|
|
|
// Depth buffer is always point sampled, since we don't want to interpolate depth values.
|
|
|
|
const bool rescale = color_tex->texture->GetWidth() != m_efb_color_texture->GetWidth() ||
|
|
|
|
color_tex->texture->GetHeight() != m_efb_color_texture->GetHeight();
|
|
|
|
|
|
|
|
// Draw the deserialized textures over the EFB.
|
|
|
|
g_renderer->BeginUtilityDrawing();
|
|
|
|
g_renderer->SetAndDiscardFramebuffer(m_efb_framebuffer.get());
|
|
|
|
g_renderer->SetViewportAndScissor(m_efb_framebuffer->GetRect());
|
|
|
|
g_renderer->SetPipeline(m_efb_restore_pipeline.get());
|
|
|
|
g_renderer->SetTexture(0, color_tex->texture.get());
|
|
|
|
g_renderer->SetTexture(1, depth_tex->texture.get());
|
|
|
|
g_renderer->SetSamplerState(0, rescale ? RenderState::GetLinearSamplerState() :
|
|
|
|
RenderState::GetPointSamplerState());
|
|
|
|
g_renderer->SetSamplerState(1, RenderState::GetPointSamplerState());
|
|
|
|
g_renderer->Draw(0, 3);
|
|
|
|
g_renderer->EndUtilityDrawing();
|
|
|
|
}
|