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
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
|
|
|
|
#include "LogManager.h"
|
|
|
|
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "CommandProcessor.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
#include "Fifo.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "OnScreenDisplay.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
#include "OpcodeDecoding.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "PixelEngine.h"
|
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "VideoConfig.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexShaderManager.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "Core.h"
|
2011-03-15 23:09:12 +00:00
|
|
|
#include "Host.h"
|
2010-07-18 10:11:34 +00:00
|
|
|
|
2011-02-13 06:06:32 +00:00
|
|
|
#include "Debugger/DebuggerPanel.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "EmuWindow.h"
|
2013-04-08 17:39:43 +00:00
|
|
|
#include "IndexGenerator.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "IniFile.h"
|
2010-11-15 09:54:07 +00:00
|
|
|
#include "VideoConfigDiag.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
|
|
|
#include "D3DUtil.h"
|
|
|
|
#include "D3DBase.h"
|
2013-03-01 18:30:37 +00:00
|
|
|
#include "PerfQuery.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
#include "PixelShaderCache.h"
|
2010-07-18 10:11:34 +00:00
|
|
|
#include "TextureCache.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "VertexShaderCache.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "VideoBackend.h"
|
|
|
|
#include "ConfigManager.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;
|
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::UpdateFPSDisplay(const char *text)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-12-19 23:13:26 +00:00
|
|
|
TCHAR temp[512];
|
2013-09-22 15:48:48 +00:00
|
|
|
swprintf_s(temp, sizeof(temp)/sizeof(TCHAR), _T("%hs | D3D | %hs"), scm_rev_str, text);
|
2011-12-19 23:13:26 +00:00
|
|
|
EmuWindow::SetWindowText(temp);
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
std::string VideoBackend::GetName()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
std::string VideoBackend::GetDisplayName()
|
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;
|
|
|
|
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
|
|
|
g_Config.backend_info.bSupportsPixelLighting = 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;
|
|
|
|
|
2013-09-07 21:02:49 +00:00
|
|
|
const SCoreStartupParameter& core_params = SConfig::GetInstance().m_LocalCoreStartupParameter;
|
|
|
|
|
2011-04-25 20:06:45 +00:00
|
|
|
g_Config.Load((File::GetUserPath(D_CONFIG_IDX) + "gfx_dx11.ini").c_str());
|
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."));
|
|
|
|
if (window_handle == NULL)
|
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;
|
|
|
|
g_renderer = NULL;
|
2012-06-21 12:21:16 +00:00
|
|
|
g_texture_cache = NULL;
|
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
|
|
|
}
|