WIP: integrate opt-in ACES renderer and inspector; Release compiles, regression validation pending

这个提交包含在:
mac 于 2026-11-03 12:44:08 +08:00 提交
1 父节点 70a50ab445
当前提交 bb5ede7be4
12 个文件已更改
+171 -20

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

+27 -4
查看文件
@@ -1,3 +1,8 @@
#import "DYManagedColor.h"
#import "../../ColorManagement/Sources/DYColorManagementGPU.h"
#import "../../ColorManagement/Sources/DYColorProfile.h"
#include <map>
#include <mutex>
#import "DYRenderer.h"
#import "../Shared/DYBetaDiagnostics.h"
#import "DYModel.h"
@@ -26,6 +31,7 @@ static id<MTLTexture> texture3D(id<MTLDevice>d,const float*values,NSUInteger n){
- (void)dealloc{[_tex release];[super dealloc];}
- (id<MTLTexture>)metalTextureForDevice:(id<MTLDevice>)d{return d.registryID==_registry?_tex:nil;}
- (void)setBounds:(FxRect)bounds origin:(FxImageOrigin)origin{_bounds=bounds;_origin=origin;}
- (CGColorSpaceRef)colorSpace{static CGColorSpaceRef s;static dispatch_once_t once;dispatch_once(&once,^{s=CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB);});return s;}
- (FxRect)tilePixelBounds{return _bounds;}
- (FxRect)imagePixelBounds{return self.tilePixelBounds;}
- (uint64_t)deviceRegistryID{return _registry;}
@@ -56,6 +62,20 @@ static void bypassIdleSkin(DYUniforms *u){
for(int i=0;i<13;i++){BOOL group=(i>=6&&i<=9)?u->colorSectionEnabled>.5:u->baseSectionEnabled>.5;if(group&&enabled[i]>.5&&values[i]!=0)return;}
u->skinProtection.x=0;
}
// Admission and identity bypass for the explicitly bounded finishing domain.
static NSArray *DYManagedActiveFinishing(DYUniforms u,NSDictionary *paths,NSData *spider,NSDictionary *tools){
bypassNeutralTools(&u);bypassIdleSkin(&u);if(u.cm.blackWhiteMix<=0)u.blackWhiteSectionEnabled=0;
NSMutableArray *active=[NSMutableArray array];
for(NSString *type in DYToolTypes()){
if([type isEqual:@"primary"])continue;
NSMutableDictionary *values=[NSMutableDictionary dictionary],*localPaths=[NSMutableDictionary dictionary];
for(NSDictionary *d in DYBaseToolDescriptors(type))if([d[@"offset"]integerValue]>=0)values[d[@"key"]]=@(*(float*)((uint8_t*)&u+[d[@"offset"]unsignedIntegerValue]));
if([type isEqual:@"look"]&&u.lookSectionEnabled>.5)for(NSString *key in paths)if([key hasPrefix:@"look"])localPaths[key]=paths[key];
NSMutableDictionary *node=[NSMutableDictionary dictionaryWithDictionary:@{@"type":type,@"values":values,@"paths":localPaths}];if([type isEqual:@"spider"]&&spider)node[@"spider"]=spider;
if(!DYToolIsNeutral(node))[active addObject:type];
}
for(NSDictionary *node in tools[@"layers"])if(!DYToolIsNeutral(node))[active addObject:node[@"type"]];return active;
}
@interface DYRenderer(){
NSMutableDictionary *_devices,*_luts,*_preparedLUTs;
NSSet *_activeLUTPaths;
@@ -65,14 +85,16 @@ static void bypassIdleSkin(DYUniforms *u){
NSData *_preview,*_lookLUTPreview;
CFTimeInterval _lastPreview;
BOOL _exporting;
NSDictionary *_toolDocument;
NSDictionary *_toolDocument,*_colorContext,*_exportManagedState;
BOOL _managedFinishing;
}
@end
@implementation DYRenderer
#include "DYFilmRender.inc.h"
#include "DYManagedRender.inc.h"
#include "DYToolRender.inc.h"
- (instancetype)init{if((self=[super init])){_previewLock=[NSObject new];_devices=[NSMutableDictionary new];_luts=[NSMutableDictionary new];_preparedLUTs=[NSMutableDictionary new];_activeLUTPaths=[NSSet new];_lutPreparationQueue=dispatch_queue_create("com.dayu.color.lut-upload",DISPATCH_QUEUE_SERIAL);dispatch_set_target_queue(_lutPreparationQueue,dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0));_tables=[DYColorTables new];}return self;}
- (void)dealloc{[_devices release];[_luts release];[_preparedLUTs release];[_activeLUTPaths release];dispatch_release(_lutPreparationQueue);[_tables release];[_preview release];[_lookLUTPreview release];[_previewLock release];[super dealloc];}
- (void)dealloc{[_devices release];[_luts release];[_preparedLUTs release];[_activeLUTPaths release];dispatch_release(_lutPreparationQueue);[_tables release];[_preview release];[_lookLUTPreview release];[_colorContext release];[_previewLock release];[super dealloc];}
- (void)trimPreparedLUTsKeeping:(NSString *)path {
if(_preparedLUTs.count<=12)return;
for(NSString *key in _preparedLUTs.allKeys)if(![_activeLUTPaths containsObject:key]&&![key isEqualToString:path])[_preparedLUTs removeObjectForKey:key];
@@ -198,17 +220,18 @@ static void bypassIdleSkin(DYUniforms *u){
- (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)u paths:(NSDictionary*)paths error:(NSError**)err{return [self exportLUT:url uniforms:u paths:paths spider:nil error:err];}
- (BOOL)exportLUT:(NSURL*)url uniforms:(DYUniforms)u paths:(NSDictionary*)paths spider:(NSData*)spider error:(NSError**)err{@synchronized(self){
if(DYFilmToolActive(u)&&DYFilmSpatialActive(u.film))return fail(err,@"胶片空间和颗粒处理不能保存到静态 Cube,请保存完整预设。");
NSMutableDictionary *e=[self device:0 error:err];if(!e)return NO;id<MTLDevice>d=e[@"device"];const NSUInteger n=33,count=n*n*n,width=n*n,height=n;
NSMutableDictionary *e=[self device:0 error:err];if(!e)return NO;id<MTLDevice>d=e[@"device"];const NSUInteger n=_exportManagedState?65:33,count=n*n*n,width=n*n,height=n;
MTLTextureDescriptor *desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA16Float width:width height:height mipmapped:NO];desc.storageMode=MTLStorageModeShared;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite|MTLTextureUsageRenderTarget;
id<MTLTexture>input=[d newTextureWithDescriptor:desc],output=[d newTextureWithDescriptor:desc];if(!input||!output){[input release];[output release];return fail(err,@"无法分配 LUT 色格");}
std::vector<__fp16>values(count*4);for(NSUInteger i=0;i<count;i++){float v[3]={(float)(i%n)/(n-1),(float)((i/n)%n)/(n-1),(float)(i/(n*n))/(n-1)};for(int c=0;c<3;c++)values[i*4+c]=v[c]<=.04045f?v[c]/12.92f:powf((v[c]+.055f)/1.055f,2.4f);values[i*4+3]=1;}
[input replaceRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0 withBytes:values.data() bytesPerRow:width*8];
DYExportTile *source=[[[DYExportTile alloc]initWithTexture:input registry:d.registryID]autorelease],*dest=[[[DYExportTile alloc]initWithTexture:output registry:d.registryID]autorelease];
u.textureEnabled=0;u.clarityEnabled=0;u.dehazeEnabled=0;BOOL ok=NO;_exporting=YES;
@try{ok=[self renderSource:source destination:dest uniforms:u paths:paths spider:spider tools:_toolDocument error:err];}@finally{_exporting=NO;}
@try{ok=[self renderSource:source destination:dest uniforms:u paths:paths spider:spider tools:_toolDocument colorManagement:_exportManagedState hostPrimaries:kFxColorPrimaries_Rec709 error:err];}@finally{_exporting=NO;}
if(ok)[output getBytes:values.data() bytesPerRow:width*8 fromRegion:MTLRegionMake2D(0,0,width,height) mipmapLevel:0];[input release];[output release];if(!ok)return NO;
NSMutableString *text=[NSMutableString stringWithString:@"TITLE \"大鱼调色\"\n# 包含 CST 与逐像素颜色;不包含纹理、清晰度和逐画面分析。\nLUT_3D_SIZE 33\nDOMAIN_MIN 0 0 0\nDOMAIN_MAX 1 1 1\n"];
for(NSUInteger i=0;i<count;i++){float rgb[3];for(int c=0;c<3;c++){float v=values[i*4+c];rgb[c]=v<=.0031308f?v*12.92f:1.055f*powf(v,1/2.4f)-.055f;if(!std::isfinite(rgb[c]))return fail(err,@"LUT 输出含无效值");}[text appendFormat:@"%.8f %.8f %.8f\n",rgb[0],rgb[1],rgb[2]];}
if(_exportManagedState){[text replaceOccurrencesOfString:@"LUT_3D_SIZE 33" withString:@"LUT_3D_SIZE 65" options:0 range:NSMakeRange(0,text.length)];[text insertString:@"# V2 input: declared camera/LUT code values, or sRGB in host mode. Output: sRGB / Rec.709.\n" atIndex:0];}
return [text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:err];
}}
@end