#import "DYDiagnostics.h" #import "DYModel.h" #import "DYRenderer.h" #import "DYAutoGrade.h" #import "DYLUTLibrary.h" #include #import #import #include #include #include #include #include // Fake host objects implement the real selectors used by the model and renderer. // They never connect to a host document or enter the FxPrincipal service loop. @interface DYDiagnosticManager : NSObject { @public NSMutableDictionary *_values,*_custom; BOOL _duplicate; } @end @implementation DYDiagnosticManager - (instancetype)init {if((self=[super init])){_values=[NSMutableDictionary new];_custom=[NSMutableDictionary new];}return self;} - (void)dealloc {[_values release];[_custom release];[super dealloc];} - (id)apiForProtocol:(Protocol *)protocol { NSString *name=NSStringFromProtocol(protocol); return [@[@"FxParameterCreationAPI_v5",@"FxParameterRetrievalAPI_v6",@"FxParameterSettingAPI_v6"]containsObject:name]?self:nil; } - (BOOL)addFloatSliderWithName:(NSString *)name parameterID:(UInt32)pid defaultValue:(double)value parameterMin:(double)minimum parameterMax:(double)maximum sliderMin:(double)sliderMinimum sliderMax:(double)sliderMaximum delta:(double)delta parameterFlags:(FxParameterFlags)flags { if(_values[@(pid)]||_custom[@(pid)]){_duplicate=YES;return NO;}_values[@(pid)]=@(value);return YES; } - (BOOL)addCustomParameterWithName:(NSString *)name parameterID:(UInt32)pid defaultValue:(NSObject *)value parameterFlags:(FxParameterFlags)flags { if(_values[@(pid)]||_custom[@(pid)]){_duplicate=YES;return NO;}_custom[@(pid)]=value;return YES; } - (BOOL)getFloatValue:(double *)value fromParameter:(UInt32)pid atTime:(CMTime)time { NSNumber *stored=_values[@(pid)];if(!stored)return NO;if(value)*value=stored.doubleValue;return YES; } - (BOOL)setFloatValue:(double)value toParameter:(UInt32)pid atTime:(CMTime)time { if(!_values[@(pid)])return NO;_values[@(pid)]=@(value);return YES; } - (BOOL)getCustomParameterValue:(NSObject **)value fromParameter:(UInt32)pid atTime:(CMTime)time { id stored=_custom[@(pid)];if(!stored)return NO;if(value)*value=stored;return YES; } - (BOOL)setCustomParameterValue:(NSObject *)value toParameter:(UInt32)pid atTime:(CMTime)time { if(!_custom[@(pid)]||!value)return NO;_custom[@(pid)]=[[value copy]autorelease];return YES; } @end @interface DYDiagnosticTile : FxImageTile { id _texture; IOSurfaceRef _surface; FxRect _bounds; uint64_t _registry; FxImageOrigin _diagnosticOrigin; } - (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height; - (void)setDiagnosticImageOrigin:(FxImageOrigin)origin; @end @implementation DYDiagnosticTile - (instancetype)initWithDevice:(id)device width:(NSUInteger)width height:(NSUInteger)height { if((self=[super init])) { NSDictionary *properties=@{(id)kIOSurfaceWidth:@(width),(id)kIOSurfaceHeight:@(height), (id)kIOSurfaceBytesPerElement:@8,(id)kIOSurfaceBytesPerRow:@(width*8), (id)kIOSurfacePixelFormat:@(kCVPixelFormatType_64RGBAHalf)}; _surface=IOSurfaceCreate((CFDictionaryRef)properties); MTLTextureDescriptor *d=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO]; d.storageMode=MTLStorageModeShared;d.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget; if(_surface)_texture=[device newTextureWithDescriptor:d iosurface:_surface plane:0]; _bounds=(FxRect){0,0,(SInt32)width,(SInt32)height};_registry=device.registryID;_diagnosticOrigin=kFxImageOrigin_TOP_LEFT; if(!_surface||!_texture){[self release];return nil;} }return self; } - (void)dealloc {[_texture release];if(_surface)CFRelease(_surface);[super dealloc];} - (id)metalTextureForDevice:(id)device {return device.registryID==_registry?_texture:nil;} - (IOSurface *)ioSurface {return (IOSurface *)_surface;} - (FxRect)tilePixelBounds {return _bounds;} - (FxRect)imagePixelBounds {return _bounds;} - (uint64_t)deviceRegistryID {return _registry;} - (FxImageOrigin)imageOrigin {return _diagnosticOrigin;} - (void)setDiagnosticImageOrigin:(FxImageOrigin)origin {_diagnosticOrigin=origin;} @end namespace { using Pixels=std::vector<__fp16>; struct Run { NSMutableArray *rows=[NSMutableArray array]; bool passed=true; void record(NSString *name,bool ok,NSDictionary *details=nil) { NSMutableDictionary *row=[NSMutableDictionary dictionaryWithDictionary:details?:@{}]; row[@"name"]=name;row[@"pass"]=@(ok);[rows addObject:row];if(!ok)passed=false; } void need(NSString *name,bool ok,NSDictionary *details=nil) { record(name,ok,details);if(!ok)@throw [NSException exceptionWithName:@"DYDiagnosticStop" reason:name userInfo:nil]; } }; static NSString *reason(NSError *error) {return error.localizedDescription?:@"未提供错误信息";} static Pixels read(DYDiagnosticTile *tile,id gpu) { id texture=[tile metalTextureForDevice:gpu];Pixels output(texture.width*texture.height*4); [texture getBytes:output.data() bytesPerRow:texture.width*8 fromRegion:MTLRegionMake2D(0,0,texture.width,texture.height) mipmapLevel:0];return output; } struct Difference {double maximum=0;size_t different=0,nonfinite=0,nonzero=0;}; static Difference difference(const Pixels& a,const Pixels& b) { Difference found;if(a.size()!=b.size()){found.nonfinite=1;return found;} for(size_t i=0;i1e-5)found.different++;if(y!=0)found.nonzero++;}return found; } static NSDictionary *measure(Difference d) {return @{@"maxAbsoluteError":@(d.maximum),@"changedComponents":@(d.different),@"nonfiniteComponents":@(d.nonfinite),@"nonzeroComponents":@(d.nonzero)};} static Pixels render(Run& run,DYRenderer *renderer,DYDiagnosticTile *source,DYDiagnosticTile *destination,id gpu,DYUniforms uniforms,NSDictionary *paths,NSString *name) { NSError *error=nil;BOOL ok=[renderer renderSource:source destination:destination uniforms:uniforms paths:paths error:&error]; run.need(name,ok,@{@"error":ok?@"":reason(error)});return read(destination,gpu); } static float *field(DYUniforms *u,NSDictionary *row){return (float *)((uint8_t *)u+[row[@"offset"]unsignedIntegerValue]);} } extern "C" int DYRunDiagnostics(void) { @autoreleasepool { Run run;NSString *runtime=nil;NSString *gpuName=@"unavailable"; @try { NSError *error=nil; runtime=[@"/Users/mac/Library/Caches/CodexBuilds/com.dayu.color/verification-runtime" stringByAppendingPathComponent:NSUUID.UUID.UUIDString]; run.need(@"runtime-directory",[[NSFileManager defaultManager]createDirectoryAtPath:runtime withIntermediateDirectories:YES attributes:nil error:&error],@{@"path":runtime,@"error":reason(error)}); NSArray *descriptors=DYDescriptors(),*sections=DYSections();NSMutableSet *pids=[NSMutableSet set],*offsets=[NSMutableSet set],*keys=[NSMutableSet set];bool schema=true; for(NSDictionary *row in descriptors){NSInteger offset=[row[@"offset"]integerValue];NSNumber *pid=row[@"pid"];bool metadata=offset==-1&&pid.unsignedIntValue==8800&&[row[@"key"]isEqual:@"copyAutoGrade"];schema&=(metadata||(offset>=0&&offset%4==0&&offset+4<=sizeof(DYUniforms)&&pid.unsignedIntValue==2000+offset/4&&![offsets containsObject:row[@"offset"]]))&&![pids containsObject:pid]&&![keys containsObject:row[@"key"]];[pids addObject:pid];if(offset>=0)[offsets addObject:row[@"offset"]];[keys addObject:row[@"key"]];} run.need(@"descriptor-unique-id-offset-key",schema,@{@"descriptors":@(descriptors.count),@"sections":@(sections.count),@"uniformBytes":@(sizeof(DYUniforms))}); DYUniforms defaults;DYDefaultUniforms(&defaults);bool finite=true,matches=true; // SIMD float3 has a fourth ABI lane that is padding, not a semantic // value. Check every represented control and every matrix component. for(NSDictionary *row in descriptors)if([row[@"offset"]integerValue]>=0){float value=*field(&defaults,row);finite&=std::isfinite(value);matches&=value==[row[@"default"]floatValue];} for(int c=0;c<3;c++)finite&=std::isfinite(defaults.primariesM0[c])&&std::isfinite(defaults.primariesM1[c])&&std::isfinite(defaults.primariesM2[c]); run.need(@"finite-real-model-defaults",finite&&matches); bool initialGroups=true; for(NSDictionary *section in sections){BOOL base=[@[@"base",@"color"]containsObject:section[@"key"]];for(NSDictionary *row in descriptors)if([row[@"pid"]isEqual:section[@"enabled"]])initialGroups&=([row[@"default"]doubleValue]>=.5)==base;} run.record(@"only-basic-adjustments-enabled-by-default",initialGroups); DYDiagnosticManager *manager=[[[DYDiagnosticManager alloc]init]autorelease];error=nil; run.need(@"native-parameter-creation",DYCreateParameters(manager,&error)&&!manager->_duplicate&&manager->_values.count==descriptors.count&&manager->_custom.count==2,@{@"error":reason(error)}); id setter=[manager apiForProtocol:@protocol(FxParameterSettingAPI_v6)];id getter=[manager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]; [setter setFloatValue:.75 toParameter:2000 atTime:kCMTimeZero];double value=0;[getter getFloatValue:&value fromParameter:2000 atTime:kCMTimeZero];DYUniforms restored;DYReadUniforms(manager,kCMTimeZero,&restored); run.record(@"native-get-set-model-roundtrip",value==.75&&restored.exposure==.75f); [setter setFloatValue:999 toParameter:2000 atTime:kCMTimeZero];DYReadUniforms(manager,kCMTimeZero,&restored);run.record(@"model-clamps-host-out-of-range",restored.exposure==5); [setter setFloatValue:NAN toParameter:2000 atTime:kCMTimeZero];DYReadUniforms(manager,kCMTimeZero,&restored);run.record(@"model-rejects-host-nonfinite",restored.exposure==defaults.exposure); DYAssetState *assets=[[[DYAssetState alloc]init]autorelease];assets.paths=@{@"input":[runtime stringByAppendingPathComponent:@"input.cube"],@"look0":[runtime stringByAppendingPathComponent:@"look.cube"]}; error=nil;NSData *archive=[NSKeyedArchiver archivedDataWithRootObject:assets requiringSecureCoding:YES error:&error];DYAssetState *decoded=archive?[NSKeyedUnarchiver unarchivedObjectOfClass:DYAssetState.class fromData:archive error:&error]:nil; run.record(@"secure-asset-archive-roundtrip",decoded&&[assets isEqual:decoded],@{@"archiveBytes":@(archive.length),@"error":reason(error)}); BOOL wrote=DYWriteAssets(manager,assets,kCMTimeZero);DYAssetState *readBack=DYReadAssets(manager,kCMTimeZero);run.record(@"native-custom-asset-get-set",wrote&&[readBack isEqual:assets]); DYAssetState *copy=[[assets copy]autorelease];copy.paths=@{};run.record(@"asset-copy-is-independent",assets.paths.count==2&©.paths.count==0); id gpu=MTLCreateSystemDefaultDevice();run.need(@"metal-device",gpu!=nil);gpuName=gpu.name; const NSUInteger width=64,height=48;DYDiagnosticTile *source=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease],*destination=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:width height:height]autorelease]; run.need(@"real-iosurface-image-tiles",source&&destination&&source.ioSurface&&destination.ioSurface); Pixels input(width*height*4);for(NSUInteger y=0;yp[2]&&p[(179*320)*4+2]>p[(179*320)*4];} run.record(@"look-preview-top-left-is-original-analysis",topOrientation,@{@"error":topRendered?@"":reason(error),@"bytes":@(topLook.length)}); [orientationRenderer invalidatePreview];[source setDiagnosticImageOrigin:kFxImageOrigin_BOTTOM_LEFT]; [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:bottomFirst.data() bytesPerRow:width*8]; error=nil;BOOL bottomRendered=[orientationRenderer renderSource:source destination:destination uniforms:defaults paths:@{} error:&error]; NSData *bottomAnalysis=[orientationRenderer preview],*bottomLook=[orientationRenderer lookLUTPreview]; bool bottomOrientation=bottomRendered&&bottomAnalysis.length==320*180*16&&bottomLook.length==bottomAnalysis.length; if(bottomOrientation){ const float*a=(const float*)bottomAnalysis.bytes,*b=(const float*)bottomLook.bytes; bottomOrientation=a[2]>a[0]&&a[(179*320)*4]>a[(179*320)*4+2]&&b[0]>b[2]&&b[(179*320)*4+2]>b[(179*320)*4]; for(NSUInteger y=0;y<180&&bottomOrientation;y++)bottomOrientation=memcmp((const uint8_t*)bottomLook.bytes+y*320*16,(const uint8_t*)bottomAnalysis.bytes+(179-y)*320*16,320*16)==0; } run.record(@"look-preview-bottom-left-flips-only-browser-rows",bottomOrientation,@{@"error":bottomRendered?@"":reason(error),@"analysisKeepsPhysicalRowOrder":@(bottomOrientation),@"all180RowsCompared":@(bottomOrientation)}); [orientationRenderer invalidatePreview];run.record(@"preview-invalidation-clears-analysis-and-browser",![orientationRenderer preview]&&![orientationRenderer lookLUTPreview]); [source setDiagnosticImageOrigin:kFxImageOrigin_TOP_LEFT]; [[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*8]; DYUniforms u=defaults;u.exposure=.8f;Pixels exposed=render(run,renderer,source,destination,gpu,u,@{},@"renderer-exposure-pass");Difference exposureDifference=difference(neutral,exposed);run.record(@"exposure-affects-actual-frame",exposureDifference.nonfinite==0&&exposureDifference.different>100,measure(exposureDifference)); u.baseSectionEnabled=0;Pixels bypass=render(run,renderer,source,destination,gpu,u,@{},@"renderer-base-bypass-pass");Difference bypassDifference=difference(neutral,bypass);run.record(@"base-group-bypass",bypassDifference.nonfinite==0&&bypassDifference.maximum==0,measure(bypassDifference)); u=defaults;u.temperature=35;u.tint=-20;Pixels wb=render(run,renderer,source,destination,gpu,u,@{},@"renderer-white-balance-pass");Difference wbDifference=difference(neutral,wb);run.record(@"white-balance-real-table-frame",wbDifference.nonfinite==0&&wbDifference.different>100,measure(wbDifference)); u.colorSectionEnabled=0;bypass=render(run,renderer,source,destination,gpu,u,@{},@"renderer-color-bypass-pass");bypassDifference=difference(neutral,bypass);run.record(@"color-group-bypass",bypassDifference.nonfinite==0&&bypassDifference.maximum==0,measure(bypassDifference)); u=defaults;u.hslSectionEnabled=1;u.hslHueA.x=28;u.hslSatA.y=45;u.hslLumB.z=-18;Pixels hsl=render(run,renderer,source,destination,gpu,u,@{},@"renderer-hsl-pass");Difference hslDifference=difference(neutral,hsl);run.record(@"hsl-real-table-frame",hslDifference.nonfinite==0&&hslDifference.different>100,measure(hslDifference)); checkFoldedGroup(u,offsetof(DYUniforms,hslSectionEnabled),@{},@"folded-hsl-bypasses-retained-adjustments"); u=defaults;u.colorGradingSectionEnabled=1;u.colorGradingHueSatA.x=210;u.colorGradingHueSatA.y=42;u.colorGradingLuma.x=18;Pixels grading=render(run,renderer,source,destination,gpu,u,@{},@"renderer-grading-pass");Difference gradingDifference=difference(neutral,grading);run.record(@"grading-real-table-frame",gradingDifference.nonfinite==0&&gradingDifference.different>100,measure(gradingDifference)); checkFoldedGroup(u,offsetof(DYUniforms,colorGradingSectionEnabled),@{},@"folded-grading-bypasses-retained-adjustments"); for(int profile=1;profile<=17;profile++){@autoreleasepool{u=defaults;u.inputSectionEnabled=1;u.inputProfile=profile;Pixels transformed=render(run,renderer,source,destination,gpu,u,@{},[NSString stringWithFormat:@"input-profile-%02d-load-render",profile]);Difference delta=difference(neutral,transformed);run.record([NSString stringWithFormat:@"input-profile-%02d-finite-nonzero",profile],delta.nonfinite==0&&delta.nonzero>100,measure(delta));}} checkFoldedGroup(u,offsetof(DYUniforms,inputSectionEnabled),@{},@"folded-input-bypasses-retained-profile"); DYRenderer *analysisRenderer=[[[DYRenderer alloc]init]autorelease];u=defaults;u.inputSectionEnabled=1;u.inputProfile=1;render(run,analysisRenderer,source,destination,gpu,u,@{},@"renderer-input-analysis-pass"); NSData *inputPreview=[analysisRenderer preview];bool analysisDifferent=inputPreview.length==preview.length&&preview.length==320*180*16;double analysisMaximum=0;size_t analysisChanges=0; if(analysisDifferent){const float *a=(const float *)preview.bytes,*b=(const float *)inputPreview.bytes;for(NSUInteger i=0;i1e-5)analysisChanges++;}}} run.record(@"analysis-applies-selected-input-LUT",analysisDifferent&&analysisChanges>100,@{@"changedComponents":@(analysisChanges),@"maxAbsoluteError":@(analysisMaximum)}); NSString *lookFile=[runtime stringByAppendingPathComponent:@"diagnostic-look.cube"];NSMutableString *cube=[NSMutableString stringWithString:@"TITLE \"Self test look\"\nLUT_3D_SIZE 2\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n"]; for(int b=0;b<2;b++)for(int g=0;g<2;g++)for(int r=0;r<2;r++)[cube appendFormat:@"%.8f %.8f %.8f\n",.7f*r+.1f,.8f*g+.05f,.85f*b+.02f];error=nil;run.need(@"temporary-look-file",[cube writeToFile:lookFile atomically:YES encoding:NSUTF8StringEncoding error:&error],@{@"error":reason(error)}); NSDictionary *paths=@{@"look0":lookFile,@"look1":lookFile,@"look2":lookFile,@"look3":lookFile,@"look4":lookFile};u=defaults;u.lookSectionEnabled=1;u.postLUTStrength=.35f;u.extraPostLUTStrengths=(DYFloat4){.4f,.5f,.6f,.7f};Pixels looks=render(run,renderer,source,destination,gpu,u,paths,@"renderer-five-look-pass");Difference looksDifference=difference(neutral,looks);run.record(@"five-look-mixes-affect-frame",looksDifference.nonfinite==0&&looksDifference.different>100,measure(looksDifference)); checkFoldedGroup(u,offsetof(DYUniforms,lookSectionEnabled),paths,@"folded-look-bypasses-retained-LUTs"); NSURL *exportURL=[NSURL fileURLWithPath:[runtime stringByAppendingPathComponent:@"diagnostic-export.cube"]];error=nil;run.need(@"renderer-export-33cube",[renderer exportLUT:exportURL uniforms:u paths:paths error:&error],@{@"error":reason(error),@"path":exportURL.path}); NSString *exported=[NSString stringWithContentsOfURL:exportURL encoding:NSUTF8StringEncoding error:&error];NSUInteger triples=0,nonzero=0;bool exportFinite=true;for(NSString *line in [exported componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]){float r,g,b;if(sscanf(line.UTF8String,"%f %f %f",&r,&g,&b)==3){triples++;exportFinite&=std::isfinite(r)&&std::isfinite(g)&&std::isfinite(b);if(r!=0||g!=0||b!=0)nonzero++;}} run.record(@"export-33cube-data-contract",[exported containsString:@"LUT_3D_SIZE 33"]&&triples==33*33*33&&exportFinite&&nonzero>0,@{@"rows":@(triples),@"nonzeroRows":@(nonzero),@"bytes":@([[[NSFileManager defaultManager]attributesOfItemAtPath:exportURL.path error:nil][NSFileSize]unsignedLongLongValue])}); // A selected external table must outlive preview-cache churn and must // not consult the file system again on the frame-render path. NSString *external=[runtime stringByAppendingPathComponent:@"external-65.cube"]; std::string externalCube="TITLE \"External activation fixture\"\nLUT_3D_SIZE 65\n";char row[128]; for(int z=0;z<65;z++)for(int y=0;y<65;y++)for(int x=0;x<65;x++){snprintf(row,sizeof(row),"%.8f %.8f %.8f\n",x/64.f*.82f,y/64.f,z/64.f*1.12f);externalCube+=row;} run.need(@"external-large-cube-written",[[NSData dataWithBytes:externalCube.data() length:externalCube.size()]writeToFile:external options:NSDataWritingAtomic error:&error]); DYRenderer *externalRenderer=[[[DYRenderer alloc]init]autorelease]; __block BOOL prepared=NO;__block NSError *preparationError=nil;__block NSUInteger beats=0;__block double last=NSProcessInfo.processInfo.systemUptime,maxGap=0; NSTimer *heartbeat=[NSTimer scheduledTimerWithTimeInterval:.005 repeats:YES block:^(NSTimer *timer){double now=NSProcessInfo.processInfo.systemUptime;maxGap=std::max(maxGap,now-last);last=now;beats++;}]; [externalRenderer prepareLUTPath:external completion:^(NSError *failure){preparationError=[failure retain];prepared=YES;}]; double deadline=NSProcessInfo.processInfo.systemUptime+30; while(!prepared&&NSProcessInfo.processInfo.systemUptime0&&maxGap<.15,@{@"heartbeats":@(beats),@"maximumGapMS":@(maxGap*1000)}); DYUniforms externalUniforms=defaults;externalUniforms.lookSectionEnabled=1;externalUniforms.postLUTStrength=1; NSDictionary *externalPaths=@{@"look0":external}; Pixels externalFrame=render(run,externalRenderer,source,destination,gpu,externalUniforms,externalPaths,@"external-first-frame-after-preparation"); run.record(@"external-lut-affects-frame",difference(neutral,externalFrame).different>100); run.need(@"external-source-removed-for-no-io-check",[[NSFileManager defaultManager]removeItemAtPath:external error:&error]); BOOL churnOK=YES; for(int i=0;i<14;i++){@autoreleasepool{ NSString *other=[runtime stringByAppendingPathComponent:[NSString stringWithFormat:@"eviction-%02d.cube",i]]; NSString *text=@"LUT_3D_SIZE 2\n0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1\n"; churnOK&=[text writeToFile:other atomically:YES encoding:NSUTF8StringEncoding error:&error]; __block BOOL ready=NO;__block BOOL success=NO; [externalRenderer prepareLUTPath:other completion:^(NSError *failure){success=failure==nil;ready=YES;}]; double until=NSProcessInfo.processInfo.systemUptime+10; while(!ready&&NSProcessInfo.processInfo.systemUptime0&&allUserFrames,@{@"files":@(userCount),@"sourceFolder":userFolder,@"sourceFilesModified":@NO}); } [gpu release]; } @catch(NSException *exception) { run.record(@"diagnostic-exception",false,@{@"exception":exception.name?:@"unknown",@"message":exception.reason?:@"unknown"}); } NSDictionary *report=@{@"pass":@(run.passed),@"checks":@(run.rows.count),@"gpu":gpuName,@"bundlePath":[NSBundle bundleForClass:DYRenderer.class].bundlePath?:@"", @"runtimePath":runtime?:@"",@"results":run.rows,@"scope":@"Native model and renderer integration with real Metal/IOSurface textures and fake FxPlug host selectors; no GUI or live host document.", @"limitations":@[@"Finite states and a 64x48 frame; live FCP discovery, inspector interaction, timeline persistence and real host export require separate acceptance.",@"Input profiles checked for load/render/finite output; independent color accuracy is covered by separate LUT/kernel evidence."]}; NSError *error=nil;NSData *json=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted|NSJSONWritingSortedKeys error:&error]; if(json){fwrite(json.bytes,1,json.length,stdout);fputc('\n',stdout);}else{fputs("{\"pass\":false,\"error\":\"Unable to encode diagnostics JSON\"}\n",stdout);run.passed=false;}fflush(stdout);return run.passed?0:1; } }