From c61515cd8d6fb508f951bb66072913db74fabfb1 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 21 Jul 2022 23:31:38 +0300 Subject: [PATCH] kwinglutils: restore alignment logic for Mali GPU Contributes to: https://invent.kde.org/teams/plasma-mobile/issues/-/issues/172 --- src/libkwineffects/kwinglutils.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libkwineffects/kwinglutils.cpp b/src/libkwineffects/kwinglutils.cpp index 230c39887a..cf1534492e 100644 --- a/src/libkwineffects/kwinglutils.cpp +++ b/src/libkwineffects/kwinglutils.cpp @@ -1335,6 +1335,14 @@ static const uint16_t indices[] = { 2029, 2028, 2031, 2031, 2030, 2029, 2033, 2032, 2035, 2035, 2034, 2033, 2037, 2036, 2039, 2039, 2038, 2037, 2041, 2040, 2043, 2043, 2042, 2041, 2045, 2044, 2047, 2047, 2046, 2045}; +// Certain GPUs, especially mobile, require the data copied to the GPU to be aligned to a +// certain amount of bytes. For example, the Mali GPU requires data to be aligned to 8 bytes. +// This function helps ensure that the data is aligned. +template +T align(T value, int bytes) +{ + return (value + bytes - 1) & ~T(bytes - 1); +} class IndexBuffer { @@ -1914,7 +1922,7 @@ void GLVertexBuffer::unmap() { if (d->persistent) { d->baseAddress = d->nextOffset; - d->nextOffset += d->mappedSize; + d->nextOffset += align(d->mappedSize, 8); d->mappedSize = 0; return; } @@ -1925,6 +1933,7 @@ void GLVertexBuffer::unmap() glUnmapBuffer(GL_ARRAY_BUFFER); d->baseAddress = d->nextOffset; + d->nextOffset += align(d->mappedSize, 8); } else { // Upload the data from local memory to the buffer object if (preferBufferSubData) { @@ -1936,7 +1945,7 @@ void GLVertexBuffer::unmap() glBufferSubData(GL_ARRAY_BUFFER, d->nextOffset, d->mappedSize, d->dataStore.constData()); d->baseAddress = d->nextOffset; - d->nextOffset += d->mappedSize; + d->nextOffset += align(d->mappedSize, 8); } else { glBufferData(GL_ARRAY_BUFFER, d->mappedSize, d->dataStore.data(), d->usage); d->baseAddress = 0;