From 90e512aabe72fff30046b4bf18d6a35f91c0c113 Mon Sep 17 00:00:00 2001 From: mac Date: Sun, 8 Nov 2026 16:15:11 +0800 Subject: [PATCH] perf: bound preview memory and reuse layer admission --- 大鱼调色/Plugin/DYRenderer.mm | 6 +----- 大鱼调色/Plugin/DYToolRender.inc.h | 11 ++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/大鱼调色/Plugin/DYRenderer.mm b/大鱼调色/Plugin/DYRenderer.mm index 53f0dae..84aac8a 100644 --- a/大鱼调色/Plugin/DYRenderer.mm +++ b/大鱼调色/Plugin/DYRenderer.mm @@ -309,11 +309,7 @@ struct DYScopeReadback { if(!direct){ MTLTextureDescriptor *td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:input.width height:input.height mipmapped:NO]; td.storageMode=MTLStorageModePrivate;td.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite; - straight=segmented?nil:e[@"legacyStraight"]; - if(straight.width!=input.width||straight.height!=input.height){ - straight=[[d newTextureWithDescriptor:td]autorelease]; - if(straight&&!segmented)e[@"legacyStraight"]=straight; - } + straight=[[d newTextureWithDescriptor:td]autorelease]; if(!straight)return fail(err,@"无法分配调色缓冲区"); MTLSize grid=MTLSizeMake(input.width,input.height,1),group=MTLSizeMake(16,16,1); BOOL fused=useCM&&!hasMasks; diff --git a/大鱼调色/Plugin/DYToolRender.inc.h b/大鱼调色/Plugin/DYToolRender.inc.h index 052812f..1067ad2 100644 --- a/大鱼调色/Plugin/DYToolRender.inc.h +++ b/大鱼调色/Plugin/DYToolRender.inc.h @@ -62,12 +62,17 @@ if(!tools)tools=@{@"schema":@1,@"layers":@[],@"baseMasks":@{}};if(!DYValidToolDocument(tools))return fail(error,@"工具或蒙版数据损坏,未更改原工程"); if(tools[@"sharedMasks"])tools=DYResolvedToolDocument(tools); DYApplyRemovedBaseTools(&u,tools);paths=DYVisibleBaseToolPaths(paths,tools);if(DYBaseToolRemoved(tools,@"spider"))spider=nil; - NSArray *layers=tools[@"layers"];BOOL active=NO,anchored=NO;for(NSDictionary *node in layers)if(!DYToolIsNeutral(node)){active=YES;anchored|=![DYToolRootAnchor(tools,node[@"id"])isEqual:@"tail"];} + NSMutableSet *activeIDs=nil;BOOL anchored=NO; + for(NSDictionary *node in tools[@"layers"])if(!DYToolIsNeutral(node)){ + if(!activeIDs)activeIDs=[NSMutableSet set]; + [activeIDs addObject:node[@"id"]]; + anchored|=![DYToolRootAnchor(tools,node[@"id"])isEqual:@"tail"]; + } // No active extra tool keeps the exact historical fused path, including HDR. - if(!active&&!DYChannelMixerActive(u)&&!DYFilmToolActive(u)&&(u.lensSectionEnabled<.5||(u.lensStrength==0&&u.lensScale==1)))return [self renderLegacy:src destination:dst uniforms:u paths:paths spider:spider masks:tools[@"baseMasks"] error:error]; + if(!activeIDs.count&&!DYChannelMixerActive(u)&&!DYFilmToolActive(u)&&(u.lensSectionEnabled<.5||(u.lensStrength==0&&u.lensScale==1)))return [self renderLegacy:src destination:dst uniforms:u paths:paths spider:spider masks:tools[@"baseMasks"] error:error]; NSMutableDictionary *entry=[self device:dst.deviceRegistryID error:error];if(!entry)return NO;idd=entry[@"device"];idinput=[src metalTextureForDevice:d];if(!input)return fail(error,@"宿主图像纹理不可用"); MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:input.width height:input.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageRenderTarget|MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite; - DYExportTile *tile=nil,*skinReference=nil,*originalReference=nil;NSArray *order=DYToolDisplayOrder(tools);NSMutableDictionary *groups=[NSMutableDictionary dictionary];for(NSString *ID in order){NSDictionary *node=DYToolWithID(tools,ID);if(!node||DYToolIsNeutral(node))continue;NSString *root=DYToolRootAnchor(tools,ID);if(!groups[root])groups[root]=[NSMutableArray array];[groups[root]addObject:node];} + DYExportTile *tile=nil,*skinReference=nil,*originalReference=nil;NSArray *order=DYToolDisplayOrder(tools);NSMutableDictionary *groups=[NSMutableDictionary dictionary];for(NSString *ID in order){if(![activeIDs containsObject:ID])continue;NSDictionary *node=DYToolWithID(tools,ID);NSString *root=DYToolRootAnchor(tools,ID);if(!groups[root])groups[root]=[NSMutableArray array];[groups[root]addObject:node];} auto makeTile=[&](){idtexture=[d newTextureWithDescriptor:desc];if(!texture)return (DYExportTile*)nil;DYExportTile *result=[[DYExportTile alloc]initWithTexture:texture registry:d.registryID];[result setBounds:src.tilePixelBounds origin:src.imageOrigin];[result setPixelAspect:src.pixelAspect];[texture release];return result;}; auto replace=[&](DYExportTile *next){[tile release];tile=next;}; auto apply=[&](NSString *anchor){for(NSDictionary *node in groups[anchor]){if(!DYRenderWithPool(error,[&]()->BOOL{DYExportTile *next=makeTile();if(!next)return fail(error,@"无法分配新增工具缓冲区");BOOL ok=[self renderExtraTool:node source:tile original:src destination:next entry:entry error:error];if(!ok){[next release];return NO;}replace(next);return YES;}))return NO;}return YES;};