title: Metal View (MTKView) Drawing Size Issue
body: <p>Here I have a MTKView and running a simple CIFilter live on camera feed.  This works fine.</p>
  
  <h2>Issue</h2>
  
  <p>On older devices' selfie camera's, such as iPhone 5, iPad Air, the feed gets drawn on a smaller area.  <strong>UPDATE</strong>: Found out that CMSampleBuffer fed to MTKView is smaller in size when this happens.  I guess the texture in each update needs to be scaled up?</p>
  
  <hr>
  
  <pre><code> import UIKit
   import MetalPerformanceShaders
   import MetalKit
   import AVFoundation
  
      final class MetalObject: NSObject, MTKViewDelegate {
  
          private var metalBufferView            : MTKView?
          private var metalDevice                = MTLCreateSystemDefaultDevice()
          private var metalCommandQueue          : MTLCommandQueue!
          private var metalSourceTexture         : MTLTexture?
          private var context                    : CIContext?
          private var filter                     : CIFilter?
  
  
          init(with frame: CGRect, filterType: Int, scaledUp: Bool) {
              super.init()
  
              self.metalCommandQueue = self.metalDevice!.makeCommandQueue()
              self.metalBufferView = MTKView(frame: frame, device: self.metalDevice)
              self.metalBufferView!.framebufferOnly = false
              self.metalBufferView!.isPaused = true
  
              self.metalBufferView!.contentScaleFactor = UIScreen.main.nativeScale
              self.metalBufferView!.delegate = self
              self.context = CIContext()
  
  
          }
  
  
          final func update (sampleBuffer: CMSampleBuffer) {
  
              var textureCache : CVMetalTextureCache?
              CVMetalTextureCacheCreate(kCFAllocatorDefault, nil, self.metalDevice!,  nil, &amp;textureCache)
              var cameraTexture: CVMetalTexture?
  
              guard
                  let cameraTextureCache = textureCache,
                  let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
                      return
              }
  
              let cameraTextureWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer, 0)
              let cameraTextureHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer, 0)
              CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault,
                                                        cameraTextureCache,
                                                        pixelBuffer,
                                                        nil,
                                                        MTLPixelFormat.bgra8Unorm,
                                                        cameraTextureWidth,
                                                        cameraTextureHeight,
                                                        0,
                                                        &amp;cameraTexture)
  
              if let cameraTexture = cameraTexture,
                  let metalTexture = CVMetalTextureGetTexture(cameraTexture) {
                  self.metalSourceTexture = metalTexture
                  self.metalBufferView!.draw()
              }
  
  
          }
  
          //MARK: - Metal View Delegate
          final func draw(in view: MTKView) {
  
              guard let currentDrawable = self.metalBufferView!.currentDrawable,
                  let sourceTexture = self.metalSourceTexture
                  else {  return  }
  
              let commandBuffer = self.metalCommandQueue!.makeCommandBuffer()
              var inputImage = CIImage(mtlTexture: sourceTexture)!.applyingOrientation(self.orientationNumber)
  
              if self.showFilter {
                  self.filter!.setValue(inputImage, forKey: kCIInputImageKey)
                  inputImage = filter!.outputImage!
              }
  
  
              self.context!.render(inputImage, to: currentDrawable.texture, commandBuffer: commandBuffer, bounds: inputImage.extent, colorSpace: self.colorSpace!)
  
              commandBuffer.present(currentDrawable)
              commandBuffer.commit()
  
          }
  
  
          final func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {
  
          }
      }
  </code></pre>
  
  <hr>
  
  <h2>Observations</h2>
  
  <ul>
  <li>Only happens on selfie cameras of older devices</li>
  <li>Selfie cameras on newer devices are fine
  when the issue occurs, new content gets drawn in a smaller area (gravitated towards top left), with old content from back camera is still remaining outside of new content.</li>
  <li>Constraints and the sizing/placement of Metal View is fine.</li>
  <li>self.metalBufferView!.contentScaleFactor = UIScreen.main.nativeScale
  solves the weird scaling issue on Plus devices.</li>
  </ul>