mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-13 07:32:23 -07:00
eliminate geo_scope, fold into base layer's 'access' construct
This commit is contained in:
@@ -31,92 +31,11 @@ geo_init(void)
|
||||
geo_shared->evictor_thread = thread_launch(geo_evictor_thread__entry_point, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Thread Context Initialization
|
||||
|
||||
internal void
|
||||
geo_tctx_ensure_inited(void)
|
||||
{
|
||||
if(geo_tctx == 0)
|
||||
{
|
||||
Arena *arena = arena_alloc();
|
||||
geo_tctx = push_array(arena, GEO_TCTX, 1);
|
||||
geo_tctx->arena = arena;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Scoped Access
|
||||
|
||||
internal GEO_Scope *
|
||||
geo_scope_open(void)
|
||||
{
|
||||
geo_tctx_ensure_inited();
|
||||
GEO_Scope *scope = geo_tctx->free_scope;
|
||||
if(scope)
|
||||
{
|
||||
SLLStackPop(geo_tctx->free_scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
scope = push_array_no_zero(geo_tctx->arena, GEO_Scope, 1);
|
||||
}
|
||||
MemoryZeroStruct(scope);
|
||||
return scope;
|
||||
}
|
||||
|
||||
internal void
|
||||
geo_scope_close(GEO_Scope *scope)
|
||||
{
|
||||
for(GEO_Touch *touch = scope->top_touch, *next = 0; touch != 0; touch = next)
|
||||
{
|
||||
U128 hash = touch->hash;
|
||||
next = touch->next;
|
||||
U64 slot_idx = hash.u64[1]%geo_shared->slots_count;
|
||||
U64 stripe_idx = slot_idx%geo_shared->stripes_count;
|
||||
GEO_Slot *slot = &geo_shared->slots[slot_idx];
|
||||
GEO_Stripe *stripe = &geo_shared->stripes[stripe_idx];
|
||||
MutexScopeR(stripe->rw_mutex)
|
||||
{
|
||||
for(GEO_Node *n = slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(u128_match(hash, n->hash))
|
||||
{
|
||||
ins_atomic_u64_dec_eval(&n->scope_ref_count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
SLLStackPush(geo_tctx->free_touch, touch);
|
||||
}
|
||||
SLLStackPush(geo_tctx->free_scope, scope);
|
||||
}
|
||||
|
||||
internal void
|
||||
geo_scope_touch_node__stripe_r_guarded(GEO_Scope *scope, GEO_Node *node)
|
||||
{
|
||||
GEO_Touch *touch = geo_tctx->free_touch;
|
||||
ins_atomic_u64_inc_eval(&node->scope_ref_count);
|
||||
ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds());
|
||||
ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, update_tick_idx());
|
||||
if(touch != 0)
|
||||
{
|
||||
SLLStackPop(geo_tctx->free_touch);
|
||||
}
|
||||
else
|
||||
{
|
||||
touch = push_array_no_zero(geo_tctx->arena, GEO_Touch, 1);
|
||||
}
|
||||
MemoryZeroStruct(touch);
|
||||
touch->hash = node->hash;
|
||||
SLLStackPush(scope->top_touch, touch);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Cache Lookups
|
||||
|
||||
internal R_Handle
|
||||
geo_buffer_from_hash(GEO_Scope *scope, U128 hash)
|
||||
geo_buffer_from_hash(Access *access, U128 hash)
|
||||
{
|
||||
R_Handle handle = {0};
|
||||
if(!u128_match(hash, u128_zero()))
|
||||
@@ -134,7 +53,9 @@ geo_buffer_from_hash(GEO_Scope *scope, U128 hash)
|
||||
{
|
||||
handle = n->buffer;
|
||||
found = !r_handle_match(r_handle_zero(), handle);
|
||||
geo_scope_touch_node__stripe_r_guarded(scope, n);
|
||||
ins_atomic_u64_eval_assign(&n->last_time_touched_us, os_now_microseconds());
|
||||
ins_atomic_u64_eval_assign(&n->last_user_clock_idx_touched, update_tick_idx());
|
||||
access_touch(access, &n->scope_ref_count, stripe->cv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -181,13 +102,13 @@ geo_buffer_from_hash(GEO_Scope *scope, U128 hash)
|
||||
}
|
||||
|
||||
internal R_Handle
|
||||
geo_buffer_from_key(GEO_Scope *scope, C_Key key)
|
||||
geo_buffer_from_key(Access *access, C_Key key)
|
||||
{
|
||||
R_Handle handle = {0};
|
||||
for(U64 rewind_idx = 0; rewind_idx < C_KEY_HASH_HISTORY_COUNT; rewind_idx += 1)
|
||||
{
|
||||
U128 hash = c_hash_from_key(key, rewind_idx);
|
||||
handle = geo_buffer_from_hash(scope, hash);
|
||||
handle = geo_buffer_from_hash(access, hash);
|
||||
if(!r_handle_match(handle, r_handle_zero()))
|
||||
{
|
||||
break;
|
||||
|
||||
@@ -36,34 +36,6 @@ struct GEO_Stripe
|
||||
CondVar cv;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Scoped Access
|
||||
|
||||
typedef struct GEO_Touch GEO_Touch;
|
||||
struct GEO_Touch
|
||||
{
|
||||
GEO_Touch *next;
|
||||
U128 hash;
|
||||
};
|
||||
|
||||
typedef struct GEO_Scope GEO_Scope;
|
||||
struct GEO_Scope
|
||||
{
|
||||
GEO_Scope *next;
|
||||
GEO_Touch *top_touch;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Thread Context
|
||||
|
||||
typedef struct GEO_TCTX GEO_TCTX;
|
||||
struct GEO_TCTX
|
||||
{
|
||||
Arena *arena;
|
||||
GEO_Scope *free_scope;
|
||||
GEO_Touch *free_touch;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Shared State
|
||||
|
||||
@@ -94,7 +66,6 @@ struct GEO_Shared
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
thread_static GEO_TCTX *geo_tctx = 0;
|
||||
global GEO_Shared *geo_shared = 0;
|
||||
|
||||
////////////////////////////////
|
||||
@@ -102,23 +73,11 @@ global GEO_Shared *geo_shared = 0;
|
||||
|
||||
internal void geo_init(void);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Thread Context Initialization
|
||||
|
||||
internal void geo_tctx_ensure_inited(void);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Scoped Access
|
||||
|
||||
internal GEO_Scope *geo_scope_open(void);
|
||||
internal void geo_scope_close(GEO_Scope *scope);
|
||||
internal void geo_scope_touch_node__stripe_r_guarded(GEO_Scope *scope, GEO_Node *node);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Cache Lookups
|
||||
|
||||
internal R_Handle geo_buffer_from_hash(GEO_Scope *scope, U128 hash);
|
||||
internal R_Handle geo_buffer_from_key(GEO_Scope *scope, C_Key key);
|
||||
internal R_Handle geo_buffer_from_hash(Access *access, U128 hash);
|
||||
internal R_Handle geo_buffer_from_key(Access *access, C_Key key);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Transfer Threads
|
||||
|
||||
@@ -4338,7 +4338,7 @@ EV_EXPAND_RULE_INFO_FUNCTION_DEF(geo3d)
|
||||
RD_VIEW_UI_FUNCTION_DEF(geo3d)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
GEO_Scope *geo_scope = geo_scope_open();
|
||||
Access *access = access_open();
|
||||
RD_Geo3DViewState *state = rd_view_state(RD_Geo3DViewState);
|
||||
|
||||
//////////////////////////////
|
||||
@@ -4360,8 +4360,8 @@ RD_VIEW_UI_FUNCTION_DEF(geo3d)
|
||||
Rng1U64 vtxs_range = r1u64(vtx_base_off, vtx_base_off+vtx_size);
|
||||
C_Key idxs_key = rd_key_from_eval_space_range(eval.space, idxs_range, 0);
|
||||
C_Key vtxs_key = rd_key_from_eval_space_range(eval.space, vtxs_range, 0);
|
||||
R_Handle idxs_buffer = geo_buffer_from_key(geo_scope, idxs_key);
|
||||
R_Handle vtxs_buffer = geo_buffer_from_key(geo_scope, vtxs_key);
|
||||
R_Handle idxs_buffer = geo_buffer_from_key(access, idxs_key);
|
||||
R_Handle vtxs_buffer = geo_buffer_from_key(access, vtxs_key);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: equip loading info
|
||||
@@ -4445,6 +4445,6 @@ RD_VIEW_UI_FUNCTION_DEF(geo3d)
|
||||
rd_store_view_param_f32(str8_lit("pitch"), pitch_target);
|
||||
rd_store_view_param_f32(str8_lit("zoom"), zoom_target);
|
||||
|
||||
geo_scope_close(geo_scope);
|
||||
access_close(access);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user