V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
albeeeeeert
V2EX  ›  问与答

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

  •  
  •   albeeeeeert · Dec 22, 2019 · 1883 views
    This topic created in 2331 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   ·   1021 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:30 · PVG 02:30 · LAX 11:30 · JFK 14:30
    ♥ Do have faith in what you're doing.