Fixed bad resize_non_zeroed impl (cannot use default_resize_bytes_align_non_zeroed, its not a resize)

This commit is contained in:
Edward R. Gonzalez 2024-03-19 12:18:39 -04:00
parent 2c321b27fc
commit bf211a8e14
15 changed files with 35 additions and 122 deletions

View File

@ -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

View File

@ -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" )

View File

@ -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 )

View File

@ -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
}

View File

@ -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))

View File

@ -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 )
}

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -1,6 +1,6 @@
package sectr
//@(optimization_mode="speed")
ui_signal_from_box :: proc ( box : ^ UI_Box ) -> UI_Signal
{
// profile(#procedure)

View File

@ -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)

View File

@ -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'

View File

@ -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) {