mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-06-13 07:32:23 -07:00
artifact cache waitable cache access; debugging / fixes; start plugging in file stream to artifact cache
This commit is contained in:
@@ -21,12 +21,12 @@ ac_init(void)
|
||||
//~ rjf: Cache Lookups
|
||||
|
||||
internal AC_Artifact
|
||||
ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType *create, AC_DestroyFunctionType *destroy, U64 slots_count)
|
||||
ac_artifact_from_key_(Access *access, String8 key, AC_ArtifactParams *params, U64 endt_us)
|
||||
{
|
||||
//- rjf: create function -> cache
|
||||
AC_Cache *cache = 0;
|
||||
{
|
||||
U64 cache_hash = u64_hash_from_str8(str8_struct(&create));
|
||||
U64 cache_hash = u64_hash_from_str8(str8_struct(¶ms->create));
|
||||
U64 cache_slot_idx = cache_hash%ac_shared->cache_slots_count;
|
||||
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
|
||||
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
|
||||
@@ -35,7 +35,7 @@ ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType
|
||||
{
|
||||
for(AC_Cache *c = ac_shared->cache_slots[cache_slot_idx]; c != 0; c = c->next)
|
||||
{
|
||||
if(c->create == create)
|
||||
if(c->create == params->create)
|
||||
{
|
||||
cache = c;
|
||||
break;
|
||||
@@ -45,10 +45,10 @@ ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType
|
||||
{
|
||||
cache = push_array(cache_stripe->arena, AC_Cache, 1);
|
||||
SLLStackPush(ac_shared->cache_slots[cache_slot_idx], cache);
|
||||
cache->create = create;
|
||||
cache->destroy = destroy;
|
||||
cache->slots_count = slots_count;
|
||||
cache->slots = push_array(cache_stripe->arena, AC_Slot, slots_count);
|
||||
cache->create = params->create;
|
||||
cache->destroy = params->destroy;
|
||||
cache->slots_count = Max(256, params->slots_count);
|
||||
cache->slots = push_array(cache_stripe->arena, AC_Slot, cache->slots_count);
|
||||
cache->stripes = stripe_array_alloc(cache_stripe->arena);
|
||||
}
|
||||
}
|
||||
@@ -59,78 +59,109 @@ ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: cache * key -> artifact
|
||||
//- rjf: unpack key
|
||||
U64 hash = u64_hash_from_str8(key);
|
||||
U64 slot_idx = hash%cache->slots_count;
|
||||
AC_Slot *slot = &cache->slots[slot_idx];
|
||||
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
|
||||
|
||||
//- rjf: cache * key -> existing artifact
|
||||
B32 got_artifact = 0;
|
||||
B32 need_request = 0;
|
||||
AC_Artifact artifact = {0};
|
||||
RWMutexScope(stripe->rw_mutex, 0)
|
||||
{
|
||||
U64 hash = u64_hash_from_str8(key);
|
||||
U64 slot_idx = hash%cache->slots_count;
|
||||
AC_Slot *slot = &cache->slots[slot_idx];
|
||||
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
|
||||
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
|
||||
for(AC_Node *n = slot->first; n != 0; n = n->next)
|
||||
{
|
||||
B32 found = 0;
|
||||
B32 need_request = 0;
|
||||
RWMutexScope(stripe->rw_mutex, write_mode)
|
||||
if(str8_match(n->key, key, 0))
|
||||
{
|
||||
// rjf: look up node
|
||||
for(AC_Node *n = slot->first; n != 0; n = n->next)
|
||||
if(ins_atomic_u64_eval(&n->completion_count) != 0 && (n->gen == params->gen || !params->wait_for_fresh))
|
||||
{
|
||||
if(str8_match(n->key, key, 0))
|
||||
{
|
||||
found = 1;
|
||||
artifact = n->val;
|
||||
access_touch(access, &n->access_pt, stripe->cv);
|
||||
if(n->gen != gen)
|
||||
{
|
||||
B32 got_task = (ins_atomic_u64_eval_cond_assign(&n->working_count, 1, 0) == 0);
|
||||
need_request = got_task;
|
||||
}
|
||||
break;
|
||||
}
|
||||
got_artifact = 1;
|
||||
artifact = n->val;
|
||||
access_touch(access, &n->access_pt, stripe->cv);
|
||||
}
|
||||
|
||||
// rjf: no node? -> create
|
||||
if(write_mode && !found)
|
||||
if(n->gen != params->gen)
|
||||
{
|
||||
need_request = 1;
|
||||
AC_Node *node = stripe->free;
|
||||
if(node)
|
||||
{
|
||||
stripe->free = node->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = push_array_no_zero(stripe->arena, AC_Node, 1);
|
||||
}
|
||||
MemoryZeroStruct(node);
|
||||
DLLPushBack(slot->first, slot->last, node);
|
||||
// TODO(rjf): string allocator for keys
|
||||
node->key = str8_copy(stripe->arena, key);
|
||||
node->working_count = 1;
|
||||
B32 got_task = (ins_atomic_u64_eval_cond_assign(&n->working_count, 1, 0) == 0);
|
||||
need_request = got_task;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: didn't get artifact we want? -> fall back to slow path
|
||||
if(!got_artifact || need_request)
|
||||
{
|
||||
RWMutexScope(stripe->rw_mutex, 1) for(;;)
|
||||
{
|
||||
B32 out_of_time = (os_now_microseconds() >= endt_us);
|
||||
|
||||
// rjf: find node in cache
|
||||
AC_Node *node = 0;
|
||||
for(AC_Node *n = slot->first; n != 0; n = n->next)
|
||||
{
|
||||
if(str8_match(n->key, key, 0))
|
||||
{
|
||||
node = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: need request -> push
|
||||
// rjf: no node? -> create
|
||||
if(node == 0)
|
||||
{
|
||||
need_request = 1;
|
||||
node = stripe->free;
|
||||
if(node)
|
||||
{
|
||||
stripe->free = node->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = push_array_no_zero(stripe->arena, AC_Node, 1);
|
||||
}
|
||||
MemoryZeroStruct(node);
|
||||
DLLPushBack(slot->first, slot->last, node);
|
||||
// TODO(rjf): string allocator for keys
|
||||
node->key = str8_copy(stripe->arena, key);
|
||||
node->working_count = 1;
|
||||
}
|
||||
|
||||
// rjf: request
|
||||
if(need_request)
|
||||
{
|
||||
need_request = 0;
|
||||
MutexScope(ac_shared->req_mutex)
|
||||
{
|
||||
AC_RequestNode *n = push_array(ac_shared->req_arena, AC_RequestNode, 1);
|
||||
SLLQueuePush(ac_shared->first_req, ac_shared->last_req, n);
|
||||
ac_shared->req_count += 1;
|
||||
n->v.key = str8_copy(ac_shared->req_arena, key);
|
||||
n->v.gen = gen;
|
||||
n->v.create = create;
|
||||
n->v.gen = params->gen;
|
||||
n->v.create = params->create;
|
||||
}
|
||||
cond_var_broadcast(async_tick_start_cond_var);
|
||||
ins_atomic_u32_eval_assign(&async_loop_again, 1);
|
||||
}
|
||||
|
||||
// rjf: found node -> break
|
||||
if(found)
|
||||
// rjf: get value from node, if possible
|
||||
if(!got_artifact && ins_atomic_u64_eval(&node->completion_count) != 0 && ((node->gen == params->gen) || !params->wait_for_fresh || out_of_time))
|
||||
{
|
||||
got_artifact = 1;
|
||||
artifact = node->val;
|
||||
access_touch(access, &node->access_pt, stripe->cv);
|
||||
}
|
||||
|
||||
// rjf: abort if needed
|
||||
if(out_of_time || got_artifact || is_async_thread)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// rjf: wait for results
|
||||
cond_var_wait_rw(stripe->cv, stripe->rw_mutex, 1, endt_us);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,9 +306,11 @@ ac_async_tick(void)
|
||||
n->gen = reqs[idx].gen;
|
||||
n->val = val;
|
||||
ins_atomic_u64_dec_eval(&n->working_count);
|
||||
ins_atomic_u64_inc_eval(&n->completion_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
cond_var_broadcast(stripe->cv);
|
||||
}
|
||||
}
|
||||
lane_sync();
|
||||
|
||||
@@ -19,6 +19,16 @@ struct AC_Artifact
|
||||
typedef AC_Artifact AC_CreateFunctionType(String8 key, B32 *retry_out);
|
||||
typedef void AC_DestroyFunctionType(AC_Artifact artifact);
|
||||
|
||||
typedef struct AC_ArtifactParams AC_ArtifactParams;
|
||||
struct AC_ArtifactParams
|
||||
{
|
||||
AC_CreateFunctionType *create;
|
||||
AC_DestroyFunctionType *destroy;
|
||||
U64 slots_count;
|
||||
U64 gen;
|
||||
B32 wait_for_fresh;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Cache Types
|
||||
|
||||
@@ -51,6 +61,7 @@ struct AC_Node
|
||||
// rjf: metadata
|
||||
AccessPt access_pt;
|
||||
U64 working_count;
|
||||
U64 completion_count;
|
||||
};
|
||||
|
||||
typedef struct AC_Slot AC_Slot;
|
||||
@@ -105,7 +116,8 @@ internal void ac_init(void);
|
||||
////////////////////////////////
|
||||
//~ rjf: Cache Lookups
|
||||
|
||||
internal AC_Artifact ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType *create, AC_DestroyFunctionType *destroy, U64 slots_count);
|
||||
internal AC_Artifact ac_artifact_from_key_(Access *access, String8 key, AC_ArtifactParams *params, U64 endt_us);
|
||||
#define ac_artifact_from_key(access, key, create_fn, destroy_fn, endt_us, ...) ac_artifact_from_key_((access), (key), &(AC_ArtifactParams){.create = (create_fn), .destroy = (destroy_fn), __VA_ARGS__}, (endt_us))
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Asynchronous Tick
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
global U64 global_update_tick_idx = 0;
|
||||
global CondVar async_tick_start_cond_var = {0};
|
||||
global CondVar async_tick_stop_cond_var = {0};
|
||||
global Mutex async_tick_start_mutex = {0};
|
||||
global Mutex async_tick_stop_mutex = {0};
|
||||
global B32 async_loop_again = 0;
|
||||
global B32 global_async_exit = 0;
|
||||
thread_static B32 is_async_thread = 0;
|
||||
|
||||
internal void
|
||||
main_thread_base_entry_point(int arguments_count, char **arguments)
|
||||
@@ -18,7 +18,6 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
|
||||
//- rjf: set up async thread group info
|
||||
async_tick_start_cond_var = cond_var_alloc();
|
||||
async_tick_start_mutex = mutex_alloc();
|
||||
async_tick_stop_cond_var = cond_var_alloc();
|
||||
async_tick_stop_mutex = mutex_alloc();
|
||||
|
||||
//- rjf: set up telemetry
|
||||
@@ -186,9 +185,11 @@ async_thread_entry_point(void *params)
|
||||
{
|
||||
LaneCtx lctx = *(LaneCtx *)params;
|
||||
lane_ctx(lctx);
|
||||
is_async_thread = 1;
|
||||
ThreadNameF("async_thread_%I64u", lane_idx());
|
||||
for(;!ins_atomic_u32_eval(&global_async_exit);)
|
||||
for(;;)
|
||||
{
|
||||
// rjf: wait for signal if we need, otherwise reset loop signal & continue
|
||||
if(!ins_atomic_u32_eval(&async_loop_again))
|
||||
{
|
||||
MutexScope(async_tick_start_mutex) cond_var_wait(async_tick_start_cond_var, async_tick_start_mutex, os_now_microseconds()+100000);
|
||||
@@ -197,6 +198,7 @@ async_thread_entry_point(void *params)
|
||||
{
|
||||
async_loop_again = 0;
|
||||
}
|
||||
|
||||
#if defined(ARTIFACT_CACHE_H)
|
||||
ac_async_tick();
|
||||
#endif
|
||||
@@ -209,6 +211,18 @@ async_thread_entry_point(void *params)
|
||||
#if defined(TEXTURE_CACHE_H)
|
||||
tex_async_tick();
|
||||
#endif
|
||||
cond_var_broadcast(async_tick_stop_cond_var);
|
||||
|
||||
// rjf: take exit signal; break if set
|
||||
lane_sync();
|
||||
B32 need_exit = 0;
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
need_exit = ins_atomic_u32_eval(&global_async_exit);
|
||||
}
|
||||
lane_sync_u64(&need_exit, 0);
|
||||
if(need_exit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,16 +90,29 @@ tctx_lane_barrier_wait(void *broadcast_ptr, U64 broadcast_size, U64 broadcast_sr
|
||||
ProfBeginFunction();
|
||||
ProfColor(0x00000ff);
|
||||
TCTX *tctx = tctx_selected();
|
||||
|
||||
// rjf: doing broadcast -> copy to broadcast memory on source lane
|
||||
U64 broadcast_size_clamped = ClampTop(broadcast_size, sizeof(tctx->lane_ctx.broadcast_memory[0]));
|
||||
if(broadcast_ptr != 0 && lane_idx() == broadcast_src_lane_idx)
|
||||
{
|
||||
MemoryCopy(tctx->lane_ctx.broadcast_memory, broadcast_ptr, broadcast_size_clamped);
|
||||
}
|
||||
|
||||
// rjf: all cases: barrier
|
||||
os_barrier_wait(tctx->lane_ctx.barrier);
|
||||
|
||||
// rjf: doing broadcast -> copy from broadcast memory on destination lanes
|
||||
if(broadcast_ptr != 0 && lane_idx() != broadcast_src_lane_idx)
|
||||
{
|
||||
MemoryCopy(broadcast_ptr, tctx->lane_ctx.broadcast_memory, broadcast_size_clamped);
|
||||
}
|
||||
|
||||
// rjf: doing broadcast -> barrier on all lanes
|
||||
if(broadcast_ptr != 0)
|
||||
{
|
||||
os_barrier_wait(tctx->lane_ctx.barrier);
|
||||
}
|
||||
|
||||
ProfEnd();
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ internal void tctx_lane_barrier_wait(void *broadcast_ptr, U64 broadcast_size, U6
|
||||
#define lane_from_task_idx(idx) ((idx)%lane_count())
|
||||
#define lane_ctx(ctx) tctx_set_lane_ctx((ctx))
|
||||
#define lane_sync() tctx_lane_barrier_wait(0, 0, 0)
|
||||
#define lane_sync_u64(ptr, src_lane_idx) tctx_lane_barrier_wait((ptr), sizeof(U64), (src_lane_idx))
|
||||
#define lane_sync_u64(ptr, src_lane_idx) tctx_lane_barrier_wait((ptr), sizeof(*(ptr)), (src_lane_idx))
|
||||
#define lane_range(count) m_range_from_n_idx_m_count(lane_idx(), lane_count(), (count))
|
||||
|
||||
//- rjf: thread names
|
||||
|
||||
@@ -7617,7 +7617,7 @@ ctrl_key_from_process_vaddr_range_new(CTRL_Handle process, Rng1U64 vaddr_range,
|
||||
} key_data = {process, vaddr_range, zero_terminated};
|
||||
String8 key = str8_struct(&key_data);
|
||||
Access *access = access_open();
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key, ctrl_mem_gen(), ctrl_memory_artifact_create, ctrl_memory_artifact_destroy, 2048);
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key, ctrl_memory_artifact_create, ctrl_memory_artifact_destroy, endt_us, .gen = ctrl_mem_gen(), .slots_count = 2048);
|
||||
C_Key content_key = {0};
|
||||
MemoryCopyStruct(&content_key, &artifact);
|
||||
access_close(access);
|
||||
|
||||
+1
-1
@@ -512,7 +512,7 @@ dasm_info_from_hash_params(Access *access, U128 hash, DASM_Params *params)
|
||||
String8 key = str8_list_join(scratch.arena, &key_parts, 0);
|
||||
|
||||
// rjf: get info
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key, fs_change_gen(), dasm_artifact_create, dasm_artifact_destroy, 1024);
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key, dasm_artifact_create, dasm_artifact_destroy, 0, .gen = fs_change_gen());
|
||||
DASM_Artifact *dasm_artifact = (DASM_Artifact *)artifact.u64[0];
|
||||
if(dasm_artifact)
|
||||
{
|
||||
|
||||
+104
-37
@@ -84,24 +84,69 @@ fs_artifact_create(String8 key, B32 *retry_out)
|
||||
key_read_off += str8_deserial_read_struct(key, key_read_off, &range);
|
||||
}
|
||||
|
||||
//- rjf: do read
|
||||
ProfBegin("read \"%.*s\" [0x%I64x, 0x%I64x)", str8_varg(path), range.min, range.max);
|
||||
FileProperties pre_props = os_properties_from_file_path(path);
|
||||
U64 range_size = dim_1u64(range);
|
||||
U64 read_size = Min(pre_props.size - range.min, range_size);
|
||||
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead|OS_AccessFlag_ShareWrite, path);
|
||||
//- rjf: measure file properties *before* read
|
||||
FileProperties pre_props = {0};
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
pre_props = os_properties_from_file_path(path);
|
||||
}
|
||||
|
||||
//- rjf: setup output data
|
||||
Arena *data_arena = 0;
|
||||
U64 data_buffer_size = 0;
|
||||
U8 *data_buffer = 0;
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
U64 range_size = dim_1u64(range);
|
||||
U64 read_size = Min(pre_props.size - range.min, range_size);
|
||||
U64 data_arena_size = read_size+ARENA_HEADER_SIZE;
|
||||
data_arena_size += KB(4)-1;
|
||||
data_arena_size -= data_arena_size%KB(4);
|
||||
data_arena = arena_alloc(.reserve_size = data_arena_size, .commit_size = data_arena_size);
|
||||
data_buffer_size = read_size;
|
||||
data_buffer = push_array_no_zero(data_arena, U8, data_buffer_size);
|
||||
}
|
||||
lane_sync_u64(&data_buffer, 0);
|
||||
lane_sync_u64(&data_buffer_size, 0);
|
||||
|
||||
//- rjf: open file
|
||||
OS_Handle file = {0};
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead|OS_AccessFlag_ShareWrite, path);
|
||||
}
|
||||
lane_sync_u64(&file, 0);
|
||||
B32 file_handle_is_valid = !os_handle_match(os_handle_zero(), file);
|
||||
U64 data_arena_size = read_size+ARENA_HEADER_SIZE;
|
||||
data_arena_size += KB(4)-1;
|
||||
data_arena_size -= data_arena_size%KB(4);
|
||||
ProfBegin("allocate");
|
||||
Arena *data_arena = arena_alloc(.reserve_size = data_arena_size, .commit_size = data_arena_size);
|
||||
ProfEnd();
|
||||
ProfBegin("read");
|
||||
String8 data = os_string_from_file_range(data_arena, file, r1u64(range.min, range.min+read_size));
|
||||
ProfEnd();
|
||||
os_file_close(file);
|
||||
FileProperties post_props = os_properties_from_file_path(path);
|
||||
|
||||
//- rjf: do read
|
||||
U64 total_bytes_read = 0;
|
||||
U64 *total_bytes_read_ptr = 0;
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
total_bytes_read_ptr = &total_bytes_read;
|
||||
}
|
||||
lane_sync_u64(&total_bytes_read_ptr, 0);
|
||||
ProfScope("read \"%.*s\" [0x%I64x, 0x%I64x)", str8_varg(path), range.min, range.max)
|
||||
{
|
||||
Rng1U64 lane_read_range = lane_range(data_buffer_size);
|
||||
U64 bytes_read = os_file_read(file, lane_read_range, data_buffer + (lane_read_range.min - range.min));
|
||||
ins_atomic_u64_add_eval(total_bytes_read_ptr, bytes_read);
|
||||
}
|
||||
lane_sync();
|
||||
lane_sync_u64(&total_bytes_read, 0);
|
||||
|
||||
//- rjf: close file
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
os_file_close(file);
|
||||
}
|
||||
|
||||
//- rjf: measure file properties *after* read
|
||||
FileProperties post_props = {0};
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
post_props = os_properties_from_file_path(path);
|
||||
}
|
||||
|
||||
//- rjf: form content key
|
||||
C_Key content_key = {0};
|
||||
@@ -109,30 +154,32 @@ fs_artifact_create(String8 key, B32 *retry_out)
|
||||
content_key.id.u128[0] = u128_hash_from_str8(key);
|
||||
}
|
||||
|
||||
//- rjf: abort if modification timestamps or sizes differ - we did not successfully read the file
|
||||
B32 read_good = (pre_props.modified == post_props.modified &&
|
||||
pre_props.size == post_props.size &&
|
||||
read_size == data.size &&
|
||||
(file_handle_is_valid || pre_props.flags & FilePropertyFlag_IsFolder));
|
||||
if(!read_good)
|
||||
//- rjf: abort if modification timestamps or sizes differ - we did not successfully read the file;
|
||||
// otherwise submit data
|
||||
if(lane_idx() == 0)
|
||||
{
|
||||
retry_out[0] = 1;
|
||||
ProfScope("abort")
|
||||
B32 read_good = (pre_props.modified == post_props.modified &&
|
||||
pre_props.size == post_props.size &&
|
||||
data_buffer_size == total_bytes_read &&
|
||||
(file_handle_is_valid || pre_props.flags & FilePropertyFlag_IsFolder));
|
||||
if(!read_good)
|
||||
{
|
||||
arena_release(data_arena);
|
||||
MemoryZeroStruct(&data);
|
||||
data_arena = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: submit to content store
|
||||
else
|
||||
{
|
||||
ProfScope("submit")
|
||||
{
|
||||
c_submit_data(content_key, &data_arena, data);
|
||||
retry_out[0] = 1;
|
||||
ProfScope("abort")
|
||||
{
|
||||
arena_release(data_arena);
|
||||
MemoryZeroStruct(&content_key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ProfScope("submit")
|
||||
{
|
||||
c_submit_data(content_key, &data_arena, str8(data_buffer, data_buffer_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
lane_sync();
|
||||
|
||||
//- rjf: bundle content key as artifact
|
||||
AC_Artifact artifact = {0};
|
||||
@@ -151,6 +198,26 @@ fs_artifact_destroy(AC_Artifact artifact)
|
||||
c_close_key(key);
|
||||
}
|
||||
|
||||
internal C_Key
|
||||
fs_key_from_path_range_new(String8 path, Rng1U64 range, U64 endt_us)
|
||||
{
|
||||
C_Key result = {0};
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
Access *access = access_open();
|
||||
{
|
||||
String8List key_parts = {0};
|
||||
str8_list_push(scratch.arena, &key_parts, str8_struct(&path.size));
|
||||
str8_list_push(scratch.arena, &key_parts, path);
|
||||
str8_list_push(scratch.arena, &key_parts, str8_struct(&range));
|
||||
String8 key = str8_list_join(scratch.arena, &key_parts, 0);
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key, fs_artifact_create, fs_artifact_destroy, endt_us);
|
||||
MemoryCopyStruct(&result, &artifact);
|
||||
}
|
||||
access_close(access);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal C_Key
|
||||
fs_key_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
|
||||
{
|
||||
|
||||
@@ -123,6 +123,9 @@ internal U64 fs_change_gen(void);
|
||||
internal AC_Artifact fs_artifact_create(String8 key, B32 *retry_out);
|
||||
internal void fs_artifact_destroy(AC_Artifact artifact);
|
||||
|
||||
internal C_Key fs_key_from_path_range_new(String8 path, Rng1U64 range, U64 endt_us);
|
||||
#define fs_key_from_path(path, endt_us) fs_key_from_path_range_new((path), r1u64(0, max_U64), (endt_us))
|
||||
|
||||
internal C_Key fs_key_from_path_range(String8 path, Rng1U64 range, U64 endt_us);
|
||||
internal U128 fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us);
|
||||
|
||||
|
||||
+19
-80
@@ -5,7 +5,7 @@
|
||||
//~ rjf: Build Options
|
||||
|
||||
#define BUILD_TITLE "ryan_scratch"
|
||||
#define OS_FEATURE_GRAPHICAL 1
|
||||
#define BUILD_CONSOLE_INTERFACE 1
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Includes
|
||||
@@ -13,93 +13,32 @@
|
||||
//- rjf: [h]
|
||||
#include "base/base_inc.h"
|
||||
#include "os/os_inc.h"
|
||||
#include "render/render_inc.h"
|
||||
#include "font_provider/font_provider_inc.h"
|
||||
#include "font_cache/font_cache.h"
|
||||
#include "draw/draw.h"
|
||||
#include "content/content.h"
|
||||
#include "artifact_cache/artifact_cache.h"
|
||||
#include "file_stream/file_stream.h"
|
||||
|
||||
//- rjf: [c]
|
||||
#include "base/base_inc.c"
|
||||
#include "os/os_inc.c"
|
||||
#include "render/render_inc.c"
|
||||
#include "font_provider/font_provider_inc.c"
|
||||
#include "font_cache/font_cache.c"
|
||||
#include "draw/draw.c"
|
||||
#include "content/content.c"
|
||||
#include "artifact_cache/artifact_cache.c"
|
||||
#include "file_stream/file_stream.c"
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Globals
|
||||
|
||||
global OS_Handle window_os = {0};
|
||||
global R_Handle window_r = {0};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Entry Points
|
||||
|
||||
internal B32
|
||||
frame(void)
|
||||
{
|
||||
B32 quit = 0;
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
|
||||
//- rjf: events test
|
||||
OS_EventList events = os_get_events(scratch.arena, 0);
|
||||
for(OS_Event *ev = events.first; ev != 0; ev = ev->next)
|
||||
{
|
||||
if(ev->kind != OS_EventKind_MouseMove)
|
||||
{
|
||||
String8 string = push_str8f(scratch.arena, "%S (%S)\n", os_string_from_event_kind(ev->kind), os_g_key_display_string_table[ev->key]);
|
||||
printf("%.*s", str8_varg(string));
|
||||
raddbg_log((char *)string.str);
|
||||
fflush(stdout);
|
||||
}
|
||||
if(ev->kind == OS_EventKind_Press && ev->key == OS_Key_X)
|
||||
{
|
||||
*(volatile int *)0 = 0;
|
||||
}
|
||||
}
|
||||
for(OS_Event *ev = events.first; ev != 0; ev = ev->next)
|
||||
{
|
||||
if(ev->kind == OS_EventKind_WindowClose)
|
||||
{
|
||||
quit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: drawing test
|
||||
r_begin_frame();
|
||||
r_window_begin_frame(window_os, window_r);
|
||||
{
|
||||
R_PassList passes = {0};
|
||||
R_Pass *pass = r_pass_from_kind(scratch.arena, &passes, R_PassKind_UI);
|
||||
R_PassParams_UI *pass_ui = pass->params_ui;
|
||||
R_BatchGroup2DNode group = {0};
|
||||
pass_ui->rects.first = pass_ui->rects.last = &group;
|
||||
pass_ui->rects.count = 1;
|
||||
group.batches = r_batch_list_make(sizeof(R_Rect2DInst));
|
||||
group.params.xform = mat_3x3f32(1.f);
|
||||
group.params.clip = os_client_rect_from_window(window_os);
|
||||
Vec2F32 mouse = os_mouse_from_window(window_os);
|
||||
R_Rect2DInst *inst = r_batch_list_push_inst(scratch.arena, &group.batches, 256);
|
||||
MemoryZeroStruct(inst);
|
||||
inst->dst = r2f32p(mouse.x+30, mouse.y+30, mouse.x+100, mouse.y+100);
|
||||
inst->src = r2f32p(0, 0, 1, 1);
|
||||
inst->colors[Corner_00] = inst->colors[Corner_01] = inst->colors[Corner_10] = inst->colors[Corner_11] = v4f32(1, 0, 0, 1);
|
||||
inst->corner_radii[Corner_00] = inst->corner_radii[Corner_01] = inst->corner_radii[Corner_10] = inst->corner_radii[Corner_11] = 8.f;
|
||||
r_window_submit(window_os, window_r, &passes);
|
||||
}
|
||||
r_window_end_frame(window_os, window_r);
|
||||
r_end_frame();
|
||||
|
||||
scratch_end(scratch);
|
||||
return quit;
|
||||
}
|
||||
//~ rjf: Entry Point
|
||||
|
||||
internal void
|
||||
entry_point(CmdLine *cmdline)
|
||||
{
|
||||
window_os = os_window_open(r2f32p(0, 0, 1280, 720), OS_WindowFlag_UseDefaultPosition, str8_lit("Window"));
|
||||
os_window_first_paint(window_os);
|
||||
window_r = r_window_equip(window_os);
|
||||
for(;!update(););
|
||||
for(;;)
|
||||
{
|
||||
C_Key key = fs_key_from_path(str8_lit("C:/devel/raddebugger/build/x.dump"), os_now_microseconds() + 100000);
|
||||
U128 hash = c_hash_from_key(key, 0);
|
||||
printf("hash: 0x%I64x, 0x%I64x\n", hash.u64[0], hash.u64[1]);
|
||||
fflush(stdout);
|
||||
if(!u128_match(u128_zero(), hash))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2254,7 +2254,7 @@ txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang)
|
||||
TXT_LangKind lang;
|
||||
} key = {hash, lang};
|
||||
String8 key_string = str8_struct(&key);
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key_string, 0, txt_artifact_create, txt_artifact_destroy, 1024);
|
||||
AC_Artifact artifact = ac_artifact_from_key(access, key_string, txt_artifact_create, txt_artifact_destroy, 0);
|
||||
TXT_Artifact *txt_artifact = (TXT_Artifact *)artifact.u64[0];
|
||||
TXT_TextInfo info = {0};
|
||||
if(txt_artifact != 0)
|
||||
|
||||
Reference in New Issue
Block a user