From 5bd6519b6a50d5bd20bfa35c3881a4a309ee5ee7 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 11 Jun 2024 22:20:19 -0400 Subject: [PATCH] Bugfixing the runtime (rendering not working yet) --- Debug.rdbg | Bin 1057 -> 1001 bytes code/font/VEFontCache/LRU.odin | 8 ++++++-- code/font/VEFontCache/atlas.odin | 2 +- code/font/VEFontCache/draw.odin | 2 +- code/font/VEFontCache/parser.odin | 2 ++ code/grime/array.odin | 7 ++++--- code/grime/hashmap_chained.odin | 17 +++++++++++------ code/sectr/font/provider_VEFontCache.odin | 2 ++ scripts/update_deps.ps1 | 3 ++- thirdparty/harfbuzz | 2 +- toolchain/Odin | 2 +- 11 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Debug.rdbg b/Debug.rdbg index 0d575e0266df6636e9bb08a01e0c0644f4ff96cd..d69e1b110c921ca5fd2dcdb698b423173e39e8a2 100644 GIT binary patch delta 282 zcmZ3;@sfRlJu4dn1B2DXkIK?%`FSNVVXkgK$~iGPBQ++aD6w2GKP5BI0w^t+UX+=e z8dH{8R8pFl6Q5X=nwJQcGz3cWKqM23i&KkACcf4bgz}4u5-Y)q9D$0IFf2f_46I6T z;ztdxjQrvfFpqJv0@GVgMxgUp@;?1yoGiyIVa@{NaR70Ad`^CHVoouLU!0ngCIY4P zGEx&$Qj7Fb5=#4RY!b^5TOtvh7i0p|{9BWjy(eYWlGm@mAWt|2Cu2mo`dglmlF9a8Ix%6Xe?M=p&fb<35g8li-{1-W}a!qtB=pRw-vs=r@nEi k39&#zILN*0AIzOInz#U3B)Y&s)O`in35-=E$62fo7$@c;k- diff --git a/code/font/VEFontCache/LRU.odin b/code/font/VEFontCache/LRU.odin index cd39711..4583364 100644 --- a/code/font/VEFontCache/LRU.odin +++ b/code/font/VEFontCache/LRU.odin @@ -31,7 +31,7 @@ pool_list_init :: proc( pool : ^PoolList, capacity : u32 ) pool.free_list, error = make( Array( PoolListIter ), u64(capacity) ) assert( error == .None, "VEFontCache.pool_list_init : Failed to allocate free_list array") - array_resize( & pool.items, u64(capacity) ) + array_resize( & pool.free_list, u64(capacity) ) pool.capacity = capacity @@ -172,10 +172,14 @@ LRU_put :: proc( cache : ^LRU_Cache, key : u64, value : i32 ) -> u64 { } pool_list_push_front( & cache.key_queue, key ) - hmap_chained_set( cache.table, key, LRU_Link { + + bytes := transmute( [8]byte ) key + hash_key := fnv64a( bytes[:] ) + hmap_chained_set( cache.table, hash_key, LRU_Link { value = value, ptr = cache.key_queue.front }) + cache.num += 1 return evict } diff --git a/code/font/VEFontCache/atlas.odin b/code/font/VEFontCache/atlas.odin index 35a941a..105bc9a 100644 --- a/code/font/VEFontCache/atlas.odin +++ b/code/font/VEFontCache/atlas.odin @@ -112,7 +112,7 @@ can_batch_glyph :: proc( ctx : ^Context, font : FontID, entry : ^Entry, glyph_in cache_glyph_to_atlas( ctx, font, glyph_index ) } - assert( LRU_get( & region.state, lru_code ) != 1 ) + assert( LRU_get( & region.state, lru_code ) != -1 ) set( ctx.temp_codepoint_seen, lru_code, true ) ctx.temp_codepoint_seen_num += 1 return true diff --git a/code/font/VEFontCache/draw.odin b/code/font/VEFontCache/draw.odin index edcf2ee..5348330 100644 --- a/code/font/VEFontCache/draw.odin +++ b/code/font/VEFontCache/draw.odin @@ -270,7 +270,7 @@ draw_filled_path :: proc( draw_list : ^DrawList, outside_point : Vec2, path : [] draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position : Vec2, scale : Vec2 ) -> b32 { assert( ctx != nil ) - assert( font > 0 && font < FontID(ctx.entries.num) ) + assert( font >= 0 && font < FontID(ctx.entries.num) ) shaped := shape_text_cached( ctx, font, text_utf8 ) diff --git a/code/font/VEFontCache/parser.odin b/code/font/VEFontCache/parser.odin index 8561ab1..fed113b 100644 --- a/code/font/VEFontCache/parser.odin +++ b/code/font/VEFontCache/parser.odin @@ -117,9 +117,11 @@ parser_find_glyph_index :: proc( font : ^ParserFontInfo, codepoint : rune ) -> ( { case .Freetype: glyph_index = transmute(Glyph) freetype.get_char_index( font.freetype_info, transmute(u32) codepoint ) + return case .STB_TrueType: glyph_index = transmute(Glyph) stbtt.FindGlyphIndex( & font.stbtt_info, codepoint ) + return } return Glyph(-1) } diff --git a/code/grime/array.odin b/code/grime/array.odin index 28891b2..dbddefb 100644 --- a/code/grime/array.odin +++ b/code/grime/array.odin @@ -79,10 +79,11 @@ array_append_array :: proc( using self: ^Array( $ Type), other : Array(Type)) -> // Note(Ed) : Original code from gencpp // libc.memcpy( ptr_offset(data, num), raw_data(items), len(items) * size_of(Type) ) - // TODO(Ed) : VERIFY VIA DEBUG THIS COPY IS FINE. - ensure(false, "time to check....") target := ptr_offset( data, num ) - copy( slice_ptr(target, int(capacity - num)), array_to_slice(other) ) + + dst_slice := slice_ptr(target, int(capacity - num)) + src_slice := array_to_slice(other) + copy( dst_slice, src_slice ) num += other.num return AllocatorError.None diff --git a/code/grime/hashmap_chained.odin b/code/grime/hashmap_chained.odin index ffcba73..6dfe156 100644 --- a/code/grime/hashmap_chained.odin +++ b/code/grime/hashmap_chained.odin @@ -14,6 +14,7 @@ and direct pointers are kept across the codebase instead of a key to the slot. package grime import "core:mem" +import "base:runtime" HTable_Minimum_Capacity :: 4 * Kilobyte @@ -111,7 +112,11 @@ hmap_chained_lookup_id :: #force_inline proc( using self : HMapChained($Type), k hmap_chained_get :: proc( using self : HMapChained($Type), key : u64) -> ^Type { // profile(#procedure) - surface_slot := lookup[hmap_chained_lookup_id(self, key)] + hash_index := hmap_chained_lookup_id(self, key) + // if hash_index == 565 { + // runtime.debug_trap() + // } + surface_slot := lookup[hash_index] if surface_slot == nil { return nil @@ -178,7 +183,7 @@ hmap_chained_set :: proc( self : HMapChained($Type), key : u64, value : Type ) - error := AllocatorError.None if slot.next == nil { block : []byte - block, error = pool_grab(pool) + block, error = pool_grab(pool, true) next := transmute( ^HMapChainedSlot(Type)) & block[0] slot.next = next next.prev = slot @@ -190,7 +195,7 @@ hmap_chained_set :: proc( self : HMapChained($Type), key : u64, value : Type ) - } if surface_slot == nil { - block, error := pool_grab(pool) + block, error := pool_grab(pool, true) surface_slot := transmute( ^HMapChainedSlot(Type)) & block[0] surface_slot.key = key surface_slot.value = value @@ -201,7 +206,7 @@ hmap_chained_set :: proc( self : HMapChained($Type), key : u64, value : Type ) - } lookup[hash_index] = surface_slot - block, error = pool_grab(pool) + block, error = pool_grab(pool, true) next := transmute( ^HMapChainedSlot(Type)) & block[0] surface_slot.next = next next.prev = surface_slot @@ -214,12 +219,12 @@ hmap_chained_set :: proc( self : HMapChained($Type), key : u64, value : Type ) - return result, error } - slot := surface_slot.next + slot : ^HMapChainedSlot(Type) = surface_slot.next for ; slot != nil; slot = slot.next { if !slot.occupied { - result, error := set_slot( self, surface_slot, key, value) + result, error := set_slot( self, slot, key, value) return result, error } } diff --git a/code/sectr/font/provider_VEFontCache.odin b/code/sectr/font/provider_VEFontCache.odin index d4a66cf..a6741a5 100644 --- a/code/sectr/font/provider_VEFontCache.odin +++ b/code/sectr/font/provider_VEFontCache.odin @@ -423,6 +423,8 @@ font_load :: proc(path_file : string, def, set_error := hmap_chained_set(font_cache, key, FontDef{}) verify( set_error == AllocatorError.None, "Failed to add new font entry to cache" ) + def.path_file = path_file + // TODO(Ed): Load even sizes from 8px to upper bound. def.ve_id = ve.load_font( & provider_data.ve_font_cache, desired_id, font_data, 36.0 ) diff --git a/scripts/update_deps.ps1 b/scripts/update_deps.ps1 index c544ba9..935c603 100644 --- a/scripts/update_deps.ps1 +++ b/scripts/update_deps.ps1 @@ -109,13 +109,14 @@ clone-gitrepo $path_sokol_tools $url_sokol_tools $path_vendor = join-path $path_odin 'vendor' $path_vendor_raylib = join-path $path_vendor 'raylib' +$path_freetype_dlls = join-path $path_freetype 'binaries/release' $path_harfbuzz_dlls = join-path $path_harfbuzz 'lib/win64' $path_raylib_dlls = join-path $path_vendor_raylib 'windows' $path_sokol_dlls = join-path $path_thirdparty 'sokol' if ( $binaries_dirty -or $true ) { - $third_party_dlls = Get-ChildItem -path $path_harfbuzz_dlls -Filter '*dll' + $third_party_dlls = Get-ChildItem -path $path_harfbuzz_dlls -Filter '*.dll' foreach ($dll in $third_party_dlls) { $destination = join-path $path_build $dll.Name Copy-Item $dll.FullName -Destination $destination -Force diff --git a/thirdparty/harfbuzz b/thirdparty/harfbuzz index 4c81e82..1bc1416 160000 --- a/thirdparty/harfbuzz +++ b/thirdparty/harfbuzz @@ -1 +1 @@ -Subproject commit 4c81e825e1b58632b9c4e5e4974172b8b6740cde +Subproject commit 1bc1416645610dcf133a70722ae0a78fd179274e diff --git a/toolchain/Odin b/toolchain/Odin index 8bfc2a0..b7a7ada 160000 --- a/toolchain/Odin +++ b/toolchain/Odin @@ -1 +1 @@ -Subproject commit 8bfc2a0af0eff7b573eb8cd33de1c15a051dddb6 +Subproject commit b7a7ada7aef38214c599e8691072f95b33c91913