2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- 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
|
2012-11-04 22:58:25 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// 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/.
|
|
|
|
|
2013-08-15 23:00:26 +00:00
|
|
|
#include "base/logging.h"
|
2015-05-13 20:28:02 +00:00
|
|
|
#include "profiler/profiler.h"
|
2017-01-31 14:29:13 +00:00
|
|
|
#include "i18n/i18n.h"
|
2013-07-26 22:44:16 +00:00
|
|
|
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2015-12-31 15:59:40 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2013-12-29 22:28:31 +00:00
|
|
|
|
2015-09-05 19:23:58 +00:00
|
|
|
#include "Core/Config.h"
|
2013-12-14 22:54:05 +00:00
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2015-04-06 01:03:50 +00:00
|
|
|
#include "Core/MemMapHelpers.h"
|
2013-01-30 20:09:53 +00:00
|
|
|
#include "Core/Host.h"
|
|
|
|
#include "Core/Config.h"
|
2013-05-11 05:51:23 +00:00
|
|
|
#include "Core/Reporting.h"
|
2013-01-30 20:09:53 +00:00
|
|
|
#include "Core/System.h"
|
2016-01-17 19:29:34 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-20 20:34:47 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "GPU/GeDisasm.h"
|
2015-09-05 19:23:58 +00:00
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-02-04 17:46:12 +00:00
|
|
|
#include "ext/native/gfx/GLStateCache.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
2016-04-10 08:27:28 +00:00
|
|
|
#include "GPU/GLES/GPU_GLES.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
2016-04-10 08:27:28 +00:00
|
|
|
#include "GPU/GLES/DrawEngineGLES.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/TextureCacheGLES.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-03-15 18:44:02 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2013-08-20 20:34:47 +00:00
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceGe.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2015-09-06 11:36:33 +00:00
|
|
|
#ifdef _WIN32
|
2015-11-03 22:22:09 +00:00
|
|
|
#include "Windows/GPU/WindowsGLContext.h"
|
2015-09-06 11:36:33 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-14 12:21:24 +00:00
|
|
|
struct GLESCommandTableEntry {
|
2017-01-23 22:15:54 +00:00
|
|
|
uint8_t cmd;
|
|
|
|
uint8_t flags;
|
2017-01-24 11:53:42 +00:00
|
|
|
uint64_t dirty;
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_GLES::CmdFunc func;
|
2013-08-23 11:35:23 +00:00
|
|
|
};
|
|
|
|
|
2014-12-06 10:21:07 +00:00
|
|
|
// This table gets crunched into a faster form by init.
|
|
|
|
// TODO: Share this table between the backends. Will have to make another indirection for the function pointers though..
|
2017-03-14 12:21:24 +00:00
|
|
|
static const GLESCommandTableEntry commandTable[] = {
|
2017-01-24 12:13:09 +00:00
|
|
|
// Changes that dirty the current texture.
|
2017-11-13 17:57:59 +00:00
|
|
|
{ GE_CMD_TEXSIZE0, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPUCommon::Execute_TexSize0 },
|
2017-03-14 12:47:34 +00:00
|
|
|
|
2013-08-23 11:35:23 +00:00
|
|
|
// Changing the vertex type requires us to flush.
|
2017-11-13 17:57:59 +00:00
|
|
|
{ GE_CMD_VERTEXTYPE, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTEONCHANGE, 0, &GPUCommon::Execute_VertexType },
|
2013-08-23 11:35:23 +00:00
|
|
|
|
2017-03-14 12:47:34 +00:00
|
|
|
{ GE_CMD_PRIM, FLAG_EXECUTE, 0, &GPU_GLES::Execute_Prim },
|
2017-11-13 09:42:05 +00:00
|
|
|
{ GE_CMD_BEZIER, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPUCommon::Execute_Bezier },
|
|
|
|
{ GE_CMD_SPLINE, FLAG_FLUSHBEFORE | FLAG_EXECUTE, 0, &GPUCommon::Execute_Spline },
|
2013-08-23 12:22:26 +00:00
|
|
|
|
2013-08-23 11:35:23 +00:00
|
|
|
// Changes that trigger data copies. Only flushing on change for LOADCLUT must be a bit of a hack...
|
2017-03-14 12:47:34 +00:00
|
|
|
{ GE_CMD_LOADCLUT, FLAG_FLUSHBEFOREONCHANGE | FLAG_EXECUTE, 0, &GPU_GLES::Execute_LoadClut },
|
2012-12-21 20:49:09 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_GLES::CommandInfo GPU_GLES::cmdInfo_[256];
|
2014-04-16 14:54:19 +00:00
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
|
2017-11-18 23:43:58 +00:00
|
|
|
: GPUCommon(gfxCtx, draw), drawEngine_(draw) {
|
2014-06-15 22:19:49 +00:00
|
|
|
UpdateVsyncInterval(true);
|
2015-09-05 17:58:47 +00:00
|
|
|
CheckGPUFeatures();
|
2013-10-09 08:44:12 +00:00
|
|
|
|
2017-11-18 23:43:58 +00:00
|
|
|
GLRenderManager *render = (GLRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
|
|
|
|
|
|
|
shaderManagerGL_ = new ShaderManagerGLES(render);
|
2017-02-05 18:51:50 +00:00
|
|
|
framebufferManagerGL_ = new FramebufferManagerGLES(draw);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManager_ = framebufferManagerGL_;
|
2017-02-05 18:51:50 +00:00
|
|
|
textureCacheGL_ = new TextureCacheGLES(draw);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCache_ = textureCacheGL_;
|
2017-01-23 20:08:16 +00:00
|
|
|
drawEngineCommon_ = &drawEngine_;
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManager_ = shaderManagerGL_;
|
2017-01-23 20:08:16 +00:00
|
|
|
drawEngineCommon_ = &drawEngine_;
|
2016-12-21 17:07:17 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
drawEngine_.SetShaderManager(shaderManagerGL_);
|
2016-12-21 17:07:17 +00:00
|
|
|
drawEngine_.SetTextureCache(textureCacheGL_);
|
|
|
|
drawEngine_.SetFramebufferManager(framebufferManagerGL_);
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.SetFragmentTestCache(&fragmentTestCache_);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->Init();
|
|
|
|
framebufferManagerGL_->SetTextureCache(textureCacheGL_);
|
2017-01-23 19:48:23 +00:00
|
|
|
framebufferManagerGL_->SetShaderManager(shaderManagerGL_);
|
2017-02-04 10:47:19 +00:00
|
|
|
framebufferManagerGL_->SetDrawEngine(&drawEngine_);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->SetFramebufferManager(framebufferManagerGL_);
|
|
|
|
textureCacheGL_->SetDepalShaderCache(&depalShaderCache_);
|
2017-01-23 19:48:23 +00:00
|
|
|
textureCacheGL_->SetShaderManager(shaderManagerGL_);
|
2017-02-04 10:47:19 +00:00
|
|
|
textureCacheGL_->SetDrawEngine(&drawEngine_);
|
2016-12-21 17:07:17 +00:00
|
|
|
fragmentTestCache_.SetTextureCache(textureCacheGL_);
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2012-11-22 19:57:41 +00:00
|
|
|
// Sanity check gstate
|
|
|
|
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
|
|
|
|
ERROR_LOG(G3D, "gstate has drifted out of sync!");
|
|
|
|
}
|
2012-12-21 20:49:09 +00:00
|
|
|
|
2014-04-17 08:36:24 +00:00
|
|
|
memset(cmdInfo_, 0, sizeof(cmdInfo_));
|
2017-03-14 12:21:24 +00:00
|
|
|
|
|
|
|
// Import both the global and local command tables, and check for dupes
|
|
|
|
std::set<u8> dupeCheck;
|
|
|
|
for (size_t i = 0; i < commonCommandTableSize; i++) {
|
|
|
|
const u8 cmd = commonCommandTable[i].cmd;
|
|
|
|
if (dupeCheck.find(cmd) != dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command table Dupe: %02x (%i)", (int)cmd, (int)cmd);
|
|
|
|
} else {
|
|
|
|
dupeCheck.insert(cmd);
|
|
|
|
}
|
|
|
|
cmdInfo_[cmd].flags |= (uint64_t)commonCommandTable[i].flags | (commonCommandTable[i].dirty << 8);
|
|
|
|
cmdInfo_[cmd].func = commonCommandTable[i].func;
|
|
|
|
if ((cmdInfo_[cmd].flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) && !cmdInfo_[cmd].func) {
|
|
|
|
Crash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-23 11:35:23 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(commandTable); i++) {
|
2014-04-17 08:36:24 +00:00
|
|
|
const u8 cmd = commandTable[i].cmd;
|
2013-08-23 11:35:23 +00:00
|
|
|
if (dupeCheck.find(cmd) != dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command table Dupe: %02x (%i)", (int)cmd, (int)cmd);
|
|
|
|
} else {
|
|
|
|
dupeCheck.insert(cmd);
|
|
|
|
}
|
2017-01-24 11:53:42 +00:00
|
|
|
cmdInfo_[cmd].flags |= (uint64_t)commandTable[i].flags | (commandTable[i].dirty << 8);
|
2014-04-17 08:36:24 +00:00
|
|
|
cmdInfo_[cmd].func = commandTable[i].func;
|
2017-01-24 09:44:02 +00:00
|
|
|
if ((cmdInfo_[cmd].flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) && !cmdInfo_[cmd].func) {
|
|
|
|
Crash();
|
2014-04-16 14:54:19 +00:00
|
|
|
}
|
2012-12-26 23:18:45 +00:00
|
|
|
}
|
2013-08-23 11:35:23 +00:00
|
|
|
// Find commands missing from the table.
|
|
|
|
for (int i = 0; i < 0xEF; i++) {
|
|
|
|
if (dupeCheck.find((u8)i) == dupeCheck.end()) {
|
|
|
|
ERROR_LOG(G3D, "Command missing from table: %02x (%i)", i, i);
|
|
|
|
}
|
2012-12-21 20:49:09 +00:00
|
|
|
}
|
2013-04-29 00:49:17 +00:00
|
|
|
|
2013-10-09 08:44:12 +00:00
|
|
|
// No need to flush before the tex scale/offset commands if we are baking
|
|
|
|
// the tex scale/offset into the vertices anyway.
|
2013-10-09 21:09:16 +00:00
|
|
|
|
2014-06-29 04:51:25 +00:00
|
|
|
UpdateCmdInfo();
|
2013-11-10 12:18:52 +00:00
|
|
|
|
2013-04-29 00:49:17 +00:00
|
|
|
BuildReportingInfo();
|
2014-06-15 22:19:49 +00:00
|
|
|
// Update again after init to be sure of any silly driver problems.
|
|
|
|
UpdateVsyncInterval(true);
|
2014-12-30 23:26:16 +00:00
|
|
|
|
|
|
|
// Some of our defaults are different from hw defaults, let's assert them.
|
|
|
|
// We restore each frame anyway, but here is convenient for tests.
|
|
|
|
glstate.Restore();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.RestoreVAO();
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->NotifyConfigChanged();
|
2016-01-17 16:11:51 +00:00
|
|
|
|
|
|
|
// Load shader cache.
|
2017-06-03 03:54:28 +00:00
|
|
|
std::string discID = g_paramSFO.GetDiscID();
|
2016-01-17 20:35:24 +00:00
|
|
|
if (discID.size()) {
|
2016-01-17 21:11:28 +00:00
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_APP_CACHE));
|
2017-05-26 21:15:04 +00:00
|
|
|
shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) + "/" + discID + ".glshadercache";
|
2017-12-03 19:30:00 +00:00
|
|
|
// Actually precompiled by IsReady() since we're single-threaded.
|
|
|
|
shaderManagerGL_->Load(shaderCachePath_);
|
2016-01-17 20:35:24 +00:00
|
|
|
}
|
2017-01-31 14:29:13 +00:00
|
|
|
|
|
|
|
if (g_Config.bHardwareTessellation) {
|
|
|
|
// Disable hardware tessellation if device is unsupported.
|
2017-12-22 02:44:47 +00:00
|
|
|
bool hasTexelFetch = gl_extensions.GLES3 || (!gl_extensions.IsGLES && gl_extensions.VersionGEThan(3, 3, 0)) || gl_extensions.EXT_gpu_shader4;
|
|
|
|
if (!gstate_c.SupportsAll(GPU_SUPPORTS_INSTANCE_RENDERING | GPU_SUPPORTS_VERTEX_TEXTURE_FETCH | GPU_SUPPORTS_TEXTURE_FLOAT) || !hasTexelFetch) {
|
2017-01-31 14:29:13 +00:00
|
|
|
// TODO: Check unsupported device name list.(Above gpu features are supported but it has issues with weak gpu, memory, shader compiler etc...)
|
|
|
|
g_Config.bHardwareTessellation = false;
|
|
|
|
ERROR_LOG(G3D, "Hardware Tessellation is unsupported, falling back to software tessellation");
|
|
|
|
I18NCategory *gr = GetI18NCategory("Graphics");
|
|
|
|
host->NotifyUserMessage(gr->T("Turn off Hardware Tessellation - unsupported"), 2.5f, 0xFF3030FF);
|
|
|
|
}
|
|
|
|
}
|
2012-11-20 09:59:23 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
GPU_GLES::~GPU_GLES() {
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerGL_->DestroyAllFBOs();
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->ClearCache(true);
|
2014-03-30 13:37:51 +00:00
|
|
|
depalShaderCache_.Clear();
|
2014-08-24 22:26:38 +00:00
|
|
|
fragmentTestCache_.Clear();
|
2016-01-17 21:11:28 +00:00
|
|
|
if (!shaderCachePath_.empty()) {
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->Save(shaderCachePath_);
|
2016-01-17 21:11:28 +00:00
|
|
|
}
|
2017-01-23 19:48:23 +00:00
|
|
|
delete shaderManagerGL_;
|
|
|
|
shaderManagerGL_ = nullptr;
|
2017-02-10 13:41:32 +00:00
|
|
|
delete framebufferManagerGL_;
|
|
|
|
delete textureCacheGL_;
|
2015-09-06 11:36:33 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-31 15:59:40 +00:00
|
|
|
gfxCtx_->SwapInterval(0);
|
2015-09-06 11:36:33 +00:00
|
|
|
#endif
|
2012-11-19 22:29:14 +00:00
|
|
|
}
|
|
|
|
|
2017-12-24 17:41:00 +00:00
|
|
|
static constexpr int MakeIntelSimpleVer(int v1, int v2, int v3) {
|
|
|
|
return (v1 << 16) | (v2 << 8) | v3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasIntelDualSrcBug(int versions[4]) {
|
|
|
|
// Intel uses a confusing set of at least 3 version numbering schemes. This is the one given to OpenGL.
|
|
|
|
switch (MakeIntelSimpleVer(versions[0], versions[1], versions[2])) {
|
|
|
|
case MakeIntelSimpleVer(9, 17, 10):
|
|
|
|
case MakeIntelSimpleVer(9, 18, 10):
|
|
|
|
return false;
|
|
|
|
case MakeIntelSimpleVer(10, 18, 10):
|
|
|
|
return versions[3] < 4061;
|
|
|
|
case MakeIntelSimpleVer(10, 18, 14):
|
|
|
|
return versions[3] < 4080;
|
|
|
|
default:
|
|
|
|
// Older than above didn't support dual src anyway, newer should have the fix.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-05 17:58:47 +00:00
|
|
|
// Take the raw GL extension and versioning data and turn into feature flags.
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::CheckGPUFeatures() {
|
2017-01-31 15:14:38 +00:00
|
|
|
u32 features = 0;
|
2017-02-18 00:35:34 +00:00
|
|
|
|
2017-02-22 15:23:04 +00:00
|
|
|
features |= GPU_SUPPORTS_16BIT_FORMATS;
|
2017-02-18 00:35:34 +00:00
|
|
|
|
2015-11-28 00:01:25 +00:00
|
|
|
if (gl_extensions.ARB_blend_func_extended || gl_extensions.EXT_blend_func_extended) {
|
2017-12-24 17:41:00 +00:00
|
|
|
if (!gl_extensions.VersionGEThan(3, 0, 0)) {
|
|
|
|
// Don't use this extension on sub 3.0 OpenGL versions as it does not seem reliable
|
|
|
|
} else if (gl_extensions.gpuVendor == GPU_VENDOR_INTEL) {
|
|
|
|
// Also on Intel, see https://github.com/hrydgard/ppsspp/issues/10117
|
|
|
|
// TODO: Remove entirely sometime reasonably far in driver years after 2015.
|
|
|
|
const std::string ver = draw_->GetInfoString(Draw::InfoField::APIVERSION);
|
|
|
|
int versions[4]{};
|
|
|
|
if (sscanf(ver.c_str(), "Build %d.%d.%d.%d", &versions[0], &versions[1], &versions[2], &versions[3]) == 4) {
|
|
|
|
if (!HasIntelDualSrcBug(versions)) {
|
|
|
|
features |= GPU_SUPPORTS_DUALSOURCE_BLEND;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
features |= GPU_SUPPORTS_DUALSOURCE_BLEND;
|
|
|
|
}
|
2015-09-05 20:11:28 +00:00
|
|
|
} else {
|
|
|
|
features |= GPU_SUPPORTS_DUALSOURCE_BLEND;
|
|
|
|
}
|
|
|
|
}
|
2015-09-05 17:58:47 +00:00
|
|
|
|
2015-09-05 19:23:58 +00:00
|
|
|
if (gl_extensions.IsGLES) {
|
|
|
|
if (gl_extensions.GLES3)
|
|
|
|
features |= GPU_SUPPORTS_GLSL_ES_300;
|
|
|
|
} else {
|
|
|
|
if (gl_extensions.VersionGEThan(3, 3, 0))
|
|
|
|
features |= GPU_SUPPORTS_GLSL_330;
|
|
|
|
}
|
|
|
|
|
2015-09-05 17:58:47 +00:00
|
|
|
if (gl_extensions.EXT_shader_framebuffer_fetch || gl_extensions.NV_shader_framebuffer_fetch || gl_extensions.ARM_shader_framebuffer_fetch) {
|
2016-04-09 19:08:43 +00:00
|
|
|
// This has caused problems in the past. Let's only enable on GLES3.
|
|
|
|
if (features & GPU_SUPPORTS_GLSL_ES_300) {
|
|
|
|
features |= GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH;
|
|
|
|
}
|
2015-09-05 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-05 20:40:45 +00:00
|
|
|
if (gl_extensions.ARB_framebuffer_object || gl_extensions.EXT_framebuffer_object || gl_extensions.IsGLES) {
|
|
|
|
features |= GPU_SUPPORTS_FBO;
|
|
|
|
}
|
|
|
|
if (gl_extensions.ARB_framebuffer_object || gl_extensions.GLES3) {
|
|
|
|
features |= GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT;
|
|
|
|
}
|
|
|
|
if (gl_extensions.NV_framebuffer_blit) {
|
|
|
|
features |= GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT;
|
2015-09-05 17:58:47 +00:00
|
|
|
}
|
2015-12-15 05:12:50 +00:00
|
|
|
if (gl_extensions.ARB_vertex_array_object && gl_extensions.IsCoreContext) {
|
2015-12-14 06:48:21 +00:00
|
|
|
features |= GPU_SUPPORTS_VAO;
|
|
|
|
}
|
2015-09-05 17:58:47 +00:00
|
|
|
|
2015-09-05 19:23:58 +00:00
|
|
|
bool useCPU = false;
|
|
|
|
if (!gl_extensions.IsGLES) {
|
|
|
|
// Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit.
|
|
|
|
// This causes glitches in games that expect the exact values.
|
|
|
|
// It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.)
|
2017-12-25 19:17:59 +00:00
|
|
|
if (gl_extensions.gpuVendor != GPU_VENDOR_NVIDIA || !gl_extensions.VersionGEThan(3, 0)) {
|
|
|
|
useCPU = true;
|
2015-09-05 17:58:47 +00:00
|
|
|
}
|
2015-09-05 19:23:58 +00:00
|
|
|
} else {
|
|
|
|
useCPU = true;
|
2015-09-05 17:58:47 +00:00
|
|
|
}
|
2015-09-05 19:23:58 +00:00
|
|
|
|
|
|
|
if (useCPU)
|
2015-09-05 17:58:47 +00:00
|
|
|
features |= GPU_PREFER_CPU_DOWNLOAD;
|
|
|
|
|
|
|
|
if ((gl_extensions.gpuVendor == GPU_VENDOR_NVIDIA) || (gl_extensions.gpuVendor == GPU_VENDOR_AMD))
|
|
|
|
features |= GPU_PREFER_REVERSE_COLOR_ORDER;
|
|
|
|
|
2015-09-05 19:23:58 +00:00
|
|
|
if (gl_extensions.OES_texture_npot)
|
|
|
|
features |= GPU_SUPPORTS_OES_TEXTURE_NPOT;
|
|
|
|
|
2017-07-01 23:13:50 +00:00
|
|
|
if (gl_extensions.EXT_unpack_subimage)
|
2015-09-05 19:23:58 +00:00
|
|
|
features |= GPU_SUPPORTS_UNPACK_SUBIMAGE;
|
|
|
|
|
2017-07-01 23:13:50 +00:00
|
|
|
if (gl_extensions.EXT_blend_minmax)
|
2015-09-05 19:23:58 +00:00
|
|
|
features |= GPU_SUPPORTS_BLEND_MINMAX;
|
|
|
|
|
2015-12-06 18:39:21 +00:00
|
|
|
if (gl_extensions.OES_copy_image || gl_extensions.NV_copy_image || gl_extensions.EXT_copy_image || gl_extensions.ARB_copy_image)
|
|
|
|
features |= GPU_SUPPORTS_ANY_COPY_IMAGE;
|
|
|
|
|
2015-09-05 20:11:28 +00:00
|
|
|
if (!gl_extensions.IsGLES)
|
|
|
|
features |= GPU_SUPPORTS_LOGIC_OP;
|
|
|
|
|
2015-09-26 14:01:16 +00:00
|
|
|
if (gl_extensions.GLES3 || !gl_extensions.IsGLES)
|
2015-09-05 21:09:06 +00:00
|
|
|
features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL;
|
2015-09-26 14:01:16 +00:00
|
|
|
|
2017-03-03 12:58:27 +00:00
|
|
|
if (gl_extensions.EXT_texture_filter_anisotropic)
|
|
|
|
features |= GPU_SUPPORTS_ANISOTROPY;
|
2016-03-18 04:56:04 +00:00
|
|
|
|
2017-03-26 10:00:20 +00:00
|
|
|
bool canUseInstanceID = gl_extensions.EXT_draw_instanced || gl_extensions.ARB_draw_instanced;
|
2017-09-22 03:20:17 +00:00
|
|
|
bool canDefInstanceID = gl_extensions.IsGLES || gl_extensions.EXT_gpu_shader4 || gl_extensions.VersionGEThan(3, 1);
|
2017-03-28 10:49:37 +00:00
|
|
|
bool instanceRendering = gl_extensions.GLES3 || (canUseInstanceID && canDefInstanceID);
|
2017-12-08 13:30:03 +00:00
|
|
|
if (instanceRendering)
|
2017-01-31 14:21:22 +00:00
|
|
|
features |= GPU_SUPPORTS_INSTANCE_RENDERING;
|
|
|
|
|
|
|
|
int maxVertexTextureImageUnits;
|
|
|
|
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxVertexTextureImageUnits);
|
|
|
|
if (maxVertexTextureImageUnits >= 3) // At least 3 for hardware tessellation
|
|
|
|
features |= GPU_SUPPORTS_VERTEX_TEXTURE_FETCH;
|
|
|
|
|
2017-03-12 15:41:28 +00:00
|
|
|
if (gl_extensions.ARB_texture_float || gl_extensions.OES_texture_float)
|
2017-01-31 14:21:22 +00:00
|
|
|
features |= GPU_SUPPORTS_TEXTURE_FLOAT;
|
|
|
|
|
2016-01-21 06:01:18 +00:00
|
|
|
// If we already have a 16-bit depth buffer, we don't need to round.
|
2017-02-06 10:35:55 +00:00
|
|
|
bool prefer24 = draw_->GetDeviceCaps().preferredDepthBufferFormat == Draw::DataFormat::D24_S8;
|
|
|
|
if (prefer24) {
|
2016-02-07 04:42:01 +00:00
|
|
|
if (!g_Config.bHighQualityDepth && (features & GPU_SUPPORTS_ACCURATE_DEPTH) != 0) {
|
2016-01-21 06:01:18 +00:00
|
|
|
features |= GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT;
|
|
|
|
} else if (PSP_CoreParameter().compat.flags().PixelDepthRounding) {
|
|
|
|
if (!gl_extensions.IsGLES || gl_extensions.GLES3) {
|
|
|
|
// Use fragment rounding on desktop and GLES3, most accurate.
|
|
|
|
features |= GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT;
|
2017-02-06 10:35:55 +00:00
|
|
|
} else if (prefer24 && (features & GPU_SUPPORTS_ACCURATE_DEPTH) != 0) {
|
2016-01-21 06:01:18 +00:00
|
|
|
// Here we can simulate a 16 bit depth buffer by scaling.
|
|
|
|
// Note that the depth buffer is fixed point, not floating, so dividing by 256 is pretty good.
|
|
|
|
features |= GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT;
|
|
|
|
} else {
|
|
|
|
// At least do vertex rounding if nothing else.
|
|
|
|
features |= GPU_ROUND_DEPTH_TO_16BIT;
|
|
|
|
}
|
|
|
|
} else if (PSP_CoreParameter().compat.flags().VertexDepthRounding) {
|
|
|
|
features |= GPU_ROUND_DEPTH_TO_16BIT;
|
2015-10-11 18:44:58 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-05 21:09:06 +00:00
|
|
|
|
2016-02-07 04:28:45 +00:00
|
|
|
// The Phantasy Star hack :(
|
|
|
|
if (PSP_CoreParameter().compat.flags().DepthRangeHack && (features & GPU_SUPPORTS_ACCURATE_DEPTH) == 0) {
|
|
|
|
features |= GPU_USE_DEPTH_RANGE_HACK;
|
|
|
|
}
|
|
|
|
|
2017-01-28 09:04:50 +00:00
|
|
|
if (PSP_CoreParameter().compat.flags().ClearToRAM) {
|
|
|
|
features |= GPU_USE_CLEAR_RAM_HACK;
|
|
|
|
}
|
|
|
|
|
2015-09-05 17:58:47 +00:00
|
|
|
gstate_c.featureFlags = features;
|
|
|
|
}
|
|
|
|
|
2017-12-03 19:30:00 +00:00
|
|
|
bool GPU_GLES::IsReady() {
|
|
|
|
return shaderManagerGL_->ContinuePrecompile();
|
|
|
|
}
|
|
|
|
|
2013-04-29 00:49:17 +00:00
|
|
|
// Let's avoid passing nulls into snprintf().
|
|
|
|
static const char *GetGLStringAlways(GLenum name) {
|
|
|
|
const GLubyte *value = glGetString(name);
|
|
|
|
if (!value)
|
|
|
|
return "?";
|
|
|
|
return (const char *)value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Needs to be called on GPU thread, not reporting thread.
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::BuildReportingInfo() {
|
2013-04-29 00:49:17 +00:00
|
|
|
const char *glVendor = GetGLStringAlways(GL_VENDOR);
|
|
|
|
const char *glRenderer = GetGLStringAlways(GL_RENDERER);
|
|
|
|
const char *glVersion = GetGLStringAlways(GL_VERSION);
|
|
|
|
const char *glSlVersion = GetGLStringAlways(GL_SHADING_LANGUAGE_VERSION);
|
2015-12-23 23:30:08 +00:00
|
|
|
const char *glExtensions = nullptr;
|
|
|
|
|
|
|
|
if (gl_extensions.VersionGEThan(3, 0)) {
|
|
|
|
glExtensions = g_all_gl_extensions.c_str();
|
|
|
|
} else {
|
|
|
|
glExtensions = GetGLStringAlways(GL_EXTENSIONS);
|
|
|
|
}
|
2013-04-29 00:49:17 +00:00
|
|
|
|
2013-05-12 08:38:42 +00:00
|
|
|
char temp[16384];
|
2013-04-29 00:49:17 +00:00
|
|
|
snprintf(temp, sizeof(temp), "%s (%s %s), %s (extensions: %s)", glVersion, glVendor, glRenderer, glSlVersion, glExtensions);
|
2013-04-29 07:30:54 +00:00
|
|
|
reportingPrimaryInfo_ = glVendor;
|
|
|
|
reportingFullInfo_ = temp;
|
2014-02-15 23:18:01 +00:00
|
|
|
|
|
|
|
Reporting::UpdateConfig();
|
2013-04-29 00:49:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::DeviceLost() {
|
2016-04-10 08:27:28 +00:00
|
|
|
ILOG("GPU_GLES: DeviceLost");
|
2013-08-08 06:27:29 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->ClearCache(false);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->Clear(false);
|
2014-08-24 22:26:38 +00:00
|
|
|
fragmentTestCache_.Clear(false);
|
2014-03-30 13:37:51 +00:00
|
|
|
depalShaderCache_.Clear();
|
2017-12-09 22:58:08 +00:00
|
|
|
drawEngine_.DeviceLost();
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->DeviceLost();
|
2016-09-11 03:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_GLES::DeviceRestore() {
|
2017-12-07 13:56:19 +00:00
|
|
|
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
|
2016-09-11 03:29:58 +00:00
|
|
|
ILOG("GPU_GLES: DeviceRestore");
|
2014-06-15 22:19:49 +00:00
|
|
|
|
2017-01-23 21:06:30 +00:00
|
|
|
UpdateCmdInfo();
|
2014-06-15 22:19:49 +00:00
|
|
|
UpdateVsyncInterval(true);
|
2017-12-07 13:56:19 +00:00
|
|
|
|
|
|
|
textureCacheGL_->DeviceRestore(draw_);
|
|
|
|
framebufferManagerGL_->DeviceRestore(draw_);
|
2017-12-09 22:58:08 +00:00
|
|
|
drawEngine_.DeviceRestore();
|
2012-12-25 14:28:34 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_GLES::Reinitialize() {
|
|
|
|
GPUCommon::Reinitialize();
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->Clear(true);
|
2014-06-28 19:29:09 +00:00
|
|
|
depalShaderCache_.Clear();
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerGL_->DestroyAllFBOs();
|
2014-06-28 19:29:09 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_GLES::InitClear() {
|
2013-08-27 14:31:50 +00:00
|
|
|
bool useNonBufferedRendering = g_Config.iRenderingMode == FB_NON_BUFFERED_MODE;
|
|
|
|
if (useNonBufferedRendering) {
|
2013-02-22 21:14:17 +00:00
|
|
|
glstate.depthWrite.set(GL_TRUE);
|
|
|
|
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2012-11-20 09:59:23 +00:00
|
|
|
glClearColor(0,0,0,1);
|
2013-01-14 18:26:10 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2012-11-20 09:59:23 +00:00
|
|
|
}
|
2013-01-06 22:23:36 +00:00
|
|
|
glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-03-17 09:48:43 +00:00
|
|
|
void GPU_GLES::BeginHostFrame() {
|
|
|
|
GPUCommon::BeginHostFrame();
|
|
|
|
UpdateCmdInfo();
|
2017-03-17 10:26:11 +00:00
|
|
|
if (resized_) {
|
|
|
|
CheckGPUFeatures();
|
2017-04-24 18:58:16 +00:00
|
|
|
framebufferManager_->Resized();
|
2017-03-17 10:26:11 +00:00
|
|
|
drawEngine_.Resized();
|
|
|
|
shaderManagerGL_->DirtyShader();
|
|
|
|
textureCacheGL_->NotifyConfigChanged();
|
|
|
|
}
|
2017-03-17 09:48:43 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
inline void GPU_GLES::UpdateVsyncInterval(bool force) {
|
2013-10-27 13:09:46 +00:00
|
|
|
#ifdef _WIN32
|
2013-08-06 15:08:57 +00:00
|
|
|
int desiredVSyncInterval = g_Config.bVSync ? 1 : 0;
|
2014-06-15 22:19:49 +00:00
|
|
|
if (PSP_CoreParameter().unthrottle) {
|
2013-06-16 21:45:06 +00:00
|
|
|
desiredVSyncInterval = 0;
|
2014-06-15 22:19:49 +00:00
|
|
|
}
|
|
|
|
if (PSP_CoreParameter().fpsLimit == 1) {
|
|
|
|
// For an alternative speed that is a clean factor of 60, the user probably still wants vsync.
|
|
|
|
if (g_Config.iFpsLimit == 0 || (g_Config.iFpsLimit != 15 && g_Config.iFpsLimit != 30 && g_Config.iFpsLimit != 60)) {
|
|
|
|
desiredVSyncInterval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desiredVSyncInterval != lastVsync_ || force) {
|
2013-08-24 09:53:54 +00:00
|
|
|
// Disabled EXT_swap_control_tear for now, it never seems to settle at the correct timing
|
|
|
|
// so it just keeps tearing. Not what I hoped for...
|
2014-06-15 22:19:49 +00:00
|
|
|
//if (gl_extensions.EXT_swap_control_tear) {
|
|
|
|
// // See http://developer.download.nvidia.com/opengl/specs/WGL_EXT_swap_control_tear.txt
|
2014-03-25 00:15:41 +00:00
|
|
|
// glstate.SetVSyncInterval(-desiredVSyncInterval);
|
|
|
|
//} else {
|
2015-12-31 15:59:40 +00:00
|
|
|
gfxCtx_->SwapInterval(desiredVSyncInterval);
|
2014-03-25 00:15:41 +00:00
|
|
|
//}
|
2013-06-16 21:45:06 +00:00
|
|
|
lastVsync_ = desiredVSyncInterval;
|
|
|
|
}
|
2013-10-27 13:09:46 +00:00
|
|
|
#endif
|
2014-06-15 22:19:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::UpdateCmdInfo() {
|
2014-06-29 04:51:25 +00:00
|
|
|
if (g_Config.bSoftwareSkinning) {
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags &= ~FLAG_FLUSHBEFOREONCHANGE;
|
2017-11-13 17:57:59 +00:00
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPUCommon::Execute_VertexTypeSkinning;
|
2014-06-29 04:51:25 +00:00
|
|
|
} else {
|
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].flags |= FLAG_FLUSHBEFOREONCHANGE;
|
2017-11-13 17:57:59 +00:00
|
|
|
cmdInfo_[GE_CMD_VERTEXTYPE].func = &GPUCommon::Execute_VertexType;
|
2014-06-29 04:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_GLES::ReapplyGfxState() {
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.RestoreVAO();
|
2015-09-06 10:23:14 +00:00
|
|
|
glstate.Restore();
|
2017-11-05 19:33:28 +00:00
|
|
|
GPUCommon::ReapplyGfxState();
|
2015-09-06 10:23:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_GLES::BeginFrame() {
|
2014-06-15 22:19:49 +00:00
|
|
|
UpdateVsyncInterval(resized_);
|
|
|
|
resized_ = false;
|
2013-06-16 21:45:06 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->StartFrame();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.DecimateTrackedVertexArrays();
|
|
|
|
drawEngine_.DecimateBuffers();
|
2014-05-31 20:08:17 +00:00
|
|
|
depalShaderCache_.Decimate();
|
2014-08-24 22:26:38 +00:00
|
|
|
fragmentTestCache_.Decimate();
|
2012-11-22 22:07:15 +00:00
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
GPUCommon::BeginFrame();
|
2016-01-17 19:29:34 +00:00
|
|
|
|
2016-01-17 16:11:51 +00:00
|
|
|
// Save the cache from time to time. TODO: How often?
|
2016-01-17 21:11:28 +00:00
|
|
|
if (!shaderCachePath_.empty() && (gpuStats.numFlips & 1023) == 0) {
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->Save(shaderCachePath_);
|
2016-01-17 20:35:24 +00:00
|
|
|
}
|
2016-01-17 16:11:51 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->DirtyShader();
|
2012-12-25 14:28:34 +00:00
|
|
|
|
|
|
|
// Not sure if this is really needed.
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_ALL_UNIFORMS);
|
2012-12-25 14:28:34 +00:00
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->BeginFrame();
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) {
|
2013-09-22 07:18:46 +00:00
|
|
|
host->GPUNotifyDisplay(framebuf, stride, format);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->SetDisplayFramebuffer(framebuf, stride, format);
|
2012-11-19 20:23:29 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_GLES::FramebufferDirty() {
|
2016-12-21 17:07:17 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManagerGL_->GetDisplayVFB();
|
2013-08-15 23:00:26 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->dirtyAfterDisplay;
|
|
|
|
vfb->dirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
bool GPU_GLES::FramebufferReallyDirty() {
|
2016-12-21 17:07:17 +00:00
|
|
|
VirtualFramebuffer *vfb = framebufferManagerGL_->GetDisplayVFB();
|
2013-08-15 23:00:26 +00:00
|
|
|
if (vfb) {
|
|
|
|
bool dirty = vfb->reallyDirtyAfterDisplay;
|
|
|
|
vfb->reallyDirtyAfterDisplay = false;
|
|
|
|
return dirty;
|
|
|
|
}
|
2013-03-03 12:00:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:33:28 +00:00
|
|
|
void GPU_GLES::CopyDisplayToOutput() {
|
2014-06-11 07:28:28 +00:00
|
|
|
// Flush anything left over.
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->RebindFramebuffer();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Flush();
|
2014-06-11 07:28:28 +00:00
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->DirtyLastShader();
|
2014-06-23 04:03:33 +00:00
|
|
|
|
2013-04-02 22:28:09 +00:00
|
|
|
glstate.depthWrite.set(GL_TRUE);
|
|
|
|
glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerGL_->CopyDisplayToOutput();
|
|
|
|
framebufferManagerGL_->EndFrame();
|
2012-11-19 22:29:14 +00:00
|
|
|
|
2013-07-26 22:44:16 +00:00
|
|
|
// If buffered, discard the depth buffer of the backbuffer. Don't even know if we need one.
|
|
|
|
#if 0
|
|
|
|
#ifdef USING_GLES2
|
|
|
|
if (gl_extensions.EXT_discard_framebuffer && g_Config.iRenderingMode != 0) {
|
|
|
|
GLenum attachments[] = {GL_DEPTH_EXT, GL_STENCIL_EXT};
|
|
|
|
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2012-11-19 22:29:14 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 12:22:26 +00:00
|
|
|
// Maybe should write this in ASM...
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::FastRunLoop(DisplayList &list) {
|
2015-05-25 22:39:27 +00:00
|
|
|
PROFILE_THIS_SCOPE("gpuloop");
|
2014-04-17 08:36:24 +00:00
|
|
|
const CommandInfo *cmdInfo = cmdInfo_;
|
2014-12-06 10:21:07 +00:00
|
|
|
int dc = downcount;
|
|
|
|
for (; dc > 0; --dc) {
|
2013-11-07 00:34:43 +00:00
|
|
|
// We know that display list PCs have the upper nibble == 0 - no need to mask the pointer
|
|
|
|
const u32 op = *(const u32 *)(Memory::base + list.pc);
|
2013-11-06 15:50:16 +00:00
|
|
|
const u32 cmd = op >> 24;
|
2017-08-17 11:53:13 +00:00
|
|
|
const CommandInfo &info = cmdInfo[cmd];
|
2013-11-06 15:50:16 +00:00
|
|
|
const u32 diff = op ^ gstate.cmdmem[cmd];
|
2017-08-17 11:53:13 +00:00
|
|
|
if (diff == 0) {
|
|
|
|
if (info.flags & FLAG_EXECUTE) {
|
|
|
|
downcount = dc;
|
|
|
|
(this->*info.func)(op, diff);
|
|
|
|
dc = downcount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint64_t flags = info.flags;
|
|
|
|
if (flags & FLAG_FLUSHBEFOREONCHANGE) {
|
|
|
|
drawEngine_.Flush();
|
|
|
|
}
|
2017-08-17 12:26:52 +00:00
|
|
|
gstate.cmdmem[cmd] = op;
|
2017-08-17 11:53:13 +00:00
|
|
|
if (flags & (FLAG_EXECUTE | FLAG_EXECUTEONCHANGE)) {
|
|
|
|
downcount = dc;
|
|
|
|
(this->*info.func)(op, diff);
|
|
|
|
dc = downcount;
|
|
|
|
} else {
|
|
|
|
uint64_t dirty = flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
|
|
|
}
|
2013-11-07 00:34:43 +00:00
|
|
|
}
|
2013-04-28 21:23:30 +00:00
|
|
|
list.pc += 4;
|
|
|
|
}
|
2014-12-06 10:21:07 +00:00
|
|
|
downcount = 0;
|
2013-04-28 21:23:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::FinishDeferred() {
|
2015-03-15 01:11:00 +00:00
|
|
|
// This finishes reading any vertex data that is pending.
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.FinishDeferred();
|
2015-03-15 01:11:00 +00:00
|
|
|
}
|
2014-12-06 10:21:07 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
inline void GPU_GLES::CheckFlushOp(int cmd, u32 diff) {
|
2014-04-17 08:36:24 +00:00
|
|
|
const u8 cmdFlags = cmdInfo_[cmd].flags;
|
2017-08-17 11:05:13 +00:00
|
|
|
if (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE)) {
|
2013-01-20 12:15:46 +00:00
|
|
|
if (dumpThisFrame_) {
|
2013-09-07 20:02:55 +00:00
|
|
|
NOTICE_LOG(G3D, "================ FLUSH ================");
|
2013-01-20 12:15:46 +00:00
|
|
|
}
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.Flush();
|
2013-01-20 12:15:46 +00:00
|
|
|
}
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::PreExecuteOp(u32 op, u32 diff) {
|
2013-08-06 17:08:38 +00:00
|
|
|
CheckFlushOp(op >> 24, diff);
|
2013-04-28 21:23:30 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::ExecuteOp(u32 op, u32 diff) {
|
2014-04-13 17:23:21 +00:00
|
|
|
const u8 cmd = op >> 24;
|
2014-04-17 08:36:24 +00:00
|
|
|
const CommandInfo info = cmdInfo_[cmd];
|
|
|
|
const u8 cmdFlags = info.flags;
|
2014-04-13 17:23:21 +00:00
|
|
|
if ((cmdFlags & FLAG_EXECUTE) || (diff && (cmdFlags & FLAG_EXECUTEONCHANGE))) {
|
2014-04-17 08:36:24 +00:00
|
|
|
(this->*info.func)(op, diff);
|
2017-01-24 09:44:02 +00:00
|
|
|
} else if (diff) {
|
|
|
|
uint64_t dirty = info.flags >> 8;
|
|
|
|
if (dirty)
|
|
|
|
gstate_c.Dirty(dirty);
|
2014-04-13 17:23:21 +00:00
|
|
|
}
|
2013-11-06 15:50:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::Execute_Prim(u32 op, u32 diff) {
|
2014-04-16 15:01:56 +00:00
|
|
|
// This drives all drawing. All other state we just buffer up, then we apply it only
|
|
|
|
// when it's time to draw. As most PSP games set state redundantly ALL THE TIME, this is a huge optimization.
|
|
|
|
|
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
u32 count = data & 0xFFFF;
|
|
|
|
if (count == 0)
|
|
|
|
return;
|
|
|
|
|
2017-01-30 13:04:20 +00:00
|
|
|
// Upper bits are ignored.
|
|
|
|
GEPrimitiveType prim = static_cast<GEPrimitiveType>((data >> 16) & 7);
|
2017-04-03 14:45:58 +00:00
|
|
|
SetDrawType(DRAW_PRIM, prim);
|
|
|
|
|
2014-04-16 15:01:56 +00:00
|
|
|
// Discard AA lines as we can't do anything that makes sense with these anyway. The SW plugin might, though.
|
|
|
|
|
|
|
|
if (gstate.isAntiAliasEnabled()) {
|
|
|
|
// Discard AA lines in DOA
|
|
|
|
if (prim == GE_PRIM_LINE_STRIP)
|
|
|
|
return;
|
|
|
|
// Discard AA lines in Summon Night 5
|
|
|
|
if ((prim == GE_PRIM_LINES) && gstate.isSkinningEnabled())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-23 19:56:48 +00:00
|
|
|
// This also makes skipping drawing very effective. This function can change the framebuffer.
|
2017-01-23 22:25:09 +00:00
|
|
|
framebufferManagerGL_->SetRenderFrameBuffer(gstate_c.IsDirty(DIRTY_FRAMEBUF), gstate_c.skipDrawReason);
|
2014-04-16 15:01:56 +00:00
|
|
|
if (gstate_c.skipDrawReason & (SKIPDRAW_SKIPFRAME | SKIPDRAW_NON_DISPLAYED_FB)) {
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.SetupVertexDecoder(gstate.vertType);
|
2014-04-16 15:01:56 +00:00
|
|
|
// Rough estimate, not sure what's correct.
|
2017-01-23 20:00:44 +00:00
|
|
|
cyclesExecuted += EstimatePerVertexCost() * count;
|
2014-04-16 15:01:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.vertexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad vertex address %08x!", gstate_c.vertexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr);
|
|
|
|
void *inds = 0;
|
|
|
|
if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) {
|
|
|
|
if (!Memory::IsValidAddress(gstate_c.indexAddr)) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Bad index address %08x!", gstate_c.indexAddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inds = Memory::GetPointerUnchecked(gstate_c.indexAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MOBILE_DEVICE
|
|
|
|
if (prim > GE_PRIM_RECTANGLES) {
|
|
|
|
ERROR_LOG_REPORT_ONCE(reportPrim, G3D, "Unexpected prim type: %d", prim);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 17:03:16 +00:00
|
|
|
if (gstate_c.dirty & DIRTY_VERTEXSHADER_STATE) {
|
|
|
|
vertexCost_ = EstimatePerVertexCost();
|
|
|
|
}
|
|
|
|
gpuStats.vertexGPUCycles += vertexCost_ * count;
|
|
|
|
cyclesExecuted += vertexCost_* count;
|
|
|
|
|
2014-05-05 01:24:49 +00:00
|
|
|
int bytesRead = 0;
|
2017-08-17 11:53:13 +00:00
|
|
|
UpdateUVScaleOffset();
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.SubmitPrim(verts, inds, prim, count, gstate.vertType, &bytesRead);
|
2014-04-16 15:01:56 +00:00
|
|
|
|
|
|
|
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
|
|
|
|
// Some games rely on this, they don't bother reloading VADDR and IADDR.
|
2014-05-05 01:24:49 +00:00
|
|
|
// The VADDR/IADDR registers are NOT updated.
|
2016-04-10 20:07:08 +00:00
|
|
|
AdvanceVerts(gstate.vertType, count, bytesRead);
|
2014-04-16 15:01:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::Execute_LoadClut(u32 op, u32 diff) {
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->LoadClut(gstate.getClutAddress(), gstate.getClutLoadBytes());
|
2014-04-17 15:29:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::GetStats(char *buffer, size_t bufsize) {
|
2016-03-31 08:17:02 +00:00
|
|
|
float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f;
|
|
|
|
snprintf(buffer, bufsize - 1,
|
|
|
|
"DL processing time: %0.2f ms\n"
|
2017-12-27 03:34:57 +00:00
|
|
|
"Draw calls: %i, flushes %i, clears %i\n"
|
2016-03-31 08:17:02 +00:00
|
|
|
"Cached Draw calls: %i\n"
|
|
|
|
"Num Tracked Vertex Arrays: %i\n"
|
|
|
|
"GPU cycles executed: %d (%f per vertex)\n"
|
|
|
|
"Commands per call level: %i %i %i %i\n"
|
|
|
|
"Vertices submitted: %i\n"
|
|
|
|
"Cached, Uncached Vertices Drawn: %i, %i\n"
|
|
|
|
"FBOs active: %i\n"
|
|
|
|
"Textures active: %i, decoded: %i invalidated: %i\n"
|
2017-12-29 03:27:45 +00:00
|
|
|
"Readbacks: %d, uploads: %d\n"
|
2016-04-02 08:28:38 +00:00
|
|
|
"Vertex, Fragment, Programs loaded: %i, %i, %i\n",
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.msProcessingDisplayLists * 1000.0f,
|
|
|
|
gpuStats.numDrawCalls,
|
|
|
|
gpuStats.numFlushes,
|
2017-12-27 03:34:57 +00:00
|
|
|
gpuStats.numClears,
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.numCachedDrawCalls,
|
|
|
|
gpuStats.numTrackedVertexArrays,
|
|
|
|
gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles,
|
|
|
|
vertexAverageCycles,
|
|
|
|
gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3],
|
|
|
|
gpuStats.numVertsSubmitted,
|
|
|
|
gpuStats.numCachedVertsDrawn,
|
|
|
|
gpuStats.numUncachedVertsDrawn,
|
2016-12-21 17:07:17 +00:00
|
|
|
(int)framebufferManagerGL_->NumVFBs(),
|
|
|
|
(int)textureCacheGL_->NumLoadedTextures(),
|
2016-03-31 08:17:02 +00:00
|
|
|
gpuStats.numTexturesDecoded,
|
|
|
|
gpuStats.numTextureInvalidations,
|
2017-11-08 10:57:53 +00:00
|
|
|
gpuStats.numReadbacks,
|
2017-12-29 03:27:45 +00:00
|
|
|
gpuStats.numUploads,
|
2017-02-08 17:07:34 +00:00
|
|
|
shaderManagerGL_->GetNumVertexShaders(),
|
|
|
|
shaderManagerGL_->GetNumFragmentShaders(),
|
|
|
|
shaderManagerGL_->GetNumPrograms());
|
2012-11-26 16:35:08 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::ClearCacheNextFrame() {
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->ClearNextFrame();
|
2013-04-30 15:20:28 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::ClearShaderCache() {
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->ClearCache(true);
|
2013-01-26 23:15:39 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::CleanupBeforeUI() {
|
2014-06-23 04:42:29 +00:00
|
|
|
// Clear any enabled vertex arrays.
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerGL_->DirtyLastShader();
|
2015-02-04 16:28:31 +00:00
|
|
|
glstate.arrayBuffer.bind(0);
|
|
|
|
glstate.elementArrayBuffer.bind(0);
|
2014-06-23 04:42:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
void GPU_GLES::DoState(PointerWrap &p) {
|
2013-01-26 23:15:39 +00:00
|
|
|
GPUCommon::DoState(p);
|
|
|
|
|
2013-09-29 20:19:32 +00:00
|
|
|
// TODO: Some of these things may not be necessary.
|
|
|
|
// None of these are necessary when saving.
|
2013-11-15 15:30:55 +00:00
|
|
|
// In Freeze-Frame mode, we don't want to do any of this.
|
|
|
|
if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) {
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCacheGL_->Clear(true);
|
2016-04-10 08:21:48 +00:00
|
|
|
drawEngine_.ClearTrackedVertexArrays();
|
2013-01-26 23:15:39 +00:00
|
|
|
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_TEXTURE_IMAGE);
|
2017-04-14 06:07:21 +00:00
|
|
|
framebufferManagerGL_->DestroyAllFBOs();
|
2013-09-29 20:19:32 +00:00
|
|
|
}
|
2012-12-29 20:21:56 +00:00
|
|
|
}
|
2013-09-23 02:03:31 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
std::vector<std::string> GPU_GLES::DebugGetShaderIDs(DebugShaderType type) {
|
2017-04-04 09:09:29 +00:00
|
|
|
switch (type) {
|
|
|
|
case SHADER_TYPE_VERTEXLOADER:
|
2016-04-10 08:21:48 +00:00
|
|
|
return drawEngine_.DebugGetVertexLoaderIDs();
|
2017-04-04 09:09:29 +00:00
|
|
|
case SHADER_TYPE_DEPAL:
|
|
|
|
return depalShaderCache_.DebugGetShaderIDs(type);
|
|
|
|
default:
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerGL_->DebugGetShaderIDs(type);
|
2015-10-21 21:06:32 +00:00
|
|
|
}
|
2015-10-14 15:45:21 +00:00
|
|
|
}
|
2015-10-21 21:06:32 +00:00
|
|
|
|
2016-04-10 08:21:48 +00:00
|
|
|
std::string GPU_GLES::DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) {
|
2017-04-04 09:09:29 +00:00
|
|
|
switch (type) {
|
|
|
|
case SHADER_TYPE_VERTEXLOADER:
|
2016-04-10 08:21:48 +00:00
|
|
|
return drawEngine_.DebugGetVertexLoaderString(id, stringType);
|
2017-04-04 09:09:29 +00:00
|
|
|
case SHADER_TYPE_DEPAL:
|
|
|
|
return depalShaderCache_.DebugGetShaderString(id, type, stringType);
|
|
|
|
default:
|
2017-01-23 19:48:23 +00:00
|
|
|
return shaderManagerGL_->DebugGetShaderString(id, type, stringType);
|
2015-10-21 21:06:32 +00:00
|
|
|
}
|
2015-10-14 15:45:21 +00:00
|
|
|
}
|