飛び道具ではないmetal #iosdc

78
iOSDC 2017 Shuichi Tsutsumi @shu223

Upload: shuichi-tsutsumi

Post on 22-Jan-2018

4.065 views

Category:

Mobile


0 download

TRANSCRIPT

Page 1: 飛び道具ではないMetal #iOSDC

iOSDC 2017

Shuichi Tsutsumi shu223

WWDC 2014

Swift Metal

WWDC2014 Metal

WWDC2014 Swift

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 2: 飛び道具ではないMetal #iOSDC

WWDC 2014

Swift Metal

WWDC2014 Metal

WWDC2014 Swift

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 3: 飛び道具ではないMetal #iOSDC

Swift Metal

WWDC2014 Metal

WWDC2014 Swift

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 4: 飛び道具ではないMetal #iOSDC

WWDC2014 Metal

WWDC2014 Swift

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 5: 飛び道具ではないMetal #iOSDC

WWDC2014 Swift

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 6: 飛び道具ではないMetal #iOSDC

Metal

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 7: 飛び道具ではないMetal #iOSDC

Metal

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 8: 飛び道具ではないMetal #iOSDC

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 9: 飛び道具ではないMetal #iOSDC

Metal

GPU

bull Core MLbull Visionbull Core Imagebull SceneKitbull SpriteKitbull MapKit

bull Core Animationbull UIKit

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 10: 飛び道具ではないMetal #iOSDC

143000Metal API

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 11: 飛び道具ではないMetal #iOSDC

143000

17000000Metal API

Metal API

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 12: 飛び道具ではないMetal #iOSDC

Metal

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 13: 飛び道具ではないMetal #iOSDC

Metal

Metal

Metal

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 14: 飛び道具ではないMetal #iOSDC

imageViewimage = image

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 15: 飛び道具ではないMetal #iOSDC

CPU GPU

CPUbull

bull

GPUbull

bull CPU

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 16: 飛び道具ではないMetal #iOSDC

bull CPU

- 100

bull GPU GPU

-

-

-

-

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 17: 飛び道具ではないMetal #iOSDC

1 60

bull CPUbull

OK

1

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 18: 飛び道具ではないMetal #iOSDC

1 60

bull CPUbull

OK

GPU

1

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 19: 飛び道具ではないMetal #iOSDC

GPU GPU

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 20: 飛び道具ではないMetal #iOSDC

GPU

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 21: 飛び道具ではないMetal #iOSDC

GPU

GPU

Your app

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 22: 飛び道具ではないMetal #iOSDC

OpenGL

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 23: 飛び道具ではないMetal #iOSDC

OpenGLbull API

bull

bull Apple

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 24: 飛び道具ではないMetal #iOSDC

Metalbull Apple

bull Apple

bull OpenGL 10

bull OpenGL Metal

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 25: 飛び道具ではないMetal #iOSDC

imageViewimage = image

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 26: 飛び道具ではないMetal #iOSDC

Metal API

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 27: 飛び道具ではないMetal #iOSDC

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 28: 飛び道具ではないMetal #iOSDC

bull MTLDevice bull MTLCommandQueue bull MTLCommandBuffer bull MTLCommandEncoder bull MTLTexture bull MTKView bull MTKTextureLoader bull etchellip

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 29: 飛び道具ではないMetal #iOSDC

$

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 30: 飛び道具ではないMetal #iOSDC

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 31: 飛び道具ではないMetal #iOSDC

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 32: 飛び道具ではないMetal #iOSDC

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTLCommandEncoder

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 33: 飛び道具ではないMetal #iOSDC

MTLCommandBuffer

MTLTexture

MTLDevice

MTLCommandQueue

MTKTextureLoader

MTLCommandEncoder

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 34: 飛び道具ではないMetal #iOSDC

MTLDevice

let device = MTLCreateSystemDefaultDevice()

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 35: 飛び道具ではないMetal #iOSDC

MTLTexture MTKTextureLoader

loader = MTKTextureLoader(device device) texture = try loadernewTexture( name ldquohoge scaleFactor viewcontentScaleFactor bundle nil)

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 36: 飛び道具ではないMetal #iOSDC

MTLCommandQueue MTLCommandBuffer

let commandBuffer = commandQueuemakeCommandBuffer()

hellip

commandBuffercommit()

commandQueue = devicemakeCommandQueue()

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 37: 飛び道具ではないMetal #iOSDC

MTLCommandEncoderbull

MTLRenderCommandEncoder

MTLComputeCommandEncoder

MTLBlitCommandEncode

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 38: 飛び道具ではないMetal #iOSDC

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 39: 飛び道具ではないMetal #iOSDC

MTLCommandEncoder (MTLBlitCommandEncoder)

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 40: 飛び道具ではないMetal #iOSDC

let commandBuffer = commandQueuemakeCommandBuffer()

let blitEncoder = commandBuffermakeBlitCommandEncoder() blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin srcOrigin sourceSize srcSize to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigindstOrigin) blitEncoderendEncoding()

commandBuffercommit()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 41: 飛び道具ではないMetal #iOSDC

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 42: 飛び道具ではないMetal #iOSDC

private let device = MTLCreateSystemDefaultDevice() private func setup() commandQueue = devicemakeCommandQueue() let textureLoader = MTKTextureLoader(device device) texture = try textureLoadernewTexture(name highsierra scaleFactor viewcontentScaleFactor bundle nil) mtkViewdevice = device mtkViewdelegate = self mtkViewcolorPixelFormat = texturepixelFormat

rarr rarr GPU

rarr GPU

rarr

func draw(in view MTKView) guard let drawable = viewcurrentDrawable else return guard let commandBuffer = commandQueuemakeCommandBuffer() else fatalError() guard let blitEncoder = commandBuffermakeBlitCommandEncoder() else fatalError() let targetW = min(texturewidth drawabletexturewidth) let targetH = min(textureheight drawabletextureheight) blitEncodercopy(from texture sourceSlice 0 sourceLevel 0 sourceOrigin MTLOrigin(x 0 y 0 z 0) sourceSize MTLSizeMake(targetW targetH texturedepth) to drawabletexture destinationSlice 0 destinationLevel 0 destinationOrigin MTLOrigin(x 0 y 0 z 0)) blitEncoderendEncoding() commandBufferpresent(drawable) commandBuffercommit() commandBufferwaitUntilCompleted()

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 43: 飛び道具ではないMetal #iOSDC

Powered by

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 44: 飛び道具ではないMetal #iOSDC

GPU

GPU

Your app

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 45: 飛び道具ではないMetal #iOSDC

Metalbull ARKit

bull MPS CNN RNN

bull Core Image

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 46: 飛び道具ではないMetal #iOSDC

GPU Metal

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 47: 飛び道具ではないMetal #iOSDC

bull Metal - UIKit

bull GPU GPU

bull Metal - Metal OpenGL

bull Metal -

httpsgithubcomshu223

Page 48: 飛び道具ではないMetal #iOSDC

httpsgithubcomshu223