From 2571e180c8b67d4e957ee46674d6264b664c6dfc Mon Sep 17 00:00:00 2001 From: chrg6 Date: Thu, 12 Nov 2026 22:46:24 -0500 Subject: [PATCH] Check the texture pool's set against the device's descriptor limits, and name the slot a carried translation reads. The larger pool asks for 655,360 sampled images in one set where 524,288 were asked before. The start now logs the device's limits for one set and one stage next to that count, warns when the count is over them, and a refused layout ends the start with the limits named instead of a bare failure. The log line for a slot registered past the pool names both slots a shader reads instead: the pool's last entry, and the last of the old length for a translation carried over from the translator before. The comments say what they say without an issue number. The translator's identity changes with this pool size: after the update every install translates its shaders again in the background, the earlier translations serve meanwhile, and a shader gets the ground fix once it is translated. Co-Authored-By: Claude Opus 5.5 --- runtime/vk.h | 5 +++-- runtime/vk_exec_draw.c | 31 ++++++++++++++++++++++++++++++- runtime/vk_texture.c | 5 +++-- tools/xlate/Program.cs | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/runtime/vk.h b/runtime/vk.h index f8cab23f..3a30a322 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -657,8 +657,9 @@ int vk_sampler_slot_count_locked(void); // 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. +// see-through ground until the area was loaded again. 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_exec_draw.c pool_layout_make logs the +// device's limits and says which one a failed layout passed. vk_texture_register logs a slot past the pool. #define VK_POOL_TEX 40960 // as the translator's Accessor.TexturePoolLength #define VK_POOL_TEX_CARRIED 32768 // the length before: carried translations still declare it #define VK_POOL_SAMP 4096 // Accessor.SamplerPoolLength diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 827da5f9..50c62df2 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -2025,6 +2025,22 @@ static struct { static void pool_marks_make(void); +// The device's limits for the sampled images of the pool's set: in one set, and in one shader stage of a pipeline +// layout (the pool's bindings are visible to every stage, and a layout adds the bound textures of set 0 to them). The +// update-after-bind limits apply when PL.uab, the plain ones otherwise. *set and *stage are 0 when unknown. +static void pool_limits(VkCtx *c, uint64_t *set, uint64_t *stage) { + VkPhysicalDeviceVulkan12Properties p12 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES}; + VkPhysicalDeviceProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, .pNext = &p12}; + vkGetPhysicalDeviceProperties2(c->phys, &p2); + if (PL.uab) { + *set = p12.maxDescriptorSetUpdateAfterBindSampledImages; + *stage = p12.maxPerStageDescriptorUpdateAfterBindSampledImages; + } else { + *set = p2.properties.limits.maxDescriptorSetSampledImages; + *stage = p2.properties.limits.maxPerStageDescriptorSampledImages; + } +} + static VkDescriptorSetLayout pool_layout_make(void) { VkCtx *c = vk_ctx(); VkPhysicalDeviceVulkan12Features f12 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; @@ -2032,6 +2048,16 @@ static VkDescriptorSetLayout pool_layout_make(void) { vkGetPhysicalDeviceFeatures2(c->phys, &f2); // create_device enables every supported feature PL.uab = f12.descriptorBindingSampledImageUpdateAfterBind && f12.descriptorBindingPartiallyBound && f12.descriptorBindingUpdateUnusedWhilePending; + // The pool needs VK_POOL_KINDS x VK_POOL_TEX sampled images in its set, whatever the game uses: a translated shader + // indexes the whole array. A device whose limits are below that is told in the log before the layout is asked for; + // a driver that accepts the layout anyway is let go on, one that refuses it ends the start with the limit named. + uint64_t need = (uint64_t)VK_POOL_KINDS * VK_POOL_TEX, lim_set = 0, lim_stage = 0; + pool_limits(c, &lim_set, &lim_stage); + int over = (lim_set && need > lim_set) || (lim_stage && need > lim_stage); + rt_log("vk: bindless texture pools: %d kinds x %d textures = %llu sampled images; the device allows %llu in a set " + "and %llu in a stage (%s limits)%s", VK_POOL_KINDS, VK_POOL_TEX, (unsigned long long)need, + (unsigned long long)lim_set, (unsigned long long)lim_stage, PL.uab ? "update-after-bind" : "plain", + over ? ": WARNING, over the device's limit" : ""); int marks = vk_pool_marks_enabled(); uint32_t nb = VK_POOL_KINDS + 1 + (marks ? 1u : 0u); // the marks buffer at VK_POOL_MARK_BINDING, last VkDescriptorSetLayoutBinding b[VK_POOL_KINDS + 2]; @@ -2054,7 +2080,10 @@ static VkDescriptorSetLayout pool_layout_make(void) { .flags = PL.uab ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT : 0, .bindingCount = nb, .pBindings = b}; VkDescriptorSetLayout l; - if (vkCreateDescriptorSetLayout(c->device, &li, NULL, &l) != VK_SUCCESS) rt_fatal("vk: the texture pool layout failed"); + if (vkCreateDescriptorSetLayout(c->device, &li, NULL, &l) != VK_SUCCESS) + rt_fatal("vk: the texture pool layout failed: it holds %llu sampled images, and this device allows %llu in a " + "set and %llu in a stage (%s limits)", (unsigned long long)need, (unsigned long long)lim_set, + (unsigned long long)lim_stage, PL.uab ? "update-after-bind" : "plain"); VkDescriptorPoolSize ps[3] = {{VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_POOL_KINDS * VK_POOL_TEX}, {VK_DESCRIPTOR_TYPE_SAMPLER, VK_POOL_SAMP}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}; uint32_t nps = marks ? 3 : 2; diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index 85910be6..edf46f74 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -4454,11 +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 + if (id >= VK_POOL_TEX) { // the translator clamps pool handles to the pool's last entry: shaders cannot reach it 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); + "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); } lock(); if (id >= ntslots) { diff --git a/tools/xlate/Program.cs b/tools/xlate/Program.cs index 4b3ff97e..a9df071c 100644 --- a/tools/xlate/Program.cs +++ b/tools/xlate/Program.cs @@ -54,7 +54,7 @@ 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). - // TexturePoolLength: the runtime's VK_POOL_TEX (vk.h), past Ocarina's pool of 33068 descriptors (#569). + // TexturePoolLength: the runtime's VK_POOL_TEX (vk.h), past Ocarina's pool of 33068 descriptors. public const int TexturePoolLength = 40960, SamplerPoolLength = 4096; public int QuerySamplerArrayLengthFromPool() => SamplerPoolLength; public int QueryTextureArrayLengthFromBuffer(int slot) => 32;