From d00f6adf114437918712d4bd68074cdb9efec255 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 15 Mar 2015 14:43:07 -0700 Subject: [PATCH] Avoid querying attrib locations in depal runtime. --- GPU/GLES/DepalettizeShader.cpp | 11 +++++++---- GPU/GLES/DepalettizeShader.h | 4 +++- GPU/GLES/TextureCache.cpp | 23 ++++++++++------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/GPU/GLES/DepalettizeShader.cpp b/GPU/GLES/DepalettizeShader.cpp index e4747500e..dd7118d1d 100644 --- a/GPU/GLES/DepalettizeShader.cpp +++ b/GPU/GLES/DepalettizeShader.cpp @@ -193,18 +193,18 @@ void DepalShaderCache::Decimate() { } } -GLuint DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) { +DepalShader *DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) { u32 id = GenerateShaderID(pixelFormat); auto shader = cache_.find(id); if (shader != cache_.end()) { - return shader->second->program; + return shader->second; } if (vertexShader_ == 0) { if (!CreateVertexShader()) { // The vertex shader failed, no need to bother trying the fragment. - return 0; + return nullptr; } } @@ -263,8 +263,11 @@ GLuint DepalShaderCache::GetDepalettizeShader(GEBufferFormat pixelFormat) { // We will delete the shader later in Clear(). glDeleteProgram(program); + } else { + depal->a_position = glGetAttribLocation(program, "a_position"); + depal->a_texcoord0 = glGetAttribLocation(program, "a_texcoord0"); } delete[] buffer; - return depal->program; + return depal->program ? depal : nullptr; } diff --git a/GPU/GLES/DepalettizeShader.h b/GPU/GLES/DepalettizeShader.h index a85ed65c0..60a80fdf5 100644 --- a/GPU/GLES/DepalettizeShader.h +++ b/GPU/GLES/DepalettizeShader.h @@ -25,6 +25,8 @@ class DepalShader { public: GLuint program; GLuint fragShader; + GLint a_position; + GLint a_texcoord0; }; class DepalTexture { @@ -40,7 +42,7 @@ public: ~DepalShaderCache(); // This also uploads the palette and binds the correct texture. - GLuint GetDepalettizeShader(GEBufferFormat pixelFormat); + DepalShader *GetDepalettizeShader(GEBufferFormat pixelFormat); GLuint GetClutTexture(const u32 clutHash, u32 *rawClut); void Clear(); void Decimate(); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 599e3297a..1d5393d7d 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1075,11 +1075,11 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe framebuffer->usageFlags |= FB_USAGE_TEXTURE; bool useBufferedRendering = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; if (useBufferedRendering) { - GLuint program = 0; + DepalShader *depal = nullptr; if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { - program = depalShaderCache_->GetDepalettizeShader(framebuffer->drawnFormat); + depal = depalShaderCache_->GetDepalettizeShader(framebuffer->drawnFormat); } - if (program) { + if (depal) { GLuint clutTexture = depalShaderCache_->GetClutTexture(clutHash_, clutBuf_); FBO *depalFBO = framebufferManager_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, FBO_8888); fbo_bind_as_render_target(depalFBO); @@ -1099,15 +1099,12 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe shaderManager_->DirtyLastShader(); - glUseProgram(program); - - GLint a_position = glGetAttribLocation(program, "a_position"); - GLint a_texcoord0 = glGetAttribLocation(program, "a_texcoord0"); + glUseProgram(depal->program); glstate.arrayBuffer.unbind(); glstate.elementArrayBuffer.unbind(); - glEnableVertexAttribArray(a_position); - glEnableVertexAttribArray(a_texcoord0); + glEnableVertexAttribArray(depal->a_position); + glEnableVertexAttribArray(depal->a_texcoord0); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, clutTexture); @@ -1128,11 +1125,11 @@ void TextureCache::SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffe #endif glViewport(0, 0, framebuffer->renderWidth, framebuffer->renderHeight); - glVertexAttribPointer(a_position, 3, GL_FLOAT, GL_FALSE, 12, pos); - glVertexAttribPointer(a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, uv); + glVertexAttribPointer(depal->a_position, 3, GL_FLOAT, GL_FALSE, 12, pos); + glVertexAttribPointer(depal->a_texcoord0, 2, GL_FLOAT, GL_FALSE, 8, uv); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, indices); - glDisableVertexAttribArray(a_position); - glDisableVertexAttribArray(a_texcoord0); + glDisableVertexAttribArray(depal->a_position); + glDisableVertexAttribArray(depal->a_texcoord0); fbo_bind_color_as_texture(depalFBO, 0); glstate.Restore();