// Nontrivial authoring and GPU regressions; runs as part of the signed CLI self-test. { DYToolDocument *empty=[[[DYToolDocument alloc]init]autorelease];NSMutableDictionary *doc=DYMutablePlist(empty.document); NSMutableDictionary *first=DYMutablePlist(DYNewTool(@"hsl")),*second=DYMutablePlist(DYNewTool(@"hsl"));doc[@"layers"]=[NSMutableArray arrayWithObjects:first,second,nil]; run.need(@"tool-document-two-independent-hsl",DYValidToolDocument(doc)&&![first[@"id"]isEqual:second[@"id"]]); first[@"values"][@"hsl0_0"]=@32;second[@"values"][@"hsl1_2"]=@55; DYToolDocument *authored=[[[DYToolDocument alloc]init]autorelease];authored.document=doc;NSData *archive=[NSKeyedArchiver archivedDataWithRootObject:authored requiringSecureCoding:YES error:&error];DYToolDocument *restored=[NSKeyedUnarchiver unarchivedObjectOfClass:DYToolDocument.class fromData:archive error:&error]; run.record(@"tool-document-secure-archive-roundtrip",[restored isEqual:authored]&&restored.hash==authored.hash); DYToolManager *one=[[[DYToolManager alloc]initWithHost:manager node:first]autorelease];DYWriteTools(manager,doc,kCMTimeZero);idaction=(id)one;[action startAction:one]; [(id)one setFloatValue:17 toParameter:2068 atTime:kCMTimeZero];[(id)one setFloatValue:26 toParameter:2076 atTime:kCMTimeZero];[action endAction:one];NSDictionary *written=DYReadTools(manager,kCMTimeZero).document; run.record(@"instance-proxy-batches-multiple-fields-without-clobber",[DYToolWithID(written,first[@"id"])[@"values"][@"hsl0_0"]isEqual:@17]&&[DYToolWithID(written,first[@"id"])[@"values"][@"hsl1_0"]isEqual:@26]&&[DYToolWithID(written,second[@"id"])[@"values"][@"hsl1_2"]isEqual:@55]); DYInspector *stackInspector=[[[DYInspector alloc]initWithAPIManager:manager renderer:renderer]autorelease];[stackInspector refresh];[stackInspector setFrameSize:NSMakeSize(360,780)];[stackInspector layoutSubtreeIfNeeded];NSDictionary *stackViews=[stackInspector valueForKey:@"_stackViews"];BOOL nativeViews=stackViews.count==2;for(NSString *ID in stackViews){NSArray *c=[stackViews[ID]valueForKey:@"_cards"];nativeViews&=c.count==1&&c[0][@"maskButton"]&&c[0][@"repeatButton"]&&[c[0][@"section"][@"key"]isEqual:@"hsl"];}run.record(@"two-native-hsl-panels-with-mask-and-repeat-buttons",nativeViews); NSMutableDictionary *invalid=DYMutablePlist(doc);invalid[@"layers"][1][@"id"]=first[@"id"];run.record(@"tool-document-rejects-duplicate-identity",!DYValidToolDocument(invalid));invalid=DYMutablePlist(doc);invalid[@"layers"][0][@"values"][@"hsl0_0"]=@(NAN);run.record(@"tool-document-rejects-nonfinite",!DYValidToolDocument(invalid)); NSMutableDictionary *mask=DYMutablePlist(DYNewMask(DYMaskRectangle));DYMaskParameters p=DYMaskAtTime(mask,kCMTimeZero);p.feather=0;p.width=.5;p.height=.5;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];CMTime a=CMTimeMake(1001,24000),b=CMTimeMake(2002,24000);DYMaskParameters moved=p;moved.centerX=.7;moved.width=.6;moved.angle=.2;mask[@"keys"]=@[DYMaskKey(a,p,YES,1),DYMaskKey(b,moved,NO,.9)]; DYMaskParameters mid=DYMaskAtTime(mask,CMTimeMake(3003,48000));run.record(@"mask-rational-time-interpolates-independent-geometry",fabs(mid.centerX-.6)<1e-6&&fabs(mid.width-.55)<1e-6&&fabs(mid.angle-.1)<1e-6); DYMaskParameters replacement=p;replacement.centerX=.8;BOOL merged=DYMergeTracking(mask,@[DYMaskKey(a,replacement,NO,.8),DYMaskKey(b,replacement,NO,.8)]);run.record(@"tracking-merge-preserves-manual-keys",merged&&fabs(DYMaskAtTime(mask,a).centerX-.5)<1e-6&&fabs(DYMaskAtTime(mask,b).centerX-.8)<1e-6); doc=DYMutablePlist(empty.document);doc[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:mask];NSDictionary *snapshot=DYToolRenderSnapshot(doc,CMTimeMake(3003,48000));DYMaskParameters resolved=DYMaskAtTime(snapshot[@"baseMasks"][@"hsl"][0],kCMTimeZero);run.record(@"render-snapshot-freezes-time-without-author-keys",[snapshot[@"baseMasks"][@"hsl"][0][@"keys"]count]==0&&fabs(resolved.centerX-.65)<1e-6&&[mask[@"keys"]count]==2); auto renderTools=[&](NSDictionary *tools,DYUniforms u,NSData *mesh,NSString *name){NSError *failure=nil;BOOL ok=[renderer renderSource:source destination:destination uniforms:u paths:@{} spider:mesh tools:tools error:&failure];run.need(name,ok,@{@"error":reason(failure)});return read(destination,gpu);}; [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; Pixels baseline=renderTools(empty.document,defaults,nil,@"empty-tool-document-render");run.record(@"empty-tool-document-preserves-legacy-pixels-exactly",difference(baseline,neutral).maximum==0); DYUniforms newPrimary=DYToolUniforms(DYNewTool(@"primary")),oldPrimary=DYToolUniforms(@{@"type":@"primary",@"values":@{}}); run.record(@"new-primary-layer-auto-mapping-on-old-omitted-default-stays-off",newPrimary.cm.toneMapping==1&&oldPrimary.cm.toneMapping==0); doc=DYMutablePlist(empty.document);for(NSString *type in DYToolTypes()){NSMutableDictionary *n=DYMutablePlist(DYNewTool(type));if([type isEqual:@"primary"])n[@"values"][@"cmtoneMapping"]=@0;[doc[@"layers"]addObject:n];}Pixels initialized=renderTools(doc,defaults,nil,@"all-initialized-tool-types-with-legacy-primary-mapping-render");run.record(@"legacy-neutral-repeated-tools-preserve-pixels",difference(initialized,neutral).maximum==0); // Reference is two explicit isolated native operations, which catches shared // uniform or lookup caches, ordering, repeated CST and accidental base replay. DYUniforms layerOne=DYToolUniforms(first),layerTwo=DYToolUniforms(second);render(run,renderer,source,destination,gpu,layerOne,@{},@"hsl-stack-first-reference");DYDiagnosticTile *intermediate=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease];Pixels single=read(destination,gpu);[[intermediate metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:single.data() bytesPerRow:width*8];Pixels expected=render(run,renderer,intermediate,destination,gpu,layerTwo,@{},@"hsl-stack-second-reference"); doc=DYMutablePlist(empty.document);doc[@"layers"]=[NSMutableArray arrayWithObjects:first,second,nil];Pixels actual=renderTools(doc,defaults,nil,@"two-hsl-stack-render");run.record(@"two-hsl-stack-matches-independent-sequential-reference",difference(expected,actual).maximum<.003&&difference(actual,single).different>20,measure(difference(expected,actual))); // A hard rectangle's exterior must match the bypassed tool and its interior // must match the active tool; alpha cannot change on either side. DYUniforms hu=defaults;hu.hslHueA.x=32;hu.skinProtection.x=0;Pixels unmasked=render(run,renderer,source,destination,gpu,hu,@{},@"mask-hsl-active-reference");DYUniforms off=hu;off.hslSectionEnabled=0;Pixels noHSL=render(run,renderer,source,destination,gpu,off,@{},@"mask-hsl-bypass-reference"); for(int kind=0;kind<6;kind++){@autoreleasepool{NSMutableDictionary *m=DYMutablePlist(DYNewMask(kind));DYMaskParameters params=DYMaskAtTime(m,kCMTimeZero);params.feather=0;params.width=.5;params.height=.5;params.angle=.21;if(kind==DYMaskLumaKey){params.inputBlack=.2;params.inputWhite=.8;}m[@"parameters"]=[NSData dataWithBytes:¶ms length:sizeof(params)];doc=DYMutablePlist(empty.document);doc[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:m];Pixels pixels=renderTools(doc,hu,nil,[NSString stringWithFormat:@"mask-type-%d-gpu",kind]);BOOL finite=difference(pixels,pixels).nonfinite==0,alpha=YES;for(NSUInteger i=0;i0))continue;float3 code;auto encode=[](float v){return v<=.0031308f?v*12.92f:1.055f*powf(MAX(0.f,v),1/2.4f)-.055f;};for(int c=0;c<3;c++)code[c]=encode((float)(__fp16)((float)input[index+c]/a));float coverage=dyMaskOperator((x+.5f)/width,(y+.5f)/height,code,params,path);for(int c=0;c<3;c++){float before=encode((float)noHSL[index+c]/a),after=encode((float)unmasked[index+c]/a),mixed=before+(after-before)*coverage;float expected=(mixed<=.04045f?mixed/12.92f:powf(MAX(0.f,(mixed+.055f)/1.055f),2.4f))*a;worst=MAX(worst,fabs(expected-(float)pixels[index+c]));}}run.record([NSString stringWithFormat:@"mask-type-%d-independent-cpu-coverage",kind],worst<.004,@{@"maximumError":@(worst)});}} mask=DYMutablePlist(DYNewMask(DYMaskRectangle));p=DYMaskAtTime(mask,kCMTimeZero);p.feather=0;p.width=p.height=.5;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];doc=DYMutablePlist(empty.document);doc[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:mask];actual=renderTools(doc,hu,nil,@"hsl-rectangle-isolated-render");BOOL region=YES;double maxRegion=0;for(NSUInteger y=0;y=width/4&&x=height/4&&y=width/4&&x=height/4&&y