V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
albeeeeeert
V2EX  ›  问与答

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

  •  
  •   albeeeeeert · 2019-12-22 14:27:02 +08:00 · 1181 次点击
    这是一个创建于 1785 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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];
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2687 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 08:15 · PVG 16:15 · LAX 00:15 · JFK 03:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.