I am encountering the exact same symptoms.
I have an iPhone 12ProMax and an iPad Pro and I tried the exact same code.
For testing, I used the time to copy the CurrentDrawable of MTKView to the CPU side with getBytes in NSLog.
Of course, both are the exact same code. Both operating systems are the latest.
iPad PRO : W2388px H1668px - 3msec
iPhone 12 Pro Max : W1920px H1440px - 40msec
I think it's strange that the difference is more than 10 times larger than the iPad PRO, which has a much larger texture size to process.
func draw(in view: MTKView) {
guard let texture = view.currentDrawable?.texture else {
print("Drawable texture is not ready.")
return
}
let w = texture.width
let h = texture.height
let bytesPerPixel: Int = 4
let imageByteCount = w * h * bytesPerPixel
let bytesPerRow = w * bytesPerPixel
var src: UnsafeMutablePointerUInt8
NSLog("Start memory alloc")
src = UnsafeMutablePointerUInt8.allocate(capacity: imageByteCount)
let region = MTLRegionMake2D(0, 0, w, h)
NSLog("Start")
texture.getBytes(src, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)
NSLog("End")
src.deallocate()
}
Topic:
Graphics & Games
SubTopic:
Metal
Tags: