Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Metal Acceleratedかどうかを調べる方法〜あなたのアプリのどこでMetalが暗躍...

shu223
February 22, 2018

Metal Acceleratedかどうかを調べる方法〜あなたのアプリのどこでMetalが暗躍しているのか #potatotips

potatotips #48 (iOS/Android開発Tips共有会)での発表資料です。
https://potatotips.connpass.com/event/77702/

shu223

February 22, 2018
Tweet

More Decks by shu223

Other Decks in Programming

Transcript

  1. Appleͷެࣜ৘ใཔΈ • API Reference • Programming Guide • Forum •

    WWDC Session • ʮWWDC LabͰதͷਓ͕ݴͬͯͨʯ ͔͠΋ɾɾɾ ͕࣌ؒܦͭͱɺެࣜ৘ใͰ΋ϝϯς͞Ε͍ͯͳ͍΋ͷ͸ূڌͱͯ͠ෆे෼ʹͳΔ
  2. MetalͷlabelػೳΛར༻ͯ͠͸Ͳ͏͔ʁ private func pushLabel(_ label: String) { let commandBuffer =

    commandQueue.makeCommandBuffer()! commandBuffer.label = label commandBuffer.commit() } ʮԿ΋͠ͳ͍MetalͷίϚϯυόοϑΝʯΛGPUʹϓογϡ͢Δ ϝιουΛ͓͍ͭͬͯͯ͘ɺ @IBAction func btnTapped(_ sender: UIButton) { pushLabel(“start”) imageView.image = UIImage(named: "highsierra") pushLabel(“end”) } ͜Μͳײ͡ͰݺͿͱɾɾɾ label͚͍ͩ࣋ͬͯΔ
  3. த਎ͷ͋ΔίϚϯυʹ͢Δ private func pushLabel(_ label: String) { let textureLoader =

    MTKTextureLoader(device: device) let srcTex = try! textureLoader.newTexture(name: “hoge”, scaleFactor: 2.0, bundle: nil) let descriptor = MTLTextureDescriptor.texture2DDescriptor( pixelFormat: srcTex.pixelFormat, width: srcTex.width, height: srcTex.height, mipmapped: false) let destTex = device.makeTexture(descriptor: descriptor)! let commandBuffer = commandQueue.makeCommandBuffer()! commandBuffer.label = label let blitEncoder = commandBuffer.makeBlitCommandEncoder()! blitEncoder.copy( from: srcTex, sourceSlice: 0, sourceLevel: 0, sourceOrigin: MTLOriginMake(0, 0, 0), sourceSize: MTLSizeMake(srcTex.width, srcTex.height, srcTex.depth), to: destTex, destinationSlice: 0, destinationLevel: 0, destinationOrigin: MTLOriginMake(0, 0, 0)) blitEncoder.endEncoding() commandBuffer.commit() } ຊ౰ʹཉ͍͠ͷ͸͚ͩ͜͜
  4. ·ͱΊ • ͍··ͰɺMetal Accelerated͔Ͳ͏͔Λ֬ೝ͢Δʹ͸ɺެࣜ৘ใཔΈͩͬͨ - Guide, API Reference, Forum, WWDC

    Session, WWDC LabͰݴͬͯͨ, etc…ʮཪऔΓʯ ͕೉͔ͬͨ͠ - MetalΛ໌ࣔతʹ༻͍͍ͯͳ͚Ε͹ɺXcodeͷGPU Report͸൓Ԡ͠ͳ͍ • InstrumentsͷMetal System TraceΛ༻͍ΔͱɺMetalΛ໌ࣔతʹ༻͍͍ͯͳ ͍৔߹ʹ΋ɺMetalͷಈ͖Λ஌Δ͜ͱ͕Ͱ͖Δ • ϦΞϧλΠϜʹ͸τϨʔεͰ͖ͳ͍ͷͰɺ໨ҹͱͯ͠labelΛషΔํ๏΋ݕ౼ - ҰԠ͏·͍ͬͨ͘ - ͕ɺ೿खʹMetalΛ࢖͏ख๏ʹͳͬͯ͠·ͬͨͷͰɺ͓͢͢Ί͠ͳ͍