减少多层调色 GPU 等待与检查器拖动写入
这个提交包含在:
1 父节点
79f1dd4545
当前提交
38e9fb25a2
19 个文件已更改
+427
-98
没有与搜索条件相匹配的文件
@@ -42,6 +42,7 @@
|
||||
"adaptations": [
|
||||
"Dedicated com.dayu.color runtime cache",
|
||||
"Standalone RGBA/alpha header, excluding unrelated layer engine",
|
||||
"No dependency on the sibling installed application"
|
||||
"No dependency on the sibling installed application",
|
||||
"Batch GPU profile prepare, Core Image and restore on the same command buffer for uncancelled render calls"
|
||||
]
|
||||
}
|
||||
@@ -123,9 +123,38 @@ CGColorSpaceRef DYCreateCMSOutputColorSpace(dycm::Output output){
|
||||
admission(uint64_t(input.width)*input.height,bytes);auto desc=[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA32Float width:input.width height:input.height mipmapped:NO];desc.storageMode=MTLStorageModePrivate;desc.usage=MTLTextureUsageShaderRead|MTLTextureUsageShaderWrite;
|
||||
auto opaque=[_device newTextureWithDescriptor:desc],converted=[_device newTextureWithDescriptor:desc];if(!opaque||!converted)throw std::runtime_error("无法分配颜色转换图像");uint64_t actual=input.allocatedSize+output.allocatedSize+opaque.allocatedSize+converted.allocatedSize;
|
||||
if(actual>bytes||2*uint64_t(input.width)*input.height*16>bytes-actual)throw std::runtime_error("颜色转换实际纹理及估算系统工作区超过预算");
|
||||
auto dispatch=[&](id<MTLComputePipelineState>pipeline,NSArray*textures){check(cancelled);auto command=[_queue commandBuffer];auto encoder=[command computeCommandEncoder];if(!encoder)throw std::runtime_error("无法建立颜色转换编码器");[encoder setComputePipelineState:pipeline];for(NSUInteger i=0;i<textures.count;i++)[encoder setTexture:textures[i] atIndex:i];uint32_t parameters[2]={alpha==dycm::Alpha::Premultiplied,uint32_t(_profile.decodeHLG)};[encoder setBytes:parameters length:sizeof(parameters) atIndex:0];NSUInteger x=pipeline.threadExecutionWidth,y=std::min(NSUInteger(8),pipeline.maxTotalThreadsPerThreadgroup/x);[encoder dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(x,y,1)];[encoder endEncoding];finish(command);};
|
||||
dispatch(_prepare,@[input,opaque]);auto image=[CIImage imageWithMTLTexture:opaque options:@{kCIImageColorSpace:(__bridge id)_profile.conversionSource,kCIImageToneMapHDRtoSDR:@NO}];auto destination=[[CIRenderDestination alloc]initWithMTLTexture:converted commandBuffer:nil];configure(destination,_profile.target);
|
||||
if(!image||!render(_context,image,destination,input.width,input.height,error)){[_context clearCaches];return NO;}check(cancelled);dispatch(_restore,@[input,converted,output]);[_context clearCaches];return YES;
|
||||
auto dispatch=[&](id<MTLCommandBuffer>command,id<MTLComputePipelineState>pipeline,NSArray*textures){
|
||||
check(cancelled);
|
||||
auto encoder=[command computeCommandEncoder];if(!encoder)throw std::runtime_error("无法建立颜色转换编码器");
|
||||
[encoder setComputePipelineState:pipeline];
|
||||
for(NSUInteger i=0;i<textures.count;i++)[encoder setTexture:textures[i] atIndex:i];
|
||||
uint32_t parameters[2]={alpha==dycm::Alpha::Premultiplied,uint32_t(_profile.decodeHLG)};
|
||||
[encoder setBytes:parameters length:sizeof(parameters) atIndex:0];
|
||||
NSUInteger x=pipeline.threadExecutionWidth,y=std::min(NSUInteger(8),pipeline.maxTotalThreadsPerThreadgroup/x);
|
||||
[encoder dispatchThreads:MTLSizeMake(input.width,input.height,1) threadsPerThreadgroup:MTLSizeMake(x,y,1)];
|
||||
[encoder endEncoding];
|
||||
};
|
||||
auto command=[_queue commandBuffer];
|
||||
dispatch(command,_prepare,@[input,opaque]);
|
||||
// Keep cancellation checkpoints for callers that supply a cancellation flag.
|
||||
if(cancelled){finish(command);command=nil;}
|
||||
auto image=[CIImage imageWithMTLTexture:opaque options:@{kCIImageColorSpace:(__bridge id)_profile.conversionSource,kCIImageToneMapHDRtoSDR:@NO}];
|
||||
auto destination=[[CIRenderDestination alloc]initWithMTLTexture:converted commandBuffer:command];
|
||||
configure(destination,_profile.target);
|
||||
NSError *underlying=nil;
|
||||
CIRenderTask *task=image?[_context startTaskToRender:image fromRect:CGRectMake(0,0,input.width,input.height)
|
||||
toDestination:destination atPoint:CGPointZero error:&underlying]:nil;
|
||||
if(!task){if(error)*error=underlying?:failure(@"系统颜色配置转换未开始");return NO;}
|
||||
if(cancelled){
|
||||
if(![task waitUntilCompletedAndReturnError:&underlying]){if(error)*error=underlying?:failure(@"系统颜色配置转换未完成");return NO;}
|
||||
command=[_queue commandBuffer];
|
||||
}
|
||||
dispatch(command,_restore,@[input,converted,output]);
|
||||
finish(command);
|
||||
if(!cancelled&&![task waitUntilCompletedAndReturnError:&underlying]){
|
||||
if(error)*error=underlying?:failure(@"系统颜色配置转换未完成");return NO;
|
||||
}
|
||||
return YES;
|
||||
}@catch(NSException*e){[_context clearCaches];if(error)*error=failure(e.reason?:@"显卡颜色转换异常");return NO;}}
|
||||
}catch(const std::exception&e){if(error)*error=failure(@(e.what()));return NO;}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户