CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/GPU/D3D11/D3D11Loader.cpp
Views: 1401
1
#include "ppsspp_config.h"
2
#include "Common/GPU/D3D11/D3D11Loader.h"
3
4
#if PPSSPP_PLATFORM(UWP)
5
#error This file should not be compiled for UWP.
6
#endif
7
8
static HMODULE g_DXGIModule;
9
static HMODULE g_D3D11Module;
10
static HMODULE g_D3DCompileModule;
11
12
LPCREATEDXGIFACTORY ptr_CreateDXGIFactory;
13
LPD3D11CREATEDEVICE ptr_D3D11CreateDevice;
14
pD3DCompile ptr_D3DCompile;
15
16
LoadD3D11Error LoadD3D11() {
17
if (g_D3D11Module) {
18
// Already done
19
return LoadD3D11Error::SUCCESS;
20
}
21
g_D3D11Module = LoadLibrary(L"d3d11.dll");
22
if (g_D3D11Module) {
23
ptr_D3D11CreateDevice = (LPD3D11CREATEDEVICE)GetProcAddress(g_D3D11Module, "D3D11CreateDevice");
24
} else {
25
return LoadD3D11Error::FAIL_NO_D3D11;
26
}
27
28
g_DXGIModule = LoadLibrary(L"dxgi.dll");
29
if (g_DXGIModule) {
30
ptr_CreateDXGIFactory = (LPCREATEDXGIFACTORY)GetProcAddress(g_DXGIModule, "CreateDXGIFactory1");
31
} else {
32
FreeLibrary(g_D3D11Module);
33
g_D3D11Module = nullptr;
34
return LoadD3D11Error::FAIL_NO_D3D11;
35
}
36
37
g_D3DCompileModule = LoadLibrary(D3DCOMPILER_DLL);
38
#if PPSSPP_ARCH(X86)
39
// Workaround for distributing both 32-bit and 64-bit versions of the DLL.
40
if (!g_D3DCompileModule)
41
g_D3DCompileModule = LoadLibrary(L"D3dcompiler_47.x86.dll");
42
#endif
43
if (!g_D3DCompileModule)
44
g_D3DCompileModule = LoadLibrary(L"D3dcompiler_42.dll");
45
46
if (!g_D3DCompileModule) {
47
FreeLibrary(g_D3D11Module);
48
g_D3D11Module = nullptr;
49
FreeLibrary(g_DXGIModule);
50
g_DXGIModule = nullptr;
51
return LoadD3D11Error::FAIL_NO_COMPILER;
52
}
53
ptr_D3DCompile = (pD3DCompile)GetProcAddress(g_D3DCompileModule, "D3DCompile");
54
55
return LoadD3D11Error::SUCCESS;
56
}
57
58
bool UnloadD3D11() {
59
if (!g_D3D11Module)
60
return false;
61
62
if (g_DXGIModule) {
63
FreeLibrary(g_DXGIModule);
64
g_DXGIModule = nullptr;
65
}
66
if (g_D3D11Module) {
67
FreeLibrary(g_D3D11Module);
68
g_D3D11Module = nullptr;
69
}
70
if (g_D3DCompileModule) {
71
FreeLibrary(g_D3DCompileModule);
72
g_D3DCompileModule = nullptr;
73
}
74
75
return true;
76
}
77
78