Files
DroidDeck/tools/upscale/bridges/wl_seam_client.h
T
The412Banner 4626cb309d upscale: bridges default to Full FSR 4.1 on the NPU; README after r5
wl_seam_parse_backend_env() fell back to the removed FSR 4.0 NPU id when no backend is set; it
now names Full FSR 4.1 NPU, as fsr4_0_npu does. The bridge README no longer says D3D11 NGX reports
DLSS unavailable (r5 routes it through DXVK's interop) and lists the r5 engine names.
2026-12-05 00:22:02 -05:00

445 lines
19 KiB
C

// DroidDeck: modified from michaelisomer-cyber/Winlator-NeuralScale 71c140d9 (see README.md).
// Windows-side in-process Vulkan Seam Client for Winlator Ludashi FSR 4.1.1 HTP NPU Layer.
// Allocates the host-coherent WlFsr4Mailbox + marker buffer on the game's VkDevice and
// rings the vkCmdUpdateBuffer doorbell so libVkLayer_winlator_fsr4_npu.so records the
// zero-copy Hexagon HTP v81 pipeline directly into the game's VkCommandBuffer.
#pragma once
#include <windows.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "fsr4_seam_proto.h"
#include "dd_env.h"
// Minimal Vulkan types for MinGW x86_64 (zero external Vulkan SDK dependency)
typedef uint32_t VkFlags;
typedef uint32_t VkBool32;
typedef uint64_t VkDeviceSize;
typedef int32_t VkResult;
typedef void *VkInstance;
typedef void *VkPhysicalDevice;
typedef void *VkDevice;
typedef void *VkCommandBuffer;
typedef uint64_t VkBuffer;
typedef uint64_t VkDeviceMemory;
typedef uint64_t VkImage;
typedef uint64_t VkImageView;
#define VK_SUCCESS 0
#define VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO 12
#define VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO 5
#define VK_BUFFER_USAGE_TRANSFER_DST_BIT 0x00000002u
#define VK_BUFFER_USAGE_STORAGE_BUFFER_BIT 0x00000020u
#define VK_SHARING_MODE_EXCLUSIVE 0
#define VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT 0x00000002u
#define VK_MEMORY_PROPERTY_HOST_COHERENT_BIT 0x00000004u
typedef struct {
uint32_t sType;
const void *pNext;
VkFlags flags;
VkDeviceSize size;
VkFlags usage;
uint32_t sharingMode;
uint32_t queueFamilyIndexCount;
const uint32_t *pQueueFamilyIndices;
} WlVkBufferCreateInfo;
typedef struct {
VkDeviceSize size;
VkDeviceSize alignment;
uint32_t memoryTypeBits;
} WlVkMemoryRequirements;
typedef struct {
uint32_t sType;
const void *pNext;
VkDeviceSize allocationSize;
uint32_t memoryTypeIndex;
} WlVkMemoryAllocateInfo;
typedef struct {
VkFlags propertyFlags;
uint32_t heapIndex;
} WlVkMemoryType;
typedef struct {
VkDeviceSize size;
VkFlags flags;
} WlVkMemoryHeap;
typedef struct {
uint32_t memoryTypeCount;
WlVkMemoryType memoryTypes[32];
uint32_t memoryHeapCount;
WlVkMemoryHeap memoryHeaps[16];
} WlVkPhysicalDeviceMemoryProperties;
typedef struct {
uint32_t sType;
const void *pNext;
uint32_t srcAccessMask;
uint32_t dstAccessMask;
uint32_t oldLayout;
uint32_t newLayout;
uint32_t srcQueueFamilyIndex;
uint32_t dstQueueFamilyIndex;
VkImage image;
struct {
uint32_t aspectMask;
uint32_t baseMipLevel;
uint32_t levelCount;
uint32_t baseArrayLayer;
uint32_t layerCount;
} subresourceRange;
} WlVkImageMemoryBarrier;
typedef struct {
struct {
uint32_t aspectMask;
uint32_t mipLevel;
uint32_t baseArrayLayer;
uint32_t layerCount;
} srcSubresource;
struct { int32_t x, y, z; } srcOffsets[2];
struct {
uint32_t aspectMask;
uint32_t mipLevel;
uint32_t baseArrayLayer;
uint32_t layerCount;
} dstSubresource;
struct { int32_t x, y, z; } dstOffsets[2];
} WlVkImageBlit;
typedef void *(__stdcall *PFN_wlVkGetDeviceProcAddr)(VkDevice, const char *);
typedef void *(__stdcall *PFN_wlVkGetInstanceProcAddr)(VkInstance, const char *);
typedef VkResult (__stdcall *PFN_wlVkCreateBuffer)(VkDevice, const WlVkBufferCreateInfo *, const void *, VkBuffer *);
typedef void (__stdcall *PFN_wlVkDestroyBuffer)(VkDevice, VkBuffer, const void *);
typedef void (__stdcall *PFN_wlVkGetBufferMemoryRequirements)(VkDevice, VkBuffer, WlVkMemoryRequirements *);
typedef VkResult (__stdcall *PFN_wlVkAllocateMemory)(VkDevice, const WlVkMemoryAllocateInfo *, const void *, VkDeviceMemory *);
typedef void (__stdcall *PFN_wlVkFreeMemory)(VkDevice, VkDeviceMemory, const void *);
typedef VkResult (__stdcall *PFN_wlVkBindBufferMemory)(VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize);
typedef VkResult (__stdcall *PFN_wlVkMapMemory)(VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkFlags, void **);
typedef void (__stdcall *PFN_wlVkUnmapMemory)(VkDevice, VkDeviceMemory);
typedef void (__stdcall *PFN_wlVkCmdUpdateBuffer)(VkCommandBuffer, VkBuffer, VkDeviceSize, VkDeviceSize, const void *);
typedef void (__stdcall *PFN_wlVkCmdPipelineBarrier)(VkCommandBuffer, uint32_t, uint32_t, uint32_t, uint32_t, const void *, uint32_t, const void *, uint32_t, const WlVkImageMemoryBarrier *);
typedef void (__stdcall *PFN_wlVkCmdBlitImage)(VkCommandBuffer, VkImage, uint32_t, VkImage, uint32_t, uint32_t, const WlVkImageBlit *, uint32_t);
typedef void (__stdcall *PFN_wlVkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice, WlVkPhysicalDeviceMemoryProperties *);
typedef struct WlSeamClient {
int ready;
VkInstance inst;
VkDevice dev;
VkPhysicalDevice phys;
VkBuffer mbox_buf;
VkDeviceMemory mbox_mem;
WlFsr4Mailbox *mbox;
VkBuffer marker_buf;
VkDeviceMemory marker_mem;
uint64_t next_seq;
PFN_wlVkDestroyBuffer DestroyBuffer;
PFN_wlVkFreeMemory FreeMemory;
PFN_wlVkUnmapMemory UnmapMemory;
PFN_wlVkCmdUpdateBuffer CmdUpdateBuffer;
PFN_wlVkCmdPipelineBarrier CmdPipelineBarrier;
PFN_wlVkCmdBlitImage CmdBlitImage;
} WlSeamClient;
static uint32_t wl_seam_pick_mem(const WlVkPhysicalDeviceMemoryProperties *mp, uint32_t bits, uint32_t want) {
if (mp) {
for (uint32_t i = 0; i < mp->memoryTypeCount; i++) {
if ((bits & (1u << i)) && (mp->memoryTypes[i].propertyFlags & want) == want) return i;
}
}
for (uint32_t i = 0; i < 32; i++) {
if (bits & (1u << i)) return i;
}
return 0xFFFFFFFFu;
}
static int wl_seam_init(WlSeamClient *c, VkInstance inst, VkPhysicalDevice phys, VkDevice dev,
PFN_wlVkGetDeviceProcAddr gdpa) {
memset(c, 0, sizeof *c);
if (!dev) return 0;
HMODULE vkmod = GetModuleHandleA("vulkan-1.dll");
if (!vkmod) vkmod = LoadLibraryA("vulkan-1.dll");
if (!gdpa && vkmod) gdpa = (PFN_wlVkGetDeviceProcAddr)(void *)GetProcAddress(vkmod, "vkGetDeviceProcAddr");
if (!gdpa) return 0;
PFN_wlVkCreateBuffer CreateBuffer = (PFN_wlVkCreateBuffer)gdpa(dev, "vkCreateBuffer");
PFN_wlVkGetBufferMemoryRequirements GetBufReqs = (PFN_wlVkGetBufferMemoryRequirements)gdpa(dev, "vkGetBufferMemoryRequirements");
PFN_wlVkAllocateMemory AllocateMemory = (PFN_wlVkAllocateMemory)gdpa(dev, "vkAllocateMemory");
PFN_wlVkBindBufferMemory BindBufferMemory = (PFN_wlVkBindBufferMemory)gdpa(dev, "vkBindBufferMemory");
PFN_wlVkMapMemory MapMemory = (PFN_wlVkMapMemory)gdpa(dev, "vkMapMemory");
c->DestroyBuffer = (PFN_wlVkDestroyBuffer)gdpa(dev, "vkDestroyBuffer");
c->FreeMemory = (PFN_wlVkFreeMemory)gdpa(dev, "vkFreeMemory");
c->UnmapMemory = (PFN_wlVkUnmapMemory)gdpa(dev, "vkUnmapMemory");
c->CmdUpdateBuffer = (PFN_wlVkCmdUpdateBuffer)gdpa(dev, "vkCmdUpdateBuffer");
c->CmdPipelineBarrier = (PFN_wlVkCmdPipelineBarrier)gdpa(dev, "vkCmdPipelineBarrier");
c->CmdBlitImage = (PFN_wlVkCmdBlitImage)gdpa(dev, "vkCmdBlitImage");
if (!CreateBuffer || !GetBufReqs || !AllocateMemory || !BindBufferMemory || !MapMemory || !c->CmdUpdateBuffer)
return 0;
WlVkPhysicalDeviceMemoryProperties mp;
memset(&mp, 0, sizeof mp);
int has_mp = 0;
if (phys && vkmod) {
PFN_wlVkGetPhysicalDeviceMemoryProperties get_mp = NULL;
if (inst) {
PFN_wlVkGetInstanceProcAddr gipa = (PFN_wlVkGetInstanceProcAddr)(void *)GetProcAddress(vkmod, "vkGetInstanceProcAddr");
if (gipa) get_mp = (PFN_wlVkGetPhysicalDeviceMemoryProperties)gipa(inst, "vkGetPhysicalDeviceMemoryProperties");
}
if (!get_mp) get_mp = (PFN_wlVkGetPhysicalDeviceMemoryProperties)(void *)GetProcAddress(vkmod, "vkGetPhysicalDeviceMemoryProperties");
if (get_mp) { get_mp(phys, &mp); has_mp = 1; }
}
// 1. Allocate MAILBOX buffer (exact signature WLFSR4_MAILBOX_BYTES + STORAGE_BUFFER | TRANSFER_DST)
WlVkBufferCreateInfo bci;
memset(&bci, 0, sizeof bci);
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bci.size = WLFSR4_MAILBOX_BYTES;
bci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (CreateBuffer(dev, &bci, NULL, &c->mbox_buf) != VK_SUCCESS) return 0;
WlVkMemoryRequirements mr;
memset(&mr, 0, sizeof mr);
GetBufReqs(dev, c->mbox_buf, &mr);
WlVkMemoryAllocateInfo mai;
memset(&mai, 0, sizeof mai);
mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mai.allocationSize = mr.size;
void *mapped = NULL;
if (has_mp) {
uint32_t mt = wl_seam_pick_mem(&mp, mr.memoryTypeBits,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (mt == 0xFFFFFFFFu) { if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL); return 0; }
mai.memoryTypeIndex = mt;
if (AllocateMemory(dev, &mai, NULL, &c->mbox_mem) != VK_SUCCESS ||
BindBufferMemory(dev, c->mbox_buf, c->mbox_mem, 0) != VK_SUCCESS ||
MapMemory(dev, c->mbox_mem, 0, WLFSR4_MAILBOX_BYTES, 0, &mapped) != VK_SUCCESS || !mapped) {
if (c->mbox_mem && c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
return 0;
}
} else {
// VkPhysicalDevice unavailable (e.g. FSR 2 VK): probe compatible memory types until vkMapMemory succeeds
int ok = 0;
for (uint32_t i = 0; i < 32; i++) {
if (!(mr.memoryTypeBits & (1u << i))) continue;
VkDeviceMemory cand = 0;
mai.memoryTypeIndex = i;
if (AllocateMemory(dev, &mai, NULL, &cand) != VK_SUCCESS) continue;
if (MapMemory(dev, cand, 0, WLFSR4_MAILBOX_BYTES, 0, &mapped) == VK_SUCCESS && mapped) {
if (BindBufferMemory(dev, c->mbox_buf, cand, 0) == VK_SUCCESS) {
c->mbox_mem = cand;
ok = 1;
break;
}
if (c->UnmapMemory) c->UnmapMemory(dev, cand);
}
if (c->FreeMemory) c->FreeMemory(dev, cand, NULL);
mapped = NULL;
}
if (!ok) {
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
return 0;
}
}
memset(mapped, 0, WLFSR4_MAILBOX_BYTES);
c->mbox = (WlFsr4Mailbox *)mapped;
c->mbox->magic = WLFSR4_MAILBOX_MAGIC;
c->mbox->version = WLFSR4_PROTO_VERSION;
// 2. Allocate MARKER buffer (exact signature WLFSR4_MARKER_BYTES + TRANSFER_DST)
bci.size = WLFSR4_MARKER_BYTES;
bci.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
if (CreateBuffer(dev, &bci, NULL, &c->marker_buf) != VK_SUCCESS) {
if (c->UnmapMemory) c->UnmapMemory(dev, c->mbox_mem);
if (c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
return 0;
}
GetBufReqs(dev, c->marker_buf, &mr);
mai.allocationSize = mr.size;
mai.memoryTypeIndex = wl_seam_pick_mem(has_mp ? &mp : NULL, mr.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
if (AllocateMemory(dev, &mai, NULL, &c->marker_mem) != VK_SUCCESS ||
BindBufferMemory(dev, c->marker_buf, c->marker_mem, 0) != VK_SUCCESS) {
if (c->marker_mem && c->FreeMemory) c->FreeMemory(dev, c->marker_mem, NULL);
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->marker_buf, NULL);
if (c->UnmapMemory) c->UnmapMemory(dev, c->mbox_mem);
if (c->FreeMemory) c->FreeMemory(dev, c->mbox_mem, NULL);
if (c->DestroyBuffer) c->DestroyBuffer(dev, c->mbox_buf, NULL);
return 0;
}
c->inst = inst;
c->dev = dev;
c->phys = phys;
c->next_seq = 1u;
c->ready = 1;
return 1;
}
static void wl_seam_destroy(WlSeamClient *c) {
if (!c || !c->ready) return;
if (c->marker_buf && c->DestroyBuffer) c->DestroyBuffer(c->dev, c->marker_buf, NULL);
if (c->marker_mem && c->FreeMemory) c->FreeMemory(c->dev, c->marker_mem, NULL);
if (c->mbox_mem && c->UnmapMemory) c->UnmapMemory(c->dev, c->mbox_mem);
if (c->mbox_buf && c->DestroyBuffer) c->DestroyBuffer(c->dev, c->mbox_buf, NULL);
if (c->mbox_mem && c->FreeMemory) c->FreeMemory(c->dev, c->mbox_mem, NULL);
memset(c, 0, sizeof *c);
}
static int wl_seam_dispatch(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *in_frame) {
if (!c || !c->ready || !cb || !in_frame || !c->mbox) return 0;
uint64_t seq = c->next_seq++;
WlFsr4FrameDesc *slot = &c->mbox->slots[seq % WLFSR4_SLOTS];
*slot = *in_frame;
slot->seq = seq;
MemoryBarrier();
WlFsr4DoorbellPayload pay;
pay.magic = WLFSR4_DOORBELL_MAGIC;
pay.seq = seq;
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
MemoryBarrier();
uint64_t ack = c->mbox->ack;
return ((ack & WLFSR4_ACK_SEQ_MASK) == seq && (ack & WLFSR4_ACK_WORK_BIT)) ? 1 : 0;
}
// Fail-closed guest-side bilinear blit fallback if the Vulkan layer did not ack a frame.
// Ensures the game's output image is NEVER left unwritten / corrupted with stale VRAM.
static int wl_seam_fallback_blit(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *f) {
if (!c || !cb || !f || !c->CmdPipelineBarrier || !c->CmdBlitImage) return 0;
if (!f->color.vk_image || !f->output.vk_image || f->color.vk_image == f->output.vk_image) return 0;
uint32_t rw = f->render_w ? f->render_w : f->color.width;
uint32_t rh = f->render_h ? f->render_h : f->color.height;
uint32_t ow = f->output_w ? f->output_w : f->output.width;
uint32_t oh = f->output_h ? f->output_h : f->output.height;
if (!rw || !rh || !ow || !oh) return 0;
uint32_t src_lay = f->color.vk_layout ? f->color.vk_layout : 1u; /* GENERAL */
uint32_t dst_lay = f->output.vk_layout ? f->output.vk_layout : 1u;
WlVkImageMemoryBarrier pre[2];
memset(pre, 0, sizeof pre);
pre[0].sType = 45u; /* VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER */
pre[0].srcAccessMask = 0x00010000u; /* MEMORY_WRITE */
pre[0].dstAccessMask = 0x00000800u; /* TRANSFER_READ */
pre[0].oldLayout = src_lay;
pre[0].newLayout = 6u; /* TRANSFER_SRC_OPTIMAL */
pre[0].srcQueueFamilyIndex = 0xFFFFFFFFu;
pre[0].dstQueueFamilyIndex = 0xFFFFFFFFu;
pre[0].image = f->color.vk_image;
pre[0].subresourceRange.aspectMask = 1u;
pre[0].subresourceRange.levelCount = 1u;
pre[0].subresourceRange.layerCount = 1u;
pre[1] = pre[0];
pre[1].srcAccessMask = 0x00018000u; /* MEMORY_READ | MEMORY_WRITE */
pre[1].dstAccessMask = 0x00001000u; /* TRANSFER_WRITE */
pre[1].oldLayout = dst_lay;
pre[1].newLayout = 7u; /* TRANSFER_DST_OPTIMAL */
pre[1].image = f->output.vk_image;
c->CmdPipelineBarrier(cb, 0x00010000u /* ALL_COMMANDS */, 0x00001000u /* TRANSFER */, 0, 0, NULL, 0, NULL, 2, pre);
WlVkImageBlit reg;
memset(&reg, 0, sizeof reg);
reg.srcSubresource.aspectMask = 1u;
reg.srcSubresource.layerCount = 1u;
reg.srcOffsets[1].x = (int32_t)rw;
reg.srcOffsets[1].y = (int32_t)rh;
reg.srcOffsets[1].z = 1;
reg.dstSubresource.aspectMask = 1u;
reg.dstSubresource.layerCount = 1u;
reg.dstOffsets[1].x = (int32_t)ow;
reg.dstOffsets[1].y = (int32_t)oh;
reg.dstOffsets[1].z = 1;
c->CmdBlitImage(cb, f->color.vk_image, 6u, f->output.vk_image, 7u, 1u, &reg, 1u /* LINEAR */);
WlVkImageMemoryBarrier post[2];
post[0] = pre[0];
post[0].srcAccessMask = 0x00000800u;
post[0].dstAccessMask = 0x00018000u;
post[0].oldLayout = 6u;
post[0].newLayout = src_lay;
post[1] = pre[1];
post[1].srcAccessMask = 0x00001000u;
post[1].dstAccessMask = 0x00018000u;
post[1].oldLayout = 7u;
post[1].newLayout = dst_lay;
c->CmdPipelineBarrier(cb, 0x00001000u /* TRANSFER */, 0x00010000u /* ALL_COMMANDS */, 0, 0, NULL, 0, NULL, 2, post);
return 1;
}
static int wl_seam_dispatch_or_blit(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *f) {
if (wl_seam_dispatch(c, cb, f)) return 1;
return wl_seam_fallback_blit(c, cb, f);
}
static int wl_seam_parse_backend_env(void) {
static const char *const names[] = {
"DROIDDECK_UPSCALE_BACKEND", "DROIDDECK_UPSCALE_ENGINE",
"WINLATOR_FSR4_BACKEND", "WINLATOR_FSR4_ENGINE", NULL,
};
char buf[64];
if (dd_env_first(names, buf, sizeof buf)) {
if (_stricmp(buf, "fsr3_gpu") == 0 || _stricmp(buf, "fsr3") == 0) return WL_FSR_BACKEND_FSR3_GPU;
if (_stricmp(buf, "sgsr2_gpu") == 0 || _stricmp(buf, "sgsr2") == 0 || _stricmp(buf, "snapdragon") == 0) return WL_FSR_BACKEND_SGSR2_GPU;
if (_stricmp(buf, "xess3_gpu") == 0 || _stricmp(buf, "xess3") == 0 || _stricmp(buf, "xess") == 0) return WL_FSR_BACKEND_XESS3_GPU;
if (_stricmp(buf, "fsr4_1_lite_npu") == 0 || _stricmp(buf, "fsr412_lite_npu") == 0) return WL_FSR_BACKEND_FSR4_1_LITE_NPU;
if (_stricmp(buf, "fsr4_1_full_npu") == 0 || _stricmp(buf, "fsr411_full_npu") == 0) return WL_FSR_BACKEND_FSR4_1_FULL_NPU;
if (_stricmp(buf, "fsr4_1_lite_gpu") == 0 || _stricmp(buf, "fsr412_lite_gpu") == 0) return WL_FSR_BACKEND_FSR4_1_LITE_GPU;
if (_stricmp(buf, "fsr4_1_full_gpu") == 0 || _stricmp(buf, "fsr411_full_gpu") == 0) return WL_FSR_BACKEND_FSR4_1_FULL_GPU;
if (_stricmp(buf, "fsr4_0_npu") == 0 || _stricmp(buf, "fsr4_npu") == 0 || _stricmp(buf, "fsr4") == 0) return WL_FSR_BACKEND_FSR4_1_FULL_NPU;
}
return WL_FSR_BACKEND_FSR4_1_FULL_NPU;
}
static int wl_seam_live_backend(const WlSeamClient *c, int *out_enabled) {
if (out_enabled) *out_enabled = 1;
if (c && c->ready && c->mbox) {
uint64_t ctrl = c->mbox->live_ctrl;
if (ctrl != 0ULL) {
if (out_enabled) *out_enabled = (ctrl & WLFSR4_CTRL_ENABLED_BIT) ? 1 : 0;
return (int)(ctrl & WLFSR4_CTRL_BACKEND_MASK);
}
}
return wl_seam_parse_backend_env();
}
static void wl_seam_telemetry_begin(WlSeamClient *c, VkCommandBuffer cb) {
if (!c || !c->ready || !cb || !c->CmdUpdateBuffer) return;
WlFsr4DoorbellPayload pay;
pay.magic = WLFSR4_TELEMETRY_MAGIC;
pay.seq = 0u;
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
}
static void wl_seam_telemetry_end(WlSeamClient *c, VkCommandBuffer cb, const WlFsr4FrameDesc *in_frame, uint32_t cpu_us) {
if (!c || !c->ready || !cb || !in_frame || !c->mbox || !c->CmdUpdateBuffer) return;
uint64_t seq = c->next_seq++;
if (seq == 0u) seq = c->next_seq++;
WlFsr4FrameDesc *slot = &c->mbox->slots[seq % WLFSR4_SLOTS];
*slot = *in_frame;
slot->seq = seq;
c->mbox->tele_gpu_us = cpu_us;
MemoryBarrier();
WlFsr4DoorbellPayload pay;
pay.magic = WLFSR4_TELEMETRY_MAGIC;
pay.seq = seq;
c->CmdUpdateBuffer(cb, c->marker_buf, 0, sizeof pay, &pay);
MemoryBarrier();
}