2015-07-26 22:38:40 +02: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 18:59:41 +01:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
2020-08-15 20:53:08 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
2016-01-05 21:18:43 +01:00
|
|
|
#include "Common/GraphicsContext.h"
|
2015-07-26 22:38:40 +02:00
|
|
|
#include "Core/Core.h"
|
2024-12-18 12:28:05 +01:00
|
|
|
#include "Core/System.h"
|
2015-07-26 22:38:40 +02:00
|
|
|
|
|
|
|
#include "GPU/GPU.h"
|
2024-12-02 10:32:57 +01:00
|
|
|
#include "GPU/GPUCommon.h"
|
2017-02-24 18:59:41 +01:00
|
|
|
|
2019-05-10 23:25:57 +02:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2017-02-25 00:25:46 +01:00
|
|
|
#include "GPU/GLES/GPU_GLES.h"
|
2019-05-04 06:06:50 +08:00
|
|
|
#endif
|
2015-10-10 16:41:19 +02:00
|
|
|
#include "GPU/Vulkan/GPU_Vulkan.h"
|
2015-07-26 22:38:40 +02:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
|
|
|
|
2019-05-11 08:37:42 +02:00
|
|
|
#if PPSSPP_API(D3D9)
|
2015-07-26 22:38:40 +02:00
|
|
|
#include "GPU/Directx9/GPU_DX9.h"
|
2019-05-11 08:37:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PPSSPP_API(D3D11)
|
2017-02-08 17:47:07 +01:00
|
|
|
#include "GPU/D3D11/GPU_D3D11.h"
|
2015-07-26 22:38:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GPUStatistics gpuStats;
|
2024-12-02 10:32:57 +01:00
|
|
|
GPUCommon *gpu;
|
2015-07-26 22:38:40 +02:00
|
|
|
GPUDebugInterface *gpuDebug;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static void SetGPU(T *obj) {
|
|
|
|
gpu = obj;
|
|
|
|
gpuDebug = obj;
|
|
|
|
}
|
|
|
|
|
2016-02-10 15:22:28 +01:00
|
|
|
#ifdef USE_CRT_DBG
|
|
|
|
#undef new
|
|
|
|
#endif
|
2016-03-20 20:04:49 +01:00
|
|
|
|
2017-12-03 10:54:38 -08:00
|
|
|
bool GPU_IsReady() {
|
2023-09-24 11:20:27 +02:00
|
|
|
return gpu != nullptr;
|
2017-12-03 10:54:38 -08:00
|
|
|
}
|
|
|
|
|
2023-01-01 06:59:14 -08:00
|
|
|
bool GPU_IsStarted() {
|
|
|
|
if (gpu)
|
2023-09-24 11:20:27 +02:00
|
|
|
return gpu->IsStarted();
|
2023-01-01 06:59:14 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 16:50:35 +01:00
|
|
|
bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {
|
2021-01-02 09:24:43 -08:00
|
|
|
const auto &gpuCore = PSP_CoreParameter().gpuCore;
|
2021-01-02 09:36:13 -08:00
|
|
|
_assert_(draw || gpuCore == GPUCORE_SOFTWARE);
|
2017-02-24 18:59:41 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2021-01-02 09:24:43 -08:00
|
|
|
if (gpuCore == GPUCORE_SOFTWARE) {
|
|
|
|
SetGPU(new SoftGPU(ctx, draw));
|
|
|
|
} else {
|
|
|
|
SetGPU(new GPU_D3D11(ctx, draw));
|
|
|
|
}
|
2017-02-24 18:59:41 +01:00
|
|
|
return true;
|
|
|
|
#else
|
2021-01-02 09:24:43 -08:00
|
|
|
switch (gpuCore) {
|
2016-04-10 10:21:48 +02:00
|
|
|
case GPUCORE_GLES:
|
2019-05-08 23:41:46 +02:00
|
|
|
// Disable GLES on ARM Windows (but leave it enabled on other ARM platforms).
|
2019-05-10 23:25:57 +02:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2017-01-30 16:50:35 +01:00
|
|
|
SetGPU(new GPU_GLES(ctx, draw));
|
2015-07-26 22:38:40 +02:00
|
|
|
break;
|
2019-05-04 06:06:50 +08:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-10 10:21:48 +02:00
|
|
|
case GPUCORE_SOFTWARE:
|
2017-01-30 16:50:35 +01:00
|
|
|
SetGPU(new SoftGPU(ctx, draw));
|
2015-07-26 22:38:40 +02:00
|
|
|
break;
|
2016-04-10 10:21:48 +02:00
|
|
|
case GPUCORE_DIRECTX9:
|
2019-05-11 08:37:42 +02:00
|
|
|
#if PPSSPP_API(D3D9)
|
2022-08-16 21:48:54 +02:00
|
|
|
SetGPU(new GPU_DX9(ctx, draw));
|
2015-07-26 22:38:40 +02:00
|
|
|
break;
|
2017-02-08 17:47:07 +01:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2016-04-10 10:21:48 +02:00
|
|
|
case GPUCORE_DIRECTX11:
|
2019-05-10 23:25:57 +02:00
|
|
|
#if PPSSPP_API(D3D11)
|
2017-02-08 18:07:34 +01:00
|
|
|
SetGPU(new GPU_D3D11(ctx, draw));
|
|
|
|
break;
|
2017-02-08 17:47:07 +01:00
|
|
|
#else
|
2016-03-20 16:25:02 -07:00
|
|
|
return false;
|
2017-02-08 17:47:07 +01:00
|
|
|
#endif
|
2022-04-02 16:34:13 -07:00
|
|
|
#if !PPSSPP_PLATFORM(SWITCH)
|
2016-04-10 10:21:48 +02:00
|
|
|
case GPUCORE_VULKAN:
|
2016-10-01 11:22:53 -07:00
|
|
|
if (!ctx) {
|
2024-07-14 14:42:59 +02:00
|
|
|
ERROR_LOG(Log::G3D, "Unable to init Vulkan GPU backend, no context");
|
2016-10-01 11:22:53 -07:00
|
|
|
break;
|
|
|
|
}
|
2017-01-30 16:50:35 +01:00
|
|
|
SetGPU(new GPU_Vulkan(ctx, draw));
|
2016-08-05 10:48:04 -07:00
|
|
|
break;
|
2022-04-02 16:34:13 -07:00
|
|
|
#endif
|
2024-12-18 12:28:05 +01:00
|
|
|
default:
|
|
|
|
break;
|
2015-07-26 22:38:40 +02:00
|
|
|
}
|
|
|
|
|
2023-09-24 11:20:27 +02:00
|
|
|
if (gpu && !gpu->IsStarted())
|
2023-01-01 06:59:14 -08:00
|
|
|
SetGPU<SoftGPU>(nullptr);
|
|
|
|
|
|
|
|
return gpu != nullptr;
|
2017-02-24 18:59:41 +01:00
|
|
|
#endif
|
2015-07-26 22:38:40 +02:00
|
|
|
}
|
2016-02-10 15:22:28 +01:00
|
|
|
#ifdef USE_CRT_DBG
|
|
|
|
#define new DBG_NEW
|
|
|
|
#endif
|
2015-07-26 22:38:40 +02:00
|
|
|
|
|
|
|
void GPU_Shutdown() {
|
2022-12-10 11:28:19 +01:00
|
|
|
|
2015-07-26 22:38:40 +02:00
|
|
|
delete gpu;
|
2018-02-26 15:19:11 +01:00
|
|
|
gpu = nullptr;
|
2015-07-26 22:38:40 +02:00
|
|
|
}
|
2023-02-04 12:05:50 +01:00
|
|
|
|
|
|
|
const char *RasterChannelToString(RasterChannel channel) {
|
|
|
|
return channel == RASTER_COLOR ? "COLOR" : "DEPTH";
|
|
|
|
}
|