See the comments in https://bugs.webkit.org/show_bug.cgi?id=211882
<rdar://problem/63332658>
If you copy/paste this into WebKit, it takes 11 seconds to complete. However, if you put it in a sample project, it takes less than 1 second to complete. Maybe the sandbox is interfering? id<MTLDevice> device = MTLCreateSystemDefaultDevice(); MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor new]; textureDescriptor.textureType = MTLTextureType2DArray; textureDescriptor.pixelFormat = MTLPixelFormatRGBA8Unorm; textureDescriptor.width = 512; textureDescriptor.height = 512; textureDescriptor.depth = 1; textureDescriptor.mipmapLevelCount = 9; textureDescriptor.sampleCount = 1; textureDescriptor.arrayLength = 2; textureDescriptor.storageMode = MTLStorageModePrivate; textureDescriptor.usage = MTLTextureUsageShaderRead; id<MTLTexture> texture = [device newTextureWithDescriptor:textureDescriptor]; id<MTLBuffer> buffer = [device newBufferWithLength:1048576 options:MTLStorageModeShared]; uint8_t* p = (uint8_t*)buffer.contents; for (int i = 0; i < 512; ++i) { for (int j = 0; j < 512; ++j) { p[i * 512 * 4 + j * 4 + 0] = 0; p[i * 512 * 4 + j * 4 + 1] = 255; p[i * 512 * 4 + j * 4 + 2] = 0; p[i * 512 * 4 + j * 4 + 3] = 255; } } id<MTLCommandQueue> queue = [device newCommandQueue]; id<MTLCommandBuffer> commandBuffer = [queue commandBuffer]; id<MTLBlitCommandEncoder> commandEncoder = [commandBuffer blitCommandEncoder]; [commandEncoder copyFromBuffer:buffer sourceOffset:0 sourceBytesPerRow:2048 sourceBytesPerImage:1048576 sourceSize:MTLSizeMake(512, 512, 1) toTexture:texture destinationSlice:0 destinationLevel:0 destinationOrigin: MTLOriginMake(0, 0, 0)]; [commandEncoder endEncoding]; [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) { NSLog(@"Test Done."); }]; NSLog(@"Test committing"); [commandBuffer commit]; [[NSRunLoop mainRunLoop] run];