2013-04-17 21:29:41 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
2014-03-12 13:33:41 -06:00
|
|
|
#include "Common/StringUtil.h"
|
2014-06-05 17:29:54 -06:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
2010-07-18 04:11:34 -06:00
|
|
|
|
2014-02-17 03:18:15 -07: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 09:43:08 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.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 13:50:06 -06:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace DX11
|
2011-01-14 08:09:30 -07:00
|
|
|
{
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
unsigned int VideoBackend::PeekMessages()
|
2010-06-13 13:50:06 -06: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 13:33:41 -06:00
|
|
|
void VideoBackend::UpdateFPSDisplay(const std::string& text)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2014-06-14 16:23:43 -06:00
|
|
|
std::string str = StringFromFormat("%s | D3D | %s", scm_rev_str, text.c_str());
|
|
|
|
SetWindowTextA((HWND)m_window_handle, str.c_str());
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:39:55 -06:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 07:51:43 -06:00
|
|
|
{
|
2013-09-22 09:48:48 -06:00
|
|
|
return "D3D";
|
2013-05-01 07:51:43 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:39:55 -06:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2013-09-22 09:48:48 -06:00
|
|
|
return "Direct3D";
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2010-11-22 15:17:35 -07:00
|
|
|
void InitBackendInfo()
|
|
|
|
{
|
2011-01-29 13:16:51 -07:00
|
|
|
HRESULT hr = DX11::D3D::LoadDXGI();
|
|
|
|
if (SUCCEEDED(hr)) hr = DX11::D3D::LoadD3D();
|
2010-11-23 12:58:02 -07:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-01-29 13:16:51 -07:00
|
|
|
DX11::D3D::UnloadDXGI();
|
2010-11-23 12:58:02 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-11-21 08:34:04 -07:00
|
|
|
|
2013-09-22 10:07:21 -06:00
|
|
|
g_Config.backend_info.APIType = API_D3D;
|
2011-05-31 14:16:59 -06:00
|
|
|
g_Config.backend_info.bUseRGBATextures = true; // the GX formats barely match any D3D11 formats
|
2013-02-18 09:14:56 -07:00
|
|
|
g_Config.backend_info.bUseMinimalMipCount = true;
|
2014-07-19 12:18:03 -06:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
2011-05-31 14:16:59 -06:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
2013-04-08 08:34:47 -06:00
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
2013-10-14 07:16:42 -06:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = false;
|
2011-05-31 14:16:59 -06:00
|
|
|
|
2010-11-15 02:54:07 -07:00
|
|
|
IDXGIFactory* factory;
|
|
|
|
IDXGIAdapter* ad;
|
2011-01-29 13:16:51 -07:00
|
|
|
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
2010-11-15 02:54:07 -07:00
|
|
|
if (FAILED(hr))
|
|
|
|
PanicAlert("Failed to create IDXGIFactory object");
|
|
|
|
|
2010-11-22 15:17:35 -07:00
|
|
|
// adapters
|
|
|
|
g_Config.backend_info.Adapters.clear();
|
2010-11-23 12:58:02 -07:00
|
|
|
g_Config.backend_info.AAModes.clear();
|
2010-11-21 07:47:28 -07:00
|
|
|
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND)
|
2010-11-15 02:54:07 -07:00
|
|
|
{
|
2013-07-22 06:38:09 -06:00
|
|
|
const size_t adapter_index = g_Config.backend_info.Adapters.size();
|
|
|
|
|
2013-02-27 17:01:48 -07:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
2010-11-15 02:54:07 -07:00
|
|
|
ad->GetDesc(&desc);
|
2010-11-23 12:58:02 -07:00
|
|
|
|
|
|
|
// TODO: These don't get updated on adapter change, yet
|
2013-07-22 06:38:09 -06:00
|
|
|
if (adapter_index == g_Config.iAdapter)
|
2010-11-23 12:58:02 -07:00
|
|
|
{
|
2014-06-02 23:08:54 -06:00
|
|
|
std::string samples;
|
|
|
|
std::vector<DXGI_SAMPLE_DESC> modes = DX11::D3D::EnumAAModes(ad);
|
2011-06-11 13:37:21 -06:00
|
|
|
for (unsigned int i = 0; i < modes.size(); ++i)
|
2010-11-23 12:58:02 -07:00
|
|
|
{
|
2014-06-02 23:08:54 -06:00
|
|
|
if (i == 0)
|
|
|
|
samples = _trans("None");
|
|
|
|
else if (modes[i].Quality)
|
|
|
|
samples = StringFromFormat(_trans("%d samples (quality level %d)"), modes[i].Count, modes[i].Quality);
|
|
|
|
else
|
|
|
|
samples = StringFromFormat(_trans("%d samples"), modes[i].Count);
|
|
|
|
|
|
|
|
g_Config.backend_info.AAModes.push_back(samples);
|
2010-11-23 12:58:02 -07:00
|
|
|
}
|
2013-07-22 06:38:09 -06: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 12:58:02 -07:00
|
|
|
}
|
|
|
|
|
2013-02-27 17:01:48 -07:00
|
|
|
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
|
2010-11-21 07:47:28 -07:00
|
|
|
ad->Release();
|
2010-11-15 02:54:07 -07:00
|
|
|
}
|
|
|
|
|
2010-11-22 15:17:35 -07:00
|
|
|
factory->Release();
|
2010-11-21 07:47:28 -07:00
|
|
|
|
2011-02-04 19:13:33 -07:00
|
|
|
// Clear ppshaders string vector
|
|
|
|
g_Config.backend_info.PPShaders.clear();
|
|
|
|
|
2011-01-29 13:16:51 -07:00
|
|
|
DX11::D3D::UnloadDXGI();
|
|
|
|
DX11::D3D::UnloadD3D();
|
2011-05-31 14:16:59 -06:00
|
|
|
}
|
|
|
|
|
2014-08-03 18:07:27 -06:00
|
|
|
void VideoBackend::ShowConfig(void *hParent)
|
2011-05-31 14:16:59 -06:00
|
|
|
{
|
|
|
|
InitBackendInfo();
|
2014-08-03 18:07:27 -06:00
|
|
|
Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_dx11");
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2011-02-25 14:14:13 -07:00
|
|
|
bool VideoBackend::Initialize(void *&window_handle)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2014-06-14 16:23:43 -06:00
|
|
|
if (window_handle == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2012-01-02 03:20:22 -07:00
|
|
|
InitializeShared();
|
2010-11-22 15:17:35 -07:00
|
|
|
InitBackendInfo();
|
|
|
|
|
2010-06-13 13:50:06 -06:00
|
|
|
frameCount = 0;
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_dx11.ini");
|
2013-09-23 00:39:14 -06:00
|
|
|
g_Config.GameIniLoad();
|
2011-05-31 14:16:59 -06:00
|
|
|
g_Config.UpdateProjectionHack();
|
|
|
|
g_Config.VerifyValidity();
|
2010-06-13 13:50:06 -06:00
|
|
|
UpdateActiveConfig();
|
|
|
|
|
2014-06-14 16:23:43 -06:00
|
|
|
m_window_handle = window_handle;
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2011-02-13 19:18:03 -07:00
|
|
|
s_BackendInitialized = true;
|
2011-02-25 14:14:13 -07:00
|
|
|
|
2011-03-02 08:13:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::Video_Prepare()
|
|
|
|
{
|
2010-09-27 20:15:02 -06:00
|
|
|
// Better be safe...
|
2010-06-13 13:50:06 -06:00
|
|
|
s_efbAccessRequested = FALSE;
|
|
|
|
s_FifoShuttingDown = FALSE;
|
|
|
|
s_swapRequested = FALSE;
|
2010-07-18 04:11:34 -06:00
|
|
|
|
|
|
|
// internal interfaces
|
2014-06-14 16:23:43 -06:00
|
|
|
g_renderer = new Renderer(m_window_handle);
|
2011-01-30 18:28:32 -07:00
|
|
|
g_texture_cache = new TextureCache;
|
|
|
|
g_vertex_manager = new VertexManager;
|
2013-03-01 11:30:37 -07:00
|
|
|
g_perf_query = new PerfQuery;
|
2011-01-30 18:28:32 -07:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
D3D::InitUtils();
|
2010-07-18 04:11:34 -06:00
|
|
|
|
|
|
|
// VideoCommon
|
|
|
|
BPInit();
|
2010-06-13 13:50:06 -06:00
|
|
|
Fifo_Init();
|
2013-04-08 11:39:43 -06:00
|
|
|
IndexGenerator::Init();
|
2010-06-13 13:50:06 -06:00
|
|
|
VertexLoaderManager::Init();
|
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2010-07-06 07:14:51 -06:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
// Tell the host that the window is ready
|
2011-03-15 17:09:12 -06:00
|
|
|
Host_Message(WM_USER_CREATE);
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
void VideoBackend::Shutdown()
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2011-02-13 19:18:03 -07:00
|
|
|
s_BackendInitialized = false;
|
2010-09-27 20:15:02 -06:00
|
|
|
|
2013-02-26 08:42:32 -07:00
|
|
|
// TODO: should be in Video_Cleanup
|
2011-03-02 08:13:13 -07: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 11:30:37 -07:00
|
|
|
delete g_perf_query;
|
2011-03-02 08:13:13 -07:00
|
|
|
delete g_vertex_manager;
|
|
|
|
delete g_texture_cache;
|
|
|
|
delete g_renderer;
|
2014-03-09 14:14:26 -06:00
|
|
|
g_renderer = nullptr;
|
|
|
|
g_texture_cache = nullptr;
|
2011-03-02 08:13:13 -07:00
|
|
|
}
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
2011-01-30 18:28:32 -07:00
|
|
|
|
2013-02-26 08:42:32 -07:00
|
|
|
void VideoBackend::Video_Cleanup() {
|
|
|
|
}
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
}
|