diff --git a/code/grime.odin b/code/grime.odin index 40aebcb..524efcb 100644 --- a/code/grime.odin +++ b/code/grime.odin @@ -9,13 +9,14 @@ import "base:intrinsics" type_has_field :: intrinsics.type_has_field type_elem_type :: intrinsics.type_elem_type import "base:runtime" - Byte :: runtime.Byte - Kilobyte :: runtime.Kilobyte - Megabyte :: runtime.Megabyte - Gigabyte :: runtime.Gigabyte - Terabyte :: runtime.Terabyte - Petabyte :: runtime.Petabyte - Exabyte :: runtime.Exabyte + Byte :: runtime.Byte + Kilobyte :: runtime.Kilobyte + Megabyte :: runtime.Megabyte + Gigabyte :: runtime.Gigabyte + Terabyte :: runtime.Terabyte + Petabyte :: runtime.Petabyte + Exabyte :: runtime.Exabyte + resize_non_zeroed :: runtime.non_zero_mem_resize import c "core:c/libc" import "core:dynlib" import "core:hash" @@ -48,7 +49,6 @@ import "core:mem" is_power_of_two_uintptr :: mem.is_power_of_two ptr_offset :: mem.ptr_offset resize :: mem.resize - reisze_non_zeroed :: mem.default_resize_bytes_align_non_zeroed slice_ptr :: mem.slice_ptr TrackingAllocator :: mem.Tracking_Allocator tracking_allocator :: mem.tracking_allocator diff --git a/code/grime_array.odin b/code/grime_array.odin index dfc6fc7..5d782b0 100644 --- a/code/grime_array.odin +++ b/code/grime_array.odin @@ -270,7 +270,7 @@ array_set_capacity :: proc( self : ^Array( $ Type ), new_capacity : u64 ) -> All old_size := header_size + cast(int) self.capacity * size_of(Type) // new_mem, result_code := resize( self.header, old_size, new_size, allocator = self.backing ) - new_mem, result_code := reisze_non_zeroed( byte_slice( self.header, old_size), new_size, mem.DEFAULT_ALIGNMENT, allocator = self.backing ) + new_mem, result_code := resize_non_zeroed( self.header, old_size, new_size, mem.DEFAULT_ALIGNMENT, allocator = self.backing ) if result_code != AllocatorError.None { ensure( false, "Failed to allocate for new array capacity" ) diff --git a/code/grime_hashmap_zpl.odin b/code/grime_hashmap_zpl.odin index aab2727..f398857 100644 --- a/code/grime_hashmap_zpl.odin +++ b/code/grime_hashmap_zpl.odin @@ -116,7 +116,7 @@ zpl_hmap_rehash :: proc( ht : ^ HMapZPL( $ Type ), new_num : u64 ) -> AllocatorE { profile(#procedure) // For now the prototype should never allow this to happen. - ensure( false, "ZPL HMAP IS REHASHING" ) + // ensure( false, "ZPL HMAP IS REHASHING" ) last_added_index : i64 new_ht, init_result := zpl_hmap_init_reserve( Type, ht.hashes.backing, new_num ) diff --git a/code/grime_memory.odin b/code/grime_memory.odin index af84e38..b55fc0b 100644 --- a/code/grime_memory.odin +++ b/code/grime_memory.odin @@ -89,81 +89,3 @@ memory_aign_forward :: #force_inline proc( address, alignment : uintptr) -> uint } //endregion Memory Math - -// Since this is a prototype, all memory is always tracked. No arena is is interfaced directly. -TrackedAllocator :: struct { - backing : Arena, - internals : Arena, - tracker : TrackingAllocator, -} - -tracked_allocator :: proc( self : ^ TrackedAllocator ) -> Allocator { - return tracking_allocator( & self.tracker ) -} - -// TODO(Ed): These allocators are bad... not sure why. -tracked_allocator_init :: proc( size, internals_size : int, allocator := context.allocator ) -> TrackedAllocator -{ - result : TrackedAllocator - - arena_size :: size_of( Arena) - backing_size := size + arena_size - internals_size := internals_size + arena_size - raw_size := backing_size + internals_size - - raw_mem, raw_mem_code := alloc( raw_size, mem.DEFAULT_ALIGNMENT, allocator ) - verify( raw_mem_code == AllocatorError.None, "Failed to allocate memory for the TrackingAllocator" ) - - backing_slice := slice_ptr( cast( ^ byte) raw_mem, backing_size ) - internals_slice := slice_ptr( memory_after( backing_slice), internals_size ) - - arena_init( & result.backing, backing_slice ) - arena_init( & result.internals, internals_slice ) - - backing_allocator := arena_allocator( & result.backing ) - internals_allocator := arena_allocator( & result.internals ) - tracking_allocator_init( & result.tracker, backing_allocator, internals_allocator ) - { - tracker_arena := cast(^Arena) result.tracker.backing.data - arena_len := len( tracker_arena.data ) - verify( arena_len == len(result.backing.data), "BAD SIZE ON TRACKER'S ARENA" ) - } - return result -} - -// TODO(Ed): Remove this we're no longer using. -arena_allocator_init_vmem :: proc( vmem : [] byte ) -> ^ Arena -{ - arena_size :: size_of( Arena) - backing_size := len(vmem) - - result := cast( ^ Arena) & vmem[0] - result_slice := slice_ptr( & vmem[0], arena_size ) - - backing_slice := slice_ptr( memory_after( result_slice), backing_size ) - arena_init( result, backing_slice ) - return result -} - -tracked_allocator_init_vmem :: proc( vmem : [] byte, internals_size : int ) -> ^ TrackedAllocator -{ - arena_size :: size_of( Arena) - tracking_allocator_size :: size_of( TrackingAllocator ) - backing_size := len(vmem) - internals_size - raw_size := backing_size + internals_size - - verify( backing_size >= 0 && len(vmem) >= raw_size, "Provided virtual memory slice is not large enough to hold the TrackedAllocator" ) - - result := cast( ^ TrackedAllocator) & vmem[0] - result_slice := slice_ptr( & vmem[0], tracking_allocator_size ) - - backing_slice := slice_ptr( memory_after( result_slice ), backing_size ) - internals_slice := slice_ptr( memory_after( backing_slice), internals_size ) - backing := & result.backing - internals := & result.internals - arena_init( backing, backing_slice ) - arena_init( internals, internals_slice ) - - tracking_allocator_init( & result.tracker, arena_allocator( backing ), arena_allocator( internals ) ) - return result -} diff --git a/code/grime_pool_allocator.odin b/code/grime_pool_allocator.odin index ad60315..eea33da 100644 --- a/code/grime_pool_allocator.odin +++ b/code/grime_pool_allocator.odin @@ -138,12 +138,10 @@ pool_grab :: proc( using pool : Pool, zero_memory := false ) -> ( block : []byte head := & pool.free_list_head // Compiler Bug? Fails to compile - // ll_pop( head ) - - last_free : ^Pool_FreeBlock = pool.free_list_head // last_free := ll_pop( & pool.free_list_head ) - pool.free_list_head = pool.free_list_head.next // ll_pop + last_free : ^Pool_FreeBlock = pool.free_list_head + pool.free_list_head = pool.free_list_head.next block = byte_slice( cast([^]byte) last_free, int(pool.block_size) ) // log( str_fmt_tmp("Returning free block: %p %d", raw_data(block), pool.block_size)) diff --git a/code/grime_slab_allocator.odin b/code/grime_slab_allocator.odin index d710d09..7eeabe1 100644 --- a/code/grime_slab_allocator.odin +++ b/code/grime_slab_allocator.odin @@ -43,9 +43,7 @@ SlabPolicy :: StackFixed(SlabSizeClass, Slab_Max_Size_Classes) SlabHeader :: struct { backing : Allocator, - - policy : SlabPolicy, // TODO(Ed) : Remove this, the policy can't be changed after its been set so its meaningless to have... - pools : StackFixed(Pool, Slab_Max_Size_Classes), + pools : StackFixed(Pool, Slab_Max_Size_Classes), } Slab :: struct { @@ -68,12 +66,11 @@ slab_init :: proc( policy : ^SlabPolicy, bucket_reserve_num : uint = 0, allocato slab.header = cast( ^SlabHeader) raw_mem slab.backing = allocator - slab.policy = (policy^) - alloc_error = slab_init_pools( slab, bucket_reserve_num ) + alloc_error = slab_init_pools( slab, policy, bucket_reserve_num ) return } -slab_init_pools :: proc ( using self : Slab, bucket_reserve_num : uint = 0 ) -> AllocatorError +slab_init_pools :: proc ( using self : Slab, policy : ^SlabPolicy, bucket_reserve_num : uint = 0 ) -> AllocatorError { profile(#procedure) for id in 0 ..< policy.idx { @@ -97,7 +94,7 @@ slab_reload :: proc ( using self : Slab, allocator : Allocator ) slab_destroy :: proc( using self : Slab ) { - for id in 0 ..< policy.idx { + for id in 0 ..< pools.idx { pool := pools.items[id] pool_destroy( pool ) } diff --git a/code/host/host.odin b/code/host/host.odin index 1ff2e1e..db2f2d8 100644 --- a/code/host/host.odin +++ b/code/host/host.odin @@ -74,9 +74,6 @@ import sectr "../." log :: sectr.log SpallProfiler :: sectr.SpallProfiler to_odin_logger :: sectr.to_odin_logger - TrackedAllocator :: sectr.TrackedAllocator - tracked_allocator :: sectr.tracked_allocator - tracked_allocator_init :: sectr.tracked_allocator_init verify :: sectr.verify file_status :: proc { diff --git a/code/tick_render.odin b/code/tick_render.odin index f51bd34..f585747 100644 --- a/code/tick_render.odin +++ b/code/tick_render.odin @@ -4,7 +4,7 @@ import "core:fmt" import rl "vendor:raylib" -//@(optimization_mode="speed") + render :: proc() { profile(#procedure) @@ -118,6 +118,7 @@ render_mode_2d :: proc() rl.BeginMode2D( project.workspace.cam ) // Draw 3D Viewport + when false { viewport_size := Vec2 { 1280.0, 720.0 } vp_half_size := viewport_size * 0.5 diff --git a/code/tick_update.odin b/code/tick_update.odin index e5e5121..dafeb8a 100644 --- a/code/tick_update.odin +++ b/code/tick_update.odin @@ -64,7 +64,7 @@ frametime_delta32 :: #force_inline proc "contextless" () -> f32 { return cast(f32) get_state().frametime_delta_seconds } -//@(optimization_mode="speed") + update :: proc( delta_time : f64 ) -> b32 { profile(#procedure) @@ -310,7 +310,7 @@ update :: proc( delta_time : f64 ) -> b32 } // Whitespace AST test - if false + if true { profile("Whitespace AST test") @@ -350,7 +350,7 @@ update :: proc( delta_time : f64 ) -> b32 // index := 0 widgets : Array(UI_Widget) - widgets, alloc_error = array_init_reserve( UI_Widget, frame_slab_allocator(), Kilobyte * 4 ) + widgets, alloc_error = array_init_reserve( UI_Widget, frame_slab_allocator(), 8 ) widgets_ptr := & widgets label_id := 0 diff --git a/code/ui.odin b/code/ui.odin index b64791b..55001d2 100644 --- a/code/ui.odin +++ b/code/ui.odin @@ -274,7 +274,7 @@ UI_Box :: struct { UI_Layout_Stack_Size :: 512 UI_Style_Stack_Size :: 512 UI_Parent_Stack_Size :: 512 -UI_Built_Boxes_Array_Size :: Kilobyte * 5 +UI_Built_Boxes_Array_Size :: 8 UI_State :: struct { // TODO(Ed) : Use these @@ -357,7 +357,6 @@ ui_box_from_key :: #force_inline proc ( cache : ^HMapZPL(UI_Box), key : UI_Key ) return zpl_hmap_get( cache, cast(u64) key ) } -//@(optimization_mode="speed") ui_box_make :: proc( flags : UI_BoxFlags, label : string ) -> (^ UI_Box) { // profile(#procedure) @@ -486,7 +485,6 @@ ui_graph_build :: proc( ui : ^ UI_State ) { ui_graph_build_begin( ui ) } -//@(optimization_mode="speed") ui_key_from_string :: #force_inline proc "contextless" ( value : string ) -> UI_Key { // profile(#procedure) diff --git a/code/ui_layout.odin b/code/ui_layout.odin index c4bfb14..8b31618 100644 --- a/code/ui_layout.odin +++ b/code/ui_layout.odin @@ -4,7 +4,7 @@ import "core:math" import "core:math/linalg" // Note(Ed): This is naturally pretty expensive -//@(optimization_mode="speed") + ui_compute_layout :: proc() { profile(#procedure) diff --git a/code/ui_signal.odin b/code/ui_signal.odin index 95d9059..37e29aa 100644 --- a/code/ui_signal.odin +++ b/code/ui_signal.odin @@ -1,6 +1,6 @@ package sectr -//@(optimization_mode="speed") + ui_signal_from_box :: proc ( box : ^ UI_Box ) -> UI_Signal { // profile(#procedure) diff --git a/code/ui_widgets.odin b/code/ui_widgets.odin index 8129b85..bab1883 100644 --- a/code/ui_widgets.odin +++ b/code/ui_widgets.odin @@ -5,7 +5,7 @@ UI_Widget :: struct { using signal : UI_Signal, } -//@(optimization_mode="speed") + ui_widget :: proc( label : string, flags : UI_BoxFlags ) -> (widget : UI_Widget) { // profile(#procedure) @@ -15,7 +15,7 @@ ui_widget :: proc( label : string, flags : UI_BoxFlags ) -> (widget : UI_Widget) return } -//@(optimization_mode="speed") + ui_button :: proc( label : string, flags : UI_BoxFlags = {} ) -> (btn : UI_Widget) { // profile(#procedure) @@ -26,7 +26,7 @@ ui_button :: proc( label : string, flags : UI_BoxFlags = {} ) -> (btn : UI_Widge return } -//@(optimization_mode="speed") + ui_text :: proc( label : string, content : StringCached, flags : UI_BoxFlags = {} ) -> UI_Widget { // profile(#procedure) @@ -39,7 +39,7 @@ ui_text :: proc( label : string, content : StringCached, flags : UI_BoxFlags = { return { box, signal } } -//@(optimization_mode="speed") + ui_text_spaces :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget { // profile(#procedure) @@ -55,7 +55,7 @@ ui_text_spaces :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget return { box, signal } } -//@(optimization_mode="speed") + ui_text_tabs :: proc( label : string, flags : UI_BoxFlags = {} ) -> UI_Widget { // profile(#procedure) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 3e656aa..27101a5 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -162,7 +162,7 @@ push-location $path_root $build_args += $flag_output_path + $module_dll # $build_args += ($flag_collection + $pkg_collection_thirdparty) $build_args += $flag_micro_architecture_native - $build_args += $flag_use_separate_modules + # $build_args += $flag_use_separate_modules $build_args += $flag_thread_count + $CoreCount_Physical $build_args += $flag_optimize_none # $build_args += $flag_optimize_minimal @@ -243,10 +243,10 @@ push-location $path_root $build_args += $flag_micro_architecture_native $build_args += $flag_use_separate_modules $build_args += $flag_thread_count + $CoreCount_Physical - # $build_args += $flag_optimize_none + $build_args += $flag_optimize_none # $build_args += $flag_optimize_minimal # $build_args += $flag_optimize_speed - $build_args += $falg_optimize_aggressive + # $build_args += $falg_optimize_aggressive $build_args += $flag_debug $build_args += $flag_pdb_name + $pdb $build_args += $flag_subsystem + 'windows' diff --git a/scripts/update_deps.ps1 b/scripts/update_deps.ps1 index 773f3df..be0fc41 100644 --- a/scripts/update_deps.ps1 +++ b/scripts/update_deps.ps1 @@ -41,7 +41,7 @@ function Update-GitRepo pop-location git -C $path rev-parse HEAD | out-file $last_built_commit - $binaries_dirty = $true + $script:binaries_dirty = $true return } @@ -63,7 +63,7 @@ function Update-GitRepo pop-location $latest_commit_hash | out-file $last_built_commit - $binaries_dirty = $true + $script:binaries_dirty = $true write-host } @@ -91,7 +91,7 @@ $path_vendor = join-path $path_odin 'vendor' $path_vendor_raylib = join-path $path_vendor 'raylib' $path_raylib_dlls = join-path $path_vendor_raylib 'windows' -if ( $binaries_dirty ) +if ( $binaries_dirty -or $true ) { $third_party_dlls = Get-ChildItem -Path $path_raylib_dlls -Filter '*.dll' foreach ($dll in $third_party_dlls) {