fix: orient LUT thumbnails to host image origin without changing auto analysis

这个提交包含在:
mac 于 2026-10-31 03:54:22 +08:00 提交
1 父节点 2e7ab4b052
当前提交 dde98c8836
6 个文件已更改
+77 -14

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

+34 -2
查看文件
@@ -50,8 +50,10 @@
IOSurfaceRef _surface;
FxRect _bounds;
uint64_t _registry;
FxImageOrigin _diagnosticOrigin;
}
- (instancetype)initWithDevice:(id<MTLDevice>)device width:(NSUInteger)width height:(NSUInteger)height;
- (void)setDiagnosticImageOrigin:(FxImageOrigin)origin;
@end
@implementation DYDiagnosticTile
- (instancetype)initWithDevice:(id<MTLDevice>)device width:(NSUInteger)width height:(NSUInteger)height {
@@ -63,7 +65,7 @@
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;
_bounds=(FxRect){0,0,(SInt32)width,(SInt32)height};_registry=device.registryID;_diagnosticOrigin=kFxImageOrigin_TOP_LEFT;
if(!_surface||!_texture){[self release];return nil;}
}return self;
}
@@ -73,7 +75,8 @@
- (FxRect)tilePixelBounds {return _bounds;}
- (FxRect)imagePixelBounds {return _bounds;}
- (uint64_t)deviceRegistryID {return _registry;}
- (FxImageOrigin)imageOrigin {return kFxImageOrigin_TOP_LEFT;}
- (FxImageOrigin)imageOrigin {return _diagnosticOrigin;}
- (void)setDiagnosticImageOrigin:(FxImageOrigin)origin {_diagnosticOrigin=origin;}
@end
namespace {
@@ -146,6 +149,35 @@ extern "C" int DYRunDiagnostics(void) { @autoreleasepool {
NSData *preview=[renderer preview];bool previewFinite=preview.length==320*180*16;if(previewFinite){const float *data=(const float *)preview.bytes;for(NSUInteger i=0;i<preview.length/4;i++)previewFinite&=std::isfinite(data[i]);}
run.record(@"renderer-analysis-320x180",previewFinite,@{@"bytes":@(preview.length)});
NSDictionary *autoGrade=DYAutoGrade(preview);run.record(@"renderer-auto-grade-integration",autoGrade.count==10,autoGrade?:@{});
// Vertical red/blue markers establish actual Metal texture row order.
// Browser bitmaps need top-first rows; the auto-analysis bytes must not
// be changed even when FxPlug supplies a bottom-left source texture.
Pixels marker(width*height*4),bottomFirst(marker.size());
for(NSUInteger y=0;y<height;y++)for(NSUInteger x=0;x<width;x++){
size_t p=(y*width+x)*4;marker[p]=y<height/2?.8f:.03f;marker[p+1]=.04f+.1f*float(x)/(width-1);marker[p+2]=y<height/2?.02f:.7f;marker[p+3]=1;
}
for(NSUInteger y=0;y<height;y++)memcpy(bottomFirst.data()+y*width*4,marker.data()+(height-1-y)*width*4,width*8);
DYRenderer *orientationRenderer=[[[DYRenderer alloc]init]autorelease];
[[source metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:marker.data() bytesPerRow:width*8];
error=nil;BOOL topRendered=[orientationRenderer renderSource:source destination:destination uniforms:defaults paths:@{} error:&error];
NSData *topAnalysis=[orientationRenderer preview],*topLook=[orientationRenderer lookLUTPreview];
bool topOrientation=topRendered&&topLook.length==320*180*16&&[topLook isEqualToData:topAnalysis];
if(topOrientation){const float*p=(const float*)topLook.bytes;topOrientation=p[0]>p[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));