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/GPU/GPU.cpp
Views: 1401
1
// Copyright (c) 2015- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "ppsspp_config.h"
19
20
#include "Common/TimeUtil.h"
21
#include "Common/GraphicsContext.h"
22
#include "Core/Core.h"
23
24
#include "GPU/GPU.h"
25
#include "GPU/GPUInterface.h"
26
27
#if PPSSPP_API(ANY_GL)
28
#include "GPU/GLES/GPU_GLES.h"
29
#endif
30
#include "GPU/Vulkan/GPU_Vulkan.h"
31
#include "GPU/Software/SoftGpu.h"
32
33
#if PPSSPP_API(D3D9)
34
#include "GPU/Directx9/GPU_DX9.h"
35
#endif
36
37
#if PPSSPP_API(D3D11)
38
#include "GPU/D3D11/GPU_D3D11.h"
39
#endif
40
41
GPUStatistics gpuStats;
42
GPUInterface *gpu;
43
GPUDebugInterface *gpuDebug;
44
45
template <typename T>
46
static void SetGPU(T *obj) {
47
gpu = obj;
48
gpuDebug = obj;
49
}
50
51
#ifdef USE_CRT_DBG
52
#undef new
53
#endif
54
55
bool GPU_IsReady() {
56
return gpu != nullptr;
57
}
58
59
bool GPU_IsStarted() {
60
if (gpu)
61
return gpu->IsStarted();
62
return false;
63
}
64
65
bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
66
const auto &gpuCore = PSP_CoreParameter().gpuCore;
67
_assert_(draw || gpuCore == GPUCORE_SOFTWARE);
68
#if PPSSPP_PLATFORM(UWP)
69
if (gpuCore == GPUCORE_SOFTWARE) {
70
SetGPU(new SoftGPU(ctx, draw));
71
} else {
72
SetGPU(new GPU_D3D11(ctx, draw));
73
}
74
return true;
75
#else
76
switch (gpuCore) {
77
case GPUCORE_GLES:
78
// Disable GLES on ARM Windows (but leave it enabled on other ARM platforms).
79
#if PPSSPP_API(ANY_GL)
80
SetGPU(new GPU_GLES(ctx, draw));
81
break;
82
#else
83
return false;
84
#endif
85
case GPUCORE_SOFTWARE:
86
SetGPU(new SoftGPU(ctx, draw));
87
break;
88
case GPUCORE_DIRECTX9:
89
#if PPSSPP_API(D3D9)
90
SetGPU(new GPU_DX9(ctx, draw));
91
break;
92
#else
93
return false;
94
#endif
95
case GPUCORE_DIRECTX11:
96
#if PPSSPP_API(D3D11)
97
SetGPU(new GPU_D3D11(ctx, draw));
98
break;
99
#else
100
return false;
101
#endif
102
#if !PPSSPP_PLATFORM(SWITCH)
103
case GPUCORE_VULKAN:
104
if (!ctx) {
105
ERROR_LOG(Log::G3D, "Unable to init Vulkan GPU backend, no context");
106
break;
107
}
108
SetGPU(new GPU_Vulkan(ctx, draw));
109
break;
110
#endif
111
}
112
113
if (gpu && !gpu->IsStarted())
114
SetGPU<SoftGPU>(nullptr);
115
116
return gpu != nullptr;
117
#endif
118
}
119
#ifdef USE_CRT_DBG
120
#define new DBG_NEW
121
#endif
122
123
void GPU_Shutdown() {
124
// Reduce the risk for weird races with the Windows GE debugger.
125
gpuDebug = nullptr;
126
127
delete gpu;
128
gpu = nullptr;
129
}
130
131
const char *RasterChannelToString(RasterChannel channel) {
132
return channel == RASTER_COLOR ? "COLOR" : "DEPTH";
133
}
134
135