Merge pull request #92575 from rune-scape/rune-text-srvr-cacher

TextServerAdvanced: 2x performance improvement by removing redundant lookups
This commit is contained in:
Rémi Verschelde 2024-08-29 10:36:23 +02:00
commit 03d1f43131
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 411 additions and 322 deletions

File diff suppressed because it is too large Load diff

View file

@ -74,6 +74,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;
@ -85,6 +86,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"
@ -151,6 +153,9 @@ class TextServerAdvanced : public TextServerExtension {
HashMap<StringName, int32_t> feature_sets; HashMap<StringName, int32_t> feature_sets;
HashMap<int32_t, FeatureInfo> feature_sets_inv; HashMap<int32_t, FeatureInfo> feature_sets_inv;
SafeNumeric<TextServer::FontLCDSubpixelLayout> lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE };
void _update_settings();
void _insert_num_systems_lang(); void _insert_num_systems_lang();
void _insert_feature_sets(); void _insert_feature_sets();
_FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false); _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false);
@ -327,7 +332,7 @@ class TextServerAdvanced : 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, FontForSizeAdvanced *, VariantHasher, VariantComparator> cache; HashMap<Vector2i, FontForSizeAdvanced *> cache;
bool face_init = false; bool face_init = false;
HashSet<uint32_t> supported_scripts; HashSet<uint32_t> supported_scripts;
@ -359,8 +364,8 @@ class TextServerAdvanced : public TextServerExtension {
#ifdef MODULE_FREETYPE_ENABLED #ifdef MODULE_FREETYPE_ENABLED
_FORCE_INLINE_ FontGlyph rasterize_bitmap(FontForSizeAdvanced *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(FontForSizeAdvanced *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(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph) const; _FORCE_INLINE_ bool _ensure_glyph(FontAdvanced *p_font_data, const Vector2i &p_size, int32_t p_glyph, FontGlyph &r_glyph) const;
_FORCE_INLINE_ bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size) const; _FORCE_INLINE_ bool _ensure_cache_for_size(FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size) const;
_FORCE_INLINE_ void _font_clear_cache(FontAdvanced *p_font_data); _FORCE_INLINE_ void _font_clear_cache(FontAdvanced *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);
@ -487,7 +492,7 @@ class TextServerAdvanced : public TextServerExtension {
/* Shaped data */ /* Shaped data */
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction. TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.
int base_para_direction = UBIDI_DEFAULT_LTR; int base_para_direction = UBIDI_DEFAULT_LTR;
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;