diff --git a/runtime/gfx.h b/runtime/gfx.h index d12709fc..3e74bfcf 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -159,6 +159,8 @@ typedef struct { uint8_t type, comps, packed; } GfxShaderIo; // GFX_TYPE_*, co int gfx_shader_stage(const GfxShader *s); // GFX_STAGE_VS, GFX_STAGE_FS or GFX_STAGE_CS int gfx_shader_resources(const GfxShader *s, int kind, const GfxShaderRes **res); // count of GFX_RES_* kind; array in *res uint32_t gfx_shader_exact_seen(void); // shaders loaded so far with a GfxShaderRes.exact texture (the texture census line) +uint32_t gfx_shader_pool_short_seen(void); // shaders in memory whose texture pool array has the earlier length, 32768 + // (gfx_shader.c pool_short_note; vk_texture_register's warning) uint32_t gfx_shader_slot_mask(const GfxShader *s); // texture/image slots whose type its translation read uint32_t gfx_shader_inputs(const GfxShader *s, GfxShaderIo io[32]); // Input Locations (VS attributes, FS varyings) as a mask uint32_t gfx_shader_outputs(const GfxShader *s, GfxShaderIo io[32]); diff --git a/runtime/gfx_shader.c b/runtime/gfx_shader.c index 8c8a5c7f..d24488f2 100644 --- a/runtime/gfx_shader.c +++ b/runtime/gfx_shader.c @@ -742,6 +742,7 @@ static void carry_served(const GfxShader *s) { } static void zpass_kick(void); +static void pool_short_note(const GfxShader *s); // Inserts s, or frees it and returns the entry another thread inserted first. static GfxShader *mem_insert(GfxShader *s) { @@ -761,7 +762,7 @@ static GfxShader *mem_insert(GfxShader *s) { plat_mutex_unlock(&cache_lock); if (added && s->carried) carry_served(s); else if (added) ids_note(); - if (added) zpass_kick(); + if (added) pool_short_note(s), zpass_kick(); return s; } @@ -1992,6 +1993,20 @@ static int pool_short(const GfxShader *s) { return 0; } +// Shaders that entered the memory cache with a texture pool array of the earlier length (mem_insert). carry_usable +// keeps the carried ones out, so these come from a translator in use that is older than the runtime's pool (a dev +// build pointed at an old one, or an install whose translator was not rebuilt). Counted, the first logged; +// vk_texture.c vk_texture_register names the count when the game registers a texture they cannot reach. +static volatile int32_t n_pool_short; +static void pool_short_note(const GfxShader *s) { + if (!pool_short(s) || plat_inc32(&n_pool_short) != 1) return; + rt_log("gfx_shader: a shader of the translator in use indexes the texture pool with %d entries: it reads slot %d " + "for every texture numbered from %d up; the translator is older than this runtime (tools/build_xlate.py " + "builds the current one)", POOL_TEX_SHORT, POOL_TEX_SHORT - 1, POOL_TEX_SHORT); +} + +uint32_t gfx_shader_pool_short_seen(void) { return (uint32_t)__atomic_load_n(&n_pool_short, __ATOMIC_RELAXED); } + // Whether previous identity j's translation s may serve. One that indexes the texture pool with the earlier length is // not used: the lookup goes on to the next previous identity and then to a translation under the current one (the boot // prewarm translates the shaders it names on the boot screen, others are translated at first use). Served, it would diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 0fb27d9b..f3d56090 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -4765,6 +4765,14 @@ void vk_texture_register(int id, const tex_t *t, const view_t *v) { rt_log("vk: texture slot %d registered, past the %d the shaders index (VK_POOL_TEX): a shader that samples it " "reads slot %d instead (%d for a translation carried over from the translator before)", id, VK_POOL_TEX, VK_POOL_TEX - 1, VK_POOL_TEX_CARRIED - 1); + } else if (id >= VK_POOL_TEX_CARRIED) { // within the pool, past what a shader of the earlier length reaches + static int said; + uint32_t n; + if (!__atomic_load_n(&said, __ATOMIC_RELAXED) && (n = gfx_shader_pool_short_seen()) && + !__atomic_exchange_n(&said, 1, __ATOMIC_RELAXED)) + rt_log("vk: texture slot %d registered while %u shaders in use index the texture pool with the earlier " + "length (%d, gfx_shader.c pool_short_note): they read slot %d in its place", id, n, + VK_POOL_TEX_CARRIED, VK_POOL_TEX_CARRIED - 1); } lock(); if (id >= ntslots) { diff --git a/tests/carry_pool_check.py b/tests/carry_pool_check.py index 373ff07e..bbfe13b4 100644 --- a/tests/carry_pool_check.py +++ b/tests/carry_pool_check.py @@ -3,7 +3,8 @@ earlier length (32768, vk.h VK_POOL_TEX_CARRIED) is never served, because its cl 32768 up with slot 32767. The check cuts pool_short, carry_usable, carry_load, carry_find and carry_find_iid out of gfx_shader.c, compiles them against stand-ins for the disk and memory caches, and walks the lookups: a refused entry is freed and the lookup goes on to the next previous identity, the owned branch (gfx_shader_load_private) frees it as -well, and entries with the current length, the sampler pool or no pool are served as before. +well, and entries with the current length, the sampler pool or no pool are served as before. pool_short_note, which +counts the shaders of the earlier length that enter the memory cache for vk_texture.c's warning, counts those only. No GPU, no game files, any Python. @@ -155,8 +156,25 @@ int main(void) { disk_len[0] = 32768; assert(!carry_find(h, &a, 1, 0) && !carry_find_iid(iid, 0, NULL) && loads == 0); + /* pool_short_note (what mem_insert calls for every shader entering the memory cache): only shaders with a pool + array of the earlier length count, the first is logged, gfx_shader_pool_short_seen gives the count. */ reset(); - printf("carry pool check: earlier-length pool translations refused and freed, the lookup goes on, others served\n"); + uint8_t k[32] = {0}; + disk_len[0] = 40960, disk_len[1] = 32768, disk_len[2] = -1; + GfxShader *cur = disk_load(k, NULL); + k[0] = 1; + GfxShader *old = disk_load(k, NULL); + k[0] = 2; + GfxShader *none = disk_load(k, NULL); + pool_short_note(cur), pool_short_note(none); + assert(gfx_shader_pool_short_seen() == 0 && logs == 0); + pool_short_note(old), pool_short_note(old); + assert(gfx_shader_pool_short_seen() == 2 && logs == 1 && strstr(last_log, "older than this runtime")); + shader_free(cur), shader_free(old), shader_free(none); + + reset(); + printf("carry pool check: earlier-length pool translations refused and freed, the lookup goes on, others served; " + "shaders of the earlier length in use counted\n"); return 0; } '''