From b3597bb4e4db637cb7c4afb4926986e3d43e3e17 Mon Sep 17 00:00:00 2001 From: mac Date: Fri, 6 Nov 2026 20:44:00 +0800 Subject: [PATCH] Add reproducible default-preview benchmark before renderer fix --- tools/benchmark_default_preview.mm | 41 ++++++++++++++++++++++++++++++ tools/benchmark_default_preview.py | 20 +++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tools/benchmark_default_preview.mm create mode 100644 tools/benchmark_default_preview.py diff --git a/tools/benchmark_default_preview.mm b/tools/benchmark_default_preview.mm new file mode 100644 index 0000000..f7f760c --- /dev/null +++ b/tools/benchmark_default_preview.mm @@ -0,0 +1,41 @@ +// Headless renderer benchmark. Link against the reviewed Release objects; never +// registers a plug-in, opens a host, or reads user media. Resources are read-only. +#import "../大鱼调色/Plugin/DYRenderer.h" +#import "../大鱼调色/Plugin/DYModel.h" +#import +#include +#include +@interface DYDiagnosticTile : FxImageTile +- (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height; +@end +@interface DYRenderer (PerformanceProbe) +- (void)prepareFaceSupport:(FxImageTile*)source; +@end +static NSUInteger faceCalls=0; +@interface DYPreviewBenchmarkRenderer : DYRenderer +@end +@implementation DYPreviewBenchmarkRenderer +- (void)prepareFaceSupport:(FxImageTile*)source {faceCalls++;[super prepareFaceSupport:source];} +@end +int main(int argc,const char*argv[]){@autoreleasepool{ + id gpu=MTLCreateSystemDefaultDevice();NSMutableArray *rows=[NSMutableArray array]; + for(int width:{1920,3840}){@autoreleasepool{ + int height=width*9/16;DYDiagnosticTile *src=[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height],*dst=[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]; + std::vector<__fp16> pixels(width*height*4);for(int y=0;y 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 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. + pixels[0]=(__fp16)(.05+i*.01);[input replaceRegion:MTLRegionMake2D(0,0,1,1) mipmapLevel:0 withBytes:pixels.data() bytesPerRow: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); + }} + 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]; + }}[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; +}} diff --git a/tools/benchmark_default_preview.py b/tools/benchmark_default_preview.py new file mode 100644 index 0000000..f0c9f70 --- /dev/null +++ b/tools/benchmark_default_preview.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""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() +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) +(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')] +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) +print(a.output)