expand artifacts a bit more, to be more useful with larger-than-ptr but not huge allocations

This commit is contained in:
Ryan Fleury
2025-09-23 11:27:56 -07:00
parent 9787c698e6
commit 6cdce22284
8 changed files with 70 additions and 35 deletions
+3 -3
View File
@@ -20,7 +20,7 @@ ac_init(void)
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Lookups //~ rjf: Cache Lookups
internal void * 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, U64 gen, AC_CreateFunctionType *create, AC_DestroyFunctionType *destroy, U64 slots_count)
{ {
//- rjf: create function -> cache //- rjf: create function -> cache
@@ -60,7 +60,7 @@ ac_artifact_from_key(Access *access, String8 key, U64 gen, AC_CreateFunctionType
} }
//- rjf: cache * key -> artifact //- rjf: cache * key -> artifact
void *artifact = 0; AC_Artifact artifact = {0};
{ {
U64 hash = u64_hash_from_str8(key); U64 hash = u64_hash_from_str8(key);
U64 slot_idx = hash%cache->slots_count; U64 slot_idx = hash%cache->slots_count;
@@ -222,7 +222,7 @@ ac_async_tick(void)
// rjf: compute val // rjf: compute val
B32 retry = 0; B32 retry = 0;
void *val = reqs[idx].create(reqs[idx].key, &retry); AC_Artifact val = reqs[idx].create(reqs[idx].key, &retry);
// rjf: retry? -> resubmit request // rjf: retry? -> resubmit request
if(retry && lane_idx() == 0) if(retry && lane_idx() == 0)
+13 -4
View File
@@ -4,11 +4,20 @@
#ifndef ARTIFACT_CACHE_H #ifndef ARTIFACT_CACHE_H
#define ARTIFACT_CACHE_H #define ARTIFACT_CACHE_H
////////////////////////////////
//~ rjf: Artifact Handle Type
typedef struct AC_Artifact AC_Artifact;
struct AC_Artifact
{
U64 u64[4];
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Artifact Computation Function Types //~ rjf: Artifact Computation Function Types
typedef void *AC_CreateFunctionType(String8 key, B32 *retry_out); typedef AC_Artifact AC_CreateFunctionType(String8 key, B32 *retry_out);
typedef void AC_DestroyFunctionType(void *artifact); typedef void AC_DestroyFunctionType(AC_Artifact artifact);
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Types //~ rjf: Cache Types
@@ -37,7 +46,7 @@ struct AC_Node
// rjf: key/gen/value // rjf: key/gen/value
String8 key; String8 key;
U64 gen; U64 gen;
void *val; AC_Artifact val;
// rjf: metadata // rjf: metadata
AccessPt access_pt; AccessPt access_pt;
@@ -96,7 +105,7 @@ internal void ac_init(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Lookups //~ rjf: Cache Lookups
internal void *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, U64 gen, AC_CreateFunctionType *create, AC_DestroyFunctionType *destroy, U64 slots_count);
//////////////////////////////// ////////////////////////////////
//~ rjf: Asynchronous Tick //~ rjf: Asynchronous Tick
+17 -2
View File
@@ -7460,6 +7460,21 @@ ASYNC_WORK_DEF(ctrl_call_stack_tree_build_work)
return 0; return 0;
} }
////////////////////////////////
//~ rjf: Process Memory Artifact Cache Hooks / Lookups
internal void *
ctrl_memory_artifact_create(String8 key, B32 *retry_out)
{
}
internal void
ctrl_memory_artifact_destroy(void *ptr)
{
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Asynchronous Tick //~ rjf: Asynchronous Tick
@@ -7467,7 +7482,7 @@ internal void
ctrl_async_tick(void) ctrl_async_tick(void)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
#if 0
//- rjf: get all memory requests //- rjf: get all memory requests
U64 mem_reqs_count = 0; U64 mem_reqs_count = 0;
CTRL_MemRequest *mem_reqs = 0; CTRL_MemRequest *mem_reqs = 0;
@@ -7642,6 +7657,6 @@ ctrl_async_tick(void)
} }
} }
} }
#endif
scratch_end(scratch); scratch_end(scratch);
} }
+6
View File
@@ -1250,6 +1250,12 @@ ASYNC_WORK_DEF(ctrl_call_stack_build_work);
ASYNC_WORK_DEF(ctrl_call_stack_tree_build_work); ASYNC_WORK_DEF(ctrl_call_stack_tree_build_work);
////////////////////////////////
//~ rjf: Process Memory Artifact Cache Hooks / Lookups
internal void *ctrl_memory_artifact_create(String8 key, B32 *retry_out);
internal void ctrl_memory_artifact_destroy(void *ptr);
//////////////////////////////// ////////////////////////////////
//~ rjf: Asynchronous Tick //~ rjf: Asynchronous Tick
+15 -13
View File
@@ -264,10 +264,10 @@ struct DASM_Artifact
DASM_Info info; DASM_Info info;
}; };
internal void * internal AC_Artifact
dasm_artifact_create(String8 key, B32 *retry_out) dasm_artifact_create(String8 key, B32 *retry_out)
{ {
void *result = 0; DASM_Artifact *artifact = 0;
if(lane_idx() == 0) if(lane_idx() == 0)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
@@ -473,27 +473,28 @@ dasm_artifact_create(String8 key, B32 *retry_out)
//- rjf: fill result //- rjf: fill result
if(info_arena != 0) if(info_arena != 0)
{ {
DASM_Artifact *artifact = push_array(info_arena, DASM_Artifact, 1); artifact = push_array(info_arena, DASM_Artifact, 1);
artifact->arena = info_arena; artifact->arena = info_arena;
artifact->info = info; artifact->info = info;
result = artifact;
} }
di_scope_close(di_scope); di_scope_close(di_scope);
access_close(access); access_close(access);
scratch_end(scratch); scratch_end(scratch);
} }
lane_sync_u64(&result, 0); lane_sync_u64(&artifact, 0);
AC_Artifact result = {0};
result.u64[0] = (U64)artifact;
return result; return result;
} }
internal void internal void
dasm_artifact_destroy(void *ptr) dasm_artifact_destroy(AC_Artifact artifact)
{ {
if(ptr == 0) { return; } DASM_Artifact *dasm_artifact = (DASM_Artifact *)artifact.u64[0];
DASM_Artifact *artifact = (DASM_Artifact *)ptr; if(dasm_artifact == 0) { return; }
c_close_key(artifact->info.text_key); c_close_key(dasm_artifact->info.text_key);
arena_release(artifact->arena); arena_release(dasm_artifact->arena);
} }
internal DASM_Info internal DASM_Info
@@ -511,10 +512,11 @@ dasm_info_from_hash_params(Access *access, U128 hash, DASM_Params *params)
String8 key = str8_list_join(scratch.arena, &key_parts, 0); String8 key = str8_list_join(scratch.arena, &key_parts, 0);
// rjf: get info // rjf: get info
DASM_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, fs_change_gen(), dasm_artifact_create, dasm_artifact_destroy, 1024);
if(artifact) DASM_Artifact *dasm_artifact = (DASM_Artifact *)artifact.u64[0];
if(dasm_artifact)
{ {
info = artifact->info; info = dasm_artifact->info;
} }
scratch_end(scratch); scratch_end(scratch);
+2 -2
View File
@@ -197,8 +197,8 @@ internal U64 dasm_line_array_code_off_from_idx(DASM_LineArray *array, U64 idx);
//////////////////////////////// ////////////////////////////////
//~ rjf: Artifact Cache Hooks / Lookups //~ rjf: Artifact Cache Hooks / Lookups
internal void *dasm_artifact_create(String8 key, B32 *retry_out); internal AC_Artifact dasm_artifact_create(String8 key, B32 *retry_out);
internal void dasm_artifact_destroy(void *ptr); internal void dasm_artifact_destroy(AC_Artifact artifact);
internal DASM_Info dasm_info_from_hash_params(Access *access, U128 hash, DASM_Params *params); internal DASM_Info dasm_info_from_hash_params(Access *access, U128 hash, DASM_Params *params);
internal DASM_Info dasm_info_from_key_params(Access *access, C_Key key, DASM_Params *params, U128 *hash_out); internal DASM_Info dasm_info_from_key_params(Access *access, C_Key key, DASM_Params *params, U128 *hash_out);
+12 -9
View File
@@ -1968,7 +1968,7 @@ struct TXT_ArtifactCreateShared
TXT_Artifact *artifact; TXT_Artifact *artifact;
}; };
internal void * internal AC_Artifact
txt_artifact_create(String8 key, B32 *retry_out) txt_artifact_create(String8 key, B32 *retry_out)
{ {
ProfBeginFunction(); ProfBeginFunction();
@@ -2232,15 +2232,17 @@ txt_artifact_create(String8 key, B32 *retry_out)
access_close(access); access_close(access);
scratch_end(scratch); scratch_end(scratch);
ProfEnd(); ProfEnd();
return shared->artifact; AC_Artifact result = {0};
result.u64[0] = (U64)shared->artifact;
return result;
} }
internal void internal void
txt_artifact_destroy(void *ptr) txt_artifact_destroy(AC_Artifact artifact)
{ {
if(ptr == 0) { return; } TXT_Artifact *txt_artifact = (TXT_Artifact *)artifact.u64[0];
TXT_Artifact *artifact = (TXT_Artifact *)ptr; if(txt_artifact == 0) { return; }
arena_release(artifact->arena); arena_release(txt_artifact->arena);
} }
internal TXT_TextInfo internal TXT_TextInfo
@@ -2252,11 +2254,12 @@ txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang)
TXT_LangKind lang; TXT_LangKind lang;
} key = {hash, lang}; } key = {hash, lang};
String8 key_string = str8_struct(&key); String8 key_string = str8_struct(&key);
TXT_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, 0, txt_artifact_create, txt_artifact_destroy, 1024);
TXT_Artifact *txt_artifact = (TXT_Artifact *)artifact.u64[0];
TXT_TextInfo info = {0}; TXT_TextInfo info = {0};
if(artifact != 0) if(txt_artifact != 0)
{ {
info = artifact->info; info = txt_artifact->info;
} }
return info; return info;
} }
+2 -2
View File
@@ -203,8 +203,8 @@ internal TXT_ScopeNode *txt_scope_node_from_info_pt(TXT_TextInfo *info, TxtPt pt
//////////////////////////////// ////////////////////////////////
//~ rjf: Artifact Cache Hooks / Lookups //~ rjf: Artifact Cache Hooks / Lookups
internal void *txt_artifact_create(String8 key, B32 *retry_out); internal AC_Artifact txt_artifact_create(String8 key, B32 *retry_out);
internal void txt_artifact_destroy(void *ptr); internal void txt_artifact_destroy(AC_Artifact artifact);
internal TXT_TextInfo txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang); internal TXT_TextInfo txt_text_info_from_hash_lang(Access *access, U128 hash, TXT_LangKind lang);
internal TXT_TextInfo txt_text_info_from_key_lang(Access *access, C_Key key, TXT_LangKind lang, U128 *hash_out); internal TXT_TextInfo txt_text_info_from_key_lang(Access *access, C_Key key, TXT_LangKind lang, U128 *hash_out);