CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/GPU.cpp
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "ppsspp_config.h"1819#include "Common/TimeUtil.h"20#include "Common/GraphicsContext.h"21#include "Core/Core.h"2223#include "GPU/GPU.h"24#include "GPU/GPUInterface.h"2526#if PPSSPP_API(ANY_GL)27#include "GPU/GLES/GPU_GLES.h"28#endif29#include "GPU/Vulkan/GPU_Vulkan.h"30#include "GPU/Software/SoftGpu.h"3132#if PPSSPP_API(D3D9)33#include "GPU/Directx9/GPU_DX9.h"34#endif3536#if PPSSPP_API(D3D11)37#include "GPU/D3D11/GPU_D3D11.h"38#endif3940GPUStatistics gpuStats;41GPUInterface *gpu;42GPUDebugInterface *gpuDebug;4344template <typename T>45static void SetGPU(T *obj) {46gpu = obj;47gpuDebug = obj;48}4950#ifdef USE_CRT_DBG51#undef new52#endif5354bool GPU_IsReady() {55return gpu != nullptr;56}5758bool GPU_IsStarted() {59if (gpu)60return gpu->IsStarted();61return false;62}6364bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) {65const auto &gpuCore = PSP_CoreParameter().gpuCore;66_assert_(draw || gpuCore == GPUCORE_SOFTWARE);67#if PPSSPP_PLATFORM(UWP)68if (gpuCore == GPUCORE_SOFTWARE) {69SetGPU(new SoftGPU(ctx, draw));70} else {71SetGPU(new GPU_D3D11(ctx, draw));72}73return true;74#else75switch (gpuCore) {76case GPUCORE_GLES:77// Disable GLES on ARM Windows (but leave it enabled on other ARM platforms).78#if PPSSPP_API(ANY_GL)79SetGPU(new GPU_GLES(ctx, draw));80break;81#else82return false;83#endif84case GPUCORE_SOFTWARE:85SetGPU(new SoftGPU(ctx, draw));86break;87case GPUCORE_DIRECTX9:88#if PPSSPP_API(D3D9)89SetGPU(new GPU_DX9(ctx, draw));90break;91#else92return false;93#endif94case GPUCORE_DIRECTX11:95#if PPSSPP_API(D3D11)96SetGPU(new GPU_D3D11(ctx, draw));97break;98#else99return false;100#endif101#if !PPSSPP_PLATFORM(SWITCH)102case GPUCORE_VULKAN:103if (!ctx) {104ERROR_LOG(Log::G3D, "Unable to init Vulkan GPU backend, no context");105break;106}107SetGPU(new GPU_Vulkan(ctx, draw));108break;109#endif110}111112if (gpu && !gpu->IsStarted())113SetGPU<SoftGPU>(nullptr);114115return gpu != nullptr;116#endif117}118#ifdef USE_CRT_DBG119#define new DBG_NEW120#endif121122void GPU_Shutdown() {123// Reduce the risk for weird races with the Windows GE debugger.124gpuDebug = nullptr;125126delete gpu;127gpu = nullptr;128}129130const char *RasterChannelToString(RasterChannel channel) {131return channel == RASTER_COLOR ? "COLOR" : "DEPTH";132}133134135