sprite prefetch

This commit is contained in:
jacob 2025-06-18 14:21:35 -05:00
parent 657e48d7b1
commit d51c694795
5 changed files with 29 additions and 10 deletions

View File

@ -80,7 +80,7 @@
#define DX12_TEST 1 #define DX12_TEST 0

View File

@ -1047,6 +1047,13 @@ struct sprite_texture *sprite_texture_from_tag_async(struct sprite_scope *scope,
return (struct sprite_texture *)data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_TEXTURE, false); return (struct sprite_texture *)data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_TEXTURE, false);
} }
void sprite_texture_from_tag_prefetch(struct sprite_scope *scope, struct sprite_tag tag)
{
__prof;
data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_TEXTURE, false);
}
/* ========================== * /* ========================== *
* Sheet * Sheet
* ========================== */ * ========================== */
@ -1063,6 +1070,13 @@ struct sprite_sheet *sprite_sheet_from_tag_async(struct sprite_scope *scope, str
return (struct sprite_sheet *)data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_SHEET, false); return (struct sprite_sheet *)data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_SHEET, false);
} }
void sprite_sheet_from_tag_prefetch(struct sprite_scope *scope, struct sprite_tag tag)
{
__prof;
data_from_tag_internal(scope, tag, CACHE_ENTRY_KIND_SHEET, false);
}
struct sprite_sheet_frame sprite_sheet_get_frame(struct sprite_sheet *sheet, u32 index) struct sprite_sheet_frame sprite_sheet_get_frame(struct sprite_sheet *sheet, u32 index)
{ {
__prof; __prof;

View File

@ -55,6 +55,7 @@ struct sprite_texture {
struct sprite_texture *sprite_texture_from_tag_await(struct sprite_scope *scope, struct sprite_tag tag); struct sprite_texture *sprite_texture_from_tag_await(struct sprite_scope *scope, struct sprite_tag tag);
struct sprite_texture *sprite_texture_from_tag_async(struct sprite_scope *scope, struct sprite_tag tag); struct sprite_texture *sprite_texture_from_tag_async(struct sprite_scope *scope, struct sprite_tag tag);
void sprite_texture_from_tag_prefetch(struct sprite_scope *scope, struct sprite_tag tag);
/* ========================== * /* ========================== *
* Sheet load * Sheet load
@ -80,6 +81,7 @@ struct sprite_sheet {
struct sprite_sheet *sprite_sheet_from_tag_await(struct sprite_scope *scope, struct sprite_tag tag); struct sprite_sheet *sprite_sheet_from_tag_await(struct sprite_scope *scope, struct sprite_tag tag);
struct sprite_sheet *sprite_sheet_from_tag_async(struct sprite_scope *scope, struct sprite_tag tag); struct sprite_sheet *sprite_sheet_from_tag_async(struct sprite_scope *scope, struct sprite_tag tag);
void sprite_sheet_from_tag_prefetch(struct sprite_scope *scope, struct sprite_tag tag);
/* ========================== * /* ========================== *
* Sheet query * Sheet query

View File

@ -1608,10 +1608,16 @@ struct sys_mutex *sys_mutex_alloc(void)
void sys_mutex_release(struct sys_mutex *mutex) void sys_mutex_release(struct sys_mutex *mutex)
{ {
__prof; __prof;
struct win32_mutex *m = (struct win32_mutex *)mutex; struct win32_mutex *m = (struct win32_mutex *)mutex;
ASSERT(atomic_i64_eval(&m->count) == 0); /* Mutex should be unlocked */
{
struct sys_lock lock = sys_mutex_lock_e(G.mutexes_mutex);
m->next_free = G.first_free_mutex;
G.first_free_mutex = m;
sys_mutex_unlock(&lock);
}
__proflock_release(m->profiling_ctx); __proflock_release(m->profiling_ctx);
/* Mutex should be unlocked */
ASSERT(atomic_i64_eval(&m->count) == 0);
} }
struct sys_lock sys_mutex_lock_e(struct sys_mutex *mutex) struct sys_lock sys_mutex_lock_e(struct sys_mutex *mutex)
@ -2361,10 +2367,10 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
timeBeginPeriod(G.scheduler_period_ms); timeBeginPeriod(G.scheduler_period_ms);
/* Setup mutexes */ /* Setup mutexes */
struct win32_mutex first_mutex = ZI;
win32_mutex_init(&first_mutex);
G.mutexes_mutex = (struct sys_mutex *)&first_mutex;
G.mutexes_arena = arena_alloc(GIGABYTE(64)); G.mutexes_arena = arena_alloc(GIGABYTE(64));
struct win32_mutex *first_mutex = arena_push(G.mutexes_arena, struct win32_mutex);
win32_mutex_init(first_mutex);
G.mutexes_mutex = (struct sys_mutex *)first_mutex;
/* Set up condition variables */ /* Set up condition variables */
G.condition_variables_mutex = sys_mutex_alloc(); G.condition_variables_mutex = sys_mutex_alloc();

View File

@ -1252,12 +1252,9 @@ INTERNAL void user_update(void)
} }
/* Draw sprite */ /* Draw sprite */
//if ((false)) {
if (!sprite_tag_is_nil(sprite)) { if (!sprite_tag_is_nil(sprite)) {
/* Async load */
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite); struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
struct sprite_texture *texture = sprite_texture_from_tag_async(sprite_frame_scope, sprite); sprite_texture_from_tag_prefetch(sprite_frame_scope, sprite);
(UNUSED)texture;
/* TODO: Fade in placeholder if texture isn't loaded */ /* TODO: Fade in placeholder if texture isn't loaded */
if (sheet->loaded) { if (sheet->loaded) {