diff --git a/tools/benchmark_default_preview.mm b/tools/benchmark_default_preview.mm index f7f760c..3f34f82 100644 --- a/tools/benchmark_default_preview.mm +++ b/tools/benchmark_default_preview.mm @@ -5,6 +5,7 @@ #import #include #include +#include @interface DYDiagnosticTile : FxImageTile - (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height; @end @@ -19,9 +20,13 @@ static NSUInteger faceCalls=0; @end int main(int argc,const char*argv[]){@autoreleasepool{ id gpu=MTLCreateSystemDefaultDevice();NSMutableArray *rows=[NSMutableArray array]; + NSBitmapImageRep *portrait=[NSBitmapImageRep imageRepWithContentsOfFile:@"tools/fixtures/astronaut.png"]; + std::vector<__fp16> face(512*512*3);for(int y=0;y<512;y++)for(int x=0;x<512;x++){NSColor*c=[[portrait colorAtX:x y:y]colorUsingColorSpace:NSColorSpace.sRGBColorSpace];float rgb[]={(float)c.redComponent,(float)c.greenComponent,(float)c.blueComponent};for(int k=0;k<3;k++){float v=rgb[k];face[(y*512+x)*3+k]=(__fp16)(v<=.04045?v/12.92:pow((v+.055)/1.055,2.4));}} 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;} @@ -29,7 +34,7 @@ int main(int argc,const char*argv[]){@autoreleasepool{ 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]; + for(size_t p=0;p=2)milliseconds.push_back((CACurrentMediaTime()-start)*1000); }} diff --git a/大鱼调色/Plugin/DYDiagnostics.mm b/大鱼调色/Plugin/DYDiagnostics.mm index 3058df9..c075408 100644 --- a/大鱼调色/Plugin/DYDiagnostics.mm +++ b/大鱼调色/Plugin/DYDiagnostics.mm @@ -188,6 +188,15 @@ static Pixels referenceFrame(id gpu,id library,const Pixe static float *field(DYUniforms *u,NSDictionary *row){return (float *)((uint8_t *)u+[row[@"offset"]unsignedIntegerValue]);} } +@interface DYRenderer (IdlePreviewProbe) +- (void)prepareFaceSupport:(FxImageTile*)source; +@end +@interface DYIdlePreviewProbe : DYRenderer { @public NSUInteger faceCalls; } +@end +@implementation DYIdlePreviewProbe +- (void)prepareFaceSupport:(FxImageTile*)source {faceCalls++;[super prepareFaceSupport:source];} +@end + extern "C" int DYRunDiagnostics(void) { @autoreleasepool { Run run;NSString *runtime=nil;NSString *gpuName=@"unavailable"; @try { @@ -335,6 +344,7 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool { defaults.cm.inputTransfer=1002;defaults.cm.inputGamut=22;defaults.cm.toneMapping=0; DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease];Pixels neutral=render(run,renderer,source,destination,gpu,defaults,@{},@"renderer-default-pass");Difference neutralDifference=difference(input,neutral); run.record(@"transparent-premultiplied-neutral",neutralDifference.nonfinite==0&&neutralDifference.maximum<=.001,measure(neutralDifference)); + #include "DYIdlePreviewDiagnostics.inc.h" NSString *cstReference=NSProcessInfo.processInfo.environment[@"DY_DIAGNOSTIC_CST_REFERENCE"]; if(cstReference.length){ error=nil;idoracle=[gpu newLibraryWithURL:[NSURL fileURLWithPath:cstReference] error:&error];run.need(@"independent-installed-cst-reference-loaded",oracle!=nil,@{@"path":cstReference,@"error":reason(error)}); diff --git a/大鱼调色/Plugin/DYFaceRender.inc.h b/大鱼调色/Plugin/DYFaceRender.inc.h index 746b33a..37c0c2c 100644 --- a/大鱼调色/Plugin/DYFaceRender.inc.h +++ b/大鱼调色/Plugin/DYFaceRender.inc.h @@ -35,7 +35,7 @@ [handler release];[request release];_faceEntries=[[NSData alloc]initWithBytes:entries.data() length:entries.size()*sizeof(DYToolMaskEntry)];[_faceCachedEntries release];_faceCachedEntries=[_faceEntries copy]; } - (BOOL)renderSource:(FxImageTile*)src destination:(FxImageTile*)dst uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider tools:(NSDictionary*)tools error:(NSError**)error {@synchronized(self){ - DYUniforms effective=u;bypassNeutralTools(&effective);bypassIdleSkin(&effective);BOOL face=effective.skinProtection.x>.5&&(u.skinFaceOnly>.5||u.skinVisualize>.5);for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);face|=[node[@"type"]isEqual:@"skin"]&&layer.skinProtection.x>.5&&layer.skinFaceOnly>.5;} + DYUniforms effective=DYEffectiveFaceUniforms(u,paths,tools);BOOL face=effective.skinProtection.x>.5&&(effective.skinProtection.y>0||effective.skinVisualize>.5)&&(effective.skinFaceOnly>.5||effective.skinVisualize>.5);for(NSDictionary *node in tools[@"layers"]){DYUniforms layer=DYToolUniforms(node);face|=[node[@"type"]isEqual:@"skin"]&&!DYToolIsNeutral(node)&&layer.skinProtection.x>.5&&(layer.skinFaceOnly>.5||layer.skinVisualize>.5);} if(face&&!_exporting)[self prepareFaceSupport:src];else{[_faceEntries release];_faceEntries=nil;} BOOL ok=[self renderToolsSource:src destination:dst uniforms:u paths:paths spider:spider tools:tools error:error]; return ok; diff --git a/大鱼调色/Plugin/DYIdlePreviewDiagnostics.inc.h b/大鱼调色/Plugin/DYIdlePreviewDiagnostics.inc.h new file mode 100644 index 0000000..df5d329 --- /dev/null +++ b/大鱼调色/Plugin/DYIdlePreviewDiagnostics.inc.h @@ -0,0 +1,24 @@ +// A fresh renderer must not detect faces or choose the polygon-mask shader +// merely because the untouched skin eye / face-only option is enabled. +{ + DYIdlePreviewProbe *probe=[[[DYIdlePreviewProbe alloc]init]autorelease]; + DYUniforms fresh;DYDefaultUniforms(&fresh);DYUniforms saved=fresh; + Pixels actual=render(run,probe,source,destination,gpu,fresh,@{},@"idle-preview-default-render"); + run.record(@"idle-preview-default-no-face-inference",probe->faceCalls==0); + BOOL masked=NO;for(NSDictionary *device in [[probe valueForKey:@"devices"]allValues])for(NSString *key in device[@"pipelines"])masked|=[key hasSuffix:@"-1-0"]; + run.record(@"idle-preview-default-no-polygon-mask-pipeline",!masked); + fresh.skinFaceOnly=0;Pixels reference=render(run,probe,source,destination,gpu,fresh,@{},@"idle-preview-reference-render"); + run.record(@"idle-preview-matches-neutral-with-face-option-off",difference(actual,reference).maximum<.002); + run.record(@"idle-preview-preserves-saved-default-controls",saved.skinFaceOnly==1&&saved.skinProtection.x==1&&saved.preLUTStrength==1&&saved.cm.blackWhiteMix==0); + fresh=saved;fresh.saturation=25;render(run,probe,source,destination,gpu,fresh,@{},@"idle-preview-active-color-render"); + run.record(@"idle-preview-active-color-still-detects-faces",probe->faceCalls==1); + fresh=saved;fresh.skinVisualize=1;render(run,probe,source,destination,gpu,fresh,@{},@"idle-preview-skin-selection-render"); + run.record(@"idle-preview-visualize-still-detects-faces",probe->faceCalls==2); + fresh=saved;fresh.lookSectionEnabled=0;render(run,probe,source,destination,gpu,fresh,@{@"look0":@"/unavailable/disabled.cube"},@"idle-preview-disabled-lut-render"); + run.record(@"idle-preview-disabled-lut-does-not-trigger-face-work",probe->faceCalls==2); + fresh=saved;fresh.cm.blackWhiteMix=.5;render(run,probe,source,destination,gpu,fresh,@{},@"idle-preview-blackwhite-render"); + run.record(@"idle-preview-active-blackwhite-still-detects-faces",probe->faceCalls==3); + fresh=saved;NSMutableDictionary *doc=DYMutablePlist(DYInitialToolDocument(nil));DYInsertTool(doc,@"skin",@"base:skin"); + NSError *idleError=nil;BOOL idleOK=[probe renderSource:source destination:destination uniforms:fresh paths:@{} spider:nil tools:doc error:&idleError]; + run.record(@"idle-preview-empty-extra-skin-does-not-trigger-face-work",idleOK&&probe->faceCalls==3); +} diff --git a/大鱼调色/Plugin/DYRenderer.mm b/大鱼调色/Plugin/DYRenderer.mm index 6287a2e..8f4a616 100644 --- a/大鱼调色/Plugin/DYRenderer.mm +++ b/大鱼调色/Plugin/DYRenderer.mm @@ -78,6 +78,22 @@ static void bypassIdleSkin(DYUniforms *u){ for(int i=0;i<13;i++){BOOL group=(i>=6&&i<=9)?u->colorSectionEnabled>.5:u->baseSectionEnabled>.5;if(group&&enabled[i]>.5&&values[i]!=0)return;} u->skinProtection.x=0; } +// Decide face work from the same effective operations that textures: and the +// legacy renderer actually execute. Saved strengths remain 1 for empty LUT +// slots, and B&W's eye remains on at a zero mix; neither changes the image. +static DYUniforms DYEffectiveFaceUniforms(DYUniforms u,NSDictionary *paths,NSDictionary *tools){ + DYApplyRemovedBaseTools(&u,tools); + paths=DYVisibleBaseToolPaths(paths,tools); + BOOL input=u.primarySectionEnabled>.5&&u.inputSectionEnabled>.5&&!managed(u,paths); + if(!input||(![paths[@"input"]length]&&u.inputProfile<.5))u.preLUTStrength=0; + for(int i=0;i<5;i++)if(u.lookSectionEnabled<.5||(i&&u.extraLookSectionEnableds[i-1]<.5)||![paths[[NSString stringWithFormat:@"look%d",i]]length]){ + if(i==0)u.postLUTStrength=0;else u.extraPostLUTStrengths[i-1]=0; + } + bypassNeutralTools(&u); + if(u.cm.blackWhiteMix<=0)u.blackWhiteSectionEnabled=0; + bypassIdleSkin(&u); + return u; +} // Admission and identity bypass for the explicitly bounded finishing domain. static NSArray *DYManagedActiveFinishing(DYUniforms u,NSDictionary *paths,NSData *spider,NSDictionary *tools){ bypassNeutralTools(&u);bypassIdleSkin(&u);if(u.cm.blackWhiteMix<=0)u.blackWhiteSectionEnabled=0; @@ -224,7 +240,8 @@ static NSArray *DYPrimaryActiveFinishing(DYUniforms u,NSDictionary *paths,NSData } if([e[@"spiderActive"]boolValue]){spiderBuffer=e[@"spiderBuffer"];spiderSize={ [e[@"spiderHues"]intValue],[e[@"spiderRings"]intValue]};} } - DYToolMaskHeader maskHeader{};idmaskBuffer=(masks.count||segmented||u.skinFaceOnly>.5||_faceEntries.length)?[self maskBuffer:masks tile:src device:d header:&maskHeader]:nil;maskHeader.faceOnly=u.skinFaceOnly>.5;BOOL hasMasks=maskHeader.count>0||maskHeader.faceOnly;if((hasMasks||segmented)&&!maskBuffer)return fail(err,@"无法分配蒙版缓冲区"); + BOOL faceOnly=u.skinProtection.x>.5&&(u.skinProtection.y>0||u.skinVisualize>.5)&&u.skinFaceOnly>.5; + DYToolMaskHeader maskHeader{};idmaskBuffer=(masks.count||segmented||faceOnly||_faceEntries.length)?[self maskBuffer:masks tile:src device:d header:&maskHeader]:nil;maskHeader.faceOnly=faceOnly;BOOL hasMasks=maskHeader.count>0||maskHeader.faceOnly;if((hasMasks||segmented)&&!maskBuffer)return fail(err,@"无法分配蒙版缓冲区"); NSMutableDictionary*ps=e[@"pipelines"];NSString*format=[NSString stringWithFormat:@"%lu-%d-%d",(unsigned long)output.pixelFormat,hasMasks,segmented];idpipeline=ps[format];if(!pipeline){MTLRenderPipelineDescriptor*p=[MTLRenderPipelineDescriptor new];p.vertexFunction=[e[@"library"]newFunctionWithName:@"dyVertex"];p.fragmentFunction=[e[@"library"]newFunctionWithName:segmented?@"dySegmentFragment":hasMasks?@"dyMaskedFragment":@"dyFragment"];p.colorAttachments[0].pixelFormat=output.pixelFormat;pipeline=[d newRenderPipelineStateWithDescriptor:p error:err];[p.vertexFunction release];[p.fragmentFunction release];[p release];if(!pipeline)return NO;ps[format]=pipeline;[pipeline release];} MTLTextureDescriptor*td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:input.width height:input.height mipmapped:NO];td.storageMode=MTLStorageModePrivate;td.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;idstraight=[d newTextureWithDescriptor:td];if(!straight)return fail(err,@"无法分配调色缓冲区"); idcb=[e[@"queue"]commandBuffer];idce=[cb computeCommandEncoder];[ce setComputePipelineState:e[@"dyUnpremultiply"]];[ce setTexture:input atIndex:0];[ce setTexture:straight atIndex:1];[ce dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[ce endEncoding]; diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index 73ea860..c5e6817 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType XPC! CFBundleShortVersionString - 1.19.0 + 1.19.1 CFBundleVersion - 109 + 110 NSHumanReadableCopyright PlugInKit diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 9380643..03a9f48 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.19.0 + 1.19.1 CFBundleVersion - 109 + 110 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright