diff --git a/runtime/vk.h b/runtime/vk.h index a807a773..c8b11fd9 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -654,7 +654,12 @@ int vk_sampler_slot_count_locked(void); // Bindless pools (vk_exec_draw.c, "texture and sampler pools"): set 2 of every pipeline layout. Shaders that index // the texture or sampler pool with handles from memory have their pool arrays moved there (vk_pipeline.c // spirv_pool_rebind); VK_POOL_KINDS image bindings, one per view kind, then the sampler pool. -#define VK_POOL_TEX 32768 // as the translator's Accessor.TexturePoolLength +// VK_POOL_TEX covers the game's whole texture pool: Ocarina makes one of 33068 descriptors (nvnTexturePoolInitialize), +// and with 32768 the translator's clamp sent every handle from 32768 up to slot 32767, so the textures the game +// numbered there (some ground after an area load) were drawn with whatever slot 32767 held, often an empty image: +// see-through ground until the area was loaded again (#569). 16 kinds x 40960 = 655,360 sampled images in set 2, under +// NVIDIA's 1,048,576 update-after-bind limit with room for the bound slots. vk_texture_register logs a slot past it. +#define VK_POOL_TEX 40960 // as the translator's Accessor.TexturePoolLength #define VK_POOL_SAMP 4096 // Accessor.SamplerPoolLength #define VK_POOL_KINDS 16 // kind = depth * 8 + dim * 2 + arrayed, dim 1D 2D 3D CUBE extern volatile uint32_t vk_pool_kinds_used; // bit k: a pipeline was made with a kind-k pool array diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 24be30b6..827da5f9 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -1712,7 +1712,7 @@ static uint32_t feedback_scan(VkExec *ex, const GfxShader *fs) { FmEnt *fm = ex->dc->fm; if (!fm && !(fm = ex->dc->fm = calloc(FM_N, sizeof *fm))) rt_fatal("vk: out of memory (feedback memo)"); for (int r = 0; r < n; r++) { - // Only bound slots (0..127) are looked at. The texture and sampler pool arrays (res.pool: 32768 and 4096 + // Only bound slots (0..127) are looked at. The texture and sampler pool arrays (res.pool: VK_POOL_TEX and 4096 // descriptors, bindless handles) have slot -1: walking them ran up to about 100,000 empty iterations per scan, // about 3.6 ms of replay per frame in Kokiri Forest, and read tex[FS][0..127] for them by mistake. if (res[r].pool || res[r].slot < 0) continue; diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 24f752cc..85910be6 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -4454,6 +4454,12 @@ void vk_texture_range_gone(uint64_t lo, uint64_t size, VmaAllocation alloc) { // ---------------------------------------------------------------- descriptor slots void vk_texture_register(int id, const tex_t *t, const view_t *v) { if (id < 0 || id >= (1 << 20)) rt_fatal("vk: texture slot %d out of range", id); + if (id >= VK_POOL_TEX) { // the translator clamps pool handles to VK_POOL_TEX - 1: shaders cannot reach this slot + static int said; + if (!__atomic_exchange_n(&said, 1, __ATOMIC_RELAXED)) + 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", id, VK_POOL_TEX, VK_POOL_TEX - 1); + } lock(); if (id >= ntslots) { int n = ntslots ? ntslots : 1024; diff --git a/tools/xlate/Program.cs b/tools/xlate/Program.cs index 8360dc9e..4b3ff97e 100644 --- a/tools/xlate/Program.cs +++ b/tools/xlate/Program.cs @@ -54,7 +54,8 @@ static class SwshXlate // GenerateBindlessAccess): arrays of TexturePoolLength textures (handle bits 0-19) and SamplerPoolLength samplers // (bits 20-31; NVN sampler ids are below 4096). res.json marks them "pool": 1 (textures) / 2 (samplers); the // runtime binds them from its global pool set (vk_exec_draw.c, texture and sampler pools). - public const int TexturePoolLength = 32768, SamplerPoolLength = 4096; + // TexturePoolLength: the runtime's VK_POOL_TEX (vk.h), past Ocarina's pool of 33068 descriptors (#569). + public const int TexturePoolLength = 40960, SamplerPoolLength = 4096; public int QuerySamplerArrayLengthFromPool() => SamplerPoolLength; public int QueryTextureArrayLengthFromBuffer(int slot) => 32; public int QueryTextureArrayLengthFromPool() => TexturePoolLength;