Avoid issuing many glTexSubImage2D() calls when uploading shm contents

Applications that use QtWidgets can have a lot of rectangles in the
damage region. For example, when you navigate between directories in
Dolphin, each individual file or folder item will be added to the
damage region rather than the container view where they are.

On the other hand, issuing multiple glTexSubImage2D() function calls
is not great because it means stalling the cpu until the texture upload
completes.

This change attempts to improve that by simplifying the input damage.
If the input damage isn't complex, use it as is; otherwise use its
bounding rect.

The gains are not impressive. On my machine, I see fewer 5ms texture
upload time spikes when navigating in Dolphin, now I can observe 4ms
spikes instead. Still, I believe the change is reasonable enough.
This commit is contained in:
Vlad Zahorodnii 2024-08-14 11:46:36 +03:00
parent 6b3f211ef7
commit 2cc3f9cdee

View file

@ -86,6 +86,15 @@ bool BasicEGLSurfaceTextureWayland::loadShmTexture(GraphicsBuffer *buffer)
return true;
}
static QRegion simplifyDamage(const QRegion &damage)
{
if (damage.rectCount() < 3) {
return damage;
} else {
return damage.boundingRect();
}
}
void BasicEGLSurfaceTextureWayland::updateShmTexture(GraphicsBuffer *buffer, const QRegion &region)
{
if (Q_UNLIKELY(m_bufferType != BufferType::Shm)) {
@ -99,7 +108,8 @@ void BasicEGLSurfaceTextureWayland::updateShmTexture(GraphicsBuffer *buffer, con
return;
}
for (const QRect &rect : region) {
const QRegion simplifiedDamage = simplifyDamage(region);
for (const QRect &rect : simplifiedDamage) {
m_texture.planes[0]->update(*view.image(), rect.topLeft(), rect);
}
}