fix: prepare and pin external LUT snapshots before acknowledging thumbnail application

这个提交包含在:
mac 于 2026-11-01 15:05:42 +08:00 提交
1 父节点 a2c8dfafcf
当前提交 593aad9ecb
12 个文件已更改
+247 -49

没有与搜索条件相匹配的文件

+42
查看文件
@@ -2,6 +2,8 @@
#import "DYModel.h"
#import "DYRenderer.h"
#import "DYAutoGrade.h"
#import "DYLUTLibrary.h"
#include <string>
#import <CoreVideo/CoreVideo.h>
#import <IOSurface/IOSurface.h>
#include <algorithm>
@@ -207,6 +209,46 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
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.systemUptime<deadline)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
[heartbeat invalidate];
run.need(@"external-decode-and-gpu-upload-complete",prepared&&!preparationError,@{@"error":reason(preparationError)});[preparationError release];
run.record(@"external-activation-main-loop-responsive",beats>0&&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.systemUptime<until)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
churnOK&=ready&&success;
}}
run.need(@"external-preview-and-gpu-cache-churn",churnOK);
Pixels retainedFrame=render(run,externalRenderer,source,destination,gpu,externalUniforms,externalPaths,@"external-render-with-source-unavailable-after-cache-churn");
Difference retainedDifference=difference(externalFrame,retainedFrame);
run.record(@"external-snapshot-is-independent-of-file-and-preview-cache",retainedDifference.maximum==0&&retainedDifference.nonfinite==0,measure(retainedDifference));
__block BOOL cancelledDone=NO;__block BOOL cancellationReported=NO;
NSProgress *cancelled=[externalRenderer prepareLUTPath:[runtime stringByAppendingPathComponent:@"eviction-00.cube"] completion:^(NSError *failure){cancellationReported=failure.code==NSUserCancelledError;cancelledDone=YES;}];[cancelled cancel];
deadline=NSProcessInfo.processInfo.systemUptime+10;
while(!cancelledDone&&NSProcessInfo.processInfo.systemUptime<deadline)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
run.record(@"external-preparation-cancellation",cancelledDone&&cancellationReported);
[gpu release];
} @catch(NSException *exception) {
run.record(@"diagnostic-exception",false,@{@"exception":exception.name?:@"unknown",@"message":exception.reason?:@"unknown"});