Metal Game Performance Optimization

WWDC 2018

Posted by Den on September 04, 2018 · 8 mins read
Metal Game Performance Optimization

Metal Game Performance Optimization

WWDC 2018

Metal Game Performance Optimization

WWDC 2018

Game Performance Template

Thread State View (new)

Frame Pacing

Micro Stuttering

Inconsistent frame rate

  • Frame time higher than display refresh interval
  • Game logic timing errors

Problem

  • Do not use sleep() to pace frames!

Best Practice

  • Target explicit frame rate
  • Use the following APIs (iOS 10.3 +)
    - MTLDrawable addPresentedHandler
    - MTLCommandBuffer presentDrawable afterMinimumDuration
    -
    MTLCommandBuffer presentDrawable atTime

Thread Stalling

Render thread gets preempted due to low priority

  • Priority decay
  • Priority inversion

Best Practice

Configure the render thread

  • Priority 45
  • Opt out of Quality of Service

Thermal Throttling

Impact on system performace

  • High device temperature
  • Low power mode enabled

Best Practice

  • Adjust the workload to the system state
  • Use the following APIs
    - iOS 11.0+ : NSProcessInfo thermalState
    - iOS 10.3+ :
    MTLCommandBuffer GPUStartTime/ GPUEndTime
    - iOS 9.0+ :
    NSProcessInfo lowPowerModeEnabled

Adjust the Workload

  • Target sustainable framerate
  • Reduce the resolution
  • Simplify the shadow maps
  • Use smaller textures
  • Decrease the level of detail (LOD) for geometry
  • Simplify post-processing and effects

Wasted GPU Time

Waste of power and GPU budget

  • Large resources
  • Unused GPU work

Best Practice

Profile the GPU

  • Understand the cost of every rendering feature
  • Remove excessive work

Metal System Trace

  • Accurate timing for Vertex, Fragment, and Compute work
  • Ideal to measure GPU budget

Dependency Viewer

Finding Hidden Complexity

Take-Away

  • Profile early and often
  • Target a consistent frame rate
  • Set the correct thread prriorites
  • Adapt to system load and thermals
  • Don’t submit unnecessary work to the GPU