Normalize motion sampling with low-pass capture; 285 native and 19 independent checks pass
这个提交包含在:
1 父节点
3b57e36eb1
当前提交
c771a9274a
7 个文件已更改
+275
-4
没有与搜索条件相匹配的文件
@@ -15,7 +15,7 @@
|
||||
- (dy::GrayFrame)toolGrayFrame:(FxImageTile*)tile error:(NSError**)error {
|
||||
@synchronized(_toolCaptureDevices){FxRect b=tile.tilePixelBounds,image=tile.imagePixelBounds;if(b.left!=image.left||b.right!=image.right||b.bottom!=image.bottom||b.top!=image.top)return {};
|
||||
NSNumber *key=@(tile.deviceRegistryID);NSMutableDictionary *entry=_toolCaptureDevices[key];if(!entry){NSArray *devices=MTLCopyAllDevices();id<MTLDevice>d=nil;for(id<MTLDevice>candidate in devices)if(candidate.registryID==tile.deviceRegistryID)d=candidate;if(d){id<MTLLibrary>library=[d newLibraryWithURL:[[NSBundle bundleForClass:self.class]URLForResource:@"default" withExtension:@"metallib"]error:error];id<MTLFunction>function=[library newFunctionWithName:@"dyToolCapture"];id<MTLComputePipelineState>pipeline=function?[d newComputePipelineStateWithFunction:function error:error]:nil;id<MTLCommandQueue>queue=[d newCommandQueue];if(pipeline&&queue){entry=[NSMutableDictionary dictionaryWithDictionary:@{@"device":d,@"pipeline":pipeline,@"queue":queue}];_toolCaptureDevices[key]=entry;}[pipeline release];[queue release];[function release];[library release];}[devices release];if(!entry)return {};}
|
||||
id<MTLTexture>texture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=tile.pixelAspect;if(!std::isfinite(aspect)||aspect<=0)return {};aspect=MAX(.01,aspect);double displayHeight=texture.height/aspect,scale=MIN(1.,MIN(3840./texture.width,2160./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>2160||width>3840)return {};
|
||||
id<MTLTexture>texture=[tile metalTextureForDevice:entry[@"device"]];if(!texture)return {};double aspect=tile.pixelAspect;if(!std::isfinite(aspect)||aspect<=0)return {};aspect=MAX(.01,aspect);double displayHeight=texture.height/aspect,scale=MIN(1.,MIN(1280./texture.width,720./displayHeight));unsigned width=(unsigned)floor(texture.width*scale),height=(unsigned)floor(displayHeight*scale);if(width<16||height<16||height>720||width>1280)return {};
|
||||
id<MTLBuffer>buffer=[entry[@"device"]newBufferWithLength:width*height*sizeof(float) options:MTLResourceStorageModeShared];if(!buffer)return {};vector_uint3 info={width,height,(unsigned)(tile.imageOrigin==kFxImageOrigin_BOTTOM_LEFT)};id<MTLCommandBuffer>commands=[entry[@"queue"]commandBuffer];id<MTLComputeCommandEncoder>encoder=[commands computeCommandEncoder];[encoder setComputePipelineState:entry[@"pipeline"]];[encoder setTexture:texture atIndex:0];[encoder setBuffer:buffer offset:0 atIndex:0];[encoder setBytes:&info length:sizeof(info) atIndex:1];[encoder dispatchThreads:MTLSizeMake(width,height,1) threadsPerThreadgroup:MTLSizeMake(16,16,1)];[encoder endEncoding];[commands commit];[commands waitUntilCompleted];dy::GrayFrame frame;if(commands.status==MTLCommandBufferStatusCompleted){frame={int(width),int(height),std::vector<float>(width*height)};memcpy(frame.pixels.data(),buffer.contents,width*height*sizeof(float));}[buffer release];return frame;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,11 @@
|
||||
DYWriteTools(base,doc,kCMTimeZero);capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];
|
||||
// Deliberately different preview pixels must not veto an authoritative analysis seed.
|
||||
for(int i=0;i<3&&callbacks;i++){setFrame(i+2);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"analysis-seed-does-not-require-preview-pixel-equality",callbacks&&[tracked[@"keys"]count]==3);
|
||||
{
|
||||
const NSUInteger w=3840,h=2160;DYDiagnosticTile *fine=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels pixels(w*h*4);
|
||||
for(NSUInteger y=0;y<h;y++)for(NSUInteger x=0;x<w;x++){float encoded=x%3==1?.8f:.2f,linear=powf((encoded+.055f)/1.055f,2.4f);auto i=(y*w+x)*4;pixels[i]=pixels[i+1]=pixels[i+2]=linear;pixels[i+3]=1;}
|
||||
[[fine metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,w,h) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:w*8];auto gray=[plugin toolGrayFrame:fine error:nil];double maximum=0;for(float v:gray.pixels)maximum=std::max(maximum,fabs(v-.4));
|
||||
run.record(@"tracking-4k-frame-lowpass-before-normalized-motion-grid",gray.valid()&&gray.width==1280&&gray.height==720&&maximum<.002,@{@"width":@(gray.width),@"height":@(gray.height),@"maximumError":@(maximum)});
|
||||
}
|
||||
[plugin release];
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "MaskCore/DYTracker.hpp"
|
||||
@interface DYToolTrackingProbe : NSObject<PROAPIAccessing> {
|
||||
@public
|
||||
id _base;CMTime _time;FxAnalysisState _state;int _forwardStarts,_backwardStarts;
|
||||
@@ -23,6 +24,7 @@
|
||||
- (BOOL)setupAnalysisForTimeRange:(CMTimeRange)range frameDuration:(CMTime)duration error:(NSError**)error;
|
||||
- (BOOL)analyzeFrame:(FxImageTile*)frame atTime:(CMTime)time error:(NSError**)error;
|
||||
- (BOOL)cleanupAnalysis:(NSError**)error;
|
||||
- (dy::GrayFrame)toolGrayFrame:(FxImageTile*)tile error:(NSError**)error;
|
||||
@end
|
||||
|
||||
@interface DYToolCanvasProbe : DYToolTrackingProbe @end
|
||||
|
||||
@@ -50,8 +50,11 @@ kernel void dyTrackFlow(device const float*prev[[buffer(0)]],device const float*
|
||||
if(lane==0)results[idx]=float4(q,error,ok?1.f:0.f);
|
||||
}
|
||||
|
||||
// Full host frame -> top-first display luma. Analysis and reference use the
|
||||
// same sampler, alpha convention and transfer; no 320x180 inspector preview.
|
||||
// Full host frame -> top-first display luma. Low-pass the source footprint
|
||||
// before decimation so 4K fabric detail cannot alias into inconsistent motion.
|
||||
// This analysis-only image never changes the full-resolution color render.
|
||||
kernel void dyToolCapture(texture2d<float> source [[texture(0)]],device float* pixels [[buffer(0)]],constant uint3& info [[buffer(1)]],uint2 pos [[thread_position_in_grid]]){
|
||||
if(pos.x>=info.x||pos.y>=info.y)return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);float2 uv=(float2(pos)+.5f)/float2(info.xy);if(info.z)uv.y=1-uv.y;float4 sample=source.sample(f,uv);float3 linear=sample.a>0?sample.rgb/sample.a:float3(0);float3 encoded=select(1.055f*pow(max(linear,float3(0)),float3(1.f/2.4f))-.055f,linear*12.92f,linear<=.0031308f);pixels[pos.y*info.x+pos.x]=dot(clamp(encoded,0.f,1.f),float3(.2126f,.7152f,.0722f));
|
||||
if(pos.x>=info.x||pos.y>=info.y)return;constexpr sampler f(coord::normalized,address::clamp_to_edge,filter::linear);uint2 taps=clamp(uint2(ceil(float2(source.get_width(),source.get_height())/float2(info.xy))),uint2(1),uint2(8));float sum=0;
|
||||
for(uint y=0;y<taps.y;y++)for(uint x=0;x<taps.x;x++){float2 uv=(float2(pos)+(float2(x,y)+.5f)/float2(taps))/float2(info.xy);if(info.z)uv.y=1-uv.y;float4 sample=source.sample(f,uv);float3 linear=sample.a>0?sample.rgb/sample.a:float3(0);float3 encoded=select(1.055f*pow(max(linear,float3(0)),float3(1.f/2.4f))-.055f,linear*12.92f,linear<=.0031308f);sum+=dot(clamp(encoded,0.f,1.f),float3(.2126f,.7152f,.0722f));}
|
||||
pixels[pos.y*info.x+pos.x]=sum/float(taps.x*taps.y);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户