From 392547a97c768f1241df853e34d3d7b52d220727 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Tue, 6 Nov 2018 10:40:49 +0100 Subject: [PATCH] gl_resource_manager: Split implementations in .cpp file Those implementations are quite costly, so there is no need to inline them to the caller. Ressource deletion is often a performance bug, so in this way, we support to add breakpoints to them. --- src/video_core/CMakeLists.txt | 1 + .../renderer_opengl/gl_resource_manager.cpp | 134 ++++++++++++++++++ .../renderer_opengl/gl_resource_manager.h | 123 +++------------- .../renderer_opengl/gl_shader_manager.h | 1 + 4 files changed, 155 insertions(+), 104 deletions(-) create mode 100644 src/video_core/renderer_opengl/gl_resource_manager.cpp diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 1e12f4ac2..2ad6d2d99 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(video_core STATIC renderer_opengl/gl_rasterizer.h renderer_opengl/gl_rasterizer_cache.cpp renderer_opengl/gl_rasterizer_cache.h + renderer_opengl/gl_resource_manager.cpp renderer_opengl/gl_resource_manager.h renderer_opengl/gl_shader_decompiler.cpp renderer_opengl/gl_shader_decompiler.h diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp new file mode 100644 index 000000000..32a7d52c6 --- /dev/null +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp @@ -0,0 +1,134 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "common/common_types.h" +#include "video_core/renderer_opengl/gl_resource_manager.h" +#include "video_core/renderer_opengl/gl_shader_util.h" +#include "video_core/renderer_opengl/gl_state.h" + +namespace OpenGL { + +void OGLTexture::Create() { + if (handle != 0) + return; + glGenTextures(1, &handle); +} + +void OGLTexture::Release() { + if (handle == 0) + return; + glDeleteTextures(1, &handle); + OpenGLState::GetCurState().ResetTexture(handle).Apply(); + handle = 0; +} + +void OGLSampler::Create() { + if (handle != 0) + return; + glGenSamplers(1, &handle); +} + +void OGLSampler::Release() { + if (handle == 0) + return; + glDeleteSamplers(1, &handle); + OpenGLState::GetCurState().ResetSampler(handle).Apply(); + handle = 0; +} + +void OGLShader::Create(const char* source, GLenum type) { + if (handle != 0) + return; + if (source == nullptr) + return; + handle = LoadShader(source, type); +} + +void OGLShader::Release() { + if (handle == 0) + return; + glDeleteShader(handle); + handle = 0; +} + +void OGLProgram::Create(bool separable_program, const std::vector& shaders) { + if (handle != 0) + return; + handle = LoadProgram(separable_program, shaders); +} + +void OGLProgram::Create(const char* vert_shader, const char* frag_shader) { + OGLShader vert, frag; + vert.Create(vert_shader, GL_VERTEX_SHADER); + frag.Create(frag_shader, GL_FRAGMENT_SHADER); + Create(false, {vert.handle, frag.handle}); +} + +void OGLProgram::Release() { + if (handle == 0) + return; + glDeleteProgram(handle); + OpenGLState::GetCurState().ResetProgram(handle).Apply(); + handle = 0; +} + +void OGLPipeline::Create() { + if (handle != 0) + return; + glGenProgramPipelines(1, &handle); +} + +void OGLPipeline::Release() { + if (handle == 0) + return; + glDeleteProgramPipelines(1, &handle); + OpenGLState::GetCurState().ResetPipeline(handle).Apply(); + handle = 0; +} + +void OGLBuffer::Create() { + if (handle != 0) + return; + glGenBuffers(1, &handle); +} + +void OGLBuffer::Release() { + if (handle == 0) + return; + glDeleteBuffers(1, &handle); + OpenGLState::GetCurState().ResetBuffer(handle).Apply(); + handle = 0; +} + +void OGLVertexArray::Create() { + if (handle != 0) + return; + glGenVertexArrays(1, &handle); +} + +void OGLVertexArray::Release() { + if (handle == 0) + return; + glDeleteVertexArrays(1, &handle); + OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); + handle = 0; +} + +void OGLFramebuffer::Create() { + if (handle != 0) + return; + glGenFramebuffers(1, &handle); +} + +void OGLFramebuffer::Release() { + if (handle == 0) + return; + glDeleteFramebuffers(1, &handle); + OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); + handle = 0; +} + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 3fbf5eafb..ce7f7fbfb 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -9,7 +9,6 @@ #include #include "common/common_types.h" #include "video_core/renderer_opengl/gl_shader_util.h" -#include "video_core/renderer_opengl/gl_state.h" namespace OpenGL { @@ -30,20 +29,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenTextures(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteTextures(1, &handle); - OpenGLState::GetCurState().ResetTexture(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -65,20 +54,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenSamplers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteSamplers(1, &handle); - OpenGLState::GetCurState().ResetSampler(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -99,20 +78,9 @@ public: return *this; } - void Create(const char* source, GLenum type) { - if (handle != 0) - return; - if (source == nullptr) - return; - handle = LoadShader(source, type); - } + void Create(const char* source, GLenum type); - void Release() { - if (handle == 0) - return; - glDeleteShader(handle); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -134,28 +102,13 @@ public: } /// Creates a new program from given shader objects - void Create(bool separable_program, const std::vector& shaders) { - if (handle != 0) - return; - handle = LoadProgram(separable_program, shaders); - } + void Create(bool separable_program, const std::vector& shaders); /// Creates a new program from given shader soruce code - void Create(const char* vert_shader, const char* frag_shader) { - OGLShader vert, frag; - vert.Create(vert_shader, GL_VERTEX_SHADER); - frag.Create(frag_shader, GL_FRAGMENT_SHADER); - Create(false, {vert.handle, frag.handle}); - } + void Create(const char* vert_shader, const char* frag_shader); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteProgram(handle); - OpenGLState::GetCurState().ResetProgram(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -175,19 +128,11 @@ public: return *this; } - void Create() { - if (handle != 0) - return; - glGenProgramPipelines(1, &handle); - } + /// Creates a new internal OpenGL resource and stores the handle + void Create(); - void Release() { - if (handle == 0) - return; - glDeleteProgramPipelines(1, &handle); - OpenGLState::GetCurState().ResetPipeline(handle).Apply(); - handle = 0; - } + /// Deletes the internal OpenGL resource + void Release(); GLuint handle = 0; }; @@ -209,20 +154,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenBuffers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteBuffers(1, &handle); - OpenGLState::GetCurState().ResetBuffer(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -244,20 +179,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenVertexArrays(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteVertexArrays(1, &handle); - OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; @@ -279,20 +204,10 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create() { - if (handle != 0) - return; - glGenFramebuffers(1, &handle); - } + void Create(); /// Deletes the internal OpenGL resource - void Release() { - if (handle == 0) - return; - glDeleteFramebuffers(1, &handle); - OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); - handle = 0; - } + void Release(); GLuint handle = 0; }; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h index 8c740f982..95c4a5f37 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.h +++ b/src/video_core/renderer_opengl/gl_shader_manager.h @@ -9,6 +9,7 @@ #include "video_core/regs_lighting.h" #include "video_core/renderer_opengl/gl_resource_manager.h" #include "video_core/renderer_opengl/gl_shader_gen.h" +#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/pica_to_gl.h" namespace OpenGL {