Skip to content

Commit

Permalink
Add ability for RenderManager to release not recently used geometry.
Browse files Browse the repository at this point in the history
To keep our buffer usage down.
  • Loading branch information
exjam committed Jan 2, 2025
1 parent 05542d6 commit 9cc16a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Include/RmlUi/Core/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {
RenderManager(RenderInterface* render_interface);
~RenderManager();

void StartFrame();
void ReleaseOldCompiledGeometry();

void PrepareRender();
void SetViewport(Vector2i dimensions);
Vector2i GetViewport() const;
Expand Down Expand Up @@ -135,6 +138,7 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {
struct GeometryData {
Mesh mesh;
CompiledGeometryHandle handle = {};
uint32_t last_used_frame_id = 0;
};

RenderInterface* render_interface = nullptr;
Expand All @@ -144,6 +148,7 @@ class RMLUICORE_API RenderManager : NonCopyMoveable {

int compiled_filter_count = 0;
int compiled_shader_count = 0;
uint32_t frame_id = 0;

RenderState state;
Vector2i viewport_dimensions;
Expand Down
17 changes: 17 additions & 0 deletions Source/Core/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ StableVectorIndex RenderManager::InsertGeometry(Mesh&& mesh)
return geometry_list.insert(GeometryData{std::move(mesh), CompiledGeometryHandle{}});
}

void RenderManager::StartFrame()
{
frame_id++;
}

CompiledGeometryHandle RenderManager::GetCompiledGeometryHandle(StableVectorIndex index)
{
if (index == StableVectorIndex::Invalid)
Expand All @@ -230,6 +235,7 @@ CompiledGeometryHandle RenderManager::GetCompiledGeometryHandle(StableVectorInde
if (!geometry.handle)
Log::Message(Log::LT_ERROR, "Got empty compiled geometry.");
}
geometry.last_used_frame_id = frame_id;
return geometry.handle;
}

Expand Down Expand Up @@ -284,6 +290,17 @@ void RenderManager::ReleaseAllCompiledGeometry()
});
}

void RenderManager::ReleaseOldCompiledGeometry()
{
geometry_list.for_each([this](GeometryData& data) {
if (data.handle && (frame_id - data.last_used_frame_id) > 5)
{
render_interface->ReleaseGeometry(data.handle);
data.handle = {};
}
});
}

CompiledFilter RenderManager::CompileFilter(const String& name, const Dictionary& parameters)
{
if (CompiledFilterHandle handle = render_interface->CompileFilter(name, parameters))
Expand Down

0 comments on commit 9cc16a9

Please sign in to comment.