From a1e49e2eb55d1175e1ea52dfcf0f7aaa48eaab7b Mon Sep 17 00:00:00 2001 From: mac Date: Tue, 3 Nov 2026 11:44:25 +0800 Subject: [PATCH] Add identity-bound GPU observations for BASIS, CST and the current primary color kernel --- .../cms-audit-20261103/gpu-observations.json | 240 ++++++++++++++++++ research/cms-audit-20261103/probe.mm | 124 +++++++++ .../cms-audit-20261103/target-identities.json | 67 +++++ 3 files changed, 431 insertions(+) create mode 100644 research/cms-audit-20261103/gpu-observations.json create mode 100644 research/cms-audit-20261103/probe.mm create mode 100644 research/cms-audit-20261103/target-identities.json diff --git a/research/cms-audit-20261103/gpu-observations.json b/research/cms-audit-20261103/gpu-observations.json new file mode 100644 index 0000000..4f7b542 --- /dev/null +++ b/research/cms-audit-20261103/gpu-observations.json @@ -0,0 +1,240 @@ +{ + "authority" : "controlled shader execution; original installed Metal libraries", + "basisDIExposurePlusOneStop" : [ + { + "absoluteCodeError" : 1.52587890625e-05, + "actualCode" : [ + 0.0208740234375, + 0.0208740234375, + 0.0208740234375 + ], + "expectedCodeDouble" : 0.0208892822265625, + "halfULPAgainstRoundedReference" : 1, + "inputCode" : 0.010444268584251404, + "shaderInputHalf" : 0.01044464111328125 + }, + { + "absoluteCodeError" : 8.2587538793865711e-07, + "actualCode" : [ + 0.133056640625, + 0.133056640625, + 0.133056640625 + ], + "expectedCodeDouble" : 0.13305581474961206, + "halfULPAgainstRoundedReference" : 0, + "inputCode" : 0.085275709629058838, + "shaderInputHalf" : 0.08526611328125 + }, + { + "absoluteCodeError" : 0.00010919044650758991, + "actualCode" : [ + 0.406982421875, + 0.406982421875, + 0.406982421875 + ], + "expectedCodeDouble" : 0.40709161232150759, + "halfULPAgainstRoundedReference" : 0, + "inputCode" : 0.33604326844215393, + "shaderInputHalf" : 0.3359375 + }, + { + "absoluteCodeError" : 0.0001436520877062808, + "actualCode" : [ + 0.58642578125, + 0.58642578125, + 0.58642578125 + ], + "expectedCodeDouble" : 0.58656943333770628, + "halfULPAgainstRoundedReference" : 0, + "inputCode" : 0.51383745670318604, + "shaderInputHalf" : 0.513671875 + }, + { + "absoluteCodeError" : 4.8850578683645729e-05, + "actualCode" : [ + 0.73291015625, + 0.73291015625, + 0.73291015625 + ], + "expectedCodeDouble" : 0.73286130567131635, + "halfULPAgainstRoundedReference" : 0, + "inputCode" : 0.65983039140701294, + "shaderInputHalf" : 0.65966796875 + } + ], + "basisExposureMaximumHalfULP" : 1, + "basisSHA256" : "e164080db3a6d553a0e75d377ac3c5bd28455bddd8a97640d9de6c74e0d105f3", + "cstForwardThenReverse" : [ + { + "displayGamma24" : [ + 0.0169219970703125, + 0.0169219970703125, + 0.0169219970703125 + ], + "reverseToLinear709" : [ + 5.2571296691894531e-05, + 5.2571296691894531e-05, + 5.2571296691894531e-05 + ], + "sourceLinear709" : 0 + }, + { + "displayGamma24" : [ + 0.0222320556640625, + 0.0222320556640625, + 0.0222320556640625 + ], + "reverseToLinear709" : [ + 0.00010114908218383789, + 0.00010114908218383789, + 0.00010114908218383789 + ], + "sourceLinear709" : 0.0010000000474974513 + }, + { + "displayGamma24" : [ + 0.0640869140625, + 0.0640869140625, + 0.0640869140625 + ], + "reverseToLinear709" : [ + 0.0012845993041992188, + 0.0012845993041992188, + 0.0012845993041992188 + ], + "sourceLinear709" : 0.0099999997764825821 + }, + { + "displayGamma24" : [ + 0.40234375, + 0.40234375, + 0.40234375 + ], + "reverseToLinear709" : [ + 0.1143798828125, + 0.1143798828125, + 0.1143798828125 + ], + "sourceLinear709" : 0.18000000715255737 + }, + { + "displayGamma24" : [ + 0.763671875, + 0.763671875, + 0.763671875 + ], + "reverseToLinear709" : [ + 0.76708984375, + 0.76708984375, + 0.76708984375 + ], + "sourceLinear709" : 1 + }, + { + "displayGamma24" : [ + 0.86328125, + 0.86328125, + 0.86328125 + ], + "reverseToLinear709" : [ + 1.275390625, + 1.275390625, + 1.275390625 + ], + "sourceLinear709" : 2 + }, + { + "displayGamma24" : [ + 0.927734375, + 0.927734375, + 0.927734375 + ], + "reverseToLinear709" : [ + 1.83984375, + 1.83984375, + 1.83984375 + ], + "sourceLinear709" : 4 + }, + { + "displayGamma24" : [ + 0.9853515625, + 0.9853515625, + 0.9853515625 + ], + "reverseToLinear709" : [ + 2.689453125, + 2.689453125, + 2.689453125 + ], + "sourceLinear709" : 16 + }, + { + "displayGamma24" : [ + 1, + 1, + 1 + ], + "reverseToLinear709" : [ + 3, + 3, + 3 + ], + "sourceLinear709" : 64 + } + ], + "cstSHA256" : "b38165dd86bb6e038f7835373dadb51a54a0ad266c67672ff8fcd9548641c2d3", + "date" : "2026-11-03", + "dayuNewPrimaryDefaultMapping" : [ + { + "hostLinearInput" : 0.01000213623046875, + "newPrimaryDefaultMappingOutput" : [ + 0.0027828216552734375, + 0.0027828216552734375, + 0.0027828216552734375 + ] + }, + { + "hostLinearInput" : 0.1800537109375, + "newPrimaryDefaultMappingOutput" : [ + 0.12066650390625, + 0.12066650390625, + 0.12066650390625 + ] + }, + { + "hostLinearInput" : 0.5, + "newPrimaryDefaultMappingOutput" : [ + 0.43310546875, + 0.43310546875, + 0.43310546875 + ] + }, + { + "hostLinearInput" : 1, + "newPrimaryDefaultMappingOutput" : [ + 0.796875, + 0.796875, + 0.796875 + ] + }, + { + "hostLinearInput" : 2, + "newPrimaryDefaultMappingOutput" : [ + 0.796875, + 0.796875, + 0.796875 + ] + } + ], + "dayuSHA256" : "6ec98b85aeb841f9988a4b66e3e5fba9e34d5ab3d7542c9205b0480c77f9ac6d", + "device" : "Apple M4", + "limitations" : [ + "Not a Final Cut Pro render, camera import test or whole-application CMS certification.", + "RGBA32Float transport; target shaders can quantize samples\/results internally to half.", + "CST inverse display mapping is not assumed to be an inverse of the forward DRT.", + "DI formula follows Blackmagic public specification; finite samples and exposure-isolation bypasses only.", + "Dayu primary rows test the actual installed color kernel with source-derived new-layer parameters, not the whole scheduler\/UI." + ], + "schema" : 1 +} \ No newline at end of file diff --git a/research/cms-audit-20261103/probe.mm b/research/cms-audit-20261103/probe.mm new file mode 100644 index 0000000..38b47c2 --- /dev/null +++ b/research/cms-audit-20261103/probe.mm @@ -0,0 +1,124 @@ +// Bounded, headless observations of the user-selected installed shaders. +// No vendor source, shader code, LUT data, app launch or host document is copied. +// Build instructions and interpretation limits are in report.md. +#import +#import +#include +#include +#include +#include +#include + +struct CSTParams { int inputGamut,inputTransfer,outputGamut,outputTransfer,toneMapping; }; +struct BasisParams { + int colorspace; + float exposure,balanceTarget,balanceStrength,contrast,pivot,highlights,midtones,shadows; + float trimLow,trimHigh,trimToeStrength,trimShoulderStrength,shadowContrast,shadowPivot,hiContrast,hiPivot,chromaMix; + unsigned char bypassBalance,bypassTone,bypassExposure,bypassContrast; + float saturation; +}; +struct DayuRenderParams { CSTParams input,output;BasisParams basis;int stages,sourceLinear,destinationLinear,reserved;CSTParams basisInput,basisOutput; }; +static_assert(sizeof(CSTParams)==20 && sizeof(BasisParams)==80); +static_assert(sizeof(DayuRenderParams)==176); +struct Vertex { simd_float2 position,uv; }; +static void need(bool value,NSString *reason) { + if(!value) @throw [NSException exceptionWithName:@"CMSAudit" reason:reason userInfo:nil]; +} +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 *s=[NSMutableString string];for(auto v:hash)[s appendFormat:@"%02x",v];return s; +} +static double encodeDI(double v) { + return v<=.00262409?v*10.44426855:(std::log2(v+.0075)+7)*.07329248; +} +static double decodeDI(double v) { + return v<=.02740668?v/10.44426855:std::exp2(v/.07329248-7)-.0075; +} +static std::vector render(iddevice,idqueue, + idpipeline,const std::vector&input,const void *params,NSUInteger length) { + NSUInteger width=input.size()/4;need(width>0 && input.size()%4==0,@"invalid input"); + auto desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA32Float width:width height:1 mipmapped:NO]; + desc.storageMode=MTLStorageModeShared;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageRenderTarget; + idsource=[device newTextureWithDescriptor:desc],output=[device newTextureWithDescriptor:desc]; + need(source && output,@"texture allocation"); + [source replaceRegion:MTLRegionMake2D(0,0,width,1) mipmapLevel:0 withBytes:input.data() bytesPerRow:width*16]; + float w=width,h=1;Vertex vertices[]={{{-w/2,-h/2},{0,1}},{{w/2,-h/2},{1,1}},{{-w/2,h/2},{0,0}},{{w/2,h/2},{1,0}}}; + simd_uint2 dims={(unsigned)width,1}; + auto pass=[MTLRenderPassDescriptor renderPassDescriptor];pass.colorAttachments[0].texture=output; + pass.colorAttachments[0].loadAction=MTLLoadActionDontCare;pass.colorAttachments[0].storeAction=MTLStoreActionStore; + auto cb=[queue commandBuffer];auto enc=[cb renderCommandEncoderWithDescriptor:pass]; + [enc setRenderPipelineState:pipeline];[enc setVertexBytes:vertices length:sizeof(vertices) atIndex:0]; + [enc setVertexBytes:&dims length:sizeof(dims) atIndex:1];[enc setFragmentTexture:source atIndex:0]; + [enc setFragmentBytes:params length:length atIndex:0];[enc drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4]; + [enc endEncoding];[cb commit];[cb waitUntilCompleted];need(cb.status==MTLCommandBufferStatusCompleted,cb.error.description?:@"GPU failure"); + std::vectorresult(input.size());[output getBytes:result.data() bytesPerRow:width*16 fromRegion:MTLRegionMake2D(0,0,width,1) mipmapLevel:0];return result; +} +static id pipeline(iddevice,idlibrary) { + auto d=[MTLRenderPipelineDescriptor new];d.vertexFunction=[library newFunctionWithName:@"vertexShader"]; + d.fragmentFunction=[library newFunctionWithName:@"fragmentShader"];d.colorAttachments[0].pixelFormat=MTLPixelFormatRGBA32Float; + NSError *error=nil;auto result=[device newRenderPipelineStateWithDescriptor:d error:&error];need(result!=nil,error.description);return result; +} +static NSArray *rgb(const std::vector&v,NSUInteger pixel) { + NSMutableArray *a=[NSMutableArray array];for(int c=0;c<3;c++){ + float x=v[pixel*4+c];[a addObject:std::isfinite(x)?(id)@(x):(id)[NSString stringWithFormat:@"%g",x]]; + }return a; +} +int main(int argc,const char *argv[]) { @autoreleasepool { @try { + need(argc==2,@"usage: probe /absolute/report.json"); + NSString *cstPath=@"/Library/Plug-Ins/FxPlug/Colour Space Transform.app/Contents/PlugIns/Colour Space Transform XPC Service.pluginkit/Contents/Resources/default.metallib"; + NSString *basisPath=@"/Library/Plug-Ins/FxPlug/BASIS.app/Contents/PlugIns/Basis XPC Service.pluginkit/Contents/Resources/default.metallib"; + need([digest(cstPath)isEqual:@"b38165dd86bb6e038f7835373dadb51a54a0ad266c67672ff8fcd9548641c2d3"],@"CST identity changed; re-inspect before probing"); + need([digest(basisPath)isEqual:@"e164080db3a6d553a0e75d377ac3c5bd28455bddd8a97640d9de6c74e0d105f3"],@"BASIS identity changed; re-inspect before probing"); + auto device=MTLCreateSystemDefaultDevice();need(device!=nil,@"Metal device unavailable");auto queue=[device newCommandQueue]; + NSError *error=nil;auto cst=[device newLibraryWithURL:[NSURL fileURLWithPath:cstPath] error:&error];need(cst!=nil,error.description); + auto basis=[device newLibraryWithURL:[NSURL fileURLWithPath:basisPath] error:&error];need(basis!=nil,error.description); + auto cp=pipeline(device,cst),bp=pipeline(device,basis); + const float levels[]={0,.001f,.01f,.18f,1,2,4,16,64};std::vectorgray; + for(auto v:levels)gray.insert(gray.end(),{v,v,v,1}); + CSTParams forward={22,20,22,1002,1},reverse={22,1002,22,20,2}; + auto mapped=render(device,queue,cp,gray,&forward,sizeof(forward)); + auto restored=render(device,queue,cp,mapped,&reverse,sizeof(reverse)); + NSMutableArray *mapping=[NSMutableArray array];for(NSUInteger i=0;icodes;for(double v:{.001,.01,.18,1.0,4.0}){float c=(float)encodeDI(v);codes.insert(codes.end(),{c,c,c,1});} + BasisParams b={};b.colorspace=10;b.exposure=2;b.contrast=b.pivot=b.trimLow=b.trimHigh=b.shadowPivot=b.hiPivot=b.saturation=1; + b.trimToeStrength=8.5;b.trimShoulderStrength=4.5;b.chromaMix=.5; + // Isolate the exposure operation rather than asserting a whole tone stack is neutral. + b.bypassBalance=b.bypassTone=b.bypassContrast=1; + auto exposed=render(device,queue,bp,codes,&b,sizeof(b));NSMutableArray *exposure=[NSMutableArray array];unsigned maximumHalfULP=0; + for(NSUInteger i=0;ihost; + for(float level:hostLevels)host.insert(host.end(),{(float)(__fp16)level,(float)(__fp16)level,(float)(__fp16)level,1}); + auto td=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA32Float width:5 height:1 mipmapped:NO];td.storageMode=MTLStorageModeShared;td.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite; + auto source=[device newTextureWithDescriptor:td],dest=[device newTextureWithDescriptor:td]; + [source replaceRegion:MTLRegionMake2D(0,0,5,1) mipmapLevel:0 withBytes:host.data() bytesPerRow:80]; + auto cb=[queue commandBuffer];auto e=[cb computeCommandEncoder];[e setComputePipelineState:dp];[e setTexture:source atIndex:0];[e setTexture:dest atIndex:1]; + [e setBytes:&p length:sizeof(p) atIndex:0];float amount=1;[e setBytes:&amount length:sizeof(amount) atIndex:1]; + [e dispatchThreads:MTLSizeMake(5,1,1) threadsPerThreadgroup:MTLSizeMake(5,1,1)];[e endEncoding];[cb commit];[cb waitUntilCompleted];need(cb.status==MTLCommandBufferStatusCompleted,cb.error.description?:@"Dayu GPU failure"); + std::vectordayuResult(20);[dest getBytes:dayuResult.data() bytesPerRow:80 fromRegion:MTLRegionMake2D(0,0,5,1) mipmapLevel:0]; + NSMutableArray *dayuRows=[NSMutableArray array];for(NSUInteger i=0;i<5;i++)[dayuRows addObject:@{@"hostLinearInput":@(host[i*4]),@"newPrimaryDefaultMappingOutput":rgb(dayuResult,i)}]; + NSDictionary *report=@{@"schema":@1,@"date":@"2026-11-03",@"device":device.name, + @"authority":@"controlled shader execution; original installed Metal libraries", + @"cstSHA256":digest(cstPath),@"basisSHA256":digest(basisPath), + @"cstForwardThenReverse":mapping,@"basisDIExposurePlusOneStop":exposure,@"basisExposureMaximumHalfULP":@(maximumHalfULP), + @"dayuSHA256":digest(dayuPath),@"dayuNewPrimaryDefaultMapping":dayuRows, + @"limitations":@[@"Not a Final Cut Pro render, camera import test or whole-application CMS certification.",@"RGBA32Float transport; target shaders can quantize samples/results internally to half.",@"CST inverse display mapping is not assumed to be an inverse of the forward DRT.",@"DI formula follows Blackmagic public specification; finite samples and exposure-isolation bypasses only.",@"Dayu primary rows test the actual installed color kernel with source-derived new-layer parameters, not the whole scheduler/UI."]}; + NSData *json=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted|NSJSONWritingSortedKeys error:&error];need(json!=nil,error.description); + need([json writeToFile:[NSString stringWithUTF8String:argv[1]] options:NSDataWritingAtomic error:&error],error.description); + puts([[NSString alloc]initWithData:json encoding:NSUTF8StringEncoding].UTF8String);return 0; +} @catch(NSException *e) {fputs(e.reason.UTF8String,stderr);return 1;} }} diff --git a/research/cms-audit-20261103/target-identities.json b/research/cms-audit-20261103/target-identities.json new file mode 100644 index 0000000..284ce17 --- /dev/null +++ b/research/cms-audit-20261103/target-identities.json @@ -0,0 +1,67 @@ +{ + "schema": 1, + "date": "2026-11-03", + "timezone": "Asia/Shanghai", + "productSourceCommit": "d0b4e9d2ba1cd27b8677cfb723f540deb9027cbe", + "targets": [ + { + "name": "BASIS", + "version": "1.0 (8)", + "path": "/Library/Plug-Ins/FxPlug/BASIS.app/Contents/PlugIns/Basis XPC Service.pluginkit/Contents/MacOS/Basis XPC Service", + "bytes": 305520, + "sha256": "4dcf7bc7d0efd97b6aa733049fe55d4cbeebf15f4490ffd490875ea8fc0b5929", + "arm64": { + "offset": 163840, + "bytes": 141680, + "sha256": "55be57c9f17a94f6fc36beaf6d260a0d2ea8fe8a65f7898fff8f9b66e0b02f3f" + }, + "metal": { + "path": "/Library/Plug-Ins/FxPlug/BASIS.app/Contents/PlugIns/Basis XPC Service.pluginkit/Contents/Resources/default.metallib", + "bytes": 26992, + "sha256": "e164080db3a6d553a0e75d377ac3c5bd28455bddd8a97640d9de6c74e0d105f3" + } + }, + { + "name": "Colour Space Transform", + "version": "2.0 (8)", + "path": "/Library/Plug-Ins/FxPlug/Colour Space Transform.app/Contents/PlugIns/Colour Space Transform XPC Service.pluginkit/Contents/MacOS/Colour Space Transform XPC Service", + "bytes": 272672, + "sha256": "48b4aa2bc6a79679386096234bf2124d4cd4d1ad75db46d080dd19f75a61bbf5", + "arm64": { + "offset": 131072, + "bytes": 141600, + "sha256": "409c1406668ef855bc55325a106cac13f7ef7527cff21d627cadd8308c91e444" + }, + "metal": { + "path": "/Library/Plug-Ins/FxPlug/Colour Space Transform.app/Contents/PlugIns/Colour Space Transform XPC Service.pluginkit/Contents/Resources/default.metallib", + "bytes": 39288, + "sha256": "b38165dd86bb6e038f7835373dadb51a54a0ad266c67672ff8fcd9548641c2d3" + } + }, + { + "name": "ColorFinale", + "version": "2.16.2 (625)", + "path": "/Applications/ColorFinale.app/Contents/PlugIns/ColorFinale.pluginkit/Contents/MacOS/ColorFinale", + "bytes": 4098720, + "sha256": "49121a6f5487060d322a59e7658166ab772e8a56f7dc1bcfa9d433a89436b30f", + "arm64": { + "offset": 16384, + "bytes": 4082336, + "sha256": "748f0119cf3a77e0d53e4c3f2b48dfa6fe7227dd44cbd75a28b070e7b962adc4" + } + }, + { + "name": "GradeKit", + "path": "/Applications/ColorFinale.app/Contents/PlugIns/ColorFinale.pluginkit/Contents/Frameworks/GradeKit.framework/Versions/A/GradeKit", + "bytes": 1462656, + "sha256": "e868a8c6df64bf03b7c24af5657c5ac7a2259a1943dfe06e01dbb7881df018a3" + }, + { + "name": "RenderingEngine", + "path": "/Applications/ColorFinale.app/Contents/PlugIns/ColorFinale.pluginkit/Contents/Frameworks/RenderingEngine.framework/Versions/A/RenderingEngine", + "bytes": 1072736, + "sha256": "32dca93459347e5ad363cb145d0ccf84b933b2045eee2c9535676a01744b84e3" + } + ], + "scope": "Read-only inspection of explicit installed targets; derived slices remain local cache; no vendor binary or LUT resource added to repository." +}