fix: protect async preview lifetime and validate real canvas and spatial tools
这个提交包含在:
1 父节点
a3bd2ceb26
当前提交
1c3e294ce9
18 个文件已更改
+151
-45
没有与搜索条件相匹配的文件
@@ -0,0 +1,56 @@
|
||||
// Exercise actual OSC hit geometry, host writes and production Metal output.
|
||||
{
|
||||
DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,nil);
|
||||
DYToolCanvasProbe *host=[[[DYToolCanvasProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero;
|
||||
id<DYViewerParameterProbe>bridge=(id)[[NSClassFromString(@"DYViewerParameterBridge")alloc]initWithAPIManager:host];
|
||||
id<DYViewerControlsProbe>panel=(id)[NSClassFromString(@"DYViewerParameterPanel")new];panel.bridge=bridge;
|
||||
auto drain=[](){double until=NSProcessInfo.processInfo.systemUptime+.06;while(NSProcessInfo.processInfo.systemUptime<until)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.002]];};
|
||||
auto publish=[&](){DYUniforms u;DYReadUniforms(host,host->_time,&u);[bridge publishUniforms:&u document:DYReadTools(host,host->_time).document atTime:host->_time];[bridge publishAssets:DYReadAssets(host,host->_time)histogram:nil atTime:host->_time];[panel prepareWithSize:NSMakeSize(1280,720)scale:1 atTime:host->_time];};
|
||||
auto area=[&](NSString *kind)->NSDictionary*{for(NSDictionary*a in [(id)panel valueForKey:@"areas"])if([a[@"kind"]isEqual:kind])return [[a copy]autorelease];return nil;};
|
||||
auto drag=[&](NSPoint a,NSPoint b){[panel event:NSEventTypeLeftMouseDown point:a atTime:host->_time];[panel event:NSEventTypeLeftMouseDragged point:b atTime:host->_time];drain();[panel event:NSEventTypeLeftMouseUp point:b atTime:host->_time];drain();publish();};
|
||||
[(id)panel setValue:@"hsl" forKey:@"toolType"];publish();NSRect plot=[area(@"hslPlot")[@"rect"]rectValue];int undo=base->_undoStarts;
|
||||
NSPoint a=NSMakePoint(NSMinX(plot)+plot.size.width*2.5/8,NSMidY(plot)),b=NSMakePoint(a.x,NSMinY(plot)-40);drag(a,b);
|
||||
DYUniforms edited;DYReadUniforms(host,kCMTimeZero,&edited);run.record(@"canvas-hsl-plot-captures-outside-and-commits-one-undo",edited.hslHueA[2]==100&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
|
||||
NSMutableDictionary *doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);NSString *layerID=DYInsertTool(doc,@"hsl",@"base:hsl")[@"id"];DYWriteTools(host,doc,kCMTimeZero);publish();[(id)panel setValue:layerID forKey:@"nodeID"];publish();plot=[area(@"hslPlot")[@"rect"]rectValue];a=NSMakePoint(NSMinX(plot)+plot.size.width*2.5/8,NSMidY(plot));b=NSMakePoint(a.x,NSMidY(plot)-plot.size.height*.25);drag(a,b);DYReadUniforms(host,kCMTimeZero,&edited);
|
||||
run.record(@"canvas-hsl-independent-uuid-does-not-edit-base",edited.hslHueA[2]==100&&fabs([DYToolWithID(DYReadTools(host,kCMTimeZero).document,layerID)[@"values"][@"hsl0_2"]doubleValue]-50)<1e-5);
|
||||
[(id)panel setValue:@"spider" forKey:@"toolType"];publish();plot=[area(@"spiderPlot")[@"rect"]rectValue];auto mesh=dy::neutralMesh();int selected=dy::meshIndex(mesh,0,2);a=NSMakePoint(plot.origin.x+mesh.x[selected]*plot.size.width,plot.origin.y+mesh.y[selected]*plot.size.height);b=NSMakePoint(a.x+9,a.y-6);undo=base->_undoStarts;drag(a,b);
|
||||
NSData *saved=DYReadAssets(host,kCMTimeZero).spiderMesh;auto changed=DYSpiderMesh(saved);run.record(@"canvas-spider-drags-real-mesh-and-closes-one-undo",saved.length&&fabs(changed.x[selected]-mesh.x[selected])>.001&&base->_undoStarts==undo+1&&base->_undoEnds==undo+1);
|
||||
doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);NSString *spiderID=DYInsertTool(doc,@"spider",@"base:spider")[@"id"];DYWriteTools(host,doc,kCMTimeZero);publish();[(id)panel setValue:spiderID forKey:@"nodeID"];publish();plot=[area(@"spiderPlot")[@"rect"]rectValue];a=NSMakePoint(plot.origin.x+mesh.x[selected]*plot.size.width,plot.origin.y+mesh.y[selected]*plot.size.height);b=NSMakePoint(a.x-8,a.y+5);drag(a,b);
|
||||
run.record(@"canvas-spider-uuid-persists-mesh-without-touching-base",[saved isEqual:DYReadAssets(host,kCMTimeZero).spiderMesh]&&[DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"]length]>0);
|
||||
NSData *current=DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"];[bridge beginSpider:current node:spiderID enabled:1 atTime:kCMTimeZero];drain();doc=DYMutablePlist(DYReadTools(host,kCMTimeZero).document);auto external=dy::neutralMesh(12,12);NSData *externalData=[NSData dataWithBytes:&external length:sizeof(external)];((NSMutableDictionary*)DYToolWithID(doc,spiderID))[@"spider"]=externalData;DYWriteTools(host,doc,kCMTimeZero);[bridge changeSpider:current];[bridge endGesture];drain();
|
||||
run.record(@"canvas-spider-external-topology-change-wins",[DYToolWithID(DYReadTools(host,kCMTimeZero).document,spiderID)[@"spider"]isEqual:externalData]);
|
||||
DYHistogram hist{};hist.samples=1;hist.bins[1][100]=1;NSData *histData=[NSData dataWithBytes:&hist length:sizeof(hist)];[bridge publishHistogram:histData atTime:kCMTimeZero];run.record(@"canvas-histogram-is-frozen-to-matching-frame",[[bridge snapshotAtTime:kCMTimeZero][@"histogram"]isEqual:histData]&&![bridge snapshotAtTime:CMTimeMake(1,24)]);
|
||||
[panel finishCapture];panel.bridge=nil;[bridge invalidate];drain();[(id)panel release];[(id)bridge release];
|
||||
}
|
||||
{
|
||||
const NSUInteger w=64,h=48;DYDiagnosticTile *src=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease],*dst=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels grid(w*h*4);
|
||||
for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++){NSUInteger i=(y*w+x)*4;grid[i]=x/double(w-1)*.5;grid[i+1]=y/double(h-1)*.5;grid[i+2]=.1;grid[i+3]=1;}
|
||||
[[src metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h)mipmapLevel:0 withBytes:grid.data()bytesPerRow:w*8];DYRenderer *lens=[[[DYRenderer alloc]init]autorelease];DYUniforms u=DYToolUniforms(@{@"type":@"lens"});
|
||||
Pixels identity=render(run,lens,src,dst,gpu,u,@{},@"lens-neutral-production-render");run.record(@"lens-neutral-is-identity-with-existing-prefix",difference(identity,grid).maximum<.002&&offsetof(DYUniforms,lensSectionEnabled)==1312);
|
||||
u.lensStrength=80;Pixels positive=render(run,lens,src,dst,gpu,u,@{},@"lens-positive-production-render");u.lensStrength=-80;Pixels negative=render(run,lens,src,dst,gpu,u,@{},@"lens-negative-production-render");NSUInteger sample=(h/2*w+w*3/4)*4;
|
||||
run.record(@"lens-directions-move-source-in-opposite-directions",positive[sample]>identity[sample]&&negative[sample]<identity[sample]&&difference(positive,negative).maximum>.01);
|
||||
BOOL finite=YES,alpha=YES;for(NSUInteger i=0;i<w*h;i++){for(int c=0;c<4;c++)finite&=std::isfinite((float)positive[i*4+c])&&std::isfinite((float)negative[i*4+c]);alpha&=positive[i*4+3]>=0&&positive[i*4+3]<=1;}
|
||||
run.record(@"lens-keeps-finite-premultiplied-border-alpha",finite&&alpha&&positive[3]<1);
|
||||
double worst=0;for(NSUInteger y=4;y<h-4;y+=5)for(NSUInteger x=4;x<w-4;x+=7){double aspect=w/double(h),qx=(x+.5)/w-.5,qy=(y+.5)/h-.5,r2=(qx*qx*aspect*aspect+qy*qy)/(.25*(aspect*aspect+1)),sx=.5+qx*(1-.2*r2),sy=.5+qy*(1-.2*r2);double expectedX=(sx*w-.5)/(w-1)*.5,expectedY=(sy*h-.5)/(h-1)*.5;worst=MAX(worst,fabs((float)negative[(y*w+x)*4]-expectedX));worst=MAX(worst,fabs((float)negative[(y*w+x)*4+1]-expectedY));}
|
||||
run.record(@"lens-gpu-matches-independent-inverse-radial-oracle",worst<.003,@{@"maximumError":@(worst)});
|
||||
NSURL *cube=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"unsupported-lens.cube"]];NSError *failure=nil;run.record(@"lens-spatial-correction-is-refused-by-cube-export",![lens exportLUT:cube uniforms:u paths:@{}spider:nil tools:[[[DYToolDocument alloc]init]autorelease].document error:&failure]&&failure);
|
||||
}
|
||||
NSString *faceFixture=NSProcessInfo.processInfo.environment[@"DY_DIAGNOSTIC_FACE_FIXTURE"];
|
||||
if(faceFixture.length){
|
||||
NSBitmapImageRep *bitmap=[NSBitmapImageRep imageRepWithContentsOfFile:faceFixture];run.need(@"face-real-portrait-fixture-loaded",bitmap.pixelsWide==512&&bitmap.pixelsHigh==512);
|
||||
const NSUInteger w=512,h=512;DYDiagnosticTile *src=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease],*dst=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels portrait(w*h*4);
|
||||
auto linear=[](double c){return c<=.04045?c/12.92:pow((c+.055)/1.055,2.4);};
|
||||
for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++){NSColor *c=[[bitmap colorAtX:x y:y]colorUsingColorSpace:NSColorSpace.sRGBColorSpace];NSUInteger i=(y*w+x)*4;portrait[i]=linear(c.redComponent);portrait[i+1]=linear(c.greenComponent);portrait[i+2]=linear(c.blueComponent);portrait[i+3]=1;}
|
||||
// Same hue as a cheek, deliberately outside the face, must remain unprotected.
|
||||
for(NSUInteger y=400;y<480;y++)for(NSUInteger x=400;x<480;x++)for(int c=0;c<3;c++)portrait[(y*w+x)*4+c]=portrait[(115*w+220)*4+c];
|
||||
auto upload=[&](const Pixels& pixels){[[src metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h)mipmapLevel:0 withBytes:pixels.data()bytesPerRow:w*8];};upload(portrait);
|
||||
DYRenderer *face=[[[DYRenderer alloc]init]autorelease];DYUniforms u=DYToolUniforms(@{@"type":@"hsl"});u.hslHueA=(DYFloat4){40,40,40,40};u.hslHueB=(DYFloat4){40,40,40,40};u.skinProtection=(DYFloat3){1,100,28};u.skinFaceOnly=1;
|
||||
Pixels protectedFrame=render(run,face,src,dst,gpu,u,@{},@"face-protected-production-render");NSData *entries=[face valueForKey:@"faceEntries"];NSInteger faces=0;const DYToolMaskEntry *values=(const DYToolMaskEntry*)entries.bytes;for(NSUInteger i=0;i<entries.length/sizeof(*values);i++)faces+=values[i].section==-100;
|
||||
double faceX=0,faceY=0;for(NSUInteger i=0;i<entries.length/sizeof(*values);i++)if(values[i].section==-100){faceX=values[i].mask.parameters.centerX;faceY=values[i].mask.parameters.centerY;break;}run.record(@"face-vision-finds-real-portrait-and-builds-support",faces>=1,@{@"faces":@(faces),@"centerX":@(faceX),@"centerY":@(faceY)});u.skinProtection.x=0;Pixels unprotected=render(run,face,src,dst,gpu,u,@{},@"face-unprotected-reference-render");double inside=0,outside=0;
|
||||
for(NSUInteger y=65;y<185;y++)for(NSUInteger x=175;x<275;x++)for(int c=0;c<3;c++)inside=MAX(inside,fabs((float)protectedFrame[(y*w+x)*4+c]-(float)unprotected[(y*w+x)*4+c]));for(NSUInteger y=410;y<470;y++)for(NSUInteger x=410;x<470;x++)for(int c=0;c<3;c++)outside=MAX(outside,fabs((float)protectedFrame[(y*w+x)*4+c]-(float)unprotected[(y*w+x)*4+c]));
|
||||
run.record(@"face-protects-face-color-without-same-hue-background",inside>.005&&outside<.002,@{@"faceDifference":@(inside),@"backgroundDifference":@(outside)});
|
||||
u.skinProtection.x=1;u.skinVisualize=1;Pixels selection=render(run,face,src,dst,gpu,u,@{},@"face-actual-selection-preview-render");double white=0,black=0;for(NSUInteger y=65;y<185;y++)for(NSUInteger x=175;x<275;x++)white=MAX(white,(float)selection[(y*w+x)*4]);for(NSUInteger y=410;y<470;y++)for(NSUInteger x=410;x<470;x++)black=MAX(black,(float)selection[(y*w+x)*4]);
|
||||
double maximum=0;NSUInteger maxX=0,maxY=0;for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++)if(selection[(y*w+x)*4]>maximum){maximum=selection[(y*w+x)*4];maxX=x;maxY=y;}
|
||||
run.record(@"face-preview-shows-actual-weight-and-excludes-background",white>.01&&black<.001,@{@"faceWeight":@(white),@"backgroundWeight":@(black),@"maximum":@(maximum),@"maxX":@(maxX),@"maxY":@(maxY)});
|
||||
Pixels noFace(w*h*4);for(NSUInteger i=0;i<w*h;i++){noFace[i*4]=.35;noFace[i*4+1]=.18;noFace[i*4+2]=.1;noFace[i*4+3]=1;}upload(noFace);u.skinVisualize=0;Pixels noFaceProtected=render(run,face,src,dst,gpu,u,@{},@"face-none-protected-render");u.skinProtection.x=0;Pixels noFacePlain=render(run,face,src,dst,gpu,u,@{},@"face-none-unprotected-reference");run.record(@"face-no-detection-clears-prior-frame-and-fails-closed",difference(noFaceProtected,noFacePlain).maximum<.002);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户