perf: bound local mosaic rendering and skip unused tracking grayscale

这个提交包含在:
mac 于 2026-11-08 17:56:14 +08:00 提交
1 父节点 f07b116398
当前提交 4b7e348ff5
11 个文件已更改
+129 -30

没有与搜索条件相匹配的文件

+12 -2
查看文件
@@ -24,7 +24,16 @@
if(!ok){if(raster)CFRelease(raster);CGImageRelease(cg);return nil;}
[boxes sortUsingComparator:^NSComparisonResult(NSArray *a,NSArray *b){NSComparisonResult x=[a[0]compare:b[0]];return x==NSOrderedSame?[a[1]compare:b[1]]:x;}];
std::vector<DYToolMaskEntry> entries;
for(NSArray *box in boxes){DYToolMaskEntry m{};m.section=-102;m.mask.parameters=dyDefaultMaskParameters();auto &p=m.mask.parameters;p.kind=DYMaskRectangle;p.centerX=[box[0]floatValue];p.centerY=[box[1]floatValue];p.width=[box[2]floatValue];p.height=[box[3]floatValue];p.feather=0;entries.push_back(m);}
for(NSArray *box in boxes){
DYToolMaskEntry m{};m.section=-102;m.mask.parameters=dyDefaultMaskParameters();
auto &p=m.mask.parameters;p.kind=DYMaskRectangle;
p.centerX=[box[0]floatValue];p.centerY=[box[1]floatValue];
p.width=[box[2]floatValue];p.height=[box[3]floatValue];p.feather=0;
constexpr float padding=1e-5f;
m.minX=p.centerX-p.width*.5f-padding;m.maxX=p.centerX+p.width*.5f+padding;
m.minY=p.centerY-p.height*.5f-padding;m.maxY=p.centerY+p.height*.5f+padding;
entries.push_back(m);
}
[_mosaicEntries release];_mosaicEntries=[[NSData alloc]initWithBytes:entries.data() length:entries.size()*sizeof(DYToolMaskEntry)];
[_mosaicRaster release];_mosaicRaster=raster?[(NSData*)raster copy]:nil;
}
@@ -46,10 +55,11 @@
if(!face&&!masks.count)return src;
NSMutableDictionary *entry=[self device:registry error:error];if(!entry)return nil;
NSData *faces=face?[self mosaicFaces:src time:tools[@"renderTime"] error:error]:nil;if(face&&!faces){fail(error,@"当前帧人脸识别失败,请重试或改用跟踪蒙版。");return nil;}
if(face&&!faces.length)return src;
DYToolMaskHeader header{};header.section=face?-102:0;
id<MTLDevice>device=entry[@"device"];id<MTLTexture>input=[src metalTextureForDevice:device];
NSData *skinEntries=_faceEntries;_faceEntries=faces;
id<MTLBuffer>buffer=[self maskBuffer:face?@{}:@{@"primary":masks} tile:src device:device header:&header];_faceEntries=skinEntries;
id<MTLBuffer>buffer=[self maskBuffer:face?@{}:@{@"primary":masks} tile:src device:device header:&header mosaic:YES];_faceEntries=skinEntries;
MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA32Float width:input.width height:input.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;
id<MTLTexture>output=[[device newTextureWithDescriptor:desc]autorelease];
id<MTLComputePipelineState>pipeline=[self computePipeline:@"dyLocalMosaic" entry:entry error:error];