metal performance shader 实现直方图均衡化,直方图计算部分没问题,到了执行 encodeTransformToCommandBuffer 计算累加直方图的时候报错.

2019-12-22 14:27:02 +08:00
 albeeeeeert

metal performance shader 实现直方图均衡化,直方图计算部分没问题,到了执行 encodeTransformToCommandBuffer 计算累加直方图的时候报错: -[MTLDebugComputeCommandEncoder setBuffer:offset:atIndex:]:283: failed assertionoffset(4096) must be < buffer length.'`

代码:

// histogram
        MPSImageHistogramInfo info;
        info.histogramForAlpha = true;
        info.numberOfHistogramEntries = 256;
        info.minPixelValue = simd_make_float4(0, 0, 0, 0);
        info.maxPixelValue = simd_make_float4(1, 1, 1, 1);
        MPSImageHistogram *histogram = [[MPSImageHistogram alloc] initWithDevice:_device histogramInfo:&info];
        size_t length = [histogram histogramSizeForSourceFormat:sourceTexture.pixelFormat];
        id<MTLBuffer> histogramInfoBuffer = [_device newBufferWithLength:length options:MTLResourceStorageModePrivate];
        [histogram encodeToCommandBuffer:commandBuffer sourceTexture:sourceTexture histogram:histogramInfoBuffer histogramOffset:0];
        
        MPSImageHistogramEqualization *equalization = [[MPSImageHistogramEqualization alloc] initWithDevice:_device histogramInfo:&info];
        // accumulative distribution function of the histogram
        [equalization encodeTransformToCommandBuffer:commandBuffer sourceTexture:sourceTexture histogram:histogramInfoBuffer histogramOffset:0];
        // apply equalisation
        [equalization encodeToCommandBuffer:commandBuffer sourceImage:sourceTexture destinationImage:destTexture];
1193 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/631220

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX