From e422ab68a74c9f8b42d143b596505d9cb3bbfab1 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 5 Dec 2026 02:58:22 -0500 Subject: [PATCH] upscale: answer each doorbell on the mailbox of the bridge that rang it Games that load more than one bridge (Bright Memory: Infinite loads the NGX bridge and, for its XeSS plugin, the XeSS bridge) have one mailbox per bridge. The layer read every doorbell from the last mailbox it had seen, so the NGX bridge's frames were read from the XeSS bridge's empty slots: the status showed reason ok with api None and 0x0 sizes, nothing was upscaled and the bridge fell back to its blit (Red Magic 12 Pro, with NGX already initialised and the bridge logging "dispatch 1"). Each bridge creates its mailbox and then its marker (wl_seam_client.h), so a marker is now paired with the mailbox created just before it. A doorbell uses that mailbox, else the one whose slot holds the doorbell's seq, else the last one as before. The protocol is unchanged. The exact-usage matching of e5d7bddf stays, but its stated cause (a full buffer table) was not confirmed on the phone; this pairing is. --- tools/upscale/layer/fsr4_layer.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/upscale/layer/fsr4_layer.c b/tools/upscale/layer/fsr4_layer.c index 5683f19c8a..2044e006d9 100644 --- a/tools/upscale/layer/fsr4_layer.c +++ b/tools/upscale/layer/fsr4_layer.c @@ -127,6 +127,7 @@ typedef struct { uint64_t size; uint32_t usage; int kind; // 1 = mailbox candidate, 2 = marker candidate + VkBuffer pair; // marker: the mailbox created just before it (each bridge creates its mailbox, then its marker) } SeamBufEnt; typedef struct { @@ -190,6 +191,7 @@ typedef struct { SeamBufEnt bufs[MAX_TRACK_BUF]; int nbufs; + VkBuffer last_mailbox; // most recently created mailbox candidate, paired with the next marker ImgEnt imgs[MAX_TRACK_IMG]; uint32_t img_count; @@ -1616,7 +1618,9 @@ static VkResult VKAPI_CALL hook_vkCreateBuffer(VkDevice device, const VkBufferCr static int full_logged = 0; pthread_mutex_lock(&g_mu); if (d->nbufs < MAX_TRACK_BUF) { - d->bufs[d->nbufs++] = (SeamBufEnt){*pBuffer, VK_NULL_HANDLE, NULL, pCreateInfo->size, pCreateInfo->usage, kind}; + d->bufs[d->nbufs++] = (SeamBufEnt){*pBuffer, VK_NULL_HANDLE, NULL, pCreateInfo->size, pCreateInfo->usage, kind, + kind == 2 ? d->last_mailbox : VK_NULL_HANDLE}; + if (kind == 1) d->last_mailbox = *pBuffer; } else if (!full_logged) { full_logged = 1; F4_LOGW("seam buffer table full (%d): a bridge buffer is not tracked", MAX_TRACK_BUF); @@ -1737,13 +1741,23 @@ static void VKAPI_CALL hook_vkCmdUpdateBuffer(VkCommandBuffer cb, VkBuffer dstBu if (d && dstOffset == 0 && dataSize == sizeof(WlFsr4DoorbellPayload) && pData) { const WlFsr4DoorbellPayload *pay = (const WlFsr4DoorbellPayload *)pData; if (pay->magic == WLFSR4_DOORBELL_MAGIC || pay->magic == WLFSR4_HELLO_MAGIC || pay->magic == WLFSR4_TELEMETRY_MAGIC) { + // Several bridges in one game (Bright Memory: Infinite loads the NGX and XeSS bridges) each have a + // mailbox: take the one paired with this marker, else the one whose slot holds this doorbell's seq, + // else the last one (the only one in most games). + VkBuffer pair = VK_NULL_HANDLE; + WlFsr4Mailbox *by_seq = NULL, *last = NULL, *paired = NULL; for (int i = 0; i < d->nbufs; i++) { - if (d->bufs[i].buf == dstBuffer && d->bufs[i].kind == 2) is_marker = 1; - if (d->bufs[i].kind == 1 && d->bufs[i].mapped) { - WlFsr4Mailbox *cand = (WlFsr4Mailbox *)d->bufs[i].mapped; - if (cand->magic == WLFSR4_MAILBOX_MAGIC) mbox = cand; - } + if (d->bufs[i].buf == dstBuffer && d->bufs[i].kind == 2) { is_marker = 1; pair = d->bufs[i].pair; } } + for (int i = 0; is_marker && i < d->nbufs; i++) { + if (d->bufs[i].kind != 1 || !d->bufs[i].mapped) continue; + WlFsr4Mailbox *cand = (WlFsr4Mailbox *)d->bufs[i].mapped; + if (cand->magic != WLFSR4_MAILBOX_MAGIC) continue; + last = cand; + if (pair != VK_NULL_HANDLE && d->bufs[i].buf == pair) paired = cand; + if (cand->slots[pay->seq % WLFSR4_SLOTS].seq == pay->seq) by_seq = cand; + } + mbox = paired ? paired : (by_seq ? by_seq : last); } } pthread_mutex_unlock(&g_mu);