Improve Android performance (#1125)

* Improve Android performance

* Remove unused memset

* Using the same code as Metal.

* Add a comment
This commit is contained in:
Sam 2023-03-21 19:43:37 +08:00 committed by GitHub
parent cd76849c4d
commit 8a4494606a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 28 deletions

View File

@ -995,8 +995,10 @@ void Renderer::TriangleCommandBufferManager::createBuffer()
{
auto device = backend::Device::getInstance();
#ifdef AX_USE_METAL
// Metal doesn't need to update buffer to make sure it has the correct size.
// Not initializing the buffer before passing it to updateData for Android/OpenGL ES.
// This change does fix the Android/OpenGL ES performance problem
// If for some reason we get reports of performance issues on OpenGL implementations,
// then we can just add pre-processor checks for OpenGL and have the updateData() allocate the full size after buffer creation.
auto vertexBuffer = device->newBuffer(Renderer::VBO_SIZE * sizeof(_verts[0]), backend::BufferType::VERTEX,
backend::BufferUsage::DYNAMIC);
if (!vertexBuffer)
@ -1009,32 +1011,6 @@ void Renderer::TriangleCommandBufferManager::createBuffer()
vertexBuffer->release();
return;
}
#else
auto tmpData = malloc(Renderer::VBO_SIZE * sizeof(V3F_C4B_T2F));
if (!tmpData)
return;
auto vertexBuffer = device->newBuffer(Renderer::VBO_SIZE * sizeof(V3F_C4B_T2F), backend::BufferType::VERTEX,
backend::BufferUsage::DYNAMIC);
if (!vertexBuffer)
{
free(tmpData);
return;
}
vertexBuffer->updateData(tmpData, Renderer::VBO_SIZE * sizeof(V3F_C4B_T2F));
auto indexBuffer = device->newBuffer(Renderer::INDEX_VBO_SIZE * sizeof(unsigned short), backend::BufferType::INDEX,
backend::BufferUsage::DYNAMIC);
if (!indexBuffer)
{
free(tmpData);
vertexBuffer->release();
return;
}
indexBuffer->updateData(tmpData, Renderer::INDEX_VBO_SIZE * sizeof(unsigned short));
free(tmpData);
#endif
_vertexBufferPool.emplace_back(vertexBuffer);
_indexBufferPool.emplace_back(indexBuffer);