Fix idle default face analysis and unnecessary polygon-mask rendering in 1.19.1
这个提交包含在:
1 父节点
b3597bb4e4
当前提交
3642a1dba6
7 个文件已更改
+63
-7
没有与搜索条件相匹配的文件
@@ -5,6 +5,7 @@
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
@interface DYDiagnosticTile : FxImageTile
|
||||
- (instancetype)initWithDevice:(id<MTLDevice>)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<MTLDevice> 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<height;y++)for(int x=0;x<width;x++){int p=(y*width+x)*4;pixels[p]=(__fp16)(.03+.8*x/width);pixels[p+1]=(__fp16)(.03+.6*y/height);pixels[p+2]=.2;pixels[p+3]=1;}
|
||||
for(int y=0;y<height;y++)for(int x=(width-height)/2;x<(width+height)/2;x++)for(int c=0;c<3;c++)pixels[(y*width+x)*4+c]=face[((y*512/height)*512+(x-(width-height)/2)*512/height)*3+c];
|
||||
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;}
|
||||
@@ -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<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);
|
||||
}}
|
||||
|
||||
@@ -188,6 +188,15 @@ static Pixels referenceFrame(id<MTLDevice> gpu,id<MTLLibrary> 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;id<MTLLibrary>oracle=[gpu newLibraryWithURL:[NSURL fileURLWithPath:cstReference] error:&error];run.need(@"independent-installed-cst-reference-loaded",oracle!=nil,@{@"path":cstReference,@"error":reason(error)});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+18
-1
@@ -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{};id<MTLBuffer>maskBuffer=(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{};id<MTLBuffer>maskBuffer=(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];id<MTLRenderPipelineState>pipeline=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;id<MTLTexture>straight=[d newTextureWithDescriptor:td];if(!straight)return fail(err,@"无法分配调色缓冲区");
|
||||
id<MTLCommandBuffer>cb=[e[@"queue"]commandBuffer];id<MTLComputeCommandEncoder>ce=[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];
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.19.0</string>
|
||||
<string>1.19.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>109</string>
|
||||
<string>110</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string></string>
|
||||
<key>PlugInKit</key>
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.19.0</string>
|
||||
<string>1.19.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>109</string>
|
||||
<string>110</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
在新工单中引用
屏蔽一个用户