Log shaders that index the texture pool with the earlier translator's length, and a texture they cannot reach.

A shader whose texture pool array has 32768 entries reads slot 32767 for every texture the game numbers from 32768 up
(Ocarina's pool has 33068), but nothing in the log said such a shader was in use: vk_texture_register warned only for
slots past VK_POOL_TEX (40960), which Ocarina never registers, and vk_pipeline.c spirv_pool_rebind accepts the shorter
arrays silently. gfx_shader.c pool_short_note now counts the shaders entering the memory cache with such an array
(carry_usable keeps carried ones out, so these come from a translator older than the runtime) and logs the first;
vk_texture_register logs once, with that count, when a slot between 32768 and 40959 is registered while one is in
use. The count is kept per shader in gfx_shader.c (gfx_shader_pool_short_seen) rather than per pipeline stage in
spirv_pool_rebind, which runs once per module built.

Diagnostics only. tests/carry_pool_check.py now also checks that pool_short_note counts only shaders of the earlier
length and logs once; every runtime file compiles, with no new warnings in gfx_shader.c and vk_texture.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:15:58 -05:00
parent 48846dc9cb
commit b04e7c85b2
4 changed files with 46 additions and 3 deletions

View File

@@ -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]);

View File

@@ -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

View File

@@ -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) {