2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
2010-06-13 19:50:06 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/LogManager.h"
|
2014-03-12 19:33:41 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
2010-07-18 10:11:34 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/VideoConfigDiag.h"
|
|
|
|
#include "DolphinWX/Debugger/DebuggerPanel.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DUtil.h"
|
|
|
|
#include "VideoBackends/D3D/Globals.h"
|
|
|
|
#include "VideoBackends/D3D/PerfQuery.h"
|
|
|
|
#include "VideoBackends/D3D/PixelShaderCache.h"
|
|
|
|
#include "VideoBackends/D3D/TextureCache.h"
|
|
|
|
#include "VideoBackends/D3D/VertexManager.h"
|
|
|
|
#include "VideoBackends/D3D/VertexShaderCache.h"
|
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/EmuWindow.h"
|
|
|
|
#include "VideoCommon/Fifo.h"
|
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
namespace DX11
|
2011-01-14 15:09:30 +00:00
|
|
|
{
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
unsigned int VideoBackend::PeekMessages()
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
return FALSE;
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
void VideoBackend::UpdateFPSDisplay(const std::string& text)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2014-03-12 19:33:41 +00:00
|
|
|
EmuWindow::SetWindowText(StringFromFormat("%s | D3D | %s", scm_rev_str, text.c_str()));
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 23:39:55 +00:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 13:51:43 +00:00
|
|
|
{
|
2013-09-22 15:48:48 +00:00
|
|
|
return "D3D";
|
2013-05-01 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 23:39:55 +00:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2013-09-22 15:48:48 +00:00
|
|
|
return "Direct3D";
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
void InitBackendInfo()
|
|
|
|
{
|
2011-01-29 20:16:51 +00:00
|
|
|
HRESULT hr = DX11::D3D::LoadDXGI();
|
|
|
|
if (SUCCEEDED(hr)) hr = DX11::D3D::LoadD3D();
|
2010-11-23 19:58:02 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-01-29 20:16:51 +00:00
|
|
|
DX11::D3D::UnloadDXGI();
|
2010-11-23 19:58:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-21 15:34:04 +00:00
|
|
|
|
2013-09-22 16:07:21 +00:00
|
|
|
g_Config.backend_info.APIType = API_D3D;
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.backend_info.bUseRGBATextures = true; // the GX formats barely match any D3D11 formats
|
2013-02-18 16:14:56 +00:00
|
|
|
g_Config.backend_info.bUseMinimalMipCount = true;
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
2013-04-08 14:34:47 +00:00
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
2013-10-14 13:16:42 +00:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = false;
|
2011-05-31 20:16:59 +00:00
|
|
|
|
2010-11-15 09:54:07 +00:00
|
|
|
IDXGIFactory* factory;
|
|
|
|
IDXGIAdapter* ad;
|
2011-01-29 20:16:51 +00:00
|
|
|
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
2010-11-15 09:54:07 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
PanicAlert("Failed to create IDXGIFactory object");
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
// adapters
|
|
|
|
g_Config.backend_info.Adapters.clear();
|
2010-11-23 19:58:02 +00:00
|
|
|
g_Config.backend_info.AAModes.clear();
|
2010-11-21 14:47:28 +00:00
|
|
|
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND)
|
2010-11-15 09:54:07 +00:00
|
|
|
{
|
2013-07-22 12:38:09 +00:00
|
|
|
const size_t adapter_index = g_Config.backend_info.Adapters.size();
|
|
|
|
|
2013-02-28 00:01:48 +00:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
2010-11-15 09:54:07 +00:00
|
|
|
ad->GetDesc(&desc);
|
2010-11-23 19:58:02 +00:00
|
|
|
|
|
|
|
// TODO: These don't get updated on adapter change, yet
|
2013-07-22 12:38:09 +00:00
|
|
|
if (adapter_index == g_Config.iAdapter)
|
2010-11-23 19:58:02 +00:00
|
|
|
{
|
|
|
|
char buf[32];
|
2011-06-11 19:37:21 +00:00
|
|
|
std::vector<DXGI_SAMPLE_DESC> modes;
|
|
|
|
modes = DX11::D3D::EnumAAModes(ad);
|
|
|
|
for (unsigned int i = 0; i < modes.size(); ++i)
|
2010-11-23 19:58:02 +00:00
|
|
|
{
|
2013-04-02 22:44:27 +00:00
|
|
|
if (i == 0) sprintf_s(buf, 32, _trans("None"));
|
|
|
|
else if (modes[i].Quality) sprintf_s(buf, 32, _trans("%d samples (quality level %d)"), modes[i].Count, modes[i].Quality);
|
|
|
|
else sprintf_s(buf, 32, _trans("%d samples"), modes[i].Count);
|
2010-11-23 19:58:02 +00:00
|
|
|
g_Config.backend_info.AAModes.push_back(buf);
|
|
|
|
}
|
2013-07-22 12:38:09 +00:00
|
|
|
|
|
|
|
// Requires the earlydepthstencil attribute (only available in shader model 5)
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = (DX11::D3D::GetFeatureLevel(ad) == D3D_FEATURE_LEVEL_11_0);
|
2010-11-23 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 00:01:48 +00:00
|
|
|
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
|
2010-11-21 14:47:28 +00:00
|
|
|
ad->Release();
|
2010-11-15 09:54:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
factory->Release();
|
2010-11-21 14:47:28 +00:00
|
|
|
|
2011-02-05 02:13:33 +00:00
|
|
|
// Clear ppshaders string vector
|
|
|
|
g_Config.backend_info.PPShaders.clear();
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
DX11::D3D::UnloadDXGI();
|
|
|
|
DX11::D3D::UnloadD3D();
|
2011-05-31 20:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::ShowConfig(void *_hParent)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
InitBackendInfo();
|
2013-09-22 15:48:48 +00:00
|
|
|
VideoConfigDiag diag((wxWindow*)_hParent, _trans("Direct3D"), "gfx_dx11");
|
2011-05-31 20:16:59 +00:00
|
|
|
diag.ShowModal();
|
2010-11-22 22:17:35 +00:00
|
|
|
#endif
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 21:14:13 +00:00
|
|
|
bool VideoBackend::Initialize(void *&window_handle)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2012-01-02 10:20:22 +00:00
|
|
|
InitializeShared();
|
2010-11-22 22:17:35 +00:00
|
|
|
InitBackendInfo();
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
frameCount = 0;
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_dx11.ini");
|
2013-09-23 06:39:14 +00:00
|
|
|
g_Config.GameIniLoad();
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.UpdateProjectionHack();
|
|
|
|
g_Config.VerifyValidity();
|
2010-06-13 19:50:06 +00:00
|
|
|
UpdateActiveConfig();
|
|
|
|
|
2011-02-25 21:14:13 +00:00
|
|
|
window_handle = (void*)EmuWindow::Create((HWND)window_handle, GetModuleHandle(0), _T("Loading - Please wait."));
|
2014-03-09 20:14:26 +00:00
|
|
|
if (window_handle == nullptr)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "An error has occurred while trying to create the window.");
|
2011-02-25 21:14:13 +00:00
|
|
|
return false;
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = true;
|
2011-02-25 21:14:13 +00:00
|
|
|
|
2011-03-02 15:13:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::Video_Prepare()
|
|
|
|
{
|
2010-09-28 02:15:02 +00:00
|
|
|
// Better be safe...
|
2010-06-13 19:50:06 +00:00
|
|
|
s_efbAccessRequested = FALSE;
|
|
|
|
s_FifoShuttingDown = FALSE;
|
|
|
|
s_swapRequested = FALSE;
|
2010-07-18 10:11:34 +00:00
|
|
|
|
|
|
|
// internal interfaces
|
2011-01-31 01:28:32 +00:00
|
|
|
g_renderer = new Renderer;
|
|
|
|
g_texture_cache = new TextureCache;
|
|
|
|
g_vertex_manager = new VertexManager;
|
2013-03-01 18:30:37 +00:00
|
|
|
g_perf_query = new PerfQuery;
|
2011-01-31 01:28:32 +00:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
D3D::InitUtils();
|
2010-07-18 10:11:34 +00:00
|
|
|
|
|
|
|
// VideoCommon
|
|
|
|
BPInit();
|
2010-06-13 19:50:06 +00:00
|
|
|
Fifo_Init();
|
2013-04-08 17:39:43 +00:00
|
|
|
IndexGenerator::Init();
|
2010-06-13 19:50:06 +00:00
|
|
|
VertexLoaderManager::Init();
|
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2010-07-06 13:14:51 +00:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Tell the host that the window is ready
|
2011-03-15 23:09:12 +00:00
|
|
|
Host_Message(WM_USER_CREATE);
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::Shutdown()
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = false;
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
// TODO: should be in Video_Cleanup
|
2011-03-02 15:13:13 +00:00
|
|
|
if (g_renderer)
|
|
|
|
{
|
|
|
|
s_efbAccessRequested = FALSE;
|
|
|
|
s_FifoShuttingDown = FALSE;
|
|
|
|
s_swapRequested = FALSE;
|
|
|
|
|
|
|
|
// VideoCommon
|
|
|
|
Fifo_Shutdown();
|
|
|
|
CommandProcessor::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
|
|
|
|
// internal interfaces
|
|
|
|
D3D::ShutdownUtils();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
2013-03-01 18:30:37 +00:00
|
|
|
delete g_perf_query;
|
2011-03-02 15:13:13 +00:00
|
|
|
delete g_vertex_manager;
|
|
|
|
delete g_texture_cache;
|
|
|
|
delete g_renderer;
|
2014-03-09 20:14:26 +00:00
|
|
|
g_renderer = nullptr;
|
|
|
|
g_texture_cache = nullptr;
|
2011-03-02 15:13:13 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
void VideoBackend::Video_Cleanup() {
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|