文件
dayu-color/tools/verify_gpu.mm
T

219 行
21 KiB
Plaintext

// Independent, headless oracle check. Reference application is read only and
// never used by production builds. See tools/kernels/README.md for scope.
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#include <CommonCrypto/CommonDigest.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include "../大鱼调色/Plugin/DYUniforms.h"
static id<MTLDevice> gpu;
static id<MTLCommandQueue> queue;
using Pixels = std::vector<__fp16>;
static void need(bool valid, NSString* message) {
if (!valid) @throw [NSException exceptionWithName:@"GPUVerification" reason:message userInfo:nil];
}
static void finish(id<MTLCommandBuffer> commands) {
[commands commit]; [commands waitUntilCompleted];
need(commands.status == MTLCommandBufferStatusCompleted, commands.error.description ?: @"GPU command failed");
}
static NSString* digest(NSString* path) {
NSData* data = [NSData dataWithContentsOfFile:path]; need(data != nil, path);
unsigned char hash[CC_SHA256_DIGEST_LENGTH]; CC_SHA256(data.bytes, (CC_LONG)data.length, hash);
NSMutableString* result = [NSMutableString string];
for (unsigned char byte : hash) [result appendFormat:@"%02x", byte];
return result;
}
static DYUniforms defaults() {
DYUniforms u = {};
u.exposureEnabled=u.contrastEnabled=u.highlightsEnabled=u.shadowsEnabled=1;
u.whitesEnabled=u.blacksEnabled=u.temperatureEnabled=u.tintEnabled=1;
u.saturationEnabled=u.vibranceEnabled=u.textureEnabled=u.clarityEnabled=u.dehazeEnabled=1;
u.inputSectionEnabled=u.baseSectionEnabled=u.colorSectionEnabled=u.lookSectionEnabled=1;
u.extraLookSectionEnableds = (DYFloat4){1,1,1,1};
u.curveSectionEnabled = u.hslSectionEnabled = u.colorGradingSectionEnabled = 1;
u.primariesSectionEnabled = u.levelsSectionEnabled = u.colorBalanceSectionEnabled = 1;
u.levelsGamma = (DYFloat4){1,1,1,1};
u.levelsInputWhite = u.levelsOutputWhite = (DYFloat4){255,255,255,255};
u.curveX = (DYFloat4){.2f,.4f,.6f,.8f};
u.redCurveX = u.greenCurveX = u.blueCurveX = (DYFloat2){.25f,.75f};
u.curveExtraX = u.redCurveExtraX = u.greenCurveExtraX = u.blueCurveExtraX = (DYFloat4){-1,-1,-1,-1};
u.primariesM0 = (DYFloat3){1,0,0}; u.primariesM1 = (DYFloat3){0,1,0}; u.primariesM2 = (DYFloat3){0,0,1};
u.colorBalancePreserveLuminosity = 1;
u.hslCustomRange = (DYFloat3){.08f,.4f,.4f};
return u;
}
static id<MTLTexture> image(const Pixels& values, NSUInteger width, NSUInteger height) {
MTLTextureDescriptor* d = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO];
d.storageMode = MTLStorageModeShared; d.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget | MTLTextureUsageShaderWrite;
id<MTLTexture> result = [gpu newTextureWithDescriptor:d]; need(result != nil, @"source texture");
if (!values.empty()) [result replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:values.data() bytesPerRow:width*8];
return result;
}
static id<MTLTexture> lut(bool transformed) {
const NSUInteger n = 17;
MTLTextureDescriptor* d = [[MTLTextureDescriptor alloc] init];
d.textureType = MTLTextureType3D; d.pixelFormat = MTLPixelFormatRGBA32Float;
d.width = d.height = d.depth = n; d.storageMode = MTLStorageModeShared; d.usage = MTLTextureUsageShaderRead;
std::vector<float> values(n*n*n*4);
for (NSUInteger z=0; z<n; ++z) for (NSUInteger y=0; y<n; ++y) for (NSUInteger x=0; x<n; ++x) {
float r=float(x)/(n-1), g=float(y)/(n-1), b=float(z)/(n-1); NSUInteger p=((z*n+y)*n+x)*4;
values[p] = transformed ? .82f*r+.09f*g+.02f : r;
values[p+1] = transformed ? .87f*g+.03f*b+.01f : g;
values[p+2] = transformed ? .78f*b+.07f*r+.03f : b;
values[p+3] = 1;
}
id<MTLTexture> result = [gpu newTextureWithDescriptor:d]; need(result != nil, @"LUT texture");
[result replaceRegion:MTLRegionMake3D(0,0,0,n,n,n) mipmapLevel:0 slice:0 withBytes:values.data() bytesPerRow:n*16 bytesPerImage:n*n*16];
return result;
}
static id<MTLRenderPipelineState> renderPipeline(id<MTLLibrary> library, bool dayu) {
MTLRenderPipelineDescriptor* d = [[MTLRenderPipelineDescriptor alloc] init];
d.vertexFunction = [library newFunctionWithName:dayu ? @"dyVertex" : @"vertexShader"];
d.fragmentFunction = [library newFunctionWithName:dayu ? @"dyFragment" : @"fragmentShader"];
d.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA16Float;
NSError* error = nil; id<MTLRenderPipelineState> p = [gpu newRenderPipelineStateWithDescriptor:d error:&error];
need(p != nil, error.description ?: @"render pipeline"); return p;
}
static Pixels render(id<MTLRenderPipelineState> pipeline, bool dayu, id<MTLTexture> source,
NSArray<id<MTLTexture>>* textures, const DYUniforms& u, NSUInteger width, NSUInteger height,
float u0=0, float u1=1, bool premultiplied=false) {
id<MTLTexture> destination=image({},width,height);
MTLRenderPassDescriptor* pass=[MTLRenderPassDescriptor renderPassDescriptor];
pass.colorAttachments[0].texture=destination; pass.colorAttachments[0].loadAction=MTLLoadActionClear;
pass.colorAttachments[0].storeAction=MTLStoreActionStore;
id<MTLCommandBuffer> commands=[queue commandBuffer]; id<MTLRenderCommandEncoder> e=[commands renderCommandEncoderWithDescriptor:pass];
[e setRenderPipelineState:pipeline];
float hw=width*.5f, hh=height*.5f;
DYVertex2D vertices[]={{{hw,-hh},{u1,1}},{{-hw,-hh},{u0,1}},{{hw,hh},{u1,0}},{{-hw,hh},{u0,0}}};
vector_uint2 viewport={(unsigned)width,(unsigned)height};
[e setVertexBytes:vertices length:sizeof(vertices) atIndex:0]; [e setVertexBytes:&viewport length:sizeof(viewport) atIndex:1];
[e setFragmentTexture:source atIndex:0];
for (NSUInteger i=0;i<textures.count;++i) [e setFragmentTexture:textures[i] atIndex:i+1];
[e setFragmentBytes:&u length:sizeof(u) atIndex:0]; float scene=.73f; [e setFragmentBytes:&scene length:4 atIndex:1];
if(dayu) { DYRenderOptions options={}; options.outputPremultiplied=premultiplied; [e setFragmentBytes:&options length:sizeof(options) atIndex:2]; }
else { float disabledWatermark[8]={}; [e setFragmentBytes:disabledWatermark length:sizeof(disabledWatermark) atIndex:2]; }
[e drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; [e endEncoding]; finish(commands);
Pixels output(width*height*4); [destination getBytes:output.data() bytesPerRow:width*8 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0]; return output;
}
static NSDictionary* compare(NSString* name, const Pixels& a, const Pixels& b, bool skipZeroAlphaRGB=false, double tolerance=0) {
need(a.size()==b.size(),@"image sizes differ"); size_t compared=0, different=0; double maxError=0;
for(size_t i=0;i<a.size();++i) {
if(skipZeroAlphaRGB && i%4!=3 && a[(i/4)*4+3]==0) continue;
double delta=std::abs(double(a[i])-double(b[i]));
need(std::isfinite(delta),@"non-finite output"); ++compared; if(delta>tolerance)++different; maxError=std::max(maxError,delta);
}
return @{@"name":name,@"components":@(compared),@"differentAboveTolerance":@(different),@"maxAbsoluteError":@(maxError),@"tolerance":@(tolerance),@"pass":@(different==0)};
}
static NSDictionary* statistics(id<MTLLibrary> reference,id<MTLLibrary> dayu,id<MTLTexture> source,id<MTLTexture> identity,const DYUniforms& u) {
float values[2]={}; id<MTLLibrary> libraries[]={reference,dayu}; NSString* names[]={@"whitesSceneStatistics",@"dyWhitesSceneStatistics"};
for(int i=0;i<2;++i) {
NSError* error=nil; id<MTLComputePipelineState> p=[gpu newComputePipelineStateWithFunction:[libraries[i] newFunctionWithName:names[i]] error:&error]; need(p!=nil,error.description);
id<MTLBuffer> result=[gpu newBufferWithLength:4 options:MTLResourceStorageModeShared];
id<MTLCommandBuffer> cb=[queue commandBuffer];id<MTLComputeCommandEncoder> e=[cb computeCommandEncoder];[e setComputePipelineState:p];
[e setTexture:source atIndex:0];[e setTexture:identity atIndex:1];[e setBytes:&u length:sizeof(u) atIndex:0];[e setBuffer:result offset:0 atIndex:1];
[e dispatchThreadgroups:MTLSizeMake(1,1,1) threadsPerThreadgroup:MTLSizeMake(256,1,1)];[e endEncoding];finish(cb);memcpy(&values[i],result.contents,4);
}
return @{@"name":@"scene-statistics",@"reference":@(values[0]),@"dayu":@(values[1]),@"pass":@(memcmp(values,values+1,4)==0)};
}
static NSDictionary* exportLUT(id<MTLLibrary> reference,id<MTLLibrary> dayu,NSArray<id<MTLTexture>>* textures,const DYUniforms& u) {
const unsigned n=17; const size_t components=n*n*n*3;std::vector<float> outputs[2];
id<MTLLibrary> libraries[]={reference,dayu};NSString* names[]={@"lutExportKernel",@"dyLUTExportKernel"};
for(int i=0;i<2;++i) {
NSError* error=nil; id<MTLComputePipelineState> p=[gpu newComputePipelineStateWithFunction:[libraries[i] newFunctionWithName:names[i]] error:&error];need(p!=nil,error.description);
id<MTLBuffer> result=[gpu newBufferWithLength:components*4 options:MTLResourceStorageModeShared];
id<MTLCommandBuffer> cb=[queue commandBuffer];id<MTLComputeCommandEncoder> e=[cb computeCommandEncoder];[e setComputePipelineState:p];
for(NSUInteger t=0;t<textures.count;++t)[e setTexture:textures[t] atIndex:t];
[e setBytes:&u length:sizeof(u) atIndex:0];[e setBuffer:result offset:0 atIndex:1];[e setBytes:&n length:4 atIndex:2];
[e dispatchThreads:MTLSizeMake(n*n*n,1,1) threadsPerThreadgroup:MTLSizeMake(64,1,1)];[e endEncoding];finish(cb);
outputs[i].resize(components);memcpy(outputs[i].data(),result.contents,components*4);
}
size_t differences=0;double maxError=0;for(size_t j=0;j<components;++j){double d=std::abs(double(outputs[0][j])-outputs[1][j]);need(std::isfinite(d),@"nonfinite LUT");if(d>0)++differences;maxError=std::max(maxError,d);}
return @{@"name":@"LUT-export-17",@"components":@(components),@"differentComponents":@(differences),@"maxAbsoluteError":@(maxError),@"pass":@(differences==0)};
}
static Pixels unpremultiply(id<MTLLibrary> library,id<MTLTexture> source) {
NSError* error=nil;
auto pipeline=[gpu newComputePipelineStateWithFunction:[library newFunctionWithName:@"dyUnpremultiply"] error:&error];need(pipeline!=nil,error.description);
auto destination=image({},source.width,source.height);
auto cb=[queue commandBuffer];auto e=[cb computeCommandEncoder];[e setComputePipelineState:pipeline];
[e setTexture:source atIndex:0];[e setTexture:destination atIndex:1];
[e dispatchThreads:MTLSizeMake(source.width,source.height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[e endEncoding];finish(cb);
Pixels output(source.width*source.height*4);[destination getBytes:output.data() bytesPerRow:source.width*8 fromRegion:MTLRegionMake2D(0,0,source.width,source.height) mipmapLevel:0];return output;
}
static NSDictionary* preview(id<MTLLibrary> library) {
NSError* error=nil;auto pipeline=[gpu newComputePipelineStateWithFunction:[library newFunctionWithName:@"dyPreview"] error:&error];need(pipeline!=nil,error.description);
size_t compared=0,different=0;double maxError=0;
for(float level:{-.1f,0.f,.0031308f,.18f,1.f,2.f}) {
Pixels input(8*8*4);for(size_t p=0;p<input.size();p+=4){input[p]=input[p+1]=input[p+2]=(__fp16)level;input[p+3]=(__fp16).375f;}
auto source=image(input,8,8);auto output=[gpu newBufferWithLength:64*64*16 options:MTLResourceStorageModeShared];
auto cb=[queue commandBuffer];auto e=[cb computeCommandEncoder];[e setComputePipelineState:pipeline];[e setTexture:source atIndex:0];[e setBuffer:output offset:0 atIndex:0];
[e dispatchThreads:MTLSizeMake(64,64,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[e endEncoding];finish(cb);
float value=float((__fp16)level),encoded=value<=.0031308f?value*12.92f:1.055f*std::pow(value,1.f/2.4f)-.055f;
const float* actual=(const float*)output.contents;for(size_t p=0;p<64*64*4;++p){float target=p%4==3?.375f:encoded;double d=std::abs(double(actual[p])-target);need(std::isfinite(d),@"nonfinite preview");++compared;if(d>2e-6)++different;maxError=std::max(maxError,d);}
}
return @{@"name":@"64x64-preview-sRGB-alpha-HDR-negative",@"components":@(compared),@"differentAboveTolerance":@(different),@"maxAbsoluteError":@(maxError),@"tolerance":@(2e-6),@"pass":@(different==0)};
}
int main(int argc,const char* argv[]) { @autoreleasepool { @try {
need(argc==3,@"Usage: verify_gpu /absolute/dayu.metallib /absolute/report.json");
gpu=MTLCreateSystemDefaultDevice();need(gpu!=nil,@"Metal unavailable");queue=[gpu newCommandQueue];
NSString* original=@"/Library/Plug-Ins/FxPlug/LumiGrade.app/Contents/PlugIns/LumiGrade XPC Service.pluginkit/Contents/Resources/default.metallib";
NSString* current=[NSString stringWithUTF8String:argv[1]];NSError* error=nil;
id<MTLLibrary> ref=[gpu newLibraryWithURL:[NSURL fileURLWithPath:original] error:&error];need(ref!=nil,error.description);
id<MTLLibrary> ours=[gpu newLibraryWithURL:[NSURL fileURLWithPath:current] error:&error];need(ours!=nil,error.description);
auto rp=renderPipeline(ref,false), dp=renderPipeline(ours,true);auto identity=lut(false), altered=lut(true);
NSArray* textures=@[identity,identity,identity,identity,identity,identity,identity,identity,identity];
const NSUInteger w=256,h=128;Pixels input(w*h*4);uint32_t rng=0x75423981;
for(NSUInteger y=0;y<h;++y)for(NSUInteger x=0;x<w;++x){size_t p=(y*w+x)*4;for(int c=0;c<3;++c){rng=rng*1664525+1013904223;float v=(rng>>8)*(1.0f/16777215);if(y<32)v=float(x)/255;if(y>=96)v=v*2-.1f;input[p+c]=(__fp16)v;}input[p+3]=1;}
auto source=image(input,w,h);NSMutableArray* cases=[NSMutableArray array];
auto runCase=[&](NSString* name,DYUniforms u,NSArray* tex){Pixels a=render(rp,false,source,tex,u,w,h),b=render(dp,true,source,tex,u,w,h);[cases addObject:compare(name,a,b)];};
DYUniforms u=defaults();runCase(@"neutral",u,textures);
for(float v:{-5.f,-1.25f,.65f,5.f}){u=defaults();u.exposure=v;runCase([NSString stringWithFormat:@"exposure-%g",v],u,textures);}
u=defaults();u.contrast=55;u.highlights=-48;u.shadows=62;u.whites=70;u.blacks=-65;runCase(@"tone-combined",u,textures);
u=defaults();u.contrast=-65;u.highlights=72;u.shadows=-55;u.whites=-72;u.blacks=48;runCase(@"tone-opposite",u,textures);
for(float v:{-65.f,65.f}){u=defaults();u.texture=v;runCase([NSString stringWithFormat:@"texture-%g",v],u,textures);u=defaults();u.clarity=v;runCase([NSString stringWithFormat:@"clarity-%g",v],u,textures);u=defaults();u.dehaze=v;runCase([NSString stringWithFormat:@"dehaze-%g",v],u,textures);}
u=defaults();u.saturation=38;u.vibrance=72;runCase(@"saturation-vibrance",u,textures);
u=defaults();u.curveShadows=-12;u.curveDarks=8;u.curveLights=15;u.curveHighlights=-8;u.redCurveShadows=13;u.greenCurveHighlights=-9;u.blueCurveShadows=5;u.curveExtraX=(DYFloat4){.1f,.3f,-1,-1};u.curveExtra=(DYFloat4){3,-6,0,0};runCase(@"master-RGB-extra-curves",u,textures);
u=defaults();u.levelsInputBlack=(DYFloat4){5,8,3,12};u.levelsInputWhite=(DYFloat4){246,238,241,245};u.levelsGamma=(DYFloat4){1.1f,.87f,1.25f,.94f};u.levelsOutputBlack=(DYFloat4){2,3,0,4};u.levelsOutputWhite=(DYFloat4){250,248,240,252};runCase(@"master-RGB-levels",u,textures);
u=defaults();u.hslCustomSample=(DYFloat3){.05f,.5f,.5f};u.hslCustomAdjust=(DYFloat3){25,-35,20};runCase(@"custom-HSL",u,textures);u.hslCustomVisualize=1;runCase(@"custom-HSL-visualization",u,textures);
u=defaults();u.blackWhiteSectionEnabled=1;u.blackWhiteMixA=(DYFloat4){25,-15,40,-30};u.blackWhiteMixB=(DYFloat2){15,-10};u.blackWhiteTint=(DYFloat2){.13f,.2f};runCase(@"black-white-mixer-tint",u,textures);
u=defaults();u.colorBalanceShadows=(DYFloat3){18,-12,6};u.colorBalanceMidtones=(DYFloat3){-9,14,-6};u.colorBalanceHighlights=(DYFloat3){8,2,-15};runCase(@"color-balance-preserve",u,textures);u.colorBalancePreserveLuminosity=0;runCase(@"color-balance",u,textures);
u=defaults();u.redPrimaryHue=25;u.primariesM0=(DYFloat3){.9f,.08f,.02f};u.primariesM1=(DYFloat3){.04f,.92f,.04f};u.primariesM2=(DYFloat3){.02f,.06f,.92f};runCase(@"primary-matrix",u,textures);
NSArray* lookTextures=@[altered,altered,altered,altered,altered,altered,identity,identity,identity];
u=defaults();u.preLUTStrength=.43f;u.postLUTStrength=.61f;u.extraPostLUTStrengths=(DYFloat4){.2f,.4f,.6f,.8f};runCase(@"pre-LUT-and-five-look-mixes",u,lookTextures);
u.skinProtection=(DYFloat3){.65f,.4f,.2f};u.exposure=.7f;u.contrast=20;u.curveDarks=-5;u.texture=25;u.clarity=-15;u.saturation=10;runCase(@"mixed-chain-skin-protection",u,lookTextures);
[cases addObject:statistics(ref,ours,source,identity,u)];[cases addObject:exportLUT(ref,ours,lookTextures,u)];
// Real cropped input tile with a 32 px halo, not a resized full-frame sample.
Pixels crop(192*h*4);for(NSUInteger y=0;y<h;++y)memcpy(crop.data()+y*192*4,input.data()+(y*w+32)*4,192*8);
Pixels full=render(dp,true,source,textures,u,w,h), expected(128*h*4);
for(NSUInteger y=0;y<h;++y)memcpy(expected.data()+y*128*4,full.data()+(y*w+64)*4,128*8);
Pixels tile=render(dp,true,image(crop,192,h),textures,u,128,h,32.f/192,160.f/192);
[cases addObject:compare(@"cropped-tile-32px-halo",expected,tile,false,.001)];
// Alpha is tested against the declared Dayu boundary, independent of original
// hidden RGB behavior at alpha zero. Premultiply only after grading.
Pixels alphaInput=input;for(size_t p=0;p<alphaInput.size();p+=4){alphaInput[p+3]=(__fp16)((p/4)%5*.25f);if(alphaInput[p+3]==0)alphaInput[p]=alphaInput[p+1]=alphaInput[p+2]=0;}
auto alphaSource=image(alphaInput,w,h);u=defaults();u.exposure=.65f;
Pixels alphaRef=render(rp,false,alphaSource,textures,u,w,h),alphaDayu=render(dp,true,alphaSource,textures,u,w,h);
[cases addObject:compare(@"straight-alpha-nonzero-oracle",alphaRef,alphaDayu,true)];
Pixels premultExpected=alphaDayu;for(size_t p=0;p<premultExpected.size();p+=4)for(int c=0;c<3;++c)premultExpected[p+c]=(__fp16)(float(premultExpected[p+c])*float(premultExpected[p+3]));
Pixels premult=render(dp,true,alphaSource,textures,u,w,h,0,1,true);[cases addObject:compare(@"output-premultiplication",premultExpected,premult)];
size_t badTransparent=0;for(size_t p=0;p<alphaDayu.size();p+=4)if(alphaInput[p+3]==0)for(int c=0;c<4;++c)if(alphaDayu[p+c]!=0)++badTransparent;
[cases addObject:@{@"name":@"zero-alpha-black",@"nonzeroComponents":@(badTransparent),@"pass":@(badTransparent==0)}];
u=defaults();Pixels neutralAlpha=render(dp,true,alphaSource,textures,u,w,h);[cases addObject:compare(@"neutral-straight-alpha",alphaInput,neutralAlpha)];
Pixels premultInput=alphaInput;for(size_t p=0;p<premultInput.size();p+=4)for(int c=0;c<3;++c)premultInput[p+c]=(__fp16)(float(premultInput[p+c])*float(premultInput[p+3]));
Pixels unpremultExpected=premultInput;for(size_t p=0;p<unpremultExpected.size();p+=4)for(int c=0;c<3;++c)unpremultExpected[p+c]=unpremultExpected[p+3]>0?(__fp16)(float(unpremultExpected[p+c])/float(unpremultExpected[p+3])):(__fp16)0;
Pixels recovered=unpremultiply(ours,image(premultInput,w,h));[cases addObject:compare(@"unpremultiply-compute-boundary",unpremultExpected,recovered)];
Pixels neutralPremult=render(dp,true,image(recovered,w,h),textures,u,w,h,0,1,true);[cases addObject:compare(@"neutral-premultiplied-roundtrip",premultInput,neutralPremult,false,.001)];
[cases addObject:preview(ours)];
bool passed=true;for(NSDictionary* row in cases)if(![row[@"pass"] boolValue])passed=false;
NSDictionary* report=@{@"pass":@(passed),@"gpu":gpu.name,@"os":[NSProcessInfo processInfo].operatingSystemVersionString,
@"referenceMetallibSHA256":digest(original),@"reconstructedMetallibSHA256":digest(current),@"imageSize":@[@(w),@(h)],
@"testCount":@(cases.count),@"cases":cases,@"scope":@"Direct GPU arithmetic and boundary checks; no GUI application was launched or modified.",
@"limitations":@[@"White balance, 8-color HSL mixer and color-grading texture generation use identity placeholders; CPU lookup-table reconstruction is outside this report.",@"Finite sample states; not exhaustive values or every host/GPU.",@"Tile test uses 32-pixel horizontal halo, full vertical input, fixed shared scene statistic.",@"16-bit float source/output follows the reference GPU ABI; premultiplied conversion and tile coordinate rounding allow absolute 0.001 tolerance. Host dispatch, save/reopen and actual FCP export remain separate."]};
NSData* data=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:&error];need(data!=nil,error.description);
NSString* destination=[NSString stringWithUTF8String:argv[2]];need([data writeToFile:destination atomically:YES],destination);
printf("%s: %lu GPU checks\n",passed?"PASS":"FAIL",(unsigned long)cases.count);return passed?0:1;
} @catch(NSException* e) { fprintf(stderr,"%s\n",e.reason.UTF8String);return 2; } } }