From a6d1ec99a896c7f6b77cb0b12416a7ff95bc58f3 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon, 11 Jul 2022 19:03:37 -0700 Subject: [PATCH] opengl: remove old geriatric texture cache --- app/render/opengl/openglrenderer.cpp | 139 ++++++--------------------- app/render/opengl/openglrenderer.h | 15 --- 2 files changed, 31 insertions(+), 123 deletions(-) diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index ade819167..5078b963c 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -84,12 +84,9 @@ QMutex global_opengl_mutex; OpenGLRenderer::OpenGLRenderer(QObject* parent) : Renderer(parent), - cache_timer_(this), context_(nullptr), framebuffer_(0) { - cache_timer_.setInterval(kTextureCacheMaxSize); - connect(&cache_timer_, &QTimer::timeout, this, &OpenGLRenderer::GarbageCollectTextureCache); } OpenGLRenderer::~OpenGLRenderer() @@ -156,8 +153,6 @@ void OpenGLRenderer::PostInit() // Set up framebuffer used for various things functions_->glGenFramebuffers(1, &framebuffer_); - - cache_timer_.start(); } void OpenGLRenderer::DestroyInternal() @@ -169,19 +164,12 @@ void OpenGLRenderer::DestroyInternal() functions_->glDeleteFramebuffers(1, &framebuffer_); framebuffer_ = 0; - for (auto it=texture_cache_.cbegin(); it!=texture_cache_.cend(); it++) { - functions_->glDeleteTextures(1, &it->texture); - } - texture_cache_.clear(); - // Delete context if it belongs to us if (context_->parent() == this) { delete context_; } context_ = nullptr; } - - cache_timer_.stop(); } void OpenGLRenderer::ClearDestination(Texture *texture, double r, double g, double b, double a) @@ -210,38 +198,25 @@ QVariant OpenGLRenderer::CreateNativeTexture3D(int width, int height, int depth, { GL_PREAMBLE; - GLuint texture = GetCachedTexture(width, height, depth, format, channel_count); + // Generate new texture + GLuint texture; + functions_->glGenTextures(1, &texture); + texture_params_.insert(texture, {width, height, depth, format, channel_count}); - // If no texture in cache, generate new texture - bool new_tex = (texture == 0); - if (new_tex) { - functions_->glGenTextures(1, &texture); - texture_params_.insert(texture, {width, height, depth, format, channel_count}); - } + functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize); - if (new_tex || data) { - functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize); + GLint current_tex; + functions_->glGetIntegerv(GL_TEXTURE_BINDING_3D, ¤t_tex); - GLint current_tex; - functions_->glGetIntegerv(GL_TEXTURE_BINDING_3D, ¤t_tex); + functions_->glBindTexture(GL_TEXTURE_3D, texture); - functions_->glBindTexture(GL_TEXTURE_3D, texture); + context_->extraFunctions()->glTexImage3D(GL_TEXTURE_3D, 0, GetInternalFormat(format, channel_count), + width, height, depth, 0, GetPixelFormat(channel_count), + GetPixelType(format), data); - if (new_tex) { - context_->extraFunctions()->glTexImage3D(GL_TEXTURE_3D, 0, GetInternalFormat(format, channel_count), - width, height, depth, 0, GetPixelFormat(channel_count), - GetPixelType(format), data); - } else { - context_->extraFunctions()->glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, - width, height, depth, - GetPixelFormat(channel_count), GetPixelType(format), - data); - } + functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - functions_->glBindTexture(GL_TEXTURE_3D, current_tex); - } + functions_->glBindTexture(GL_TEXTURE_3D, current_tex); return texture; } @@ -268,10 +243,7 @@ void OpenGLRenderer::DestroyNativeTexture(QVariant texture) GLuint t = texture.value(); if (t > 0) { - TextureCacheKey key = texture_params_.value(t); - TextureCacheEntry entry = {key, t, QDateTime::currentMSecsSinceEpoch()}; - - texture_cache_.append(entry); + functions_->glDeleteTextures(1, &t); } } @@ -818,41 +790,27 @@ void OpenGLRenderer::ClearDestinationInternal(double r, double g, double b, doub QVariant OpenGLRenderer::CreateNativeTexture2DInternal(int width, int height, VideoParams::Format format, int channel_count, const void *data, int linesize) { - GLuint texture = GetCachedTexture(width, height, 1, format, channel_count); + GLuint texture; + functions_->glGenTextures(1, &texture); + texture_params_.insert(texture, {width, height, 1, format, channel_count}); - // If no texture in cache, generate new texture - bool new_tex = (texture == 0); - if (new_tex) { - functions_->glGenTextures(1, &texture); - texture_params_.insert(texture, {width, height, 1, format, channel_count}); + functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize); + + GLint current_tex; + functions_->glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + + functions_->glBindTexture(GL_TEXTURE_2D, texture); + + { + PRINT_GL_ERRORS; + functions_->glTexImage2D(GL_TEXTURE_2D, 0, GetInternalFormat(format, channel_count), + width, height, 0, GetPixelFormat(channel_count), + GetPixelType(format), data); } - if (new_tex || data) { - functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize); + functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - GLint current_tex; - functions_->glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - - functions_->glBindTexture(GL_TEXTURE_2D, texture); - - { - PRINT_GL_ERRORS; - if (new_tex) { - functions_->glTexImage2D(GL_TEXTURE_2D, 0, GetInternalFormat(format, channel_count), - width, height, 0, GetPixelFormat(channel_count), - GetPixelType(format), data); - } else { - functions_->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - width, height, - GetPixelFormat(channel_count), GetPixelType(format), - data); - } - } - - functions_->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - - functions_->glBindTexture(GL_TEXTURE_2D, current_tex); - } + functions_->glBindTexture(GL_TEXTURE_2D, current_tex); return texture; } @@ -862,25 +820,6 @@ QVariant OpenGLRenderer::CreateNativeTexture2DInternal(const VideoParams ¶ms return CreateNativeTexture2DInternal(params.effective_width(), params.effective_height(), params.format(), params.channel_count(), data, linesize); } -GLuint OpenGLRenderer::GetCachedTexture(int width, int height, int depth, VideoParams::Format format, int channel_count) -{ - TextureCacheKey input_key = {width, height, depth, format, channel_count}; - - for (int i=0; iage < max_age) { - GL_PREAMBLE; - GLuint t = it->texture; - texture_params_.remove(t); - functions_->glDeleteTextures(1, &t); - it = texture_cache_.erase(it); - } else { - it++; - } - } -} - } diff --git a/app/render/opengl/openglrenderer.h b/app/render/opengl/openglrenderer.h index b1ec02474..2e51480b1 100644 --- a/app/render/opengl/openglrenderer.h +++ b/app/render/opengl/openglrenderer.h @@ -96,12 +96,8 @@ private: QVariant CreateNativeTexture2DInternal(int width, int height, olive::VideoParams::Format format, int channel_count, const void* data = nullptr, int linesize = 0); QVariant CreateNativeTexture2DInternal(const VideoParams ¶ms, const void* data = nullptr, int linesize = 0); - GLuint GetCachedTexture(int width, int height, int depth, VideoParams::Format format, int channel_count); - GLuint CompileShader(GLenum type, const QString &code); - QTimer cache_timer_; - QOpenGLContext* context_; QOpenGLFunctions* functions_; @@ -124,21 +120,10 @@ private: } }; - struct TextureCacheEntry { - TextureCacheKey key; - GLuint texture; - qint64 age; - }; - - QVector texture_cache_; - QMap texture_params_; static const int kTextureCacheMaxSize; -private slots: - void GarbageCollectTextureCache(); - }; }