From 7cbb7a09e5cb7c9af3679b647c59f7896286da36 Mon Sep 17 00:00:00 2001 From: haoruiwang <1905811497@qq.com> Date: Tue, 18 Apr 2023 19:18:38 +0800 Subject: [PATCH] [what][style][gpu] some coding style refine --- Common/GPU/OpenGL/GLQueueRunner.cpp | 24 ++++-------------------- Common/GPU/OpenGL/GLQueueRunner.h | 5 ----- Common/GPU/OpenGL/GLRenderManager.cpp | 4 ++-- Common/GPU/OpenGL/GLRenderManager.h | 13 +++---------- Common/GPU/OpenGL/thin3d_gl.cpp | 2 +- Common/Render/TextureAtlas.h | 2 +- SDL/SDLGLGraphicsContext.h | 2 +- 7 files changed, 12 insertions(+), 40 deletions(-) diff --git a/Common/GPU/OpenGL/GLQueueRunner.cpp b/Common/GPU/OpenGL/GLQueueRunner.cpp index 097ecdc2c4..80a3193e40 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.cpp +++ b/Common/GPU/OpenGL/GLQueueRunner.cpp @@ -78,10 +78,6 @@ void GLQueueRunner::CreateDeviceObjects() { void GLQueueRunner::DestroyDeviceObjects() { CHECK_GL_ERROR_IF_DEBUG(); - if (!nameCache_.empty()) { - glDeleteTextures((GLsizei)nameCache_.size(), &nameCache_[0]); - nameCache_.clear(); - } if (gl_extensions.ARB_vertex_array_object) { glDeleteVertexArrays(1, &globalVAO_); } @@ -327,8 +323,8 @@ void GLQueueRunner::RunInitSteps(const std::vector &steps, bool ski glCompileShader(shader); GLint success = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &success); - std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog); if (!success) { + std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog); std::string errorString = StringFromFormat( "Error in shader compilation for: %s\n" "Info log: %s\n" @@ -799,10 +795,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last glDisable(GL_COLOR_LOGIC_OP); } #endif - } - - if (first && gl_extensions.ARB_vertex_array_object) { - glBindVertexArray(globalVAO_); + if (gl_extensions.ARB_vertex_array_object) { + glBindVertexArray(globalVAO_); + } } GLRProgram *curProgram = nullptr; @@ -1630,17 +1625,6 @@ void GLQueueRunner::CopyFromReadbackBuffer(GLRFramebuffer *framebuffer, int widt } } -GLuint GLQueueRunner::AllocTextureName() { - if (nameCache_.empty()) { - nameCache_.resize(TEXCACHE_NAME_CACHE_SIZE); - glGenTextures(TEXCACHE_NAME_CACHE_SIZE, &nameCache_[0]); - } - u32 name = nameCache_.back(); - nameCache_.pop_back(); - CHECK_GL_ERROR_IF_DEBUG(); - return name; -} - // On PC, we always use GL_DEPTH24_STENCIL8. // On Android, we try to use what's available. diff --git a/Common/GPU/OpenGL/GLQueueRunner.h b/Common/GPU/OpenGL/GLQueueRunner.h index f51f8e9999..e662b43dd1 100644 --- a/Common/GPU/OpenGL/GLQueueRunner.h +++ b/Common/GPU/OpenGL/GLQueueRunner.h @@ -228,7 +228,6 @@ struct GLRInitStep { union { struct { GLRTexture *texture; - GLenum target; } create_texture; struct { GLRShader *shader; @@ -420,10 +419,6 @@ private: GLuint currentDrawHandle_ = 0; GLuint currentReadHandle_ = 0; - GLuint AllocTextureName(); - - // Texture name cache. Ripped straight from TextureCacheGLES. - std::vector nameCache_; std::unordered_map glStrings_; bool sawOutOfMemory_ = false; diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index b10caa2541..be72f8aff1 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -189,7 +189,7 @@ void GLRenderManager::BindFramebufferAsRenderTarget(GLRFramebuffer *fb, GLRRende #endif // Eliminate dupes. - if (steps_.size() && steps_.back()->render.framebuffer == fb && steps_.back()->stepType == GLRStepType::RENDER) { + if (steps_.size() && steps_.back()->stepType == GLRStepType::RENDER && steps_.back()->render.framebuffer == fb) { if (color != GLRRenderPassAction::CLEAR && depth != GLRRenderPassAction::CLEAR && stencil != GLRRenderPassAction::CLEAR) { // We don't move to a new step, this bind was unnecessary and we can safely skip it. curRenderStep_ = steps_.back(); @@ -197,7 +197,7 @@ void GLRenderManager::BindFramebufferAsRenderTarget(GLRFramebuffer *fb, GLRRende } } if (curRenderStep_ && curRenderStep_->commands.size() == 0) { - VLOG("Empty render step. Usually happens after uploading pixels.."); + VLOG("Empty render step. Usually happens after uploading pixels."); } GLRStep *step = new GLRStep{ GLRStepType::RENDER }; diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 281a42353f..55b565fb65 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -413,7 +413,6 @@ public: void BeginFrame(); // Can run on a different thread! void Finish(); - bool Run(GLRRenderThreadTask &task); // Creation commands. These were not needed in Vulkan since there we can do that on the main thread. // We pass in width/height here even though it's not strictly needed until we support glTextureStorage @@ -535,7 +534,7 @@ public: // This starts a new step (like a "render pass" in Vulkan). // - // After a "CopyFramebuffer" or the other functions that start "steps", you need to call this beforce + // After a "CopyFramebuffer" or the other functions that start "steps", you need to call this before // making any new render state changes or draw calls. // // The following state needs to be reset by the caller after calling this (and will thus not safely carry over from @@ -632,14 +631,6 @@ public: #endif } - void BindPixelPackBuffer(GLRBuffer *buffer) { // Want to support an offset but can't in ES 2.0. We supply an offset when binding the buffers instead. - _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data{ GLRRenderCommand::BIND_BUFFER }; - data.bind_buffer.buffer = buffer; - data.bind_buffer.target = GL_PIXEL_PACK_BUFFER; - curRenderStep_->commands.push_back(data); - } - void BindIndexBuffer(GLRBuffer *buffer) { // Want to support an offset but can't in ES 2.0. We supply an offset when binding the buffers instead. _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); GLRRenderData data{ GLRRenderCommand::BIND_BUFFER}; @@ -1008,6 +999,8 @@ public: } private: + bool Run(GLRRenderThreadTask &task); + // Bad for performance but sometimes necessary for synchronous CPU readbacks (screenshots and whatnot). void FlushSync(); diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 0f04ee0415..b073dbe8c5 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -1262,7 +1262,7 @@ bool OpenGLPipeline::LinkShaders(const PipelineDesc &desc) { for (int i = 0; i < (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS); i++) { queries.push_back({ &locs_->samplerLocs_[i], samplers_[i].name, true }); } - samplersToCheck = (int)samplers_.size(); + samplersToCheck = (int)std::min((const uint32_t)samplers_.size(), MAX_TEXTURE_SLOTS); } else { queries.push_back({ &locs_->samplerLocs_[0], "sampler0" }); queries.push_back({ &locs_->samplerLocs_[1], "sampler1" }); diff --git a/Common/Render/TextureAtlas.h b/Common/Render/TextureAtlas.h index aed38e273f..4c73e0a120 100644 --- a/Common/Render/TextureAtlas.h +++ b/Common/Render/TextureAtlas.h @@ -110,7 +110,7 @@ struct AtlasFont { char name[32]; // Returns 0 on no match. - const AtlasChar *getChar(int utf32) const ; + const AtlasChar *getChar(int utf32) const; }; struct AtlasImage { diff --git a/SDL/SDLGLGraphicsContext.h b/SDL/SDLGLGraphicsContext.h index 83392925a9..06832470a7 100644 --- a/SDL/SDLGLGraphicsContext.h +++ b/SDL/SDLGLGraphicsContext.h @@ -44,7 +44,7 @@ public: private: Draw::DrawContext *draw_ = nullptr; - SDL_Window *window_; + SDL_Window *window_ = nullptr; SDL_GLContext glContext = nullptr; GLRenderManager *renderManager_ = nullptr; };