Skip to content

Commit

Permalink
Add an escape route to D3D9 in case D3D11 fails to initialize. Cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Feb 17, 2017
1 parent b807442 commit 522ac5c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
7 changes: 7 additions & 0 deletions UI/PauseScreen.cpp
Expand Up @@ -43,6 +43,13 @@
#include "UI/OnScreenDisplay.h"
#include "UI/GameInfoCache.h"

AsyncImageFileView::AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams)
: UI::Clickable(layoutParams), canFocus_(true), filename_(filename), color_(0xFFFFFFFF), sizeMode_(sizeMode), texture_(nullptr), textureFailed_(false), fixedSizeW_(0.0f), fixedSizeH_(0.0f) {}

AsyncImageFileView::~AsyncImageFileView() {
delete texture_;
}

void AsyncImageFileView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
if (texture_) {
float texw = (float)texture_->Width();
Expand Down
7 changes: 2 additions & 5 deletions UI/PauseScreen.h
Expand Up @@ -69,11 +69,8 @@ class PrioritizedWorkQueue;
// of the view. TODO: Actually make async using the task.
class AsyncImageFileView : public UI::Clickable {
public:
AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams = 0)
: UI::Clickable(layoutParams), canFocus_(true), filename_(filename), color_(0xFFFFFFFF), sizeMode_(sizeMode), texture_(nullptr), textureFailed_(false), fixedSizeW_(0.0f), fixedSizeH_(0.0f) {}
~AsyncImageFileView() {
delete texture_;
}
AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams = 0);
~AsyncImageFileView();

void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;
Expand Down
19 changes: 17 additions & 2 deletions Windows/GPU/D3D11Context.cpp
Expand Up @@ -34,7 +34,6 @@ void D3D11Context::SwapInterval(int interval) {
bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
bool windowed = true;
hWnd_ = wnd;
HRESULT hr = S_OK;

UINT createDeviceFlags = 0;
#ifdef _DEBUG
Expand All @@ -56,6 +55,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
};
UINT numFeatureLevels = ARRAYSIZE(featureLevels);

HRESULT hr = S_OK;
// Temporarily commenting out until we can dynamically load D3D11CreateDevice.
for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) {
driverType_ = driverTypes[driverTypeIndex];
Expand All @@ -70,8 +70,23 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
if (SUCCEEDED(hr))
break;
}
if (FAILED(hr))

if (FAILED(hr)) {
const char *defaultError = "Your GPU does not appear to support Direct3D 11.\n\nWould you like to try again using Direct3D 9 instead?";
I18NCategory *err = GetI18NCategory("Error");

std::wstring error = ConvertUTF8ToWString(err->T("D3D11NotSupported", defaultError));
std::wstring title = ConvertUTF8ToWString(err->T("D3D11InitializationError", "Direct3D 11 initialization error"));
bool yes = IDYES == MessageBox(hWnd_, error.c_str(), title.c_str(), MB_ICONERROR | MB_YESNO);
if (yes) {
// Change the config to D3D and restart.
g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D9;
g_Config.Save();

W32Util::ExitAndRestart();
}
return false;
}

#ifdef _DEBUG
if (SUCCEEDED(device_->QueryInterface(__uuidof(ID3D11Debug), (void**)&d3dDebug_))) {
Expand Down
6 changes: 5 additions & 1 deletion ext/native/thin3d/thin3d_d3d11.cpp
Expand Up @@ -211,7 +211,11 @@ D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *co
}

D3D11DrawContext::~D3D11DrawContext() {

// Release references.
ID3D11RenderTargetView *view = nullptr;
context_->OMSetRenderTargets(1, &view, nullptr);
ID3D11ShaderResourceView *srv[2]{};
context_->PSSetShaderResources(0, 2, srv);
}

void D3D11DrawContext::HandleEvent(Event ev) {
Expand Down

0 comments on commit 522ac5c

Please sign in to comment.