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