mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[client] egl: only upload the damage rects if they actually changed
Profiling shows that a considerable amount of time is spent in glBindBuffer and glBufferSubData when the damage rects are updated. Since the amount of data here is quite small it's far faster to check if it's different then to just blindly overwrite the buffer on each call. Profiled on an Intel CPU with UHD P630 Graphics using magic-trace
This commit is contained in:
parent
6b9fa2b628
commit
2901e7aec5
@ -32,6 +32,10 @@
|
||||
|
||||
struct EGL_DesktopRects
|
||||
{
|
||||
GLfloat * lastVertices;
|
||||
int lastVerticesCount;
|
||||
int lastVerticesSize;
|
||||
|
||||
GLuint buffers[2];
|
||||
GLuint vao;
|
||||
int count;
|
||||
@ -88,6 +92,7 @@ void egl_desktopRectsFree(EGL_DesktopRects ** rects_)
|
||||
|
||||
glDeleteVertexArrays(1, &rects->vao);
|
||||
glDeleteBuffers(2, rects->buffers);
|
||||
free(rects->lastVertices);
|
||||
free(rects);
|
||||
*rects_ = NULL;
|
||||
}
|
||||
@ -113,7 +118,8 @@ void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects *
|
||||
return;
|
||||
}
|
||||
|
||||
GLfloat vertices[(!data || data->count < 0 ? 1 : data->count) * 8];
|
||||
const int count = (!data || data->count < 0 ? 1 : data->count) * 8;
|
||||
GLfloat vertices[count];
|
||||
if (!data || data->count < 0)
|
||||
{
|
||||
FrameDamageRect full = {
|
||||
@ -131,6 +137,30 @@ void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects *
|
||||
rectToVertices(vertices + i * 8, data->rects + i);
|
||||
}
|
||||
|
||||
// check if the value actually changed and needs updating
|
||||
if (count == rects->lastVerticesCount &&
|
||||
memcmp(rects->lastVertices, vertices, sizeof(GLfloat) * count) == 0)
|
||||
return;
|
||||
|
||||
// ensure the local storage is large enough
|
||||
if (count > rects->lastVerticesSize)
|
||||
{
|
||||
if (rects->lastVertices)
|
||||
free(rects->lastVertices);
|
||||
|
||||
rects->lastVertices = malloc(sizeof(GLfloat) * count);
|
||||
if (!rects->lastVertices)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return;
|
||||
}
|
||||
rects->lastVerticesSize = count;
|
||||
}
|
||||
|
||||
// copy the last value for later comparison
|
||||
rects->lastVerticesCount = count;
|
||||
memcpy(rects->lastVertices, vertices, sizeof(GLfloat) * count);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rects->buffers[0]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, rects->count * 8 * sizeof(GLfloat), vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user