Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #20595, lots of memory leaks on Renderer::addCommand using CustomCommand #20598

Open
wants to merge 3 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cocos/renderer/backend/ProgramState.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "renderer/backend/Types.h"
#include "renderer/backend/Program.h"
#include "renderer/backend/VertexLayout.h"
#include "renderer/backend/Buffer.h"

CC_BACKEND_BEGIN

Expand Down Expand Up @@ -182,14 +183,14 @@ class ProgramState : public Ref
* @param[out] size Specifies the size of the buffer in bytes.
*/
void getVertexUniformBuffer(char** buffer, std::size_t& size) const;

/**
* Get fragment uniform buffer. The buffer store all the fragment uniform's data for metal.
* @param[out] buffer Specifies the pointer points to a fragment uniform storage.
* @param[out] size Specifies the size of the buffer in bytes.
*/
void getFragmentUniformBuffer(char** buffer, std::size_t& size) const;

/**
* An abstract base class that can be extended to support custom material auto bindings.
*
Expand Down Expand Up @@ -323,7 +324,7 @@ class ProgramState : public Ref
char* _fragmentUniformBuffer = nullptr;
std::size_t _vertexUniformBufferSize = 0;
std::size_t _fragmentUniformBufferSize = 0;

std::unordered_map<int, TextureInfo> _vertexTextureInfos;
std::unordered_map<int, TextureInfo> _fragmentTextureInfos;

Expand Down
14 changes: 5 additions & 9 deletions cocos/renderer/backend/metal/CommandBufferMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,14 @@ inline int clamp(int value, int min, int max) {
{
cb.second(_programState, cb.first);
}

// Uniform buffer is bound to index 1.

std::size_t bufferSize = 0;
char* vertexBuffer = nullptr;
_programState->getVertexUniformBuffer(&vertexBuffer, bufferSize);
if(vertexBuffer)
{
[_mtlRenderEncoder setVertexBytes:vertexBuffer
length:bufferSize
atIndex:1];
}

[_mtlRenderEncoder setVertexBytes:vertexBuffer
length:bufferSize
atIndex:1];

char* fragmentBuffer = nullptr;
_programState->getFragmentUniformBuffer(&fragmentBuffer, bufferSize);
if(fragmentBuffer)
Expand Down