misc changes

* draw_text_string_pos_extent_zoomed can now oversample text futher (if desired)
* render_ui_via_box_tree has a rudimentary render pass layering optimization

Add support for the slab allocator to accept arbitrary alignments (odin's map container needs it)
Messing around with 64-byte alignment as the default for the allocator...
This commit is contained in:
2024-06-25 19:13:41 -04:00
parent 268ba29ec6
commit 1533a14a1b
13 changed files with 94 additions and 51 deletions

View File

@ -181,12 +181,12 @@ array_append_at_slice :: proc( using self : ^Array( $ Type ), items : []Type, id
return AllocatorError.None
}
array_back :: proc( self : Array($Type) ) -> Type {
array_back :: #force_inline proc "contextless" ( self : Array($Type) ) -> Type {
value := self.data[self.num - 1]
return value
}
array_push_back :: proc( using self : Array( $ Type)) -> b32 {
array_push_back :: #force_inline proc "contextless" ( using self : Array( $ Type)) -> b32 {
if num == capacity {
return false
}

View File

@ -3,16 +3,16 @@ package grime
import "base:runtime"
reload_array :: proc( self : ^[dynamic]$Type, allocator : Allocator ) {
raw := transmute(runtime.Raw_Dynamic_Array) self
raw := transmute( ^runtime.Raw_Dynamic_Array) self
raw.allocator = allocator
}
reload_queue :: proc( self : ^Queue($Type), allocator : Allocator ) {
raw_array := transmute(runtime.Raw_Dynamic_Array) self.data
raw_array := transmute( ^runtime.Raw_Dynamic_Array) self.data
raw_array.allocator = allocator
}
reload_map :: proc( self : ^map [$KeyType] $EntryType, allocator : Allocator ) {
raw := transmute(runtime.Raw_Map) self
raw := transmute( ^runtime.Raw_Map) self
raw.allocator = allocator
}

View File

@ -87,6 +87,11 @@ memory_aign_forward :: #force_inline proc( address, alignment : uintptr) -> uint
return aligned_address
}
// align_up :: proc(address: uintptr, alignment: uintptr) -> uintptr {
// return (address + alignment - 1) & ~(alignment - 1)
// }
//endregion Memory Math
swap :: #force_inline proc( a, b : ^ $Type ) -> ( ^ Type, ^ Type ) { return b, a }

View File

@ -353,11 +353,12 @@ pool_validate_ownership :: proc( using self : Pool, block : [] byte ) -> b32
{
misalignment := (block_address - start) % uintptr(block_size)
if misalignment != 0 {
ensure(false, "pool_validate_ownership: This data is within this pool's buckets, however its not aligned to the start of a block")
log(str_fmt("Block address: %p Misalignment: %p closest: %p",
transmute(rawptr)block_address,
transmute(rawptr)misalignment,
rawptr(block_address - misalignment)))
// TODO(Ed): We cannot use thsi to validate that the data is within the pool bucket as we can provide the user different alignments
// ensure(false, "pool_validate_ownership: This data is within this pool's buckets, however its not aligned to the start of a block")
// log(str_fmt("Block address: %p Misalignment: %p closest: %p",
// transmute(rawptr)block_address,
// transmute(rawptr)misalignment,
// rawptr(block_address - misalignment)))
}
within_bucket = true

View File

@ -17,13 +17,13 @@ set_profiler_module_context :: #force_inline proc "contextless" ( ctx : ^SpallPr
@(deferred_none = profile_end)
profile :: #force_inline proc "contextless" ( name : string, loc := #caller_location ) {
spall._buffer_begin( & Module_Context.ctx, & Module_Context.buffer, name, "", loc )
// spall._buffer_begin( & Module_Context.ctx, & Module_Context.buffer, name, "", loc )
}
profile_begin :: #force_inline proc "contextless" ( name : string, loc := #caller_location ) {
spall._buffer_begin( & Module_Context.ctx, & Module_Context.buffer, name, "", loc )
// spall._buffer_begin( & Module_Context.ctx, & Module_Context.buffer, name, "", loc )
}
profile_end :: #force_inline proc "contextless" () {
spall._buffer_end( & Module_Context.ctx, & Module_Context.buffer)
// spall._buffer_end( & Module_Context.ctx, & Module_Context.buffer)
}

View File

@ -129,19 +129,24 @@ slab_alloc :: proc( self : Slab,
loc := #caller_location
) -> ( data : []byte, alloc_error : AllocatorError )
{
// profile(#procedure)
pool : Pool
id : u32 = 0
for ; id < self.pools.idx; id += 1 {
pool = self.pools.items[id]
if pool.block_size >= size && pool.alignment >= alignment {
adjusted_alignment := clamp(alignment, pool.alignment, alignment)
aligned_size := size + (adjusted_alignment - 1)
if pool.block_size >= aligned_size {
break
}
}
verify( id < self.pools.idx, "There is not a size class in the slab's policy to satisfy the requested allocation", location = loc )
verify( pool.header != nil, "Requested alloc not supported by the slab allocator", location = loc )
adjusted_alignment := clamp(alignment, pool.alignment, alignment)
block : []byte
slab_validate_pools( self )
block, alloc_error = pool_grab(pool)
@ -153,7 +158,11 @@ slab_alloc :: proc( self : Slab,
}
// log( str_fmt_tmp("%v: Retrieved block: %p %d", self.dbg_name, raw_data(block), len(block) ))
data = byte_slice(raw_data(block), size)
// Align the block
block_start := uintptr(raw_data(block))
aligned_start := memory_aign_forward(block_start, uintptr(adjusted_alignment))
data = byte_slice(transmute(rawptr) aligned_start, size)
if zero_memory {
slice.zero(data)
}

View File

@ -39,14 +39,15 @@ Module_String_Cache : ^StringCache
str_cache_init :: proc( table_allocator, slabs_allocator : Allocator ) -> (cache : StringCache)
{
alignment := uint(mem.DEFAULT_ALIGNMENT)
// alignment := uint(mem.DEFAULT_ALIGNMENT)
alignment := uint(64)
policy : SlabPolicy
policy_ptr := & policy
push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 8, alignment })
push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 16, alignment })
push( policy_ptr, SlabSizeClass { 128 * Kilobyte, 32, alignment })
push( policy_ptr, SlabSizeClass { 128 * Kilobyte, 64, alignment })
// push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 8, alignment })
// push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 16, alignment })
// push( policy_ptr, SlabSizeClass { 128 * Kilobyte, 32, alignment })
push( policy_ptr, SlabSizeClass { 640 * Kilobyte, 64, alignment })
push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 128, alignment })
push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 256, alignment })
push( policy_ptr, SlabSizeClass { 64 * Kilobyte, 512, alignment })