mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-06 13:58:40 +00:00
eliminate geo cache fallback key/hash cache; we can just use the hash store to rewind
This commit is contained in:
@@ -1112,39 +1112,13 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(geo)
|
|||||||
DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread);
|
DF_Entity *thread = df_entity_from_handle(ctrl_ctx->thread);
|
||||||
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
|
||||||
|
|
||||||
//- rjf: produce unique keys for index buffer
|
//- rjf: obtain keys for index buffer & vertex buffer memory
|
||||||
U128 index_buffer_key = {0};
|
U128 index_buffer_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, index_buffer_vaddr_range, 0);
|
||||||
{
|
U128 vertex_buffer_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vertex_buffer_vaddr_range, 0);
|
||||||
U64 data[] =
|
|
||||||
{
|
|
||||||
(U64)process->ctrl_machine_id,
|
|
||||||
(U64)process->ctrl_handle.u64[0],
|
|
||||||
index_buffer_vaddr_range.min,
|
|
||||||
index_buffer_vaddr_range.max,
|
|
||||||
};
|
|
||||||
index_buffer_key = hs_hash_from_data(str8((U8 *)data, sizeof(data)));
|
|
||||||
}
|
|
||||||
|
|
||||||
//- rjf: produce unique keys for vertex buffer
|
|
||||||
U128 vertex_buffer_key = {0};
|
|
||||||
{
|
|
||||||
U64 data[] =
|
|
||||||
{
|
|
||||||
(U64)process->ctrl_machine_id,
|
|
||||||
(U64)process->ctrl_handle.u64[0],
|
|
||||||
vertex_buffer_vaddr_range.min,
|
|
||||||
vertex_buffer_vaddr_range.max,
|
|
||||||
};
|
|
||||||
vertex_buffer_key = hs_hash_from_data(str8((U8 *)data, sizeof(data)));
|
|
||||||
}
|
|
||||||
|
|
||||||
//- rjf: address range -> hash
|
|
||||||
U128 index_buffer_hash = ctrl_stored_hash_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, index_buffer_vaddr_range, 0, 0, 0);
|
|
||||||
U128 vertex_buffer_hash = ctrl_stored_hash_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vertex_buffer_vaddr_range, 0, 0, 0);
|
|
||||||
|
|
||||||
//- rjf: get gpu buffers
|
//- rjf: get gpu buffers
|
||||||
R_Handle index_buffer = geo_buffer_from_key_hash(geo_scope, index_buffer_key, index_buffer_hash);
|
R_Handle index_buffer = geo_buffer_from_key(geo_scope, index_buffer_key);
|
||||||
R_Handle vertex_buffer = geo_buffer_from_key_hash(geo_scope, vertex_buffer_key, vertex_buffer_hash);
|
R_Handle vertex_buffer = geo_buffer_from_key(geo_scope, vertex_buffer_key);
|
||||||
|
|
||||||
//- rjf: build preview
|
//- rjf: build preview
|
||||||
F32 rate = 1 - pow_f32(2, (-15.f * df_dt()));
|
F32 rate = 1 - pow_f32(2, (-15.f * df_dt()));
|
||||||
|
|||||||
+21
-81
@@ -21,16 +21,6 @@ geo_init(void)
|
|||||||
geo_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
geo_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
||||||
geo_shared->stripes[idx].cv = os_condition_variable_alloc();
|
geo_shared->stripes[idx].cv = os_condition_variable_alloc();
|
||||||
}
|
}
|
||||||
geo_shared->fallback_slots_count = 1024;
|
|
||||||
geo_shared->fallback_stripes_count = Min(geo_shared->fallback_slots_count, os_logical_core_count());
|
|
||||||
geo_shared->fallback_slots = push_array(arena, GEO_KeyFallbackSlot, geo_shared->fallback_slots_count);
|
|
||||||
geo_shared->fallback_stripes = push_array(arena, GEO_Stripe, geo_shared->fallback_stripes_count);
|
|
||||||
for(U64 idx = 0; idx < geo_shared->fallback_stripes_count; idx += 1)
|
|
||||||
{
|
|
||||||
geo_shared->fallback_stripes[idx].arena = arena_alloc();
|
|
||||||
geo_shared->fallback_stripes[idx].rw_mutex = os_rw_mutex_alloc();
|
|
||||||
geo_shared->fallback_stripes[idx].cv = os_condition_variable_alloc();
|
|
||||||
}
|
|
||||||
geo_shared->u2x_ring_size = KB(64);
|
geo_shared->u2x_ring_size = KB(64);
|
||||||
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
|
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
|
||||||
geo_shared->u2x_ring_cv = os_condition_variable_alloc();
|
geo_shared->u2x_ring_cv = os_condition_variable_alloc();
|
||||||
@@ -144,7 +134,7 @@ geo_scope_touch_node__stripe_r_guarded(GEO_Scope *scope, GEO_Node *node)
|
|||||||
//~ rjf: Cache Lookups
|
//~ rjf: Cache Lookups
|
||||||
|
|
||||||
internal R_Handle
|
internal R_Handle
|
||||||
geo_buffer_from_key_hash(GEO_Scope *scope, U128 key, U128 hash)
|
geo_buffer_from_hash(GEO_Scope *scope, U128 hash)
|
||||||
{
|
{
|
||||||
R_Handle handle = {0};
|
R_Handle handle = {0};
|
||||||
if(!u128_match(hash, u128_zero()))
|
if(!u128_match(hash, u128_zero()))
|
||||||
@@ -201,42 +191,23 @@ geo_buffer_from_key_hash(GEO_Scope *scope, U128 key, U128 hash)
|
|||||||
}
|
}
|
||||||
if(node_is_new)
|
if(node_is_new)
|
||||||
{
|
{
|
||||||
geo_u2x_enqueue_req(key, hash, max_U64);
|
geo_u2x_enqueue_req(hash, max_U64);
|
||||||
}
|
}
|
||||||
if(r_handle_match(handle, r_handle_zero()))
|
}
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal R_Handle
|
||||||
|
geo_buffer_from_key(GEO_Scope *scope, U128 key)
|
||||||
|
{
|
||||||
|
R_Handle handle = {0};
|
||||||
|
for(U64 rewind_idx = 0; rewind_idx < 2; rewind_idx += 1)
|
||||||
|
{
|
||||||
|
U128 hash = hs_hash_from_key(key, rewind_idx);
|
||||||
|
handle = geo_buffer_from_hash(scope, hash);
|
||||||
|
if(!r_handle_match(handle, r_handle_zero()))
|
||||||
{
|
{
|
||||||
U128 fallback_hash = {0};
|
break;
|
||||||
U64 fallback_slot_idx = key.u64[1]%geo_shared->fallback_slots_count;
|
|
||||||
U64 fallback_stripe_idx = fallback_slot_idx%geo_shared->fallback_stripes_count;
|
|
||||||
GEO_KeyFallbackSlot *fallback_slot = &geo_shared->fallback_slots[fallback_slot_idx];
|
|
||||||
GEO_Stripe *fallback_stripe = &geo_shared->fallback_stripes[fallback_stripe_idx];
|
|
||||||
OS_MutexScopeR(fallback_stripe->rw_mutex) for(GEO_KeyFallbackNode *n = fallback_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(key, n->key))
|
|
||||||
{
|
|
||||||
fallback_hash = n->hash;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!u128_match(fallback_hash, u128_zero()))
|
|
||||||
{
|
|
||||||
U64 retry_slot_idx = fallback_hash.u64[1]%geo_shared->slots_count;
|
|
||||||
U64 retry_stripe_idx = retry_slot_idx%geo_shared->stripes_count;
|
|
||||||
GEO_Slot *retry_slot = &geo_shared->slots[retry_slot_idx];
|
|
||||||
GEO_Stripe *retry_stripe = &geo_shared->stripes[retry_stripe_idx];
|
|
||||||
OS_MutexScopeR(retry_stripe->rw_mutex)
|
|
||||||
{
|
|
||||||
for(GEO_Node *n = retry_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(fallback_hash, n->hash))
|
|
||||||
{
|
|
||||||
handle = n->buffer;
|
|
||||||
geo_scope_touch_node__stripe_r_guarded(scope, n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return handle;
|
return handle;
|
||||||
@@ -246,17 +217,16 @@ geo_buffer_from_key_hash(GEO_Scope *scope, U128 key, U128 hash)
|
|||||||
//~ rjf: Transfer Threads
|
//~ rjf: Transfer Threads
|
||||||
|
|
||||||
internal B32
|
internal B32
|
||||||
geo_u2x_enqueue_req(U128 key, U128 hash, U64 endt_us)
|
geo_u2x_enqueue_req(U128 hash, U64 endt_us)
|
||||||
{
|
{
|
||||||
B32 good = 0;
|
B32 good = 0;
|
||||||
OS_MutexScope(geo_shared->u2x_ring_mutex) for(;;)
|
OS_MutexScope(geo_shared->u2x_ring_mutex) for(;;)
|
||||||
{
|
{
|
||||||
U64 unconsumed_size = geo_shared->u2x_ring_write_pos-geo_shared->u2x_ring_read_pos;
|
U64 unconsumed_size = geo_shared->u2x_ring_write_pos-geo_shared->u2x_ring_read_pos;
|
||||||
U64 available_size = geo_shared->u2x_ring_size-unconsumed_size;
|
U64 available_size = geo_shared->u2x_ring_size-unconsumed_size;
|
||||||
if(available_size >= sizeof(key)+sizeof(hash))
|
if(available_size >= sizeof(hash))
|
||||||
{
|
{
|
||||||
good = 1;
|
good = 1;
|
||||||
geo_shared->u2x_ring_write_pos += ring_write_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_write_pos, &key);
|
|
||||||
geo_shared->u2x_ring_write_pos += ring_write_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_write_pos, &hash);
|
geo_shared->u2x_ring_write_pos += ring_write_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_write_pos, &hash);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -274,14 +244,13 @@ geo_u2x_enqueue_req(U128 key, U128 hash, U64 endt_us)
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
geo_u2x_dequeue_req(U128 *key_out, U128 *hash_out)
|
geo_u2x_dequeue_req(U128 *hash_out)
|
||||||
{
|
{
|
||||||
OS_MutexScope(geo_shared->u2x_ring_mutex) for(;;)
|
OS_MutexScope(geo_shared->u2x_ring_mutex) for(;;)
|
||||||
{
|
{
|
||||||
U64 unconsumed_size = geo_shared->u2x_ring_write_pos-geo_shared->u2x_ring_read_pos;
|
U64 unconsumed_size = geo_shared->u2x_ring_write_pos-geo_shared->u2x_ring_read_pos;
|
||||||
if(unconsumed_size >= sizeof(*key_out)+sizeof(*hash_out))
|
if(unconsumed_size >= sizeof(*hash_out))
|
||||||
{
|
{
|
||||||
geo_shared->u2x_ring_read_pos += ring_read_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_read_pos, key_out);
|
|
||||||
geo_shared->u2x_ring_read_pos += ring_read_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_read_pos, hash_out);
|
geo_shared->u2x_ring_read_pos += ring_read_struct(geo_shared->u2x_ring_base, geo_shared->u2x_ring_size, geo_shared->u2x_ring_read_pos, hash_out);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -298,9 +267,8 @@ geo_xfer_thread__entry_point(void *p)
|
|||||||
HS_Scope *scope = hs_scope_open();
|
HS_Scope *scope = hs_scope_open();
|
||||||
|
|
||||||
//- rjf: decode
|
//- rjf: decode
|
||||||
U128 key = {0};
|
|
||||||
U128 hash = {0};
|
U128 hash = {0};
|
||||||
geo_u2x_dequeue_req(&key, &hash);
|
geo_u2x_dequeue_req(&hash);
|
||||||
|
|
||||||
//- rjf: unpack hash
|
//- rjf: unpack hash
|
||||||
U64 slot_idx = hash.u64[1]%geo_shared->slots_count;
|
U64 slot_idx = hash.u64[1]%geo_shared->slots_count;
|
||||||
@@ -351,34 +319,6 @@ geo_xfer_thread__entry_point(void *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- rjf: commit this key/hash pair to fallback cache
|
|
||||||
if(got_task && !u128_match(key, u128_zero()) && !u128_match(hash, u128_zero()))
|
|
||||||
{
|
|
||||||
U64 fallback_slot_idx = key.u64[1]%geo_shared->fallback_slots_count;
|
|
||||||
U64 fallback_stripe_idx = fallback_slot_idx%geo_shared->fallback_stripes_count;
|
|
||||||
GEO_KeyFallbackSlot *fallback_slot = &geo_shared->fallback_slots[fallback_slot_idx];
|
|
||||||
GEO_Stripe *fallback_stripe = &geo_shared->fallback_stripes[fallback_stripe_idx];
|
|
||||||
OS_MutexScopeW(fallback_stripe->rw_mutex)
|
|
||||||
{
|
|
||||||
GEO_KeyFallbackNode *node = 0;
|
|
||||||
for(GEO_KeyFallbackNode *n = fallback_slot->first; n != 0; n = n->next)
|
|
||||||
{
|
|
||||||
if(u128_match(n->key, key))
|
|
||||||
{
|
|
||||||
node = n;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(node == 0)
|
|
||||||
{
|
|
||||||
node = push_array(fallback_stripe->arena, GEO_KeyFallbackNode, 1);
|
|
||||||
SLLQueuePush(fallback_slot->first, fallback_slot->last, node);
|
|
||||||
}
|
|
||||||
node->key = key;
|
|
||||||
node->hash = hash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hs_scope_close(scope);
|
hs_scope_close(scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,6 @@
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Cache Types
|
//~ rjf: Cache Types
|
||||||
|
|
||||||
typedef struct GEO_KeyFallbackNode GEO_KeyFallbackNode;
|
|
||||||
struct GEO_KeyFallbackNode
|
|
||||||
{
|
|
||||||
GEO_KeyFallbackNode *next;
|
|
||||||
U128 key;
|
|
||||||
U128 hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct GEO_KeyFallbackSlot GEO_KeyFallbackSlot;
|
|
||||||
struct GEO_KeyFallbackSlot
|
|
||||||
{
|
|
||||||
GEO_KeyFallbackNode *first;
|
|
||||||
GEO_KeyFallbackNode *last;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct GEO_Node GEO_Node;
|
typedef struct GEO_Node GEO_Node;
|
||||||
struct GEO_Node
|
struct GEO_Node
|
||||||
{
|
{
|
||||||
@@ -97,12 +82,6 @@ struct GEO_Shared
|
|||||||
GEO_Stripe *stripes;
|
GEO_Stripe *stripes;
|
||||||
GEO_Node **stripes_free_nodes;
|
GEO_Node **stripes_free_nodes;
|
||||||
|
|
||||||
// rjf: fallback cache
|
|
||||||
U64 fallback_slots_count;
|
|
||||||
U64 fallback_stripes_count;
|
|
||||||
GEO_KeyFallbackSlot *fallback_slots;
|
|
||||||
GEO_Stripe *fallback_stripes;
|
|
||||||
|
|
||||||
// rjf: user -> xfer thread
|
// rjf: user -> xfer thread
|
||||||
U64 u2x_ring_size;
|
U64 u2x_ring_size;
|
||||||
U8 *u2x_ring_base;
|
U8 *u2x_ring_base;
|
||||||
@@ -151,13 +130,14 @@ internal void geo_scope_touch_node__stripe_r_guarded(GEO_Scope *scope, GEO_Node
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Cache Lookups
|
//~ rjf: Cache Lookups
|
||||||
|
|
||||||
internal R_Handle geo_buffer_from_key_hash(GEO_Scope *scope, U128 key, U128 hash);
|
internal R_Handle geo_buffer_from_hash(GEO_Scope *scope, U128 hash);
|
||||||
|
internal R_Handle geo_buffer_from_key(GEO_Scope *scope, U128 key);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Transfer Threads
|
//~ rjf: Transfer Threads
|
||||||
|
|
||||||
internal B32 geo_u2x_enqueue_req(U128 key, U128 hash, U64 endt_us);
|
internal B32 geo_u2x_enqueue_req(U128 hash, U64 endt_us);
|
||||||
internal void geo_u2x_dequeue_req(U128 *key_out, U128 *hash_out);
|
internal void geo_u2x_dequeue_req(U128 *hash_out);
|
||||||
internal void geo_xfer_thread__entry_point(void *p);
|
internal void geo_xfer_thread__entry_point(void *p);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user