From dda3ca3d5fb0ba39630ab30c60d898f9aef49492 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 20 Sep 2014 21:55:58 +0200 Subject: [PATCH] D3D9 init error reporting improved. Use "override" properly in Host. --- Core/Host.h | 4 +-- UI/HostTypes.h | 45 +++++++++++------------ Windows/D3D9Base.cpp | 25 +++++++++---- Windows/EmuThread.cpp | 4 +-- Windows/WindowsHost.cpp | 8 +++-- Windows/WindowsHost.h | 56 ++++++++++++++--------------- headless/Headless.cpp | 4 +-- headless/StubHost.h | 30 ++++++++-------- headless/WindowsHeadlessHost.cpp | 4 +-- headless/WindowsHeadlessHost.h | 14 ++++---- headless/WindowsHeadlessHostDx9.cpp | 4 +-- headless/WindowsHeadlessHostDx9.h | 8 ++--- 12 files changed, 108 insertions(+), 98 deletions(-) diff --git a/Core/Host.h b/Core/Host.h index 545b81b24a..aeb2436eaf 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -40,8 +40,8 @@ public: virtual void SetDebugMode(bool mode) { } - virtual bool InitGL(std::string *error_string) = 0; - virtual void ShutdownGL() = 0; + virtual bool InitGraphics(std::string *error_string) = 0; + virtual void ShutdownGraphics() = 0; virtual void InitSound(PMixer *mixer) = 0; virtual void UpdateSound() {} diff --git a/UI/HostTypes.h b/UI/HostTypes.h index 3c6fc92923..7f16f1693a 100644 --- a/UI/HostTypes.h +++ b/UI/HostTypes.h @@ -28,31 +28,28 @@ class NativeHost : public Host { public: NativeHost() { - // hasRendered = false; } - virtual void UpdateUI() {} + void UpdateUI() override {} - virtual void UpdateMemView() {} - virtual void UpdateDisassembly() {} + void UpdateMemView() override {} + void UpdateDisassembly() override {} - virtual void SetDebugMode(bool mode) { } + void SetDebugMode(bool mode) override { } - virtual bool InitGL(std::string *error_message) { return true; } - virtual void ShutdownGL() {} + bool InitGraphics(std::string *error_message) override { return true; } + void ShutdownGraphics() override {} - virtual void InitSound(PMixer *mixer); - virtual void UpdateSound() {} - virtual void ShutdownSound(); + void InitSound(PMixer *mixer) override; + void UpdateSound() override {} + void ShutdownSound() override; // this is sent from EMU thread! Make sure that Host handles it properly! - virtual void BootDone() {} + void BootDone() override {} - virtual bool IsDebuggingEnabled() {return false;} - virtual bool AttemptLoadSymbolMap() {return false;} - virtual void ResetSymbolMap() {} - virtual void AddSymbol(std::string name, u32 addr, u32 size, int type=0) {} - virtual void SetWindowTitle(const char *message) {} + bool IsDebuggingEnabled() override {return false;} + bool AttemptLoadSymbolMap() override {return false;} + void SetWindowTitle(const char *message) override {} }; #if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) @@ -76,31 +73,31 @@ public: m_GPUFlag = 0; } - virtual void UpdateUI() { + virtual void UpdateUI() override { mainWindow->updateMenus(); } - virtual void UpdateMemView() { + virtual void UpdateMemView() override { if(mainWindow->GetDialogMemory()) mainWindow->GetDialogMemory()->Update(); } - virtual void UpdateDisassembly() { + virtual void UpdateDisassembly() override { if(mainWindow->GetDialogDisasm()) mainWindow->GetDialogDisasm()->Update(); if(mainWindow->GetDialogDisplaylist()) mainWindow->GetDialogDisplaylist()->Update(); } - virtual void SetDebugMode(bool mode) { + virtual void SetDebugMode(bool mode) override { if(mainWindow->GetDialogDisasm()) mainWindow->GetDialogDisasm()->SetDebugMode(mode); } - virtual bool InitGL(std::string *error_message) { return true; } - virtual void ShutdownGL() {} + virtual bool InitGraphics(std::string *error_message) override { return true; } + virtual void ShutdownGraphics() override {} - virtual void InitSound(PMixer *mixer); - virtual void UpdateSound() {} + virtual void InitSound(PMixer *mixer) override; + virtual void UpdateSound() override {} virtual void ShutdownSound(); // this is sent from EMU thread! Make sure that Host handles it properly! diff --git a/Windows/D3D9Base.cpp b/Windows/D3D9Base.cpp index a5bc1fab8f..899efe7409 100644 --- a/Windows/D3D9Base.cpp +++ b/Windows/D3D9Base.cpp @@ -58,6 +58,13 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { DIRECT3DCREATE9EX g_pfnCreate9ex; HMODULE hD3D9 = LoadLibrary(TEXT("d3d9.dll")); + + if (!hD3D9) { + ELOG("Missing d3d9.dll"); + *error_message = "D3D9.dll missing"; + return false; + } + g_pfnCreate9ex = (DIRECT3DCREATE9EX)GetProcAddress(hD3D9, "Direct3DCreate9Ex"); has9Ex = (g_pfnCreate9ex != NULL); @@ -67,13 +74,13 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { HRESULT result = g_pfnCreate9ex(D3D_SDK_VERSION, &d3dEx); d3d = d3dEx; if (FAILED(result)) { - ELOG("Failed to create D3D9Ex context"); + *error_message = "D3D9Ex available but context creation failed"; return false; } } else { d3d = Direct3DCreate9(D3D_SDK_VERSION); if (!d3d) { - ELOG("Failed to create D3D context"); + *error_message = "Failed to create D3D9 context"; return false; } } @@ -83,12 +90,14 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { D3DDISPLAYMODE d3ddm; if (FAILED(d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) { + *error_message = "GetAdapterDisplayMode failed"; d3d->Release(); return false; } adapterId = D3DADAPTER_DEFAULT; if (FAILED(d3d->GetDeviceCaps(adapterId, D3DDEVTYPE_HAL, &d3dCaps))) { + *error_message = "GetDeviceCaps failed (???)"; d3d->Release(); return false; } @@ -101,6 +110,7 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { D3DRTYPE_SURFACE, D3DFMT_D24S8))) { if (hr == D3DERR_NOTAVAILABLE) { + *error_message = "D24S8 depth/stencil not available"; d3d->Release(); return false; } @@ -143,7 +153,7 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { } if (FAILED(hr)) { - ELOG("Failed to create D3D device"); + *error_message = "Failed to create D3D device"; if (has9Ex) { d3dEx->Release(); } else { @@ -169,7 +179,7 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) { } void D3D9_Resize(HWND window) { - + // TODO! } void D3D9_Shutdown() { @@ -178,7 +188,8 @@ void D3D9_Shutdown() { device->EndScene(); device->Release(); d3d->Release(); - DX9::pD3Ddevice = NULL; - DX9::pD3Ddevice = NULL; - hWnd = NULL; + DX9::pD3Ddevice = nullptr; + DX9::pD3DdeviceEx = nullptr; + device = nullptr; + hWnd = nullptr; } diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index d46463ba43..e1f70f4fd9 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -125,7 +125,7 @@ unsigned int WINAPI TheThread(void *) } std::string error_string; - if (!host->InitGL(&error_string)) { + if (!host->InitGraphics(&error_string)) { Reporting::ReportMessage("Graphics init error: %s", error_string.c_str()); std::string full_error = StringFromFormat( "Failed initializing OpenGL. Try upgrading your graphics drivers.\n\nError message:\n\n%s", error_string.c_str()); MessageBox(0, ConvertUTF8ToWString(full_error).c_str(), L"OpenGL Error", MB_OK | MB_ICONERROR); @@ -172,7 +172,7 @@ shutdown: host = nativeHost; NativeShutdown(); host = oldHost; - host->ShutdownGL(); + host->ShutdownGraphics(); _InterlockedExchange(&emuThreadReady, THREAD_END); diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index b5f0060b62..b7a2bfc841 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -89,7 +89,7 @@ WindowsHost::WindowsHost(HWND mainWindow, HWND displayWindow) SetConsolePosition(); } -bool WindowsHost::InitGL(std::string *error_message) { +bool WindowsHost::InitGraphics(std::string *error_message) { switch (g_Config.iGPUBackend) { case GPU_BACKEND_OPENGL: return GL_Init(displayWindow_, error_message); @@ -100,7 +100,7 @@ bool WindowsHost::InitGL(std::string *error_message) { } } -void WindowsHost::ShutdownGL() { +void WindowsHost::ShutdownGraphics() { switch (g_Config.iGPUBackend) { case GPU_BACKEND_OPENGL: GL_Shutdown(); @@ -316,6 +316,10 @@ HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathL return hres; } +bool WindowsHost::CanCreateShortcut() { + return false; // Turn on when below function fixed +} + bool WindowsHost::CreateDesktopShortcut(std::string argumentPath, std::string gameTitle) { // TODO: not working correctly return false; diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index fc922ba1e9..5dc96cf1bf 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -24,47 +24,45 @@ extern float mouseDeltaX; extern float mouseDeltaY; -class WindowsHost : public Host -{ +class WindowsHost : public Host { public: WindowsHost(HWND mainWindow, HWND displayWindow); - ~WindowsHost() - { + ~WindowsHost() { UpdateConsolePosition(); } - void UpdateMemView(); - void UpdateDisassembly(); - void UpdateUI(); - virtual void UpdateScreen(); - void SetDebugMode(bool mode); + void UpdateMemView() override; + void UpdateDisassembly() override; + void UpdateUI() override; + void UpdateScreen() override; + void SetDebugMode(bool mode) override; - bool InitGL(std::string *error_message); - void PollControllers(InputState &input_state); - void ShutdownGL(); + bool InitGraphics(std::string *error_message) override; + void PollControllers(InputState &input_state) override; + void ShutdownGraphics() override; - void InitSound(PMixer *mixer); - void UpdateSound(); - void ShutdownSound(); + void InitSound(PMixer *mixer) override; + void UpdateSound() override; + void ShutdownSound() override; - bool IsDebuggingEnabled(); - void BootDone(); - bool AttemptLoadSymbolMap(); - void SaveSymbolMap(); - void SetWindowTitle(const char *message); + bool IsDebuggingEnabled() override; + void BootDone() override; + bool AttemptLoadSymbolMap() override; + void SaveSymbolMap() override; + void SetWindowTitle(const char *message) override; - virtual bool GPUDebuggingActive(); - virtual void GPUNotifyCommand(u32 pc); - virtual void GPUNotifyDisplay(u32 framebuf, u32 stride, int format); - virtual void GPUNotifyDraw(); - virtual void GPUNotifyTextureAttachment(u32 addr); - virtual void ToggleDebugConsoleVisibility(); + bool GPUDebuggingActive() override; + void GPUNotifyCommand(u32 pc) override; + void GPUNotifyDisplay(u32 framebuf, u32 stride, int format) override; + void GPUNotifyDraw() override; + void GPUNotifyTextureAttachment(u32 addr) override; + void ToggleDebugConsoleVisibility() override; - virtual bool CanCreateShortcut() {return false;} // Turn on when fixed - virtual bool CreateDesktopShortcut(std::string argumentPath, std::string title); + bool CanCreateShortcut() override; + bool CreateDesktopShortcut(std::string argumentPath, std::string title) override; - virtual void GoFullscreen(bool); + void GoFullscreen(bool) override; std::shared_ptr keyboard; diff --git a/headless/Headless.cpp b/headless/Headless.cpp index aca7eb2c55..37a89e3fef 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -292,7 +292,7 @@ int main(int argc, const char* argv[]) host = headlessHost; std::string error_string; - bool glWorking = host->InitGL(&error_string); + bool glWorking = host->InitGraphics(&error_string); LogManager::Init(); LogManager *logman = LogManager::GetInstance(); @@ -423,7 +423,7 @@ int main(int argc, const char* argv[]) } } - host->ShutdownGL(); + host->ShutdownGraphics(); delete host; host = NULL; headlessHost = NULL; diff --git a/headless/StubHost.h b/headless/StubHost.h index 99a49b169b..47dafe1e36 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -24,30 +24,30 @@ class HeadlessHost : public Host { public: - // virtual void StartThread() - virtual void UpdateUI() {} + // void StartThread() override + void UpdateUI() override {} - virtual void UpdateMemView() {} - virtual void UpdateDisassembly() {} + void UpdateMemView() override {} + void UpdateDisassembly() override {} - virtual void SetDebugMode(bool mode) { } + void SetDebugMode(bool mode) { } - virtual bool InitGL(std::string *error_message) {return false;} - virtual void ShutdownGL() {} + bool InitGraphics(std::string *error_message) override {return false;} + void ShutdownGraphics() override {} - virtual void InitSound(PMixer *mixer) {} - virtual void UpdateSound() {} - virtual void ShutdownSound() {} + void InitSound(PMixer *mixer) override {} + void UpdateSound() override {} + void ShutdownSound() override {} // this is sent from EMU thread! Make sure that Host handles it properly - virtual void BootDone() {} + void BootDone() override {} - virtual bool IsDebuggingEnabled() {return false;} - virtual bool AttemptLoadSymbolMap() { symbolMap.Clear(); return false; } + bool IsDebuggingEnabled() override { return false; } + bool AttemptLoadSymbolMap() override { symbolMap.Clear(); return false; } - virtual bool ShouldSkipUI() { return true; } + bool ShouldSkipUI() override { return true; } - virtual void SendDebugOutput(const std::string &output) { + void SendDebugOutput(const std::string &output) override { if (output.find('\n') != output.npos) { DoFlushDebugOutput(); fwrite(output.data(), sizeof(char), output.length(), stdout); diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index acf3639684..2680765d5e 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -154,7 +154,7 @@ void WindowsHeadlessHost::SetComparisonScreenshot(const std::string &filename) comparisonScreenshot = filename; } -bool WindowsHeadlessHost::InitGL(std::string *error_message) +bool WindowsHeadlessHost::InitGraphics(std::string *error_message) { hWnd = CreateHiddenWindow(); @@ -193,7 +193,7 @@ bool WindowsHeadlessHost::InitGL(std::string *error_message) return ResizeGL(); } -void WindowsHeadlessHost::ShutdownGL() +void WindowsHeadlessHost::ShutdownGraphics() { if (hRC) { diff --git a/headless/WindowsHeadlessHost.h b/headless/WindowsHeadlessHost.h index cdd9da913c..e5c70f2690 100644 --- a/headless/WindowsHeadlessHost.h +++ b/headless/WindowsHeadlessHost.h @@ -28,17 +28,17 @@ class WindowsHeadlessHost : public HeadlessHost { public: - virtual bool InitGL(std::string *error_message); - virtual void ShutdownGL(); + virtual bool InitGraphics(std::string *error_message) override; + virtual void ShutdownGraphics() override; - virtual void SwapBuffers(); + virtual void SwapBuffers() override; - virtual void SendDebugOutput(const std::string &output); - virtual void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h); - virtual void SetComparisonScreenshot(const std::string &filename); + virtual void SendDebugOutput(const std::string &output) override; + virtual void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) override; + virtual void SetComparisonScreenshot(const std::string &filename) override; protected: - bool ResizeGL(); + virtual bool ResizeGL(); void LoadNativeAssets(); void SendOrCollectDebugOutput(const std::string &output); diff --git a/headless/WindowsHeadlessHostDx9.cpp b/headless/WindowsHeadlessHostDx9.cpp index 2527cee166..da9260c89f 100644 --- a/headless/WindowsHeadlessHostDx9.cpp +++ b/headless/WindowsHeadlessHostDx9.cpp @@ -58,7 +58,7 @@ HWND DxCreateWindow() return CreateWindowEx(0, _T("PPSSPPHeadless"), _T("PPSSPPHeadless"), style, CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, NULL, NULL); } -bool WindowsHeadlessHostDx9::InitGL(std::string *error_message) +bool WindowsHeadlessHostDx9::InitGraphics(std::string *error_message) { LoadD3DX9Dynamic(); hWnd = DxCreateWindow(); @@ -79,7 +79,7 @@ bool WindowsHeadlessHostDx9::InitGL(std::string *error_message) return true; } -void WindowsHeadlessHostDx9::ShutdownGL() +void WindowsHeadlessHostDx9::ShutdownGraphics() { DX9::DestroyShaders(); DX9::fbo_shutdown(); diff --git a/headless/WindowsHeadlessHostDx9.h b/headless/WindowsHeadlessHostDx9.h index ef8093a632..ea41e64db6 100644 --- a/headless/WindowsHeadlessHostDx9.h +++ b/headless/WindowsHeadlessHostDx9.h @@ -29,11 +29,11 @@ class WindowsHeadlessHostDx9 : public WindowsHeadlessHost { public: - virtual bool InitGL(std::string *error_message); - virtual void ShutdownGL(); + bool InitGraphics(std::string *error_message) override; + void ShutdownGraphics() override; - virtual void SwapBuffers(); + void SwapBuffers() override; private: - bool ResizeGL(); + bool ResizeGL() override; }; \ No newline at end of file