2015-07-26 20:38:40 +00:00
|
|
|
// Copyright (c) 2015- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-02-24 17:59:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
2020-08-15 18:53:08 +00:00
|
|
|
#include "Common/TimeUtil.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
|
|
|
|
#include "GPU/GPU.h"
|
|
|
|
#include "GPU/GPUInterface.h"
|
2017-02-24 17:59:41 +00:00
|
|
|
|
2019-05-10 21:25:57 +00:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2017-02-24 23:25:46 +00:00
|
|
|
#include "GPU/GLES/GPU_GLES.h"
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/Vulkan/GPU_Vulkan.h"
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
|
|
|
|
2019-05-11 06:37:42 +00:00
|
|
|
#if PPSSPP_API(D3D9)
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "GPU/Directx9/GPU_DX9.h"
|
2019-05-11 06:37:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PPSSPP_API(D3D11)
|
2017-02-08 16:47:07 +00:00
|
|
|
#include "GPU/D3D11/GPU_D3D11.h"
|
2015-07-26 20:38:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GPUStatistics gpuStats;
|
|
|
|
GPUInterface *gpu;
|
|
|
|
GPUDebugInterface *gpuDebug;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void SetGPU(T *obj) {
|
|
|
|
gpu = obj;
|
|
|
|
gpuDebug = obj;
|
|
|
|
}
|
|
|
|
|
2016-02-10 14:22:28 +00:00
|
|
|
#ifdef USE_CRT_DBG
|
|
|
|
#undef new
|
|
|
|
#endif
|
2016-03-20 19:04:49 +00:00
|
|
|
|
2017-12-03 18:54:38 +00:00
|
|
|
bool GPU_IsReady() {
|
2023-09-24 09:20:27 +00:00
|
|
|
return gpu != nullptr;
|
2017-12-03 18:54:38 +00:00
|
|
|
}
|
|
|
|
|
2023-01-01 14:59:14 +00:00
|
|
|
bool GPU_IsStarted() {
|
|
|
|
if (gpu)
|
2023-09-24 09:20:27 +00:00
|
|
|
return gpu->IsStarted();
|
2023-01-01 14:59:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
|
2021-01-02 17:24:43 +00:00
|
|
|
const auto &gpuCore = PSP_CoreParameter().gpuCore;
|
2021-01-02 17:36:13 +00:00
|
|
|
_assert_(draw || gpuCore == GPUCORE_SOFTWARE);
|
2017-02-24 17:59:41 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2021-01-02 17:24:43 +00:00
|
|
|
if (gpuCore == GPUCORE_SOFTWARE) {
|
|
|
|
SetGPU(new SoftGPU(ctx, draw));
|
|
|
|
} else {
|
|
|
|
SetGPU(new GPU_D3D11(ctx, draw));
|
|
|
|
}
|
2017-02-24 17:59:41 +00:00
|
|
|
return true;
|
|
|
|
#else
|
2021-01-02 17:24:43 +00:00
|
|
|
switch (gpuCore) {
|
2016-04-10 08:21:48 +00:00
|
|
|
case GPUCORE_GLES:
|
2019-05-08 21:41:46 +00:00
|
|
|
// Disable GLES on ARM Windows (but leave it enabled on other ARM platforms).
|
2019-05-10 21:25:57 +00:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2017-01-30 15:50:35 +00:00
|
|
|
SetGPU(new GPU_GLES(ctx, draw));
|
2015-07-26 20:38:40 +00:00
|
|
|
break;
|
2019-05-03 22:06:50 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-10 08:21:48 +00:00
|
|
|
case GPUCORE_SOFTWARE:
|
2017-01-30 15:50:35 +00:00
|
|
|
SetGPU(new SoftGPU(ctx, draw));
|
2015-07-26 20:38:40 +00:00
|
|
|
break;
|
2016-04-10 08:21:48 +00:00
|
|
|
case GPUCORE_DIRECTX9:
|
2019-05-11 06:37:42 +00:00
|
|
|
#if PPSSPP_API(D3D9)
|
2022-08-16 19:48:54 +00:00
|
|
|
SetGPU(new GPU_DX9(ctx, draw));
|
2015-07-26 20:38:40 +00:00
|
|
|
break;
|
2017-02-08 16:47:07 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-10 08:21:48 +00:00
|
|
|
case GPUCORE_DIRECTX11:
|
2019-05-10 21:25:57 +00:00
|
|
|
#if PPSSPP_API(D3D11)
|
2017-02-08 17:07:34 +00:00
|
|
|
SetGPU(new GPU_D3D11(ctx, draw));
|
|
|
|
break;
|
2017-02-08 16:47:07 +00:00
|
|
|
#else
|
2016-03-20 23:25:02 +00:00
|
|
|
return false;
|
2017-02-08 16:47:07 +00:00
|
|
|
#endif
|
2022-04-02 23:34:13 +00:00
|
|
|
#if !PPSSPP_PLATFORM(SWITCH)
|
2016-04-10 08:21:48 +00:00
|
|
|
case GPUCORE_VULKAN:
|
2016-10-01 18:22:53 +00:00
|
|
|
if (!ctx) {
|
2024-07-14 12:42:59 +00:00
|
|
|
ERROR_LOG(Log::G3D, "Unable to init Vulkan GPU backend, no context");
|
2016-10-01 18:22:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-30 15:50:35 +00:00
|
|
|
SetGPU(new GPU_Vulkan(ctx, draw));
|
2016-08-05 17:48:04 +00:00
|
|
|
break;
|
2022-04-02 23:34:13 +00:00
|
|
|
#endif
|
2015-07-26 20:38:40 +00:00
|
|
|
}
|
|
|
|
|
2023-09-24 09:20:27 +00:00
|
|
|
if (gpu && !gpu->IsStarted())
|
2023-01-01 14:59:14 +00:00
|
|
|
SetGPU<SoftGPU>(nullptr);
|
|
|
|
|
|
|
|
return gpu != nullptr;
|
2017-02-24 17:59:41 +00:00
|
|
|
#endif
|
2015-07-26 20:38:40 +00:00
|
|
|
}
|
2016-02-10 14:22:28 +00:00
|
|
|
#ifdef USE_CRT_DBG
|
|
|
|
#define new DBG_NEW
|
|
|
|
#endif
|
2015-07-26 20:38:40 +00:00
|
|
|
|
|
|
|
void GPU_Shutdown() {
|
2022-12-10 10:28:19 +00:00
|
|
|
|
2015-07-26 20:38:40 +00:00
|
|
|
delete gpu;
|
2018-02-26 14:19:11 +00:00
|
|
|
gpu = nullptr;
|
2015-07-26 20:38:40 +00:00
|
|
|
}
|
2023-02-04 11:05:50 +00:00
|
|
|
|
|
|
|
const char *RasterChannelToString(RasterChannel channel) {
|
|
|
|
return channel == RASTER_COLOR ? "COLOR" : "DEPTH";
|
|
|
|
}
|