所以,我一直在尝试运行一些 MPS 内核。基于我之前的问题:MPSImageIntegral 返回全零
,我试图在浮点值上运行 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
MPSImageIntegral
://developer.apple.com/documentation/metalperformanceshaders/image_filters?language=objc支持MTLPixelFormatR32Uint
,我在这里做错了什么吗?