I have the following code using MPSImage Canny that performs as expected on my iPhone 12 pro (running iOS 15):
UIImage *image = [UIImage imageNamed:@"image.png" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection: nil];
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
MTKTextureLoader *textureLoader = [[MTKTextureLoader alloc] initWithDevice:device];
id<MTLTexture> imageTexture = [textureLoader newTextureWithCGImage:image.CGImage options:@{MTKTextureLoaderOptionTextureStorageMode: @0} error:nil];
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatR32Float width:imageTexture.width height:imageTexture.height mipmapped:NO];
id<MTLTexture> edgesTexture = [device newTextureWithDescriptor:textureDescriptor];
float luminanceWeights[3] = {0.33, 0.34, 0.33};
MPSImageCanny *canny = [[MPSImageCanny alloc] initWithDevice:commandBuffer.device linearToGrayScaleTransform:luminanceWeights sigma:1.5];
canny.useFastMode = YES;
canny.lowThreshold = 0.8;
canny.highThreshold = 0.2;
[canny encodeToCommandBuffer:commandBuffer sourceTexture:imageTexture destinationTexture:edgesTexture]; // Error thrown here
[commandBuffer commit];
[commandBuffer waitUntilCompleted];
The problem is when I run the same block on an iPhone 7 (running iOS 14) it crashes at the call to encodeToCommandBuffer line with the following output "failed assertion 0 at line 1161 in dispatchTheadgroupDimensionMismatchedWithComputePipeline".
Is this a bug in the Canny performance shaders or is it not possible to use this shader on a device that doesn't support non-uniform threadgroup sizes? Any help/pointers would be greatly appreciated 😊