fixed hot reload

there is still memory issues T-T
This commit is contained in:
Edward R. Gonzalez 2024-03-20 01:23:50 -04:00
parent 2d5e308046
commit fb1a6063a7
5 changed files with 26 additions and 20 deletions

View File

@ -15,6 +15,10 @@ import rl "vendor:raylib"
Path_Assets :: "../assets/"
Path_Input_Replay :: "scratch.sectr_replay"
Persistent_Slab_DBG_Name :: "Peristent Slab"
Frame_Slab_DBG_Name :: "Frame Slab"
Transient_Slab_DBG_Name :: "Transient Slab"
ModuleAPI :: struct {
lib : dynlib.Library,
write_time : FileTime,
@ -103,10 +107,10 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
}
alloc_error : AllocatorError
persistent_slab, alloc_error = slab_init( policy_ptr, allocator = persistent_allocator(), dbg_name = "persistent slab" )
persistent_slab, alloc_error = slab_init( policy_ptr, allocator = persistent_allocator(), dbg_name = Persistent_Slab_DBG_Name )
verify( alloc_error == .None, "Failed to allocate the persistent slab" )
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = "transient slab" )
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = Transient_Slab_DBG_Name )
verify( alloc_error == .None, "Failed to allocate transient slab" )
transient_clear_time = 120 // Seconds, 2 Minutes
@ -269,7 +273,6 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
transient = transient_mem
files_buffer = files_buffer_mem
context.allocator = persistent_allocator()
context.temp_allocator = transient_allocator()
@ -280,6 +283,8 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
// Or as done below, correct containers using allocators on reload.
// Thankfully persistent dynamic allocations are rare, and thus we know exactly which ones they are.
slab_reload( persistent_slab, persistent_allocator() )
font_provider_data.font_cache.hashes.backing = persistent_slab_allocator()
font_provider_data.font_cache.entries.backing = persistent_slab_allocator()
@ -287,7 +292,7 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
string_cache.table.hashes.backing = persistent_slab_allocator()
string_cache.table.entries.backing = persistent_slab_allocator()
// slab_reload( frame_slab, frame_allocator())
slab_reload( frame_slab, frame_allocator())
slab_reload( transient_slab, transient_allocator())
ui_reload( & get_state().project.workspace.ui, cache_allocator = persistent_slab_allocator() )
@ -295,8 +300,6 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
log("Module reloaded")
}
@export
tick :: proc( host_delta_time : f64, host_delta_ns : Duration ) -> b32
{
@ -313,7 +316,7 @@ tick :: proc( host_delta_time : f64, host_delta_ns : Duration ) -> b32
// Setup Frame Slab
{
alloc_error : AllocatorError
frame_slab, alloc_error = slab_init( & default_slab_policy, bucket_reserve_num = 0, allocator = frame_allocator(), dbg_name = "frame slab" )
frame_slab, alloc_error = slab_init( & default_slab_policy, bucket_reserve_num = 0, allocator = frame_allocator(), dbg_name = Frame_Slab_DBG_Name )
verify( alloc_error == .None, "Failed to allocate frame slab" )
}
@ -394,7 +397,7 @@ clean_frame :: proc()
free_all( transient_allocator() )
alloc_error : AllocatorError
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = "transient slab" )
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = Transient_Slab_DBG_Name )
verify( alloc_error == .None, "Failed to allocate transient slab" )
}
}

View File

@ -71,8 +71,8 @@ pool_init :: proc (
return
}
pool_reload :: proc( using self : Pool, allocator : Allocator ) {
self.backing = allocator
pool_reload :: proc( pool : Pool, allocator : Allocator ) {
pool.backing = allocator
}
pool_destroy :: proc ( using self : Pool )

View File

@ -86,11 +86,13 @@ slab_init_pools :: proc ( using self : Slab, policy : ^SlabPolicy, bucket_reserv
return .None
}
slab_reload :: proc ( using self : Slab, allocator : Allocator )
slab_reload :: proc ( slab : Slab, allocator : Allocator )
{
for id in 0 ..< pools.idx {
pool := pools.items[id]
pool_reload( pool, allocator )
slab.backing = allocator
for id in 0 ..< slab.pools.idx {
pool := slab.pools.items[id]
pool_reload( pool, slab.backing )
}
}

View File

@ -52,8 +52,10 @@ str_cache_init :: proc( /*allocator : Allocator*/ ) -> ( cache : StringCache ) {
header_size :: size_of( Slab )
@static dbg_name := "StringCache slab"
alloc_error : AllocatorError
cache.slab, alloc_error = slab_init( & policy, allocator = persistent_allocator(), dbg_name = "StringCache slab" )
cache.slab, alloc_error = slab_init( & policy, allocator = persistent_allocator(), dbg_name = dbg_name )
verify(alloc_error == .None, "Failed to initialize the string cache" )
cache.table, alloc_error = zpl_hmap_init_reserve( StringCached, persistent_slab_allocator(), 64 * Kilobyte )

View File

@ -243,7 +243,6 @@ sync_sectr_api :: proc( sectr_api : ^sectr.ModuleAPI, memory : ^ClientMemory, lo
}
}
fmt_backing : [16 * Kilobyte] u8
persistent_backing : [2 * Megabyte] byte
@ -326,16 +325,16 @@ main :: proc()
{
spall.SCOPED_EVENT( & profiler.ctx, & profiler.buffer, "Host Tick" )
// Hot-Reload
sync_sectr_api( & sectr_api, & memory, & logger, & profiler )
running = sectr_api.tick( duration_seconds( delta_ns ), delta_ns )
sectr_api.clean_frame()
delta_ns = time.tick_lap_time( & host_tick )
host_tick = time.tick_now()
// free_all( arena_allocator( & state.transient))
free_all( arena_allocator( & state.transient))
// Hot-Reload
sync_sectr_api( & sectr_api, & memory, & logger, & profiler )
}
// Determine how the run_cyle completed, if it failed due to an error,