iOS Metal Framework - NSMeetup - @greensamuelm

24
For Rockstars Sam Green @greensamuelm http://kamcord.com

description

Slides for a talk I gave at the October NSMeetup group in San Francisco. This covers the basics of Apple's new Metal framework for iOS. Sample Code: https://dl.dropboxusercontent.com/u/1180680/MetalSample.zip

Transcript of iOS Metal Framework - NSMeetup - @greensamuelm

Page 1: iOS Metal Framework - NSMeetup - @greensamuelm

For RockstarsSam Green

@greensamuelmhttp://kamcord.com

Page 2: iOS Metal Framework - NSMeetup - @greensamuelm

You know the drill

but I have to say it:

The views I express here do not necessarily reflect those of my employer.

(But, we are recruiting!)

Page 3: iOS Metal Framework - NSMeetup - @greensamuelm
Page 4: iOS Metal Framework - NSMeetup - @greensamuelm
Page 5: iOS Metal Framework - NSMeetup - @greensamuelm

Overview

● Low overhead● Unified graphics and compute shaders● Efficient multithreading● Designed for A7 & A8

○ iPhone 5S, 6, 6+○ iPad Mini Retina

Page 6: iOS Metal Framework - NSMeetup - @greensamuelm
Page 7: iOS Metal Framework - NSMeetup - @greensamuelm
Page 8: iOS Metal Framework - NSMeetup - @greensamuelm

Setting up texturing in OpenGLglGenTextures(1, &texName);glBindTexture(GL_TEXTURE_2D, texName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);

Page 9: iOS Metal Framework - NSMeetup - @greensamuelm
Page 10: iOS Metal Framework - NSMeetup - @greensamuelm

Design Goals

● Thinnest API Possible● Modern GPU features● Predictable performance● Explicit control over commands● Do expensive tasks less often

Page 11: iOS Metal Framework - NSMeetup - @greensamuelm

Demo

Page 12: iOS Metal Framework - NSMeetup - @greensamuelm

Why GPU programming is expensive

● State validation● Shader compilation● Sending work to the GPU

Page 13: iOS Metal Framework - NSMeetup - @greensamuelm

Metal Objects

● Device● Command Queue● Command Buffer● Command Encoder● State● Code● Resources

Page 14: iOS Metal Framework - NSMeetup - @greensamuelm
Page 15: iOS Metal Framework - NSMeetup - @greensamuelm

Command Submission Model

● Convert API commands into hardware commands

● Three types of command encoders○ Compute○ Blit○ Render

Page 16: iOS Metal Framework - NSMeetup - @greensamuelm

Resource Update Model

Designed for the unified memory system of iOS devices.CPU and GPU share the exact same storage.Two types of resources:● Textures (formatted images)● Buffers (unformatted bytes)

Page 17: iOS Metal Framework - NSMeetup - @greensamuelm

Command Encoder Types

● Render● Compute● Blit

Page 18: iOS Metal Framework - NSMeetup - @greensamuelm

Render Command Encoder

● Combines all commands for a single FBO● State● No more “draw time” compilation

Page 19: iOS Metal Framework - NSMeetup - @greensamuelm

Compute Command Encoder

● Called the compute kernel● Local atomics● Barriers● Memory loads and stores● User-specified workgroup dimensions

Page 20: iOS Metal Framework - NSMeetup - @greensamuelm

Blit Command Encoder

Enables async copies in parallel with graphics and compute

Page 21: iOS Metal Framework - NSMeetup - @greensamuelm

Metal Shading Language

Unified shading language for graphics and compute

C++11

Multiple shaders per source file

Page 22: iOS Metal Framework - NSMeetup - @greensamuelm

Argument Tables

Textures, buffers, and samplers passed as arguments to functions

Each command encoder includes a set of Argument Tables

Page 23: iOS Metal Framework - NSMeetup - @greensamuelm

Developer Tools

● Shader compiler● Visual frame debugger● API trace and navigation● Live shader editing● Graphics and compute state inspection● Debug mode!

Page 24: iOS Metal Framework - NSMeetup - @greensamuelm

Thanks!

● To all of you for attending!

● Steve Derico for organizing!

● My colleagues at Kamcord for their unending

support!