Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/GPU.cpp
3185 views
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
#include "Core/System.h"
24
25
#include "GPU/GPU.h"
26
#include "GPU/GPUCommon.h"
27
28
#if PPSSPP_API(ANY_GL)
29
#include "GPU/GLES/GPU_GLES.h"
30
#endif
31
#include "GPU/Vulkan/GPU_Vulkan.h"
32
#include "GPU/Software/SoftGpu.h"
33
34
#if PPSSPP_API(D3D11)
35
#include "GPU/D3D11/GPU_D3D11.h"
36
#endif
37
38
GPUStatistics gpuStats;
39
GPUCommon *gpu;
40
GPUDebugInterface *gpuDebug;
41
42
#ifdef USE_CRT_DBG
43
#undef new
44
#endif
45
46
static GPUCommon *CreateGPUCore(GPUCore gpuCore, GraphicsContext *ctx, Draw::DrawContext *draw) {
47
#if PPSSPP_PLATFORM(UWP)
48
// TODO: Can probably remove this special case.
49
if (gpuCore == GPUCORE_SOFTWARE) {
50
return new SoftGPU(ctx, draw);
51
} else {
52
return new GPU_D3D11(ctx, draw);
53
}
54
#else
55
switch (gpuCore) {
56
case GPUCORE_GLES:
57
// Disable GLES on ARM Windows (but leave it enabled on other ARM platforms).
58
#if PPSSPP_API(ANY_GL)
59
return new GPU_GLES(ctx, draw);
60
#else
61
return nullptr;
62
#endif
63
case GPUCORE_SOFTWARE:
64
return new SoftGPU(ctx, draw);
65
case GPUCORE_DIRECTX11:
66
#if PPSSPP_API(D3D11)
67
return new GPU_D3D11(ctx, draw);
68
#else
69
return nullptr;
70
#endif
71
#if !PPSSPP_PLATFORM(SWITCH)
72
case GPUCORE_VULKAN:
73
if (!ctx) {
74
// Can this happen?
75
ERROR_LOG(Log::G3D, "Unable to init Vulkan GPU backend, no context");
76
return nullptr;
77
}
78
return new GPU_Vulkan(ctx, draw);
79
#endif
80
default:
81
return nullptr;
82
}
83
#endif
84
}
85
86
bool GPU_Init(GPUCore gpuCore, GraphicsContext *ctx, Draw::DrawContext *draw) {
87
_dbg_assert_(draw || gpuCore == GPUCORE_SOFTWARE);
88
GPUCommon *createdGPU = CreateGPUCore(gpuCore, ctx, draw);
89
90
// This can happen on some memory allocation failure, but can probably just be ignored in practice.
91
if (createdGPU && !createdGPU->IsStarted()) {
92
delete createdGPU;
93
createdGPU = nullptr;
94
}
95
96
if (createdGPU) {
97
gpu = createdGPU;
98
gpuDebug = createdGPU;
99
}
100
101
return gpu != nullptr;
102
}
103
104
#ifdef USE_CRT_DBG
105
#define new DBG_NEW
106
#endif
107
108
void GPU_Shutdown() {
109
delete gpu;
110
gpu = nullptr;
111
gpuDebug = nullptr;
112
}
113
114
const char *RasterChannelToString(RasterChannel channel) {
115
return channel == RASTER_COLOR ? "COLOR" : "DEPTH";
116
}
117
118