针对UInt32_t

时间:2019-06-13 07:38:47

标签: macos metal metal-performance-shaders

因此,我一直在尝试运行一些MPS内核。根据我之前在这里的问题:MPSImageIntegral returning all zeros 我试图在float值上运行MPSImageIntegral的地方。现在,我转到uint32_t值。但是事实证明,我总是断言

  

/BuildRoot/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShaders/MetalPerformanceShaders-121.4.2/MPSImage/Filters/MPSIntegral.mm:196:   断言失败`目标0x600003b62760纹理格式不正确   匹配源0x600003b62680纹理格式'

断言是令人误解的,因为我的纹理类型不是不匹配的。

这就是创建MTLTexture

的工作
+ (id<MTLTexture>) createTestTexture: (float)val metalDevice:(id<MTLDevice>)device textureWidth:(int)widthTex
{
    std::vector<uint32_t> testData;
    for(int i = 0; i < widthTex; i++)
        testData.push_back(i);

    MTLTextureDescriptor* desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR32Uint 
                    width: widthTex height:1 mipmapped:NO];
    [desc setResourceOptions:MTLResourceStorageModeManaged];
    [desc setStorageMode:MTLStorageModeManaged];
    [desc setUsage:(MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite)];

    id<MTLTexture> tex = [device newTextureWithDescriptor:desc];

    MTLRegion texDataRegion = MTLRegionMake2D(0, 0, widthTex, 1);
    [tex replaceRegion:texDataRegion mipmapLevel:0 withBytes:testData.data() bytesPerRow:1024];
    return tex;
}

这是我用来创建输入和输出纹理的函数。 然后我继续像这样运行我的MPSImageIntegral:

id<MTLTexture> inTex = [ViewController createTestTexture:1.0f metalDevice:_device textureWidth:100];
id<MTLTexture> outTex = [ViewController createTestTexture:1.0f metalDevice:_device textureWidth:100];

id<MTLCommandQueue> _commandQueue = [_device newCommandQueue];
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];

// Create a MPS filter.
[integral encodeToCommandBuffer:commandBuffer sourceTexture:inTex destinationTexture:outTex];

基于此处的文档:https://developer.apple.com/documentation/metalperformanceshaders/image_filters?language=objc MPSImageIntegral支持MTLPixelFormatR32Uint,我在这里做错什么了吗?

0 个答案:

没有答案