twn_textures.c: remove hacky .rodata texture lookup method, it turns out to be not anyhow faster than the simplest solution. also fix path=NULL case
This commit is contained in:
parent
6cb166522e
commit
732b61e207
@ -461,55 +461,10 @@ void textures_update_atlas(TextureCache *cache) {
|
|||||||
arrfree(rects);
|
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) {
|
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||||
if (rodata_stop == NULL)
|
/* to prevent hashing errors */
|
||||||
if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop))
|
if (!path) path = "";
|
||||||
CRY("Section inference", ".rodata section lookup failed");
|
|
||||||
|
|
||||||
/* 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 */
|
/* hash tables are assumed to be stable, so we just return indices */
|
||||||
const ptrdiff_t texture = shgeti(cache->hash, path);
|
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 };
|
return (TextureKey){ (uint16_t)texture };
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* generic implementation of textures_get_key() */
|
|
||||||
|
|
||||||
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key) {
|
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key) {
|
||||||
if (m_texture_key_is_valid(key)) {
|
if (m_texture_key_is_valid(key)) {
|
||||||
if (cache->hash[key.id].value.loner_texture != 0)
|
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) {
|
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