Browse Source

Add font texture atlas benchmark profiling zones [no-merge]

Michael Ragazzon 4 months ago
parent
commit
f52b436e62

+ 5 - 2
Source/Core/FontEngineDefault/SpriteSet.cpp

@@ -1,4 +1,5 @@
 #include "SpriteSet.h"
+#include "../../../Include/RmlUi/Core/Log.h"
 #include "../../../Include/RmlUi/Core/Profiling.h"
 #include "../../../Include/RmlUi/Core/Types.h"
 #include <algorithm>
@@ -132,7 +133,7 @@ SpriteSet::Handle SpriteSet::Add(const unsigned int width, const unsigned int he
 
 unsigned int SpriteSet::Allocate(const unsigned int width, const unsigned int height)
 {
-	ZoneScoped;
+	RMLUI_ZoneScoped;
 
 	// Try to allocate in an existing page.
 	if (first_page_index != null_index)
@@ -178,7 +179,7 @@ unsigned int SpriteSet::Allocate(const unsigned int width, const unsigned int he
 	Page& page = page_pool[last_page_index];
 	page.texture_id = page_count;
 	page.texture_data = UniquePtr<unsigned char[]>(new unsigned char[page_size * page_size * bytes_per_pixel]);
-	Log::Message(Log::LT_INFO, "SpriteSet - Allocating new page %u with size %u x %u", page_count, page_size, page_size);
+	Log::Message(Log::LT_INFO, "SpriteSet - Allocating new page %u with size %u x %u", last_page_index, page_size, page_size);
 	memset(page.texture_data.get(), 0, page_size * page_size * bytes_per_pixel);
 	page.first_dirty_y = page_size;
 	page.past_last_dirty_y = 0;
@@ -404,6 +405,8 @@ unsigned int SpriteSet::Remove(const unsigned int slot_index)
 		return slot_pixels;
 	FreeEntry<Slot>(slot_pool, next_free_slot_index, slot_index);
 	FreeEntry<Shelf>(shelf_pool, next_free_shelf_index, page.first_shelf_index);
+	if (page.texture_data)
+		Log::Message(Log::LT_INFO, "SpriteSet - Deallocating page %u with size %u x %u", page_index, page_size, page_size);
 	page.texture_data.reset();
 	page_pool[page.previous_index].next_index = page.next_index;
 	if (page_index != last_page_index)

+ 17 - 7
Tests/Source/Benchmarks/FontTextureAtlas.cpp

@@ -3,6 +3,7 @@
 #include <RmlUi/Core/Core.h>
 #include <RmlUi/Core/Element.h>
 #include <RmlUi/Core/ElementDocument.h>
+#include <RmlUi/Core/Profiling.h>
 #include <RmlUi/Core/Types.h>
 #include <doctest.h>
 #include <nanobench.h>
@@ -50,6 +51,7 @@ TEST_CASE("font_texture_atlas")
 	bench.title("Font texture atlas (incremental)");
 	//}
 	bench.relative(true);
+	bench.epochIterations(50);
 
 	for (const int font_size : {12})
 	{
@@ -70,15 +72,23 @@ TEST_CASE("font_texture_atlas")
 			if (incremental)
 			{
 				bench.run(benchmark_name, [&]() {
-					ReleaseFontResources();
-					std::string inner_rml;
-					for (int i = 0; i < glyph_count; ++i)
+					RMLUI_ZoneScopedN("Font texture atlas incremental");
 					{
-						inner_rml += StringUtilities::ToUTF8(static_cast<Character>(rml_font_texture_atlas_start_codepoint + i));
-						body->SetInnerRML(inner_rml);
+						RMLUI_ZoneScopedN("ReleaseFontResources");
+						ReleaseFontResources();
+					}
+
+					{
+						RMLUI_ZoneScopedN("Change RML");
+						std::string inner_rml;
+						for (int i = 0; i < glyph_count; ++i)
+						{
+							inner_rml += StringUtilities::ToUTF8(static_cast<Character>(rml_font_texture_atlas_start_codepoint + i));
+							body->SetInnerRML(inner_rml);
+						}
+						context->Update();
+						context->Render();
 					}
-					context->Update();
-					context->Render();
 				});
 			}
 			else