VideoCommon: Move some common initialization logic to RenderBase

This commit is contained in:
Stenzek 2017-03-04 16:40:08 +10:00
parent 277829d842
commit 238a70b006
22 changed files with 67 additions and 87 deletions

View File

@ -98,18 +98,10 @@ D3DTexture2D*& FramebufferManager::GetResolvedEFBDepthTexture()
}
}
FramebufferManager::FramebufferManager()
FramebufferManager::FramebufferManager(int target_width, int target_height)
{
m_target_width = g_renderer->GetTargetWidth();
m_target_height = g_renderer->GetTargetHeight();
if (m_target_height < 1)
{
m_target_height = 1;
}
if (m_target_width < 1)
{
m_target_width = 1;
}
m_target_width = static_cast<unsigned int>(std::max(target_width, 1));
m_target_height = static_cast<unsigned int>(std::max(target_height, 1));
DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples;
sample_desc.Quality = 0;

View File

@ -60,7 +60,7 @@ struct XFBSource : public XFBSourceBase
class FramebufferManager : public FramebufferManagerBase
{
public:
FramebufferManager();
FramebufferManager(int target_width, int target_height);
~FramebufferManager();
static D3DTexture2D*& GetEFBColorTexture();

View File

@ -84,8 +84,6 @@ static void SetupDeviceObjects()
{
s_television.Init();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
HRESULT hr;
D3D11_DEPTH_STENCIL_DESC ddesc;
@ -235,25 +233,13 @@ static void Create3DVisionTexture(int width, int height)
delete[] sysData.pSysMem;
}
Renderer::Renderer(void*& window_handle)
Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
{
D3D::Create((HWND)window_handle);
s_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight();
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
g_framebuffer_manager = std::make_unique<FramebufferManager>(s_target_width, s_target_height);
SetupDeviceObjects();
// Setup GX pipeline state
@ -907,7 +893,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr);
g_framebuffer_manager.reset();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_framebuffer_manager = std::make_unique<FramebufferManager>(s_target_width, s_target_height);
float clear_col[4] = {0.f, 0.f, 0.f, 1.f};
D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(),
clear_col);

View File

@ -16,8 +16,8 @@ class D3DTexture2D;
class Renderer : public ::Renderer
{
public:
Renderer(void*& window_handle);
~Renderer();
Renderer();
~Renderer() override;
void SetColorMask() override;
void SetBlendMode(bool forceUpdate) override;

View File

@ -6,6 +6,7 @@
#include <string>
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "VideoBackends/D3D/BoundingBox.h"
@ -144,11 +145,15 @@ bool VideoBackend::Initialize(void* window_handle)
void VideoBackend::Video_Prepare()
{
if (FAILED(D3D::Create(reinterpret_cast<HWND>(m_window_handle))))
PanicAlert("Failed to create D3D device.");
// internal interfaces
g_renderer = std::make_unique<Renderer>(m_window_handle);
g_renderer = std::make_unique<Renderer>();
g_texture_cache = std::make_unique<TextureCache>();
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>();
g_renderer->InitializeCommon();
VertexShaderCache::Init();
PixelShaderCache::Init();
GeometryShaderCache::Init();

View File

@ -84,10 +84,10 @@ D3DTexture2D*& FramebufferManager::GetResolvedEFBDepthTexture()
}
}
FramebufferManager::FramebufferManager()
FramebufferManager::FramebufferManager(int target_width, int target_height)
{
m_target_width = std::max(g_renderer->GetTargetWidth(), 1);
m_target_height = std::max(g_renderer->GetTargetHeight(), 1);
m_target_width = static_cast<unsigned int>(std::max(target_width, 1));
m_target_height = static_cast<unsigned int>(std::max(target_height, 1));
DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples;

View File

@ -58,7 +58,7 @@ struct XFBSource final : public XFBSourceBase
class FramebufferManager final : public FramebufferManagerBase
{
public:
FramebufferManager();
FramebufferManager(int target_width, int target_height);
~FramebufferManager();
static D3DTexture2D*& GetEFBColorTexture();

View File

@ -101,8 +101,6 @@ StateCache gx_state_cache;
static void SetupDeviceObjects()
{
g_framebuffer_manager = std::make_unique<FramebufferManager>();
D3D12_DEPTH_STENCIL_DESC depth_desc;
depth_desc.DepthEnable = FALSE;
depth_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO;
@ -211,7 +209,7 @@ static void Create3DVisionTexture(int width, int height)
// D3D12TODO: 3D Vision not implemented on D3D12 backend.
}
Renderer::Renderer(void*& window_handle)
Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
{
if (g_ActiveConfig.iStereoMode == STEREO_3DVISION)
{
@ -219,21 +217,11 @@ Renderer::Renderer(void*& window_handle)
return;
}
s_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight();
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
g_framebuffer_manager = std::make_unique<FramebufferManager>(s_target_width, s_target_height);
SetupDeviceObjects();
// Setup GX pipeline state
@ -877,7 +865,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
nullptr);
g_framebuffer_manager.reset();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_framebuffer_manager = std::make_unique<FramebufferManager>(s_target_width, s_target_height);
const float clear_color[4] = {0.f, 0.f, 0.f, 1.f};
FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(

View File

@ -17,8 +17,8 @@ class D3DTexture2D;
class Renderer final : public ::Renderer
{
public:
Renderer(void*& window_handle);
~Renderer();
Renderer();
~Renderer() override;
void SetColorMask() override;
void SetBlendMode(bool force_update) override;

View File

@ -163,11 +163,12 @@ bool VideoBackend::Initialize(void* window_handle)
void VideoBackend::Video_Prepare()
{
// internal interfaces
g_renderer = std::make_unique<Renderer>(m_window_handle);
g_renderer = std::make_unique<Renderer>();
g_texture_cache = std::make_unique<TextureCache>();
g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>();
g_xfb_encoder = std::make_unique<XFBEncoder>();
g_renderer->InitializeCommon();
ShaderCache::Init();
ShaderConstantsManager::Init();
StaticShaderCache::Init();

View File

@ -67,6 +67,7 @@ void VideoBackend::Video_Prepare()
g_perf_query = std::make_unique<PerfQuery>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCache>();
g_renderer->InitializeCommon();
VertexShaderCache::s_instance = std::make_unique<VertexShaderCache>();
GeometryShaderCache::s_instance = std::make_unique<GeometryShaderCache>();
PixelShaderCache::s_instance = std::make_unique<PixelShaderCache>();

View File

@ -11,7 +11,7 @@
namespace Null
{
// Init functions
Renderer::Renderer()
Renderer::Renderer() : ::Renderer(1, 1)
{
g_Config.bRunning = true;
UpdateActiveConfig();

View File

@ -12,7 +12,7 @@ class Renderer : public ::Renderer
{
public:
Renderer();
~Renderer();
~Renderer() override;
void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }

View File

@ -329,6 +329,8 @@ static void InitDriverInfo()
// Init functions
Renderer::Renderer()
: ::Renderer(static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u)))
{
bool bSuccess = true;
@ -687,26 +689,11 @@ Renderer::Renderer()
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
// Decide framebuffer size
s_backbuffer_width = static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u));
s_backbuffer_height = static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u));
// Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
GLInterface->SwapInterval(s_vsync);
// TODO: Move these somewhere else?
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_efb_scale = g_ActiveConfig.iEFBScale;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
// Because of the fixed framebuffer size we need to disable the resolution
// options while running
g_Config.bRunning = true;
@ -786,6 +773,8 @@ void Renderer::Shutdown()
void Renderer::Init()
{
InitializeCommon();
// Initialize the FramebufferManager
g_framebuffer_manager =
std::make_unique<FramebufferManager>(s_target_width, s_target_height, s_MSAASamples);

View File

@ -69,7 +69,7 @@ class Renderer : public ::Renderer
{
public:
Renderer();
~Renderer();
~Renderer() override;
void Init();
void Shutdown();

View File

@ -25,6 +25,11 @@
static u8* s_xfbColorTexture[2];
static int s_currentColorTexture = 0;
SWRenderer::SWRenderer()
: ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT))
{
}
SWRenderer::~SWRenderer()
{
delete[] s_xfbColorTexture[0];

View File

@ -13,6 +13,7 @@
class SWRenderer : public Renderer
{
public:
SWRenderer();
~SWRenderer() override;
static void Init();

View File

@ -181,6 +181,7 @@ void VideoSoftware::Video_Prepare()
g_vertex_manager = std::make_unique<SWVertexLoader>();
g_perf_query = std::make_unique<PerfQuery>();
g_texture_cache = std::make_unique<TextureCache>();
g_renderer->InitializeCommon();
SWRenderer::Init();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
}

View File

@ -42,7 +42,10 @@
namespace Vulkan
{
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain) : m_swap_chain(std::move(swap_chain))
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain)
: ::Renderer(swap_chain ? static_cast<int>(swap_chain->GetWidth()) : 1,
swap_chain ? static_cast<int>(swap_chain->GetHeight()) : 0),
m_swap_chain(std::move(swap_chain))
{
g_Config.bRunning = true;
UpdateActiveConfig();
@ -50,17 +53,6 @@ Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain) : m_swap_chain(std::mo
// Set to something invalid, forcing all states to be re-initialized.
for (size_t i = 0; i < m_sampler_states.size(); i++)
m_sampler_states[i].bits = std::numeric_limits<decltype(m_sampler_states[i].bits)>::max();
// These have to be initialized before FramebufferManager is created.
// If running surfaceless, assume a window size of MAX_XFB_{WIDTH,HEIGHT}.
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
s_backbuffer_width = m_swap_chain ? m_swap_chain->GetWidth() : MAX_XFB_WIDTH;
s_backbuffer_height = m_swap_chain ? m_swap_chain->GetHeight() : MAX_XFB_HEIGHT;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
UpdateDrawRectangle();
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
}
Renderer::~Renderer()

View File

@ -28,7 +28,7 @@ class Renderer : public ::Renderer
{
public:
Renderer(std::unique_ptr<SwapChain> swap_chain);
~Renderer();
~Renderer() override;
static Renderer* GetInstance();

View File

@ -50,6 +50,7 @@
#include "VideoCommon/FramebufferManagerBase.h"
#include "VideoCommon/ImageWrite.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/PostProcessing.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/TextureCacheBase.h"
@ -75,10 +76,19 @@ static float AspectToWidescreen(float aspect)
return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f));
}
Renderer::Renderer()
Renderer::Renderer(int backbuffer_width, int backbuffer_height)
{
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateActiveConfig();
s_backbuffer_width = backbuffer_width;
s_backbuffer_height = backbuffer_height;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
CalculateTargetSize();
UpdateDrawRectangle();
OSDChoice = 0;
OSDTime = 0;
}
@ -606,6 +616,11 @@ void Renderer::UpdateDrawRectangle()
target_rc.bottom = YOffset + iHeight;
}
void Renderer::InitializeCommon()
{
PixelShaderManager::SetEfbScaleChanged();
}
void Renderer::SetWindowSize(int width, int height)
{
if (width < 1)

View File

@ -50,7 +50,7 @@ extern int OSDChoice;
class Renderer
{
public:
Renderer();
Renderer(int backbuffer_width, int backbuffer_height);
virtual ~Renderer();
enum PixelPerfQuery
@ -79,6 +79,10 @@ public:
virtual void RestoreState() {}
virtual void ResetAPIState() {}
virtual void RestoreAPIState() {}
// Some of the methods called by here assume g_renderer is initialized, therefore
// we must call it after constructing the backend's Renderer instance.
void InitializeCommon();
// Ideal internal resolution - determined by display resolution (automatic scaling) and/or a
// multiple of the native EFB resolution
int GetTargetWidth() { return s_target_width; }