WIP: benchmark Metal mask flow and reduce inspector repeated work

这个提交包含在:
mac 于 2026-11-06 17:56:41 +08:00 提交
1 父节点 ca4abaf2c3
当前提交 48ac192d4b
12 个文件已更改
+392 -18

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

+10 -4
查看文件
@@ -395,12 +395,13 @@ BOOL DYToolIsNeutral(NSDictionary *node){NSString *type=node[@"type"];DYUniforms
@implementation DYToolManager {
id<PROAPIAccessing> _host;NSString *_nodeID,*_type;NSInteger _depth;CMTime _time;NSMutableDictionary *_pending;DYInspectorToken *_token;
DYUniforms _readUniforms;BOOL _readUniformsValid;
}
@synthesize host=_host,nodeID=_nodeID,type=_type;
- (instancetype)initWithHost:(id<PROAPIAccessing>)h node:(NSDictionary*)n{if((self=[super init])){_host=h;_nodeID=[n[@"id"]copy];_type=[n[@"type"]copy];}return self;}
- (void)dealloc{[_nodeID release];[_type release];[_pending release];[_token release];[super dealloc];}
- (id)apiForProtocol:(Protocol*)p{if(protocol_isEqual(p,@protocol(FxParameterRetrievalAPI_v6))||protocol_isEqual(p,@protocol(FxParameterSettingAPI_v6))||protocol_isEqual(p,@protocol(FxCustomParameterActionAPI_v4)))return self;return [_host apiForProtocol:p];}
- (void)startAction:(id)sender{if(_depth++==0){[[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]startAction:sender];_time=[(id<FxCustomParameterActionAPI_v4>)[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]currentTime];[_pending release];_pending=[DYMutablePlist(DYReadTools(_host,_time).document)retain];}}
- (void)startAction:(id)sender{if(_depth++==0){_readUniformsValid=NO;[[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]startAction:sender];_time=[(id<FxCustomParameterActionAPI_v4>)[_host apiForProtocol:@protocol(FxCustomParameterActionAPI_v4)]currentTime];[_pending release];_pending=[DYMutablePlist(DYReadTools(_host,_time).document)retain];}}
- (void)endAction:(id)sender{
if(_depth<=0||--_depth>0)return;
@try{
@@ -415,9 +416,14 @@ BOOL DYToolIsNeutral(NSDictionary *node){NSString *type=node[@"type"];DYUniforms
}
}
- (CMTime)currentTime{return _time;}
- (NSDictionary*)node{return DYToolWithID(_pending?:DYReadTools(_host,_time).document,_nodeID);}
- (BOOL)getFloatValue:(double*)out fromParameter:(UInt32)pid atTime:(CMTime)t{NSDictionary *n=[self node];DYUniforms u=DYToolUniforms(n?:@{@"type":_type});for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){*out=[d[@"offset"]integerValue]>=0?*(float*)((uint8_t*)&u+[d[@"offset"]unsignedIntegerValue]):[d[@"default"]doubleValue];return YES;}return NO;}
- (BOOL)setFloatValue:(double)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth||!std::isfinite(v))return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){NSString *key=d[@"key"];if(n[@"primaryFollow"]&&([key hasSuffix:@"Transfer"]||[key hasSuffix:@"Gamut"])){NSUInteger bit=[key hasPrefix:@"cminput"]?1:[key hasPrefix:@"cmworking"]?2:[key hasPrefix:@"cmoutput"]?4:0;n[@"primaryFollow"]=@([n[@"primaryFollow"]unsignedIntegerValue]&~bit);}n[@"values"][key]=@(v);return YES;}return NO;}
- (NSDictionary*)node{return DYToolWithID(_depth?_pending:DYReadTools(_host,_time).document,_nodeID);}
- (BOOL)getFloatValue:(double*)out fromParameter:(UInt32)pid atTime:(CMTime)t{
// One coherent snapshot per action, invalidated by any authoring write.
// Inspector controls previously rebuilt every section for every scalar.
if(!_depth||!_readUniformsValid){_readUniforms=DYToolUniforms([self node]?:@{@"type":_type});_readUniformsValid=_depth>0;}
for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){if(out)*out=[d[@"offset"]integerValue]>=0?*(float*)((uint8_t*)&_readUniforms+[d[@"offset"]unsignedIntegerValue]):[d[@"default"]doubleValue];return YES;}return NO;
}
- (BOOL)setFloatValue:(double)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth||!std::isfinite(v))return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;for(NSDictionary *d in DYDescriptors())if([d[@"pid"]unsignedIntValue]==pid){NSString *key=d[@"key"];if(n[@"primaryFollow"]&&([key hasSuffix:@"Transfer"]||[key hasSuffix:@"Gamut"])){NSUInteger bit=[key hasPrefix:@"cminput"]?1:[key hasPrefix:@"cmworking"]?2:[key hasPrefix:@"cmoutput"]?4:0;n[@"primaryFollow"]=@([n[@"primaryFollow"]unsignedIntegerValue]&~bit);}n[@"values"][key]=@(v);_readUniformsValid=NO;return YES;}return NO;}
- (BOOL)getCustomParameterValue:(id*)out fromParameter:(UInt32)pid atTime:(CMTime)t{if(pid==DYAssetsParameterID){DYAssetState *a=[[[DYAssetState alloc]init]autorelease];NSDictionary *n=[self node];a.paths=n[@"paths"]?:@{};a.spiderMesh=n[@"spider"];a.spiderLinked=[n[@"spiderLinked"]boolValue];*out=a;return YES;}if(pid==DYInspectorParameterID){DYInspectorToken *global=_token; if(!global)[[_host apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getCustomParameterValue:&global fromParameter:pid atTime:t];DYInspectorToken *local=[[[DYInspectorToken alloc]init]autorelease];NSMutableDictionary *folds=[NSMutableDictionary dictionary];for(NSString *key in global.folds)if([key hasPrefix:[_nodeID stringByAppendingString:@":"]])folds[[key substringFromIndex:_nodeID.length+1]]=global.folds[key];local.folds=folds;*out=local;return YES;}return NO;}
- (BOOL)setCustomParameterValue:(id)v toParameter:(UInt32)pid atTime:(CMTime)t{if(!_depth)return NO;NSMutableDictionary *n=(id)[self node];if(!n)return NO;if(pid==DYAssetsParameterID&&[v isKindOfClass:DYAssetState.class]){n[@"paths"]=DYMutablePlist([v paths]);if([v spiderMesh])n[@"spider"]=[v spiderMesh];else[n removeObjectForKey:@"spider"];n[@"spiderLinked"]=@([v spiderLinked]);return YES;}if(pid==DYInspectorParameterID){DYInspectorToken *old=nil;[[_host apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)]getCustomParameterValue:&old fromParameter:pid atTime:t];[_token release];_token=old?[old copy]:[DYInspectorToken new];NSMutableDictionary *folds=[[_token.folds mutableCopy]autorelease];for(NSString *key in [v folds])folds[[_nodeID stringByAppendingFormat:@":%@",key]]=[v folds][key];_token.folds=folds;return YES;}return NO;}
@end