albeeeeeert
V2EX  ›  问与答

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

  •  
  •   albeeeeeert · Dec 22, 2019 · 1903 views
    This topic created in 2336 days ago, the information mentioned may be changed or developed.

    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];
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5113 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:43 · PVG 17:43 · LAX 02:43 · JFK 05:43
    ♥ Do have faith in what you're doing.