O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Metal Programming Guide: Tutorial and Reference via Swift

Book Description

Master Metal: The Next-Generation Graphics and GPU Programming Platform for Apple Developers

 

Metal enables Apple developers to maximize performance in demanding tasks like 3D graphics, games, scientific programming, visualization, and GPU-accelerated machine learning. Metal® Programming Guide is the authoritative, practical guide to Metal for all iOS programmers who are interested in graphics programming but don’t know where to start.

 

Pioneering Apple developer Janie Clayton covers everything from basic draw calls to advanced parallel computing, combining easy-to-understand conceptual explanations with well-tested Swift 4/Xcode 9 sample code (available for download at GitHub).

 

Clayton introduces the essential Metal, graphics, and math concepts every graphics programmer needs to know. She also discusses key graphics-specific libraries, concepts, and Metal Classes, presenting techniques and examples you’ll find valuable for both graphics and data processing. Clayton also provides coverage of the Metal Compute Pipeline, demonstrating practical GPU programming applications ranging from image processing to neural networking.

  • Quickly get a basic Metal project running
  • Work with Metal resources and memory management
  • Learn how shaders are compiled and accessed by the CPU
  • Program both 2D and 3D graphics with Metal
  • Import 3D models and assets from Blender, Maya, and other programs
  • Apply imported textures to model objects
  • Use multipass rendering to efficiently implement computationally expensive techniques
  • Leverage tessellation to reduce mesh detail
  • Use the GPU for a wide spectrum of general-purpose computing applications
  • Get started with the Metal Performance Shaders Framework

Register your product at informit.com/register for convenient access to downloads, updates, and/or corrections as they become available.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Table of Contents
  5. Preface
  6. Acknowledgments
  7. About the Author
  8. Part I: Metal Basics
    1. Chapter 1. What Is Metal?
      1. History of Graphics APIs
      2. Metal: The New Way to Do Graphics on Apple Platforms
      3. Metal in Context: How Metal Complements and Supports Other Platform Frameworks
      4. Summary
    2. Chapter 2. Overview of Rendering and Raster Graphics
      1. Representing the GPU
      2. Preparing Data for the GPU
      3. Summary
    3. Chapter 3. Your First Metal Application (Hello, Triangle!)
      1. Creating a Metal Application in Xcode (without Using a Template)
      2. Creating a MTLDevice
      3. Creating a CAMetalLayer
      4. Creating a Vertex Buffer
      5. A First Look at Shaders
      6. Libraries, Functions, and Pipeline States
      7. Introducing Render Passes
      8. Introducing MetalKit Features and MTKView
      9. Summary
  9. Part II: Rendering and Graphics
    1. Chapter 4. Essential Mathematics for Graphics
      1. Language of Mathematics
      2. Coordinate Spaces and Moving among Them
      3. Points, Vectors, and Vector Operations
      4. Normalization and Unit Vectors
      5. Pythagorean Theorem
      6. Sine, Cosine, and Tangent
      7. Matrices and Matrix Operations
      8. Transformations: Scale, Translation, Rotation, Projection
      9. Summary
    2. Chapter 5. Introduction to Shaders
      1. Metal Shading Language Overview
      2. Setting Up Shaders
      3. Your First Shader: Pass Through
      4. Writing Your First Shader
      5. Uniform Buffer
      6. Summary
    3. Chapter 6. Metal Resources and Memory Management
      1. Introduction to Resources in Metal
      2. The Argument Table: Mapping between Shader Parameters and Resources
      3. Buffers
      4. Resource Options: Storage Mode, Cache Mode, Purgeability
      5. Preparing Data for the Vertex Shader and Vertex Descriptors
      6. Copying to and from Buffers
      7. Introduction to Textures
      8. Copying to and from Textures
      9. Compressed Texture Support
      10. The Blit Command Encoder
      11. Generating Mipmaps
      12. Summary
    4. Chapter 7. Libraries, Functions, and Pipeline States
      1. What Are Libraries and Functions?
      2. The Metal Two-Phase Compilation Architecture
      3. Creating Libraries at Compile Time and Runtime
      4. Command Encoders
      5. Render Pipeline Descriptors and State
      6. Pipeline Reflection
      7. Summary
    5. Chapter 8. 2D Drawing
      1. Metal Graphics Rendering Pipeline
      2. Sample Project: Build a Star
      3. Metal Primitive Types
      4. Responding to MTKViewDelegate Methods
      5. Retrieving a Drawable
      6. Creating a Command Buffer
      7. Creating a Command Encoder
      8. Fixed-Function State on the Command Encoder
      9. Passing Data to Shaders
      10. Issuing Draw Calls
      11. Scheduling and Enqueuing Command Buffers
      12. Summary
    6. Chapter 9. Introduction to 3D Drawing
      1. Model-View-Projection Transformations
      2. Clip Space and the View Frustum
      3. Shading Models
      4. Basic Lighting
      5. Animation
      6. Summary
    7. Chapter 10. Advanced 3D Drawing
      1. Constructing a Hierarchical World with Scene Graphs
      2. Instanced Rendering
      3. Summary
    8. Chapter 11. Interfacing with Model I/O
      1. What Are Model Files?
      2. Importing a Model
      3. Meshes and Submeshes
      4. Render State Pipeline
      5. Asset Initialization
      6. Render State Setup and Drawing
      7. Exporting Files
      8. Summary
    9. Chapter 12. Texturing and Sampling
      1. Texture Mapping
      2. Mipmapping
      3. Sampling
      4. Precompiled Sampler States
      5. Passing Textures and Samplers to Graphics Functions
      6. Summary
    10. Chapter 13. Multipass Rendering Techniques
      1. When (and Why) to Use Multipass Rendering
      2. Metal Render Pass Descriptors
      3. Creating and Managing Render Targets
      4. Revisiting Load-Store Actions
      5. Summary
    11. Chapter 14. Geometry Unleashed: Tessellation in Metal
      1. Removing Bottlenecks by Using Tessellation
      2. Catmull-Clark Subdivision
      3. Per-Patch Tessellation Factors
      4. Metal Tessellation Fixed-Function Pipeline
      5. Setting Up a Tessellation Kernel
      6. Post-Tessellation Vertex Function
      7. Draw Patches
      8. Summary
  10. Part III: Data Parallel Programming
    1. Chapter 15. The Metal Compute Pipeline
      1. Introduction to GPU Programming
      2. Concurrency versus Parallelism
      3. Using GPUs for General Computation
      4. Kernel Functions
      5. The Metal Compute Command Encoder
      6. Issuing Grids of Work
      7. Finding Your Way in the Grid inside the Kernel Function
      8. Reading and Writing Resources in Kernel Functions
      9. Summary
    2. Chapter 16. Image Processing in Metal
      1. Introduction to Image Processing
      2. Creating a Metal Texture
      3. Desaturation Kernels
      4. Convolution and Dispatching a 2D Grid
      5. Blur Effects
      6. Selecting an Optimal Threadgroup Size
      7. Summary
    3. Chapter 17. Machine Vision
      1. How a Computer Sees the World
      2. Noise and Smoothing
      3. Sobel Edge Detection
      4. Thresholding
      5. Histograms
      6. Facial Recognition
      7. Summary
    4. Chapter 18. Metal Performance Shaders Framework
      1. Overview of Metal Performance Shaders Framework
      2. Image Processing with the MPS Framework
      3. Matrix Operations with MPS
      4. Summary
    5. Chapter 19. Neural Network Concepts
      1. Overview of Neural Networks
      2. Neural Network Components
      3. Neural Network Architecture
      4. Summary
    6. Chapter 20. Convolutional Neural Networks
      1. History of Convolutional Neural Networks
      2. MPSImage
      3. Convolutional Neural Network Kernels
      4. Convolution Data Source
      5. Neural Network Graph
      6. Summary
  11. Index
  12. Code Snippets