mirror of
https://github.com/citra-emu/citra-nightly.git
synced 2024-12-27 02:16:03 +00:00
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.
This commit is contained in:
parent
d3b1b5f22c
commit
392547a97c
|
@ -27,6 +27,7 @@ add_library(video_core STATIC
|
||||||
renderer_opengl/gl_rasterizer.h
|
renderer_opengl/gl_rasterizer.h
|
||||||
renderer_opengl/gl_rasterizer_cache.cpp
|
renderer_opengl/gl_rasterizer_cache.cpp
|
||||||
renderer_opengl/gl_rasterizer_cache.h
|
renderer_opengl/gl_rasterizer_cache.h
|
||||||
|
renderer_opengl/gl_resource_manager.cpp
|
||||||
renderer_opengl/gl_resource_manager.h
|
renderer_opengl/gl_resource_manager.h
|
||||||
renderer_opengl/gl_shader_decompiler.cpp
|
renderer_opengl/gl_shader_decompiler.cpp
|
||||||
renderer_opengl/gl_shader_decompiler.h
|
renderer_opengl/gl_shader_decompiler.h
|
||||||
|
|
134
src/video_core/renderer_opengl/gl_resource_manager.cpp
Normal file
134
src/video_core/renderer_opengl/gl_resource_manager.cpp
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
// Copyright 2015 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#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<GLuint>& 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
|
|
@ -9,7 +9,6 @@
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||||
#include "video_core/renderer_opengl/gl_state.h"
|
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
|
@ -30,20 +29,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
void Create() {
|
void Create();
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
glGenTextures(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteTextures(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetTexture(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -65,20 +54,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
void Create() {
|
void Create();
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
glGenSamplers(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteSamplers(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetSampler(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -99,20 +78,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create(const char* source, GLenum type) {
|
void Create(const char* source, GLenum type);
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
if (source == nullptr)
|
|
||||||
return;
|
|
||||||
handle = LoadShader(source, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteShader(handle);
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -134,28 +102,13 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new program from given shader objects
|
/// Creates a new program from given shader objects
|
||||||
void Create(bool separable_program, const std::vector<GLuint>& shaders) {
|
void Create(bool separable_program, const std::vector<GLuint>& shaders);
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
handle = LoadProgram(separable_program, shaders);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new program from given shader soruce code
|
/// Creates a new program from given shader soruce code
|
||||||
void Create(const char* vert_shader, const char* frag_shader) {
|
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});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteProgram(handle);
|
|
||||||
OpenGLState::GetCurState().ResetProgram(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -175,19 +128,11 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create() {
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
if (handle != 0)
|
void Create();
|
||||||
return;
|
|
||||||
glGenProgramPipelines(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Release() {
|
/// Deletes the internal OpenGL resource
|
||||||
if (handle == 0)
|
void Release();
|
||||||
return;
|
|
||||||
glDeleteProgramPipelines(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetPipeline(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -209,20 +154,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
void Create() {
|
void Create();
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
glGenBuffers(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteBuffers(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetBuffer(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -244,20 +179,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
void Create() {
|
void Create();
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
glGenVertexArrays(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteVertexArrays(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetVertexArray(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
@ -279,20 +204,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new internal OpenGL resource and stores the handle
|
/// Creates a new internal OpenGL resource and stores the handle
|
||||||
void Create() {
|
void Create();
|
||||||
if (handle != 0)
|
|
||||||
return;
|
|
||||||
glGenFramebuffers(1, &handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the internal OpenGL resource
|
/// Deletes the internal OpenGL resource
|
||||||
void Release() {
|
void Release();
|
||||||
if (handle == 0)
|
|
||||||
return;
|
|
||||||
glDeleteFramebuffers(1, &handle);
|
|
||||||
OpenGLState::GetCurState().ResetFramebuffer(handle).Apply();
|
|
||||||
handle = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint handle = 0;
|
GLuint handle = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "video_core/regs_lighting.h"
|
#include "video_core/regs_lighting.h"
|
||||||
#include "video_core/renderer_opengl/gl_resource_manager.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_shader_gen.h"
|
||||||
|
#include "video_core/renderer_opengl/gl_state.h"
|
||||||
#include "video_core/renderer_opengl/pica_to_gl.h"
|
#include "video_core/renderer_opengl/pica_to_gl.h"
|
||||||
|
|
||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
Loading…
Reference in a new issue