Compare commits
2 Commits
916e433753
...
732b61e207
Author | SHA1 | Date | |
---|---|---|---|
|
732b61e207 | ||
|
6cb166522e |
@ -268,6 +268,24 @@
|
||||
{ "name": "value", "type": "Rect" },
|
||||
{ "name": "identity", "type": "char *" }
|
||||
]
|
||||
},
|
||||
|
||||
"profile_start": {
|
||||
"module": "util",
|
||||
"symbol": "profile_start",
|
||||
"header": "twn_util.h",
|
||||
"params": [
|
||||
{ "name": "profile", "type": "char *" }
|
||||
]
|
||||
},
|
||||
|
||||
"profile_end": {
|
||||
"module": "util",
|
||||
"symbol": "profile_end",
|
||||
"header": "twn_util.h",
|
||||
"params": [
|
||||
{ "name": "profile", "type": "char *" }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -461,55 +461,10 @@ void textures_update_atlas(TextureCache *cache) {
|
||||
arrfree(rects);
|
||||
}
|
||||
|
||||
/* EXPERIMANTAL: LIKELY TO BE REMOVED! */
|
||||
#if defined(__linux_x_) /* use rodata elf section for fast lookups of repeating textures */
|
||||
|
||||
#include "system/linux/twn_elf.h"
|
||||
|
||||
static const char *rodata_start;
|
||||
static const char *rodata_stop;
|
||||
|
||||
static const char *last_path = NULL;
|
||||
static TextureKey last_texture;
|
||||
static struct PtrToTexture {
|
||||
const void *key;
|
||||
TextureKey value;
|
||||
} *ptr_to_texture;
|
||||
|
||||
/* TODO: separate and reuse */
|
||||
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||
if (rodata_stop == NULL)
|
||||
if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop))
|
||||
CRY("Section inference", ".rodata section lookup failed");
|
||||
/* to prevent hashing errors */
|
||||
if (!path) path = "";
|
||||
|
||||
/* the fastest path */
|
||||
if (path == last_path)
|
||||
return last_texture;
|
||||
else {
|
||||
/* moderately fast path, by pointer hashing */
|
||||
const ptrdiff_t texture = hmgeti(ptr_to_texture, path);
|
||||
if (texture != -1) {
|
||||
if (path >= rodata_start && path < rodata_stop)
|
||||
last_path = path;
|
||||
last_texture = ptr_to_texture[texture].value;
|
||||
return last_texture;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: this will be bad when dynamic strings are involved */
|
||||
/* to mitigate that we could free ptr_to_texture each frame */
|
||||
/* try loading */
|
||||
last_texture = textures_load(cache, path);
|
||||
hmput(ptr_to_texture, path, last_texture);
|
||||
|
||||
if (path >= rodata_start && path < rodata_stop)
|
||||
last_path = path;
|
||||
|
||||
return last_texture;
|
||||
}
|
||||
|
||||
#else
|
||||
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||
/* hash tables are assumed to be stable, so we just return indices */
|
||||
const ptrdiff_t texture = shgeti(cache->hash, path);
|
||||
|
||||
@ -520,8 +475,6 @@ TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||
return (TextureKey){ (uint16_t)texture };
|
||||
}
|
||||
|
||||
#endif /* generic implementation of textures_get_key() */
|
||||
|
||||
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key) {
|
||||
if (m_texture_key_is_valid(key)) {
|
||||
if (cache->hash[key.id].value.loner_texture != 0)
|
||||
@ -628,10 +581,4 @@ size_t textures_get_num_atlases(const TextureCache *cache) {
|
||||
}
|
||||
|
||||
void textures_reset_state(void) {
|
||||
#if defined(__linux__x) && !defined(HOT_RELOAD_SUPPORT)
|
||||
last_path = NULL;
|
||||
last_texture = (TextureKey){0};
|
||||
shfree(ptr_to_texture);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user