TextServerFallback: improve performance by removing redundant lookups

+ caching editor setting
+ using a faster hash method on the FontForSizeFallback cache
+ SafeFlag instead of mutex for ShapedTextDataFallback::valid bc its read Very often
This commit is contained in:
rune-scape 2024-05-30 22:57:28 -07:00
parent 40b378e9e2
commit 2fc5321d39
2 changed files with 374 additions and 295 deletions

File diff suppressed because it is too large Load Diff

View File

@ -72,6 +72,7 @@
#include <godot_cpp/templates/hash_map.hpp> #include <godot_cpp/templates/hash_map.hpp>
#include <godot_cpp/templates/hash_set.hpp> #include <godot_cpp/templates/hash_set.hpp>
#include <godot_cpp/templates/rid_owner.hpp> #include <godot_cpp/templates/rid_owner.hpp>
#include <godot_cpp/templates/safe_refcount.hpp>
#include <godot_cpp/templates/vector.hpp> #include <godot_cpp/templates/vector.hpp>
using namespace godot; using namespace godot;
@ -83,6 +84,7 @@ using namespace godot;
#include "core/object/worker_thread_pool.h" #include "core/object/worker_thread_pool.h"
#include "core/templates/hash_map.h" #include "core/templates/hash_map.h"
#include "core/templates/rid_owner.h" #include "core/templates/rid_owner.h"
#include "core/templates/safe_refcount.h"
#include "scene/resources/image_texture.h" #include "scene/resources/image_texture.h"
#include "servers/text/text_server_extension.h" #include "servers/text/text_server_extension.h"
@ -116,6 +118,9 @@ class TextServerFallback : public TextServerExtension {
HashMap<StringName, int32_t> feature_sets; HashMap<StringName, int32_t> feature_sets;
HashMap<int32_t, StringName> feature_sets_inv; HashMap<int32_t, StringName> feature_sets_inv;
SafeNumeric<TextServer::FontLCDSubpixelLayout> lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE };
void _update_settings();
void _insert_feature_sets(); void _insert_feature_sets();
_FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag); _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag);
@ -278,7 +283,7 @@ class TextServerFallback : public TextServerExtension {
int extra_spacing[4] = { 0, 0, 0, 0 }; int extra_spacing[4] = { 0, 0, 0, 0 };
double baseline_offset = 0.0; double baseline_offset = 0.0;
HashMap<Vector2i, FontForSizeFallback *, VariantHasher, VariantComparator> cache; HashMap<Vector2i, FontForSizeFallback *> cache;
bool face_init = false; bool face_init = false;
Dictionary supported_varaitions; Dictionary supported_varaitions;
@ -308,8 +313,8 @@ class TextServerFallback : public TextServerExtension {
#ifdef MODULE_FREETYPE_ENABLED #ifdef MODULE_FREETYPE_ENABLED
_FORCE_INLINE_ FontGlyph rasterize_bitmap(FontForSizeFallback *p_data, int p_rect_margin, FT_Bitmap p_bitmap, int p_yofs, int p_xofs, const Vector2 &p_advance, bool p_bgra) const; _FORCE_INLINE_ FontGlyph rasterize_bitmap(FontForSizeFallback *p_data, int p_rect_margin, FT_Bitmap p_bitmap, int p_yofs, int p_xofs, const Vector2 &p_advance, bool p_bgra) const;
#endif #endif
_FORCE_INLINE_ bool _ensure_glyph(FontFallback *p_font_data, const Vector2i &p_size, int32_t p_glyph) const; _FORCE_INLINE_ bool _ensure_glyph(FontFallback *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph) const;
_FORCE_INLINE_ bool _ensure_cache_for_size(FontFallback *p_font_data, const Vector2i &p_size) const; _FORCE_INLINE_ bool _ensure_cache_for_size(FontFallback *p_font_data, const Vector2i &p_size, FontForSizeFallback *&r_cache_for_size) const;
_FORCE_INLINE_ void _font_clear_cache(FontFallback *p_font_data); _FORCE_INLINE_ void _font_clear_cache(FontFallback *p_font_data);
static void _generateMTSDF_threaded(void *p_td, uint32_t p_y); static void _generateMTSDF_threaded(void *p_td, uint32_t p_y);
@ -432,7 +437,7 @@ class TextServerFallback : public TextServerExtension {
/* Shaped data */ /* Shaped data */
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction. TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.
bool valid = false; // String is shaped. SafeFlag valid{ false }; // String is shaped.
bool line_breaks_valid = false; // Line and word break flags are populated (and virtual zero width spaces inserted). bool line_breaks_valid = false; // Line and word break flags are populated (and virtual zero width spaces inserted).
bool justification_ops_valid = false; // Virtual elongation glyphs are added to the string. bool justification_ops_valid = false; // Virtual elongation glyphs are added to the string.
bool sort_valid = false; bool sort_valid = false;