From ad53a5e4ee745f0633348aef3fb2fb77d071250f Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 4 Aug 2026 10:54:45 +1000 Subject: [PATCH] [client] egl: stop aliasing damage tracking layouts Pass damage rectangle arrays and counts explicitly to the EGL mesh updater instead of casting DesktopDamage to DamageRects. --- client/renderers/EGL/damage.c | 2 +- client/renderers/EGL/desktop.c | 6 ++++-- client/renderers/EGL/desktop_rects.c | 31 ++++++++++++++-------------- client/renderers/EGL/desktop_rects.h | 6 +++--- client/renderers/EGL/postprocess.c | 6 ++++-- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/client/renderers/EGL/damage.c b/client/renderers/EGL/damage.c index b4479741..f3d2a356 100644 --- a/client/renderers/EGL/damage.c +++ b/client/renderers/EGL/damage.c @@ -169,7 +169,7 @@ bool egl_damageRender(EGL_Damage * damage, LG_RendererRotate rotate, const struc egl_shaderUse(damage->shader); if (data && data->count != 0) - egl_desktopRectsUpdate(damage->mesh, (const struct DamageRects *) data, + egl_desktopRectsUpdate(damage->mesh, data->rects, data->count, damage->width, damage->height); egl_desktopRectsRender(damage->mesh); diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index fe59cc02..dd214bc3 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -508,7 +508,9 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth, egl_desktopRectsMatrix(desktop->matrix, width, height, x, y, scaleX, scaleY, rotate); - egl_desktopRectsUpdate(desktop->mesh, rects, width, height); + egl_desktopRectsUpdate(desktop->mesh, + rects ? rects->rects : NULL, rects ? rects->count : -1, + width, height); const bool hdr = desktop->hdr && !desktop->useSpice; uint32_t hdrPeak = 0; @@ -539,7 +541,7 @@ bool egl_desktopRender(EGL_Desktop * desktop, unsigned int outputWidth, { /* The filter output may have changed everywhere, but this only applies * to the render that actually evaluated the filter. */ - egl_desktopRectsUpdate(desktop->mesh, NULL, width, height); + egl_desktopRectsUpdate(desktop->mesh, NULL, -1, width, height); *fullFrame = true; } } diff --git a/client/renderers/EGL/desktop_rects.c b/client/renderers/EGL/desktop_rects.c index 74568da6..37cfea76 100644 --- a/client/renderers/EGL/desktop_rects.c +++ b/client/renderers/EGL/desktop_rects.c @@ -107,18 +107,18 @@ inline static void rectToVertices(GLfloat * vertex, const FrameDamageRect * rect vertex[7] = rect->y + rect->height; } -void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * data, - int width, int height) +void egl_desktopRectsUpdate(EGL_DesktopRects * rects, + const FrameDamageRect * data, int count, int width, int height) { - if (data && data->count == 0) + if (count == 0) { rects->count = 0; return; } - const int count = (!data || data->count < 0 ? 1 : data->count) * 8; - GLfloat vertices[count]; - if (!data || data->count < 0) + const int vertexCount = (count < 0 ? 1 : count) * 8; + GLfloat vertices[vertexCount]; + if (count < 0) { FrameDamageRect full = { .x = 0, .y = 0, .width = width, .height = height, @@ -128,36 +128,37 @@ void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * } else { - rects->count = data->count; + rects->count = count; DEBUG_ASSERT(rects->count <= rects->maxCount); for (int i = 0; i < rects->count; ++i) - rectToVertices(vertices + i * 8, data->rects + i); + rectToVertices(vertices + i * 8, data + i); } // check if the value actually changed and needs updating - if (count == rects->lastVerticesCount && - memcmp(rects->lastVertices, vertices, sizeof(GLfloat) * count) == 0) + if (vertexCount == rects->lastVerticesCount && + memcmp(rects->lastVertices, vertices, + sizeof(GLfloat) * vertexCount) == 0) return; // ensure the local storage is large enough - if (count > rects->lastVerticesSize) + if (vertexCount > rects->lastVerticesSize) { if (rects->lastVertices) free(rects->lastVertices); - rects->lastVertices = malloc(sizeof(GLfloat) * count); + rects->lastVertices = malloc(sizeof(GLfloat) * vertexCount); if (!rects->lastVertices) { DEBUG_ERROR("out of memory"); return; } - rects->lastVerticesSize = count; + rects->lastVerticesSize = vertexCount; } // copy the last value for later comparison - rects->lastVerticesCount = count; - memcpy(rects->lastVertices, vertices, sizeof(GLfloat) * count); + rects->lastVerticesCount = vertexCount; + memcpy(rects->lastVertices, vertices, sizeof(GLfloat) * vertexCount); egl_stateBindBuffer(GL_ARRAY_BUFFER, rects->buffers[0]); glBufferSubData(GL_ARRAY_BUFFER, 0, rects->count * 8 * sizeof(GLfloat), vertices); diff --git a/client/renderers/EGL/desktop_rects.h b/client/renderers/EGL/desktop_rects.h index b7c4da39..41724585 100644 --- a/client/renderers/EGL/desktop_rects.h +++ b/client/renderers/EGL/desktop_rects.h @@ -48,6 +48,6 @@ void egl_screenToDesktopMatrix(double matrix[6], int frameWidth, int frameHeight bool egl_screenToDesktop(struct FrameDamageRect * output, const double matrix[6], const struct Rect * rect, int width, int height); -void egl_desktopRectsUpdate(EGL_DesktopRects * rects, const struct DamageRects * data, - int width, int height); -void egl_desktopRectsRender(EGL_DesktopRects * rects); \ No newline at end of file +void egl_desktopRectsUpdate(EGL_DesktopRects * rects, + const FrameDamageRect * data, int count, int width, int height); +void egl_desktopRectsRender(EGL_DesktopRects * rects); diff --git a/client/renderers/EGL/postprocess.c b/client/renderers/EGL/postprocess.c index bc91ee5d..3df60887 100644 --- a/client/renderers/EGL/postprocess.c +++ b/client/renderers/EGL/postprocess.c @@ -906,13 +906,15 @@ bool egl_postProcessRun(EGL_PostProcess * this, EGL_Texture * tex, } rects = this->rects; - egl_desktopRectsUpdate(rects, NULL, desktopWidth, desktopHeight); + egl_desktopRectsUpdate( + rects, NULL, -1, desktopWidth, desktopHeight); } if (this->config.fullFrame) { rects = this->rects; - egl_desktopRectsUpdate(rects, NULL, desktopWidth, desktopHeight); + egl_desktopRectsUpdate( + rects, NULL, -1, desktopWidth, desktopHeight); } EGL_FilterRects filterRects = {