fix: replay paused scopes and bound per-pixel face masks

这个提交包含在:
mac 于 2026-11-08 16:41:55 +08:00 提交
1 父节点 cdf6ddc1d7
当前提交 8a434b8e40
14 个文件已更改
+105 -52

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

+13 -5
查看文件
@@ -6,6 +6,7 @@
#include <algorithm>
#include <vector>
#include <cmath>
#import <CommonCrypto/CommonDigest.h>
@interface DYDiagnosticTile : FxImageTile
- (instancetype)initWithDevice:(id<MTLDevice>)device width:(NSUInteger)width height:(NSUInteger)height;
@end
@@ -13,12 +14,14 @@
- (void)prepareFaceSupport:(FxImageTile*)source;
@end
static NSUInteger faceCalls=0;
static double facePreparationMs=0;
@interface DYPreviewBenchmarkRenderer : DYRenderer
@end
@implementation DYPreviewBenchmarkRenderer
- (void)prepareFaceSupport:(FxImageTile*)source {faceCalls++;[super prepareFaceSupport:source];}
- (void)prepareFaceSupport:(FxImageTile*)source {faceCalls++;double start=CACurrentMediaTime();[super prepareFaceSupport:source];facePreparationMs+=(CACurrentMediaTime()-start)*1000;}
@end
int main(int argc,const char*argv[]){@autoreleasepool{
bool activeFace=argc>1&&strcmp(argv[1],"--active-face")==0;
id<MTLDevice> gpu=MTLCreateSystemDefaultDevice();NSMutableArray *rows=[NSMutableArray array];
NSBitmapImageRep *portrait=(NSBitmapImageRep*)[NSBitmapImageRep imageRepWithContentsOfFile:@"tools/fixtures/astronaut.png"];
if(portrait.pixelsWide!=512||portrait.pixelsHigh!=512){fputs("Missing 512x512 public portrait fixture\n",stderr);return 1;}
@@ -30,17 +33,22 @@ int main(int argc,const char*argv[]){@autoreleasepool{
const auto reference=pixels;
id<MTLTexture> input=[src metalTextureForDevice:gpu];[input replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:width*8];
for(int mode=0;mode<3;mode++){@autoreleasepool{
DYRenderer *renderer=[DYPreviewBenchmarkRenderer new];DYUniforms u;DYDefaultUniforms(&u);if(mode==1)u.skinFaceOnly=0;if(mode==2){u.skinProtection.x=0;u.skinFaceOnly=0;}
std::vector<double> milliseconds;NSUInteger before=faceCalls;NSError *error=nil;BOOL ok=YES;
DYRenderer *renderer=[DYPreviewBenchmarkRenderer new];DYUniforms u;DYDefaultUniforms(&u);if(activeFace){u=DYToolUniforms(@{@"type":@"hsl"});u.hslHueA=(DYFloat4){40,40,40,40};u.hslHueB=u.hslHueA;u.skinProtection=(DYFloat3){1,100,28};u.skinFaceOnly=1;}if(mode==1)u.skinFaceOnly=0;if(mode==2){u.skinProtection.x=0;u.skinFaceOnly=0;}
facePreparationMs=0;std::vector<double> milliseconds;NSUInteger before=faceCalls;NSError *error=nil;BOOL ok=YES;
for(int i=0;i<14;i++){@autoreleasepool{
// A different real input each frame prevents the face raster cache from
// disguising unnecessary inference as a still-frame-only workload.
for(size_t p=0;p<pixels.size();p++)pixels[p]=p%4==3?reference[p]:(__fp16)(reference[p]*(.92+i*.01));[input replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:width*8];
double start=CACurrentMediaTime();ok=[renderer renderSource:src destination:dst uniforms:u paths:@{} spider:nil tools:nil colorManagement:nil hostPrimaries:-1 error:&error];
if(!ok){fprintf(stderr,"%s\n",error.description.UTF8String);return 1;}if(i>=2)milliseconds.push_back((CACurrentMediaTime()-start)*1000);
if(!ok){fprintf(stderr,"%s\n",error.description.UTF8String);return 1;}if(i==1)facePreparationMs=0;if(i>=2)milliseconds.push_back((CACurrentMediaTime()-start)*1000);
}}
std::sort(milliseconds.begin(),milliseconds.end());double sum=0;for(double v:milliseconds)sum+=v;
[rows addObject:@{@"width":@(width),@"height":@(height),@"mode":@[@"default",@"faceOnlyOff",@"skinOff"][mode],@"frames":@(milliseconds.size()),@"meanMs":@(sum/milliseconds.size()),@"medianMs":@(milliseconds[milliseconds.size()/2]),@"maxMs":@(milliseconds.back()),@"faceCalls":@(faceCalls-before)}];[renderer release];
id<MTLTexture> output=[dst metalTextureForDevice:gpu];
[output getBytes:pixels.data() bytesPerRow:width*8 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0];
unsigned char digest[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(pixels.data(),(CC_LONG)(pixels.size()*sizeof(__fp16)),digest);
NSMutableString *hash=[NSMutableString string];for(unsigned char byte:digest)[hash appendFormat:@"%02x",byte];
[rows addObject:@{@"width":@(width),@"height":@(height),@"mode":@[activeFace?@"faceOnly":@"default",@"faceOnlyOff",@"skinOff"][mode],@"outputSHA256":hash,@"meanFacePreparationMs":@(facePreparationMs/milliseconds.size()),@"frames":@(milliseconds.size()),@"meanMs":@(sum/milliseconds.size()),@"medianMs":@(milliseconds[milliseconds.size()/2]),@"maxMs":@(milliseconds.back()),@"faceCalls":@(faceCalls-before)}];[renderer release];
}}[src release];[dst release];
}}
NSData *json=[NSJSONSerialization dataWithJSONObject:@{@"gpu":gpu.name,@"cases":rows} options:NSJSONWritingPrettyPrinted error:nil];fwrite(json.bytes,1,json.length,stdout);puts("");[gpu release];return 0;
+8 -4
查看文件
@@ -2,13 +2,15 @@
"""Link a headless benchmark against existing Release objects and run it."""
from pathlib import Path
import argparse, plistlib, subprocess
p=argparse.ArgumentParser();p.add_argument('--output',type=Path,required=True);a=p.parse_args()
p=argparse.ArgumentParser();p.add_argument('--output',type=Path,required=True);p.add_argument('--resources',type=Path);p.add_argument('--active-face',action='store_true');a=p.parse_args()
root=Path(__file__).resolve().parent.parent
cache=Path('/Users/mac/Library/Caches/CodexBuilds/com.dayu.color')
objects=cache/'DerivedData/Build/Intermediates.noindex/大鱼调色.build/Release/XPC Service.build/Objects-normal/arm64'
work=cache/'performance-1.19.1/benchmark.bundle/Contents';(work/'MacOS').mkdir(parents=True,exist_ok=True)
resources=Path('/Library/Plug-Ins/FxPlug/大鱼调色.app/Contents/PlugIns/大鱼调色 XPC Service.pluginkit/Contents/Resources')
if not (work/'Resources').exists():(work/'Resources').symlink_to(resources)
resources=a.resources or Path('/Library/Plug-Ins/FxPlug/大鱼调色.app/Contents/PlugIns/大鱼调色 XPC Service.pluginkit/Contents/Resources')
resource_link=work/'Resources'
if resource_link.is_symlink():resource_link.unlink()
resource_link.symlink_to(resources.resolve(strict=True))
(work/'Info.plist').write_bytes(plistlib.dumps({'CFBundleExecutable':'benchmark','CFBundleIdentifier':'com.dayu.color.headless-benchmark','CFBundlePackageType':'BNDL'}))
cmd=['xcrun','clang++','-std=c++17','-O2','-mmacosx-version-min=14.6','-fno-objc-arc','-F/Library/Developer/SDKs/FxPlug.sdk/Library/Frameworks','-F/Library/Developer/Frameworks',str(root/'tools/benchmark_default_preview.mm')]
cmd += [str(x) for x in objects.glob('*.o') if x.name!='main.o' and not x.name.endswith('_lto.o')]
@@ -16,5 +18,7 @@ cmd += ['@'+str(cache/'cms-runtime/bridge-link.rsp')]
for f in ['Metal','MetalPerformanceShaders','Vision','QuartzCore','Accelerate','PluginManager','Foundation','AppKit','FxPlug','Security','CoreVideo','IOSurface','CoreMedia','CoreImage','CoreGraphics','ImageIO','UniformTypeIdentifiers','AVFoundation']:cmd+=['-framework',f]
cmd+=['-lcompression','-lz','-Wl,-rpath,/Library/Developer/Frameworks','-o',str(work/'MacOS/benchmark')]
subprocess.run(cmd,check=True,cwd=root)
with a.output.open('w') as out:subprocess.run([str(work/'MacOS/benchmark')],stdout=out,check=True,cwd=root)
benchmark=[str(work/'MacOS/benchmark')]
if a.active_face:benchmark.append('--active-face')
with a.output.open('w') as out:subprocess.run(benchmark,stdout=out,check=True,cwd=root)
print(a.output)