Are UIViews that are subviews of MTKViews being handled / rendered on the GPU?

390 Views Asked by At

I am adding a UIView to a MTKView and animating the UIView in the DRAW delegate method of the MTKViewDelegate.

Will this animation be handled by the GPU / Metal? Should the animation be smoother or the same as if I were using UIView.animate?

     func draw(in view: MTKView) {

      let newdescriptor = self.metalview.currentRenderPassDescriptor
      let commandbuffer = self.metalqueue.makeCommandBuffer()
      let commandencoder = commandbuffer?.makeRenderCommandEncoder(descriptor: newdescriptor!)



      // //////////////////////////// //
      timer += 0.01
      var currenttime = sin(timer)
      uiviewbox.transform = CGAffineTransform(rotationAngle: CGFloat(sin(timer)))
      // //////////////////////////// //




      commandencoder?.endEncoding()
      let thedrawable = self.metalview.currentDrawable
      commandbuffer?.present(thedrawable!)
      commandbuffer?.commit()
 }
1

There are 1 best solutions below

0
On

Short answer: no, and no. In effect, the fact that this view is a subview of the MTKView and that you are using the draw method as a clock is completely irrelevant. What you're doing is no different from changing something about the view on every callback from a CADisplayLink — and you would never ask whether that was more efficient or on the GPU. In fact, because this is done on the main thread, this is arguably less efficient than normal view animation (in the same way as UIKit Dynamics which uses the CADisplayLink technique as well).