mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 22:08:41 +00:00
font cache: add additional layer of caching for runs
This commit is contained in:
@@ -121,6 +121,9 @@ update(void)
|
|||||||
{
|
{
|
||||||
ProfTick(0);
|
ProfTick(0);
|
||||||
ins_atomic_u64_inc_eval(&global_update_tick_idx);
|
ins_atomic_u64_inc_eval(&global_update_tick_idx);
|
||||||
|
#if defined(FONT_CACHE_H)
|
||||||
|
fnt_frame();
|
||||||
|
#endif
|
||||||
#if OS_FEATURE_GRAPHICAL
|
#if OS_FEATURE_GRAPHICAL
|
||||||
B32 result = frame();
|
B32 result = frame();
|
||||||
#else
|
#else
|
||||||
|
|||||||
+105
-50
@@ -24,9 +24,9 @@ fnt_hash_from_string(String8 string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal U64
|
internal U64
|
||||||
fnt_little_hash_from_string(String8 string)
|
fnt_little_hash_from_string(U64 seed, String8 string)
|
||||||
{
|
{
|
||||||
U64 result = XXH3_64bits(string.str, string.size);
|
U64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,10 +65,10 @@ internal FP_Handle
|
|||||||
fnt_handle_from_tag(FNT_Tag tag)
|
fnt_handle_from_tag(FNT_Tag tag)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
U64 slot_idx = tag.u64[1] % f_state->font_hash_table_size;
|
U64 slot_idx = tag.u64[1] % fnt_state->font_hash_table_size;
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&tag, &n->tag))
|
if(MemoryMatchStruct(&tag, &n->tag))
|
||||||
{
|
{
|
||||||
@@ -90,10 +90,10 @@ internal FP_Metrics
|
|||||||
fnt_fp_metrics_from_tag(FNT_Tag tag)
|
fnt_fp_metrics_from_tag(FNT_Tag tag)
|
||||||
{
|
{
|
||||||
ProfBeginFunction();
|
ProfBeginFunction();
|
||||||
U64 slot_idx = tag.u64[1] % f_state->font_hash_table_size;
|
U64 slot_idx = tag.u64[1] % fnt_state->font_hash_table_size;
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&tag, &n->tag))
|
if(MemoryMatchStruct(&tag, &n->tag))
|
||||||
{
|
{
|
||||||
@@ -125,12 +125,12 @@ fnt_tag_from_path(String8 path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: tag -> slot index
|
//- rjf: tag -> slot index
|
||||||
U64 slot_idx = result.u64[1] % f_state->font_hash_table_size;
|
U64 slot_idx = result.u64[1] % fnt_state->font_hash_table_size;
|
||||||
|
|
||||||
//- rjf: slot * tag -> existing node
|
//- rjf: slot * tag -> existing node
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&result, &n->tag))
|
if(MemoryMatchStruct(&result, &n->tag))
|
||||||
{
|
{
|
||||||
@@ -144,12 +144,12 @@ fnt_tag_from_path(String8 path)
|
|||||||
FNT_FontHashNode *new_node = 0;
|
FNT_FontHashNode *new_node = 0;
|
||||||
if(existing_node == 0)
|
if(existing_node == 0)
|
||||||
{
|
{
|
||||||
FNT_FontHashSlot *slot = &f_state->font_hash_table[slot_idx];
|
FNT_FontHashSlot *slot = &fnt_state->font_hash_table[slot_idx];
|
||||||
new_node = push_array(f_state->permanent_arena, FNT_FontHashNode, 1);
|
new_node = push_array(fnt_state->permanent_arena, FNT_FontHashNode, 1);
|
||||||
new_node->tag = result;
|
new_node->tag = result;
|
||||||
new_node->handle = fp_font_open(path);
|
new_node->handle = fp_font_open(path);
|
||||||
new_node->metrics = fp_metrics_from_font(new_node->handle);
|
new_node->metrics = fp_metrics_from_font(new_node->handle);
|
||||||
new_node->path = push_str8_copy(f_state->permanent_arena, path);
|
new_node->path = push_str8_copy(fnt_state->permanent_arena, path);
|
||||||
SLLQueuePush_N(slot->first, slot->last, new_node, hash_next);
|
SLLQueuePush_N(slot->first, slot->last, new_node, hash_next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +172,12 @@ fnt_tag_from_static_data_string(String8 *data_ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: tag -> slot index
|
//- rjf: tag -> slot index
|
||||||
U64 slot_idx = result.u64[1] % f_state->font_hash_table_size;
|
U64 slot_idx = result.u64[1] % fnt_state->font_hash_table_size;
|
||||||
|
|
||||||
//- rjf: slot * tag -> existing node
|
//- rjf: slot * tag -> existing node
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&result, &n->tag))
|
if(MemoryMatchStruct(&result, &n->tag))
|
||||||
{
|
{
|
||||||
@@ -191,8 +191,8 @@ fnt_tag_from_static_data_string(String8 *data_ptr)
|
|||||||
FNT_FontHashNode *new_node = 0;
|
FNT_FontHashNode *new_node = 0;
|
||||||
if(existing_node == 0)
|
if(existing_node == 0)
|
||||||
{
|
{
|
||||||
FNT_FontHashSlot *slot = &f_state->font_hash_table[slot_idx];
|
FNT_FontHashSlot *slot = &fnt_state->font_hash_table[slot_idx];
|
||||||
new_node = push_array(f_state->permanent_arena, FNT_FontHashNode, 1);
|
new_node = push_array(fnt_state->permanent_arena, FNT_FontHashNode, 1);
|
||||||
new_node->tag = result;
|
new_node->tag = result;
|
||||||
new_node->handle = fp_font_open_from_static_data_string(data_ptr);
|
new_node->handle = fp_font_open_from_static_data_string(data_ptr);
|
||||||
new_node->metrics = fp_metrics_from_font(new_node->handle);
|
new_node->metrics = fp_metrics_from_font(new_node->handle);
|
||||||
@@ -209,12 +209,12 @@ internal String8
|
|||||||
fnt_path_from_tag(FNT_Tag tag)
|
fnt_path_from_tag(FNT_Tag tag)
|
||||||
{
|
{
|
||||||
//- rjf: tag -> slot index
|
//- rjf: tag -> slot index
|
||||||
U64 slot_idx = tag.u64[1] % f_state->font_hash_table_size;
|
U64 slot_idx = tag.u64[1] % fnt_state->font_hash_table_size;
|
||||||
|
|
||||||
//- rjf: slot * tag -> existing node
|
//- rjf: slot * tag -> existing node
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&tag, &n->tag))
|
if(MemoryMatchStruct(&tag, &n->tag))
|
||||||
{
|
{
|
||||||
@@ -514,7 +514,7 @@ fnt_piece_array_copy(Arena *arena, FNT_PieceArray *src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Rasterization Cache
|
//~ rjf: Cache Usage
|
||||||
|
|
||||||
internal FNT_Hash2StyleRasterCacheNode *
|
internal FNT_Hash2StyleRasterCacheNode *
|
||||||
fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags)
|
fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags)
|
||||||
@@ -530,15 +530,15 @@ fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags)
|
|||||||
*(U64 *)(&size_f64),
|
*(U64 *)(&size_f64),
|
||||||
(U64)flags,
|
(U64)flags,
|
||||||
};
|
};
|
||||||
style_hash = fnt_little_hash_from_string(str8((U8 *)buffer, sizeof(buffer)));
|
style_hash = fnt_little_hash_from_string(5381, str8((U8 *)buffer, sizeof(buffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: style hash -> style node
|
//- rjf: style hash -> style node
|
||||||
FNT_Hash2StyleRasterCacheNode *hash2style_node = 0;
|
FNT_Hash2StyleRasterCacheNode *hash2style_node = 0;
|
||||||
{
|
{
|
||||||
ProfBegin("style hash -> style node");
|
ProfBegin("style hash -> style node");
|
||||||
U64 slot_idx = style_hash%f_state->hash2style_slots_count;
|
U64 slot_idx = style_hash%fnt_state->hash2style_slots_count;
|
||||||
FNT_Hash2StyleRasterCacheSlot *slot = &f_state->hash2style_slots[slot_idx];
|
FNT_Hash2StyleRasterCacheSlot *slot = &fnt_state->hash2style_slots[slot_idx];
|
||||||
for(FNT_Hash2StyleRasterCacheNode *n = slot->first;
|
for(FNT_Hash2StyleRasterCacheNode *n = slot->first;
|
||||||
n != 0;
|
n != 0;
|
||||||
n = n->hash_next)
|
n = n->hash_next)
|
||||||
@@ -552,14 +552,14 @@ fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags)
|
|||||||
if(Unlikely(hash2style_node == 0))
|
if(Unlikely(hash2style_node == 0))
|
||||||
{
|
{
|
||||||
FNT_Metrics metrics = fnt_metrics_from_tag_size(tag, size);
|
FNT_Metrics metrics = fnt_metrics_from_tag_size(tag, size);
|
||||||
hash2style_node = push_array(f_state->raster_arena, FNT_Hash2StyleRasterCacheNode, 1);
|
hash2style_node = push_array(fnt_state->raster_arena, FNT_Hash2StyleRasterCacheNode, 1);
|
||||||
DLLPushBack_NP(slot->first, slot->last, hash2style_node, hash_next, hash_prev);
|
DLLPushBack_NP(slot->first, slot->last, hash2style_node, hash_next, hash_prev);
|
||||||
hash2style_node->style_hash = style_hash;
|
hash2style_node->style_hash = style_hash;
|
||||||
hash2style_node->ascent = metrics.ascent;
|
hash2style_node->ascent = metrics.ascent;
|
||||||
hash2style_node->descent = metrics.descent;
|
hash2style_node->descent = metrics.descent;
|
||||||
hash2style_node->utf8_class1_direct_map = push_array_no_zero(f_state->raster_arena, F_RasterCacheInfo, 256);
|
hash2style_node->utf8_class1_direct_map = push_array_no_zero(fnt_state->raster_arena, FNT_RasterCacheInfo, 256);
|
||||||
hash2style_node->hash2info_slots_count = 1024;
|
hash2style_node->hash2info_slots_count = 1024;
|
||||||
hash2style_node->hash2info_slots = push_array(f_state->raster_arena, FNT_Hash2InfoRasterCacheSlot, hash2style_node->hash2info_slots_count);
|
hash2style_node->hash2info_slots = push_array(fnt_state->raster_arena, FNT_Hash2InfoRasterCacheSlot, hash2style_node->hash2info_slots_count);
|
||||||
}
|
}
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
}
|
}
|
||||||
@@ -575,6 +575,43 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
//- rjf: map tag/size to style node
|
//- rjf: map tag/size to style node
|
||||||
FNT_Hash2StyleRasterCacheNode *hash2style_node = fnt_hash2style_from_tag_size_flags(tag, size, flags);
|
FNT_Hash2StyleRasterCacheNode *hash2style_node = fnt_hash2style_from_tag_size_flags(tag, size, flags);
|
||||||
|
|
||||||
|
//- rjf: set up this style's run cache if needed
|
||||||
|
if(hash2style_node->run_slots_frame_index != fnt_state->frame_index)
|
||||||
|
{
|
||||||
|
hash2style_node->run_slots_count = 1024;
|
||||||
|
hash2style_node->run_slots = push_array(fnt_state->frame_arena, FNT_RunCacheSlot, hash2style_node->run_slots_count);
|
||||||
|
hash2style_node->run_slots_frame_index = fnt_state->frame_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- rjf: unpack run params
|
||||||
|
U64 run_hash = fnt_little_hash_from_string(5381, string);
|
||||||
|
U64 run_slot_idx = run_hash%hash2style_node->run_slots_count;
|
||||||
|
FNT_RunCacheSlot *run_slot = &hash2style_node->run_slots[run_slot_idx];
|
||||||
|
|
||||||
|
//- rjf: find existing run node for this string
|
||||||
|
FNT_RunCacheNode *run_node = 0;
|
||||||
|
{
|
||||||
|
for(FNT_RunCacheNode *n = run_slot->first; n != 0; n = n->next)
|
||||||
|
{
|
||||||
|
if(str8_match(n->string, string, 0))
|
||||||
|
{
|
||||||
|
run_node = n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- rjf: no run node? -> cache miss - compute & build & fill node if possible
|
||||||
|
B32 run_is_cacheable = 1;
|
||||||
|
FNT_Run run = {0};
|
||||||
|
if(run_node)
|
||||||
|
{
|
||||||
|
run = run_node->run;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ProfScope("no run node? -> cache miss")
|
||||||
|
ProfScope("compute & build & fill node for '%.*s'", str8_varg(string))
|
||||||
|
{
|
||||||
//- rjf: decode string & produce run pieces
|
//- rjf: decode string & produce run pieces
|
||||||
FNT_PieceChunkList piece_chunks = {0};
|
FNT_PieceChunkList piece_chunks = {0};
|
||||||
Vec2F32 dim = {0};
|
Vec2F32 dim = {0};
|
||||||
@@ -623,11 +660,12 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
B32 is_tab = (piece_substring.size == 1 && piece_substring.str[0] == '\t');
|
B32 is_tab = (piece_substring.size == 1 && piece_substring.str[0] == '\t');
|
||||||
if(is_tab)
|
if(is_tab)
|
||||||
{
|
{
|
||||||
|
run_is_cacheable = 0;
|
||||||
piece_substring = str8_lit(" ");
|
piece_substring = str8_lit(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: piece substring -> raster cache info
|
//- rjf: piece substring -> raster cache info
|
||||||
F_RasterCacheInfo *info = 0;
|
FNT_RasterCacheInfo *info = 0;
|
||||||
U64 piece_hash = 0;
|
U64 piece_hash = 0;
|
||||||
{
|
{
|
||||||
// rjf: fast path for utf8 class 1 -> direct map
|
// rjf: fast path for utf8 class 1 -> direct map
|
||||||
@@ -639,10 +677,10 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
// rjf: more general, slower path for other glyphs
|
// rjf: more general, slower path for other glyphs
|
||||||
if(piece_substring.size > 1)
|
if(piece_substring.size > 1)
|
||||||
{
|
{
|
||||||
piece_hash = fnt_little_hash_from_string(piece_substring);
|
piece_hash = fnt_little_hash_from_string(5381, piece_substring);
|
||||||
U64 slot_idx = piece_hash%hash2style_node->hash2info_slots_count;
|
U64 slot_idx = piece_hash%hash2style_node->hash2info_slots_count;
|
||||||
FNT_Hash2InfoRasterCacheSlot *slot = &hash2style_node->hash2info_slots[slot_idx];
|
FNT_Hash2InfoRasterCacheSlot *slot = &hash2style_node->hash2info_slots[slot_idx];
|
||||||
for(F_Hash2InfoRasterCacheNode *node = slot->first; node != 0; node = node->hash_next)
|
for(FNT_Hash2InfoRasterCacheNode *node = slot->first; node != 0; node = node->hash_next)
|
||||||
{
|
{
|
||||||
if(node->hash == piece_hash)
|
if(node->hash == piece_hash)
|
||||||
{
|
{
|
||||||
@@ -665,12 +703,12 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
font_handle_mapped_on_miss = 1;
|
font_handle_mapped_on_miss = 1;
|
||||||
|
|
||||||
// rjf: tag -> font slot index
|
// rjf: tag -> font slot index
|
||||||
U64 font_slot_idx = tag.u64[1] % f_state->font_hash_table_size;
|
U64 font_slot_idx = tag.u64[1] % fnt_state->font_hash_table_size;
|
||||||
|
|
||||||
// rjf: tag * slot -> existing node
|
// rjf: tag * slot -> existing node
|
||||||
FNT_FontHashNode *existing_node = 0;
|
FNT_FontHashNode *existing_node = 0;
|
||||||
{
|
{
|
||||||
for(FNT_FontHashNode *n = f_state->font_hash_table[font_slot_idx].first; n != 0 ; n = n->hash_next)
|
for(FNT_FontHashNode *n = fnt_state->font_hash_table[font_slot_idx].first; n != 0 ; n = n->hash_next)
|
||||||
{
|
{
|
||||||
if(MemoryMatchStruct(&n->tag, &tag))
|
if(MemoryMatchStruct(&n->tag, &tag))
|
||||||
{
|
{
|
||||||
@@ -704,15 +742,15 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
if(raster.atlas_dim.x != 0 && raster.atlas_dim.y != 0)
|
if(raster.atlas_dim.x != 0 && raster.atlas_dim.y != 0)
|
||||||
{
|
{
|
||||||
U64 num_atlases = 0;
|
U64 num_atlases = 0;
|
||||||
for(FNT_Atlas *atlas = f_state->first_atlas;; atlas = atlas->next, num_atlases += 1)
|
for(FNT_Atlas *atlas = fnt_state->first_atlas;; atlas = atlas->next, num_atlases += 1)
|
||||||
{
|
{
|
||||||
// rjf: create atlas if needed
|
// rjf: create atlas if needed
|
||||||
if(atlas == 0 && num_atlases < 64)
|
if(atlas == 0 && num_atlases < 64)
|
||||||
{
|
{
|
||||||
atlas = push_array(f_state->raster_arena, FNT_Atlas, 1);
|
atlas = push_array(fnt_state->raster_arena, FNT_Atlas, 1);
|
||||||
DLLPushBack(f_state->first_atlas, f_state->last_atlas, atlas);
|
DLLPushBack(fnt_state->first_atlas, fnt_state->last_atlas, atlas);
|
||||||
atlas->root_dim = v2s16(1024, 1024);
|
atlas->root_dim = v2s16(1024, 1024);
|
||||||
atlas->root = push_array(f_state->raster_arena, FNT_AtlasRegionNode, 1);
|
atlas->root = push_array(fnt_state->raster_arena, FNT_AtlasRegionNode, 1);
|
||||||
atlas->root->max_free_size[Corner_00] =
|
atlas->root->max_free_size[Corner_00] =
|
||||||
atlas->root->max_free_size[Corner_01] =
|
atlas->root->max_free_size[Corner_01] =
|
||||||
atlas->root->max_free_size[Corner_10] =
|
atlas->root->max_free_size[Corner_10] =
|
||||||
@@ -724,7 +762,7 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
if(atlas != 0)
|
if(atlas != 0)
|
||||||
{
|
{
|
||||||
Vec2S16 needed_dimensions = v2s16(raster.atlas_dim.x + 2, raster.atlas_dim.y + 2);
|
Vec2S16 needed_dimensions = v2s16(raster.atlas_dim.x + 2, raster.atlas_dim.y + 2);
|
||||||
chosen_atlas_region = fnt_atlas_region_alloc(f_state->raster_arena, atlas, needed_dimensions);
|
chosen_atlas_region = fnt_atlas_region_alloc(fnt_state->raster_arena, atlas, needed_dimensions);
|
||||||
if(chosen_atlas_region.x1 != chosen_atlas_region.x0)
|
if(chosen_atlas_region.x1 != chosen_atlas_region.x0)
|
||||||
{
|
{
|
||||||
chosen_atlas = atlas;
|
chosen_atlas = atlas;
|
||||||
@@ -763,7 +801,7 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
{
|
{
|
||||||
U64 slot_idx = piece_hash%hash2style_node->hash2info_slots_count;
|
U64 slot_idx = piece_hash%hash2style_node->hash2info_slots_count;
|
||||||
FNT_Hash2InfoRasterCacheSlot *slot = &hash2style_node->hash2info_slots[slot_idx];
|
FNT_Hash2InfoRasterCacheSlot *slot = &hash2style_node->hash2info_slots[slot_idx];
|
||||||
F_Hash2InfoRasterCacheNode *node = push_array_no_zero(f_state->raster_arena, F_Hash2InfoRasterCacheNode, 1);
|
FNT_Hash2InfoRasterCacheNode *node = push_array_no_zero(fnt_state->raster_arena, FNT_Hash2InfoRasterCacheNode, 1);
|
||||||
DLLPushBack_NP(slot->first, slot->last, node, hash_next, hash_prev);
|
DLLPushBack_NP(slot->first, slot->last, node, hash_next, hash_prev);
|
||||||
node->hash = piece_hash;
|
node->hash = piece_hash;
|
||||||
info = &node->info;
|
info = &node->info;
|
||||||
@@ -790,7 +828,7 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
if(info->subrect.x1 != 0 && info->subrect.y1 != 0)
|
if(info->subrect.x1 != 0 && info->subrect.y1 != 0)
|
||||||
{
|
{
|
||||||
S32 num = 0;
|
S32 num = 0;
|
||||||
for(FNT_Atlas *a = f_state->first_atlas; a != 0; a = a->next, num += 1)
|
for(FNT_Atlas *a = fnt_state->first_atlas; a != 0; a = a->next, num += 1)
|
||||||
{
|
{
|
||||||
if(info->atlas_num == num)
|
if(info->atlas_num == num)
|
||||||
{
|
{
|
||||||
@@ -810,7 +848,7 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
|
|
||||||
// rjf: push piece
|
// rjf: push piece
|
||||||
{
|
{
|
||||||
FNT_Piece *piece = fnt_piece_chunk_list_push_new(arena, &piece_chunks, string.size);
|
FNT_Piece *piece = fnt_piece_chunk_list_push_new(fnt_state->frame_arena, &piece_chunks, string.size);
|
||||||
{
|
{
|
||||||
piece->texture = atlas ? atlas->texture : r_handle_zero();
|
piece->texture = atlas ? atlas->texture : r_handle_zero();
|
||||||
piece->subrect = r2s16p(info->subrect.x0,
|
piece->subrect = r2s16p(info->subrect.x0,
|
||||||
@@ -828,8 +866,7 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: tighten & return
|
//- rjf: tighten & fill
|
||||||
FNT_Run run = {0};
|
|
||||||
{
|
{
|
||||||
if(piece_chunks.node_count == 1)
|
if(piece_chunks.node_count == 1)
|
||||||
{
|
{
|
||||||
@@ -838,12 +875,22 @@ fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
run.pieces = fnt_piece_array_from_chunk_list(arena, &piece_chunks);
|
run.pieces = fnt_piece_array_from_chunk_list(fnt_state->frame_arena, &piece_chunks);
|
||||||
}
|
}
|
||||||
run.dim = dim;
|
run.dim = dim;
|
||||||
run.ascent = hash2style_node->ascent;
|
run.ascent = hash2style_node->ascent;
|
||||||
run.descent = hash2style_node->descent;
|
run.descent = hash2style_node->descent;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- rjf: build node for cacheable runs
|
||||||
|
if(run_is_cacheable)
|
||||||
|
{
|
||||||
|
run_node = push_array(fnt_state->frame_arena, FNT_RunCacheNode, 1);
|
||||||
|
SLLQueuePush(run_slot->first, run_slot->last, run_node);
|
||||||
|
run_node->string = push_str8_copy(fnt_state->frame_arena, string);
|
||||||
|
run_node->run = run;
|
||||||
|
}
|
||||||
|
|
||||||
ProfEnd();
|
ProfEnd();
|
||||||
return run;
|
return run;
|
||||||
@@ -1057,23 +1104,31 @@ internal void
|
|||||||
fnt_init(void)
|
fnt_init(void)
|
||||||
{
|
{
|
||||||
Arena *arena = arena_alloc();
|
Arena *arena = arena_alloc();
|
||||||
f_state = push_array(arena, FNT_State, 1);
|
fnt_state = push_array(arena, FNT_State, 1);
|
||||||
f_state->permanent_arena = arena;
|
fnt_state->permanent_arena = arena;
|
||||||
f_state->raster_arena = arena_alloc();
|
fnt_state->raster_arena = arena_alloc();
|
||||||
f_state->font_hash_table_size = 64;
|
fnt_state->frame_arena = arena_alloc();
|
||||||
f_state->font_hash_table = push_array(f_state->permanent_arena, FNT_FontHashSlot, f_state->font_hash_table_size);
|
fnt_state->font_hash_table_size = 64;
|
||||||
|
fnt_state->font_hash_table = push_array(fnt_state->permanent_arena, FNT_FontHashSlot, fnt_state->font_hash_table_size);
|
||||||
fnt_reset();
|
fnt_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
fnt_reset(void)
|
fnt_reset(void)
|
||||||
{
|
{
|
||||||
for(FNT_Atlas *a = f_state->first_atlas; a != 0; a = a->next)
|
for(FNT_Atlas *a = fnt_state->first_atlas; a != 0; a = a->next)
|
||||||
{
|
{
|
||||||
r_tex2d_release(a->texture);
|
r_tex2d_release(a->texture);
|
||||||
}
|
}
|
||||||
f_state->first_atlas = f_state->last_atlas = 0;
|
fnt_state->first_atlas = fnt_state->last_atlas = 0;
|
||||||
arena_clear(f_state->raster_arena);
|
arena_clear(fnt_state->raster_arena);
|
||||||
f_state->hash2style_slots_count = 1024;
|
fnt_state->hash2style_slots_count = 1024;
|
||||||
f_state->hash2style_slots = push_array(f_state->raster_arena, FNT_Hash2StyleRasterCacheSlot, f_state->hash2style_slots_count);
|
fnt_state->hash2style_slots = push_array(fnt_state->raster_arena, FNT_Hash2StyleRasterCacheSlot, fnt_state->hash2style_slots_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void
|
||||||
|
fnt_frame(void)
|
||||||
|
{
|
||||||
|
fnt_state->frame_index += 1;
|
||||||
|
arena_clear(fnt_state->frame_arena);
|
||||||
}
|
}
|
||||||
|
|||||||
+43
-13
@@ -93,8 +93,10 @@ struct FNT_FontHashSlot
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Rasterization Cache Types
|
//~ rjf: Rasterization Cache Types
|
||||||
|
|
||||||
typedef struct F_RasterCacheInfo F_RasterCacheInfo;
|
//- rjf: base glyph rasterization / dimensions cache
|
||||||
struct F_RasterCacheInfo
|
|
||||||
|
typedef struct FNT_RasterCacheInfo FNT_RasterCacheInfo;
|
||||||
|
struct FNT_RasterCacheInfo
|
||||||
{
|
{
|
||||||
Rng2S16 subrect;
|
Rng2S16 subrect;
|
||||||
Vec2S16 raster_dim;
|
Vec2S16 raster_dim;
|
||||||
@@ -102,22 +104,41 @@ struct F_RasterCacheInfo
|
|||||||
F32 advance;
|
F32 advance;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct F_Hash2InfoRasterCacheNode F_Hash2InfoRasterCacheNode;
|
typedef struct FNT_Hash2InfoRasterCacheNode FNT_Hash2InfoRasterCacheNode;
|
||||||
struct F_Hash2InfoRasterCacheNode
|
struct FNT_Hash2InfoRasterCacheNode
|
||||||
{
|
{
|
||||||
F_Hash2InfoRasterCacheNode *hash_next;
|
FNT_Hash2InfoRasterCacheNode *hash_next;
|
||||||
F_Hash2InfoRasterCacheNode *hash_prev;
|
FNT_Hash2InfoRasterCacheNode *hash_prev;
|
||||||
U64 hash;
|
U64 hash;
|
||||||
F_RasterCacheInfo info;
|
FNT_RasterCacheInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct FNT_Hash2InfoRasterCacheSlot FNT_Hash2InfoRasterCacheSlot;
|
typedef struct FNT_Hash2InfoRasterCacheSlot FNT_Hash2InfoRasterCacheSlot;
|
||||||
struct FNT_Hash2InfoRasterCacheSlot
|
struct FNT_Hash2InfoRasterCacheSlot
|
||||||
{
|
{
|
||||||
F_Hash2InfoRasterCacheNode *first;
|
FNT_Hash2InfoRasterCacheNode *first;
|
||||||
F_Hash2InfoRasterCacheNode *last;
|
FNT_Hash2InfoRasterCacheNode *last;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//- rjf: run cache (arrangements of many glyphs to represent a full string)
|
||||||
|
|
||||||
|
typedef struct FNT_RunCacheNode FNT_RunCacheNode;
|
||||||
|
struct FNT_RunCacheNode
|
||||||
|
{
|
||||||
|
FNT_RunCacheNode *next;
|
||||||
|
String8 string;
|
||||||
|
FNT_Run run;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct FNT_RunCacheSlot FNT_RunCacheSlot;
|
||||||
|
struct FNT_RunCacheSlot
|
||||||
|
{
|
||||||
|
FNT_RunCacheNode *first;
|
||||||
|
FNT_RunCacheNode *last;
|
||||||
|
};
|
||||||
|
|
||||||
|
//- rjf: style hash -> artifacts/metrics cache
|
||||||
|
|
||||||
typedef struct FNT_Hash2StyleRasterCacheNode FNT_Hash2StyleRasterCacheNode;
|
typedef struct FNT_Hash2StyleRasterCacheNode FNT_Hash2StyleRasterCacheNode;
|
||||||
struct FNT_Hash2StyleRasterCacheNode
|
struct FNT_Hash2StyleRasterCacheNode
|
||||||
{
|
{
|
||||||
@@ -127,10 +148,13 @@ struct FNT_Hash2StyleRasterCacheNode
|
|||||||
F32 ascent;
|
F32 ascent;
|
||||||
F32 descent;
|
F32 descent;
|
||||||
F32 column_width;
|
F32 column_width;
|
||||||
F_RasterCacheInfo *utf8_class1_direct_map;
|
FNT_RasterCacheInfo *utf8_class1_direct_map;
|
||||||
U64 utf8_class1_direct_map_mask[4];
|
U64 utf8_class1_direct_map_mask[4];
|
||||||
U64 hash2info_slots_count;
|
U64 hash2info_slots_count;
|
||||||
FNT_Hash2InfoRasterCacheSlot *hash2info_slots;
|
FNT_Hash2InfoRasterCacheSlot *hash2info_slots;
|
||||||
|
U64 run_slots_count;
|
||||||
|
FNT_RunCacheSlot *run_slots;
|
||||||
|
U64 run_slots_frame_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct FNT_Hash2StyleRasterCacheSlot FNT_Hash2StyleRasterCacheSlot;
|
typedef struct FNT_Hash2StyleRasterCacheSlot FNT_Hash2StyleRasterCacheSlot;
|
||||||
@@ -189,6 +213,8 @@ struct FNT_State
|
|||||||
{
|
{
|
||||||
Arena *permanent_arena;
|
Arena *permanent_arena;
|
||||||
Arena *raster_arena;
|
Arena *raster_arena;
|
||||||
|
Arena *frame_arena;
|
||||||
|
U64 frame_index;
|
||||||
|
|
||||||
// rjf: font table
|
// rjf: font table
|
||||||
U64 font_hash_table_size;
|
U64 font_hash_table_size;
|
||||||
@@ -206,13 +232,13 @@ struct FNT_State
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Globals
|
//~ rjf: Globals
|
||||||
|
|
||||||
global FNT_State *f_state = 0;
|
global FNT_State *fnt_state = 0;
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Basic Functions
|
//~ rjf: Basic Functions
|
||||||
|
|
||||||
internal U128 fnt_hash_from_string(String8 string);
|
internal U128 fnt_hash_from_string(String8 string);
|
||||||
internal U64 fnt_little_hash_from_string(String8 string);
|
internal U64 fnt_little_hash_from_string(U64 seed, String8 string);
|
||||||
internal Vec2S32 fnt_vertex_from_corner(Corner corner);
|
internal Vec2S32 fnt_vertex_from_corner(Corner corner);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
@@ -241,10 +267,13 @@ internal FNT_PieceArray fnt_piece_array_from_chunk_list(Arena *arena, FNT_PieceC
|
|||||||
internal FNT_PieceArray fnt_piece_array_copy(Arena *arena, FNT_PieceArray *src);
|
internal FNT_PieceArray fnt_piece_array_copy(Arena *arena, FNT_PieceArray *src);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Rasterization Cache
|
//~ rjf: Cache Usage
|
||||||
|
|
||||||
|
//- rjf: base cache lookups
|
||||||
internal FNT_Hash2StyleRasterCacheNode *fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags);
|
internal FNT_Hash2StyleRasterCacheNode *fnt_hash2style_from_tag_size_flags(FNT_Tag tag, F32 size, FNT_RasterFlags flags);
|
||||||
internal FNT_Run fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, FNT_RasterFlags flags, String8 string);
|
internal FNT_Run fnt_push_run_from_string(Arena *arena, FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, FNT_RasterFlags flags, String8 string);
|
||||||
|
|
||||||
|
//- rjf: helpers
|
||||||
internal String8List fnt_wrapped_string_lines_from_font_size_string_max(Arena *arena, FNT_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, String8 string, F32 max);
|
internal String8List fnt_wrapped_string_lines_from_font_size_string_max(Arena *arena, FNT_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, String8 string, F32 max);
|
||||||
internal Vec2F32 fnt_dim_from_tag_size_string(FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, String8 string);
|
internal Vec2F32 fnt_dim_from_tag_size_string(FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, String8 string);
|
||||||
internal Vec2F32 fnt_dim_from_tag_size_string_list(FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, String8List list);
|
internal Vec2F32 fnt_dim_from_tag_size_string_list(FNT_Tag tag, F32 size, F32 base_align_px, F32 tab_size_px, String8List list);
|
||||||
@@ -262,5 +291,6 @@ internal F32 fnt_line_height_from_metrics(FNT_Metrics *metrics);
|
|||||||
|
|
||||||
internal void fnt_init(void);
|
internal void fnt_init(void);
|
||||||
internal void fnt_reset(void);
|
internal void fnt_reset(void);
|
||||||
|
internal void fnt_frame(void);
|
||||||
|
|
||||||
#endif // FONT_CACHE_H
|
#endif // FONT_CACHE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user