summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/Render.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2017-11-21 19:53:38 +1000
committerStenzek <stenzek@gmail.com>2017-11-22 18:47:04 +1000
commitd9400f708a5af50a38273e25c103143968e16b67 (patch)
treeb91698fe4888b6481fe944aa6aa6f87a3a916641 /Source/Core/VideoBackends/D3D/Render.cpp
parent798ec96e1447f8c21b4b774d3be9c50ed30a9318 (diff)
D3D: Move remaining static variables from Render.cpp to Renderer class
Diffstat (limited to 'Source/Core/VideoBackends/D3D/Render.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/Render.cpp197
1 files changed, 92 insertions, 105 deletions
diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp
index 41a48e9a8d..762404d581 100644
--- a/Source/Core/VideoBackends/D3D/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Render.cpp
@@ -53,20 +53,46 @@ typedef struct _Nv_Stereo_Image_Header
#define NVSTEREO_IMAGE_SIGNATURE 0x4433564e
-static u32 s_last_multisamples = 1;
-static bool s_last_stereo_mode = false;
-static bool s_last_fullscreen_mode = false;
+Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
+{
+ m_last_multisamples = g_ActiveConfig.iMultisamples;
+ m_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;
+ m_last_fullscreen_mode = D3D::GetFullscreenState();
-static std::array<ID3D11BlendState*, 4> s_clear_blend_states{};
-static std::array<ID3D11DepthStencilState*, 3> s_clear_depth_states{};
-static ID3D11BlendState* s_reset_blend_state = nullptr;
-static ID3D11DepthStencilState* s_reset_depth_state = nullptr;
-static ID3D11RasterizerState* s_reset_rast_state = nullptr;
+ g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
+ SetupDeviceObjects();
-static ID3D11Texture2D* s_screenshot_texture = nullptr;
-static D3DTexture2D* s_3d_vision_texture = nullptr;
+ // Setup GX pipeline state
+ for (auto& sampler : m_gx_state.samplers)
+ sampler.hex = RenderState::GetPointSamplerState().hex;
+
+ m_gx_state.zmode.testenable = false;
+ m_gx_state.zmode.updateenable = false;
+ m_gx_state.zmode.func = ZMode::NEVER;
+ m_gx_state.raster.cullmode = GenMode::CULL_NONE;
-static void SetupDeviceObjects()
+ // Clear EFB textures
+ constexpr std::array<float, 4> clear_color{{0.f, 0.f, 0.f, 1.f}};
+ D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(),
+ clear_color.data());
+ D3D::context->ClearDepthStencilView(FramebufferManager::GetEFBDepthTexture()->GetDSV(),
+ D3D11_CLEAR_DEPTH, 0.f, 0);
+
+ D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)m_target_width, (float)m_target_height);
+ D3D::context->RSSetViewports(1, &vp);
+ FramebufferManager::BindEFBRenderTarget();
+ D3D::BeginFrame();
+}
+
+Renderer::~Renderer()
+{
+ TeardownDeviceObjects();
+ D3D::EndFrame();
+ D3D::Present();
+ D3D::Close();
+}
+
+void Renderer::SetupDeviceObjects()
{
HRESULT hr;
@@ -77,22 +103,22 @@ static void SetupDeviceObjects()
ddesc.StencilEnable = FALSE;
ddesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
ddesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
- hr = D3D::device->CreateDepthStencilState(&ddesc, &s_clear_depth_states[0]);
+ hr = D3D::device->CreateDepthStencilState(&ddesc, &m_clear_depth_states[0]);
CHECK(hr == S_OK, "Create depth state for Renderer::ClearScreen");
ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
ddesc.DepthEnable = TRUE;
- hr = D3D::device->CreateDepthStencilState(&ddesc, &s_clear_depth_states[1]);
+ hr = D3D::device->CreateDepthStencilState(&ddesc, &m_clear_depth_states[1]);
CHECK(hr == S_OK, "Create depth state for Renderer::ClearScreen");
ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
- hr = D3D::device->CreateDepthStencilState(&ddesc, &s_clear_depth_states[2]);
+ hr = D3D::device->CreateDepthStencilState(&ddesc, &m_clear_depth_states[2]);
CHECK(hr == S_OK, "Create depth state for Renderer::ClearScreen");
- D3D::SetDebugObjectName(s_clear_depth_states[0],
+ D3D::SetDebugObjectName(m_clear_depth_states[0],
"depth state for Renderer::ClearScreen (depth buffer disabled)");
D3D::SetDebugObjectName(
- s_clear_depth_states[1],
+ m_clear_depth_states[1],
"depth state for Renderer::ClearScreen (depth buffer enabled, writing enabled)");
D3D::SetDebugObjectName(
- s_clear_depth_states[2],
+ m_clear_depth_states[2],
"depth state for Renderer::ClearScreen (depth buffer enabled, writing disabled)");
D3D11_BLEND_DESC blenddesc;
@@ -106,24 +132,24 @@ static void SetupDeviceObjects()
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blenddesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
- hr = D3D::device->CreateBlendState(&blenddesc, &s_reset_blend_state);
+ hr = D3D::device->CreateBlendState(&blenddesc, &m_reset_blend_state);
CHECK(hr == S_OK, "Create blend state for Renderer::ResetAPIState");
- D3D::SetDebugObjectName(s_reset_blend_state, "blend state for Renderer::ResetAPIState");
+ D3D::SetDebugObjectName(m_reset_blend_state, "blend state for Renderer::ResetAPIState");
- s_clear_blend_states[0] = s_reset_blend_state;
- s_reset_blend_state->AddRef();
+ m_clear_blend_states[0] = m_reset_blend_state;
+ m_reset_blend_state->AddRef();
blenddesc.RenderTarget[0].RenderTargetWriteMask =
D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
- hr = D3D::device->CreateBlendState(&blenddesc, &s_clear_blend_states[1]);
+ hr = D3D::device->CreateBlendState(&blenddesc, &m_clear_blend_states[1]);
CHECK(hr == S_OK, "Create blend state for Renderer::ClearScreen");
blenddesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
- hr = D3D::device->CreateBlendState(&blenddesc, &s_clear_blend_states[2]);
+ hr = D3D::device->CreateBlendState(&blenddesc, &m_clear_blend_states[2]);
CHECK(hr == S_OK, "Create blend state for Renderer::ClearScreen");
blenddesc.RenderTarget[0].RenderTargetWriteMask = 0;
- hr = D3D::device->CreateBlendState(&blenddesc, &s_clear_blend_states[3]);
+ hr = D3D::device->CreateBlendState(&blenddesc, &m_clear_blend_states[3]);
CHECK(hr == S_OK, "Create blend state for Renderer::ClearScreen");
ddesc.DepthEnable = FALSE;
@@ -132,39 +158,39 @@ static void SetupDeviceObjects()
ddesc.StencilEnable = FALSE;
ddesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
ddesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
- hr = D3D::device->CreateDepthStencilState(&ddesc, &s_reset_depth_state);
+ hr = D3D::device->CreateDepthStencilState(&ddesc, &m_reset_depth_state);
CHECK(hr == S_OK, "Create depth state for Renderer::ResetAPIState");
- D3D::SetDebugObjectName(s_reset_depth_state, "depth stencil state for Renderer::ResetAPIState");
+ D3D::SetDebugObjectName(m_reset_depth_state, "depth stencil state for Renderer::ResetAPIState");
D3D11_RASTERIZER_DESC rastdesc = CD3D11_RASTERIZER_DESC(D3D11_FILL_SOLID, D3D11_CULL_NONE, false,
0, 0.f, 0.f, false, false, false, false);
- hr = D3D::device->CreateRasterizerState(&rastdesc, &s_reset_rast_state);
+ hr = D3D::device->CreateRasterizerState(&rastdesc, &m_reset_rast_state);
CHECK(hr == S_OK, "Create rasterizer state for Renderer::ResetAPIState");
- D3D::SetDebugObjectName(s_reset_rast_state, "rasterizer state for Renderer::ResetAPIState");
+ D3D::SetDebugObjectName(m_reset_rast_state, "rasterizer state for Renderer::ResetAPIState");
- s_screenshot_texture = nullptr;
+ m_screenshot_texture = nullptr;
}
// Kill off all device objects
-static void TeardownDeviceObjects()
+void Renderer::TeardownDeviceObjects()
{
g_framebuffer_manager.reset();
- SAFE_RELEASE(s_clear_blend_states[0]);
- SAFE_RELEASE(s_clear_blend_states[1]);
- SAFE_RELEASE(s_clear_blend_states[2]);
- SAFE_RELEASE(s_clear_blend_states[3]);
- SAFE_RELEASE(s_clear_depth_states[0]);
- SAFE_RELEASE(s_clear_depth_states[1]);
- SAFE_RELEASE(s_clear_depth_states[2]);
- SAFE_RELEASE(s_reset_blend_state);
- SAFE_RELEASE(s_reset_depth_state);
- SAFE_RELEASE(s_reset_rast_state);
- SAFE_RELEASE(s_screenshot_texture);
- SAFE_RELEASE(s_3d_vision_texture);
+ SAFE_RELEASE(m_clear_blend_states[0]);
+ SAFE_RELEASE(m_clear_blend_states[1]);
+ SAFE_RELEASE(m_clear_blend_states[2]);
+ SAFE_RELEASE(m_clear_blend_states[3]);
+ SAFE_RELEASE(m_clear_depth_states[0]);
+ SAFE_RELEASE(m_clear_depth_states[1]);
+ SAFE_RELEASE(m_clear_depth_states[2]);
+ SAFE_RELEASE(m_reset_blend_state);
+ SAFE_RELEASE(m_reset_depth_state);
+ SAFE_RELEASE(m_reset_rast_state);
+ SAFE_RELEASE(m_screenshot_texture);
+ SAFE_RELEASE(m_3d_vision_texture);
}
-static void Create3DVisionTexture(int width, int height)
+void Renderer::Create3DVisionTexture(int width, int height)
{
// Create a staging texture for 3D vision with signature information in the last row.
// Nvidia 3D Vision supports full SBS, so there is no loss in resolution during this process.
@@ -184,50 +210,11 @@ static void Create3DVisionTexture(int width, int height)
sys_data.SysMemPitch = pitch;
sys_data.pSysMem = memory.get();
- s_3d_vision_texture =
+ m_3d_vision_texture =
D3DTexture2D::Create(width * 2, height + 1, D3D11_BIND_RENDER_TARGET, D3D11_USAGE_DEFAULT,
DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, &sys_data);
}
-Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
-{
- s_last_multisamples = g_ActiveConfig.iMultisamples;
- s_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;
- s_last_fullscreen_mode = D3D::GetFullscreenState();
-
- g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
- SetupDeviceObjects();
-
- // Setup GX pipeline state
- for (auto& sampler : m_gx_state.samplers)
- sampler.hex = RenderState::GetPointSamplerState().hex;
-
- m_gx_state.zmode.testenable = false;
- m_gx_state.zmode.updateenable = false;
- m_gx_state.zmode.func = ZMode::NEVER;
- m_gx_state.raster.cullmode = GenMode::CULL_NONE;
-
- // Clear EFB textures
- constexpr std::array<float, 4> clear_color{{0.f, 0.f, 0.f, 1.f}};
- D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(),
- clear_color.data());
- D3D::context->ClearDepthStencilView(FramebufferManager::GetEFBDepthTexture()->GetDSV(),
- D3D11_CLEAR_DEPTH, 0.f, 0);
-
- D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)m_target_width, (float)m_target_height);
- D3D::context->RSSetViewports(1, &vp);
- FramebufferManager::BindEFBRenderTarget();
- D3D::BeginFrame();
-}
-
-Renderer::~Renderer()
-{
- TeardownDeviceObjects();
- D3D::EndFrame();
- D3D::Present();
- D3D::Close();
-}
-
void Renderer::RenderText(const std::string& text, int left, int top, u32 color)
{
D3D::DrawTextScaled(static_cast<float>(left + 1), static_cast<float>(top + 1), 20.f, 0.0f,
@@ -430,8 +417,8 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num
}
else // if (type == EFBAccessType::PokeZ)
{
- D3D::stateman->PushBlendState(s_clear_blend_states[3]);
- D3D::stateman->PushDepthState(s_clear_depth_states[1]);
+ D3D::stateman->PushBlendState(m_clear_blend_states[3]);
+ D3D::stateman->PushDepthState(m_clear_depth_states[1]);
D3D11_VIEWPORT vp =
CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight());
@@ -513,21 +500,21 @@ void Renderer::ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaE
ResetAPIState();
if (colorEnable && alphaEnable)
- D3D::stateman->PushBlendState(s_clear_blend_states[0]);
+ D3D::stateman->PushBlendState(m_clear_blend_states[0]);
else if (colorEnable)
- D3D::stateman->PushBlendState(s_clear_blend_states[1]);
+ D3D::stateman->PushBlendState(m_clear_blend_states[1]);
else if (alphaEnable)
- D3D::stateman->PushBlendState(s_clear_blend_states[2]);
+ D3D::stateman->PushBlendState(m_clear_blend_states[2]);
else
- D3D::stateman->PushBlendState(s_clear_blend_states[3]);
+ D3D::stateman->PushBlendState(m_clear_blend_states[3]);
// TODO: Should we enable Z testing here?
// if (!bpmem.zmode.testenable) D3D::stateman->PushDepthState(s_clear_depth_states[0]);
// else
if (zEnable)
- D3D::stateman->PushDepthState(s_clear_depth_states[1]);
+ D3D::stateman->PushDepthState(m_clear_depth_states[1]);
else /*if (!zEnable)*/
- D3D::stateman->PushDepthState(s_clear_depth_states[2]);
+ D3D::stateman->PushDepthState(m_clear_depth_states[2]);
// Update the view port for clearing the picture
TargetRectangle targetRc = Renderer::ConvertEFBRectangle(rc);
@@ -633,33 +620,33 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
const bool window_resized = CheckForResize();
const bool fullscreen = D3D::GetFullscreenState();
- const bool fs_changed = s_last_fullscreen_mode != fullscreen;
+ const bool fs_changed = m_last_fullscreen_mode != fullscreen;
// Flip/present backbuffer to frontbuffer here
D3D::Present();
// Resize the back buffers NOW to avoid flickering
if (CalculateTargetSize() || window_resized || fs_changed ||
- s_last_multisamples != g_ActiveConfig.iMultisamples ||
- s_last_stereo_mode != (g_ActiveConfig.stereo_mode != StereoMode::Off))
+ m_last_multisamples != g_ActiveConfig.iMultisamples ||
+ m_last_stereo_mode != (g_ActiveConfig.stereo_mode != StereoMode::Off))
{
- s_last_multisamples = g_ActiveConfig.iMultisamples;
- s_last_fullscreen_mode = fullscreen;
+ m_last_multisamples = g_ActiveConfig.iMultisamples;
+ m_last_fullscreen_mode = fullscreen;
PixelShaderCache::InvalidateMSAAShaders();
if (window_resized || fs_changed)
{
// TODO: Aren't we still holding a reference to the back buffer right now?
D3D::Reset();
- SAFE_RELEASE(s_screenshot_texture);
- SAFE_RELEASE(s_3d_vision_texture);
+ SAFE_RELEASE(m_screenshot_texture);
+ SAFE_RELEASE(m_3d_vision_texture);
m_backbuffer_width = D3D::GetBackBufferWidth();
m_backbuffer_height = D3D::GetBackBufferHeight();
}
UpdateDrawRectangle();
- s_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;
+ m_last_stereo_mode = g_ActiveConfig.stereo_mode != StereoMode::Off;
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr);
@@ -689,9 +676,9 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region
// ALWAYS call RestoreAPIState for each ResetAPIState call you're doing
void Renderer::ResetAPIState()
{
- D3D::stateman->PushBlendState(s_reset_blend_state);
- D3D::stateman->PushDepthState(s_reset_depth_state);
- D3D::stateman->PushRasterizerState(s_reset_rast_state);
+ D3D::stateman->PushBlendState(m_reset_blend_state);
+ D3D::stateman->PushDepthState(m_reset_depth_state);
+ D3D::stateman->PushRasterizerState(m_reset_rast_state);
}
void Renderer::RestoreAPIState()
@@ -818,7 +805,7 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
}
else if (g_ActiveConfig.stereo_mode == StereoMode::Nvidia3DVision)
{
- if (!s_3d_vision_texture)
+ if (!m_3d_vision_texture)
Create3DVisionTexture(m_backbuffer_width, m_backbuffer_height);
D3D11_VIEWPORT leftVp = CD3D11_VIEWPORT((float)dst.left, (float)dst.top, (float)dst.GetWidth(),
@@ -827,7 +814,7 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
(float)dst.GetWidth(), (float)dst.GetHeight());
// Render to staging texture which is double the width of the backbuffer
- D3D::context->OMSetRenderTargets(1, &s_3d_vision_texture->GetRTV(), nullptr);
+ D3D::context->OMSetRenderTargets(1, &m_3d_vision_texture->GetRTV(), nullptr);
D3D::context->RSSetViewports(1, &leftVp);
D3D::drawShadedTexQuad(src_texture->GetSRV(), src.AsRECT(), src_width, src_height,
@@ -845,7 +832,7 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
// recognize the signature and automatically include the right eye frame.
D3D11_BOX box = CD3D11_BOX(0, 0, 0, m_backbuffer_width, m_backbuffer_height, 1);
D3D::context->CopySubresourceRegion(D3D::GetBackBuffer()->GetTex(), 0, 0, 0, 0,
- s_3d_vision_texture->GetTex(), 0, &box);
+ m_3d_vision_texture->GetTex(), 0, &box);
// Restore render target to backbuffer
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr);