Skip to content

Commit 05e597f

Browse files
Reduce GPU mem usage / spikes
Change creates a cap for the texture size to increase reuse of textures from the BitmapTexturePool. A fix is also added to account for the depth buffer in the pool usage accounting algorithm.
1 parent 6ba89b2 commit 05e597f

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ RefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, Opt
7070
m_textures.append(Entry(BitmapTexture::create(size, flags)));
7171
selectedEntry = &m_textures.last();
7272
m_poolSize += size.unclampedArea();
73+
74+
if (flags.contains(BitmapTexture::Flags::DepthBuffer))
75+
m_poolSize += size.unclampedArea();
7376
} else
7477
selectedEntry->m_texture->reset(size, flags);
7578

@@ -100,6 +103,10 @@ void BitmapTexturePool::releaseUnusedTexturesTimerFired()
100103
m_textures.removeAllMatching([this, &minUsedTime](const Entry& entry) {
101104
if (entry.canBeReleased(minUsedTime)) {
102105
m_poolSize -= entry.m_texture->size().unclampedArea();
106+
107+
if (entry.m_texture->flags().contains(BitmapTexture::Flags::DepthBuffer))
108+
m_poolSize -= entry.m_texture->size().unclampedArea();
109+
103110
return true;
104111
}
105112
return false;

Source/WebCore/platform/graphics/texmap/TextureMapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ class TextureMapperGLData {
112112
SharedGLData()
113113
{
114114
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize);
115+
116+
#ifdef GL_TEXTURE_MAX_SIZE
117+
// Limit the max texture size to allow textures reuse and reduce GPU mem spikes
118+
if (m_maxTextureSize > GL_TEXTURE_MAX_SIZE)
119+
m_maxTextureSize = GL_TEXTURE_MAX_SIZE;
120+
#endif
115121
}
116122

117123
HashMap<unsigned, RefPtr<TextureMapperShaderProgram>> m_programs;

Source/cmake/OptionsWPE.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ if (USER_AGENT_BRANDING)
382382
add_definitions(-DUSER_AGENT_BRANDING=${USER_AGENT_BRANDING})
383383
endif ()
384384

385+
if (GL_TEXTURE_MAX_SIZE)
386+
add_definitions(-DGL_TEXTURE_MAX_SIZE=${GL_TEXTURE_MAX_SIZE})
387+
endif ()
388+
385389
if (NOT EXISTS "${TOOLS_DIR}/glib/apply-build-revision-to-files.py")
386390
set(BUILD_REVISION "tarball")
387391
endif ()

0 commit comments

Comments
 (0)