2010-06-13 13:50:06 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <d3dx11.h>
|
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/notebook.h>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "Atomic.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "LogManager.h"
|
|
|
|
|
|
|
|
#include "VideoConfig.h"
|
|
|
|
#include "Fifo.h"
|
|
|
|
#include "OpcodeDecoding.h"
|
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "VertexLoaderManager.h"
|
|
|
|
#include "VertexShaderManager.h"
|
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "CommandProcessor.h"
|
|
|
|
#include "PixelEngine.h"
|
|
|
|
#include "OnScreenDisplay.h"
|
2010-07-18 04:11:34 -06:00
|
|
|
#include "VideoState.h"
|
|
|
|
#include "XFBConvert.h"
|
|
|
|
#include "Render.h"
|
|
|
|
|
2010-11-17 19:21:26 -07:00
|
|
|
#include "MainBase.h"
|
2010-07-18 04:11:34 -06:00
|
|
|
#include "main.h"
|
|
|
|
#include "resource.h"
|
2010-11-15 02:54:07 -07:00
|
|
|
#include "VideoConfigDiag.h"
|
2010-07-18 04:11:34 -06:00
|
|
|
#include "TextureCache.h"
|
|
|
|
#include "VertexManager.h"
|
|
|
|
#include "VertexShaderCache.h"
|
|
|
|
#include "PixelShaderCache.h"
|
2010-06-13 13:50:06 -06:00
|
|
|
#include "D3DTexture.h"
|
|
|
|
#include "D3DUtil.h"
|
|
|
|
#include "W32Util/Misc.h"
|
|
|
|
#include "EmuWindow.h"
|
2010-09-27 20:15:02 -06:00
|
|
|
#include "FramebufferManager.h"
|
2010-08-29 17:08:56 -06:00
|
|
|
#include "DLCache.h"
|
2010-06-13 13:50:06 -06:00
|
|
|
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
|
|
|
|
bool IsD3D()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is used for the functions right below here which use wxwidgets
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-06-18 12:40:58 -06:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
2010-06-13 13:50:06 -06:00
|
|
|
#endif
|
|
|
|
|
2010-07-21 20:05:28 -06:00
|
|
|
void *DllDebugger(void *_hParent, bool Show)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2010-07-21 20:05:28 -06:00
|
|
|
return NULL;
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2010-07-06 07:14:51 -06:00
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
2010-06-13 13:50:06 -06:00
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
wxInitialize();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxUninitialize();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Callback_PeekMessages()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
return FALSE;
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
void UpdateFPSDisplay(const char *text)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
|
|
|
char temp[512];
|
2010-07-08 09:25:01 -06:00
|
|
|
sprintf_s(temp, 512, "SVN R%s: DX11: %s", svn_rev_str, text);
|
2010-07-06 07:14:51 -06:00
|
|
|
SetWindowTextA(EmuWindow::GetWnd(), temp);
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2010-06-18 12:40:58 -06:00
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
|
2010-09-27 20:15:02 -06:00
|
|
|
#ifdef DEBUGFAST
|
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D11 (DebugFast)");
|
|
|
|
#elif defined _DEBUG
|
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D11 (Debug)");
|
|
|
|
#else
|
|
|
|
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D11");
|
|
|
|
#endif
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
|
|
|
globals = _pPluginGlobals;
|
|
|
|
LogManager::SetInstance((LogManager*)globals->logManager);
|
|
|
|
}
|
|
|
|
|
2010-07-29 21:51:49 -06:00
|
|
|
void DllConfig(void *_hParent)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2010-11-17 20:50:50 -07:00
|
|
|
g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
|
|
|
|
|
2010-11-21 08:34:04 -07:00
|
|
|
HRESULT hr = D3D::GetDXGIFuncPointers();
|
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2010-11-15 02:54:07 -07:00
|
|
|
IDXGIFactory* factory;
|
|
|
|
IDXGIAdapter* ad;
|
2010-11-21 08:34:04 -07:00
|
|
|
hr = PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
2010-11-15 02:54:07 -07:00
|
|
|
if (FAILED(hr))
|
|
|
|
PanicAlert("Failed to create IDXGIFactory object");
|
|
|
|
|
|
|
|
char tmpstr[512] = {};
|
|
|
|
|
|
|
|
DXGI_ADAPTER_DESC desc;
|
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
|
|
|
{
|
|
|
|
ad->GetDesc(&desc);
|
|
|
|
WideCharToMultiByte(/*CP_UTF8*/CP_ACP, 0, desc.Description, -1, tmpstr, 512, 0, false);
|
2010-11-21 07:47:28 -07:00
|
|
|
g_Config.backend_info.Adapters.push_back(tmpstr);
|
|
|
|
ad->Release();
|
2010-11-15 02:54:07 -07:00
|
|
|
}
|
|
|
|
|
2010-11-21 07:47:28 -07:00
|
|
|
g_Config.backend_info.APIType = API_D3D11;
|
|
|
|
g_Config.backend_info.bUseRGBATextures = true; // the GX formats barely match any D3D11 formats
|
|
|
|
g_Config.backend_info.bSupportsEFBToRAM = false;
|
|
|
|
g_Config.backend_info.bSupportsRealXFB = false;
|
|
|
|
g_Config.backend_info.bAllowSignedBytes = true;
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
VideoConfigDiag *const diag = new VideoConfigDiag((wxWindow*)_hParent, "Direct3D11");
|
2010-11-15 02:54:07 -07:00
|
|
|
diag->ShowModal();
|
|
|
|
diag->Destroy();
|
2010-11-21 07:47:28 -07:00
|
|
|
#endif
|
|
|
|
UpdateActiveConfig();
|
2010-11-15 02:54:07 -07:00
|
|
|
|
|
|
|
g_Config.Save((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
|
2010-11-21 07:47:28 -07:00
|
|
|
|
|
|
|
factory->Release();
|
2010-11-21 08:34:04 -07:00
|
|
|
|
|
|
|
D3D::UnloadDXGI();
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
void Initialize(void *init)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
|
|
|
frameCount = 0;
|
2010-09-27 20:15:02 -06:00
|
|
|
SVideoInitialize *_pVideoInitialize = (SVideoInitialize*)init;
|
|
|
|
// Create a shortcut to _pVideoInitialize that can also update it
|
|
|
|
g_VideoInitialize = *(_pVideoInitialize);
|
2010-06-13 13:50:06 -06:00
|
|
|
InitXFBConvTables();
|
|
|
|
|
|
|
|
g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
|
|
|
|
g_Config.GameIniLoad(globals->game_ini);
|
|
|
|
UpdateActiveConfig();
|
|
|
|
|
|
|
|
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, _T("Loading - Please wait."));
|
|
|
|
if (g_VideoInitialize.pWindowHandle == NULL)
|
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "An error has occurred while trying to create the window.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_VideoInitialize.pPeekMessages = &Callback_PeekMessages;
|
|
|
|
g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay;
|
|
|
|
|
2010-07-06 07:14:51 -06:00
|
|
|
_pVideoInitialize->pPeekMessages = g_VideoInitialize.pPeekMessages;
|
|
|
|
_pVideoInitialize->pUpdateFPSDisplay = g_VideoInitialize.pUpdateFPSDisplay;
|
2010-09-27 20:15:02 -06:00
|
|
|
|
|
|
|
// Now the window handle is written
|
2010-07-06 07:14:51 -06:00
|
|
|
_pVideoInitialize->pWindowHandle = g_VideoInitialize.pWindowHandle;
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
OSD::AddMessage("Dolphin Direct3D11 Video Plugin.", 5000);
|
2010-06-13 13:50:06 -06:00
|
|
|
s_PluginInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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
|
2010-11-17 19:21:26 -07:00
|
|
|
g_renderer = new DX11::Renderer;
|
2010-10-19 16:24:27 -06:00
|
|
|
g_texture_cache = new DX11::TextureCache;
|
2010-10-02 18:41:06 -06:00
|
|
|
g_vertex_manager = new DX11::VertexManager;
|
2010-07-18 04:11:34 -06:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
D3D::InitUtils();
|
|
|
|
|
|
|
|
// VideoCommon
|
|
|
|
BPInit();
|
2010-06-13 13:50:06 -06:00
|
|
|
Fifo_Init();
|
|
|
|
VertexLoaderManager::Init();
|
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2010-07-06 07:14:51 -06:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
2010-08-29 17:08:56 -06:00
|
|
|
DLCache::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
|
2010-06-13 13:50:06 -06:00
|
|
|
g_VideoInitialize.pCoreMessage(WM_USER_CREATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown()
|
|
|
|
{
|
2010-09-27 20:15:02 -06:00
|
|
|
s_PluginInitialized = false;
|
|
|
|
|
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
|
|
|
|
|
|
|
// VideoCommon
|
2010-08-29 17:08:56 -06:00
|
|
|
DLCache::Shutdown();
|
2010-09-27 20:15:02 -06:00
|
|
|
Fifo_Shutdown();
|
2010-06-13 13:50:06 -06:00
|
|
|
CommandProcessor::Shutdown();
|
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
2010-07-18 04:11:34 -06:00
|
|
|
|
|
|
|
// internal interfaces
|
|
|
|
D3D::ShutdownUtils();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
2010-10-02 18:41:06 -06:00
|
|
|
delete g_vertex_manager;
|
2010-10-19 16:24:27 -06:00
|
|
|
delete g_texture_cache;
|
2010-11-17 19:21:26 -07:00
|
|
|
delete g_renderer;
|
2010-06-13 13:50:06 -06:00
|
|
|
EmuWindow::Close();
|
2010-07-18 04:11:34 -06:00
|
|
|
|
2010-06-13 13:50:06 -06:00
|
|
|
s_PluginInitialized = false;
|
|
|
|
}
|
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
void DoState(unsigned char **ptr, int mode)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2010-09-27 20:15:02 -06:00
|
|
|
// Clear texture cache because it might have written to RAM
|
2010-06-13 13:50:06 -06:00
|
|
|
CommandProcessor::FifoCriticalEnter();
|
|
|
|
TextureCache::Invalidate(false);
|
|
|
|
CommandProcessor::FifoCriticalLeave();
|
2010-09-27 20:15:02 -06:00
|
|
|
// No need to clear shader caches
|
2010-06-13 13:50:06 -06:00
|
|
|
PointerWrap p(ptr, mode);
|
|
|
|
VideoCommon_DoState(p);
|
|
|
|
}
|