Metal Shader Debugging and Profiling

快来打我* 2022-05-15 15:56 702阅读 0赞

https://medium.com/@nilotic2/metal-shader-debugging-and-profiling-48da25a400e8

Metal Shader Debugging and Profiling

WWDC 2018

Metal Frame Debugger

  • Step through API calls
  • Resource inspection
  • Shader edit and reload
  • GPU counters
  • Pipeline statics
  • Integrated into Xcode
  • Dependency viewer (new)
  • Geometry viewer (new)
  • Shader debugger (new)
  • Enhanced shader profiler (new)

Geometry Viewer

  • Visualize the post-vertex transform data in 3D
  • Access to all vertex data
  • Per-draw call view

Visibly Wrong Triangles

1_5G3iAj1jQyi6c5-DmOsjNA.gif

Out of Frustum Objects

1_ny7pgt7USL13xsVffbLu7w.gif

Missing Triangles

1_5Nf0pRTqVlrZNnm31Rokag.gif

Why use Shader Debugger?

  • Math heavy code
  • Highly parallel
  • Unity’s “Book of the Deed”
    - ~10 million vertex shader invocations
    - ~60 million pixels rendered

1_HBbfPFyOY2nypC7zQhTQOg.png

Shader Debugging

  • New tool for debugging Metal shaders
  • Rich variable visualization across thousands of threads
  • Real data from GPU
  • Flexible stepping
  • Integrated into Metal Frame Debugger

1_iT1BPBQ0A6ebWSEKy5JmPQ.png

1_x5SU3-aDWw_xkl-EyRmA-w.png

Demo

Problem (negative value)

1_yjm1bo6MsLMuUcnS-4SJwA.gif


Fining the bug

1_Wp0H4Mibwfv2Nty3R_S0GA.gif

Values in realtime

1_I0bB_uoufF39T3GA5dv6jQ.gif

Call Stack


Fix the Bug

1_VsS4ty3V9Ow1WaJCSemAYg.gif


Refresh

(You don’t need to rebuild)

1_aDxC1T7-540WVbFL7huPVQ.gif


1_Gk7EeBrX-dFwRjPE3OxHYQ.gif

Starting the Shader Debugger

1_DjnC7ElBV_FenghTe7Az-A.gif

Inspecting Variables

1_C6ghVJwsFycZGwXBv1qCeQ.png

1_jJL--vsBoNqfLI-fkabw6Q.png

1_TEQI881IpHBcDffU7yfFWQ.png

1_99Y4d2Q3F7tQWvoa_pyb9Q.png

Following the Execution

1_9izHk-xBPkISzt12gt-NfQ.gif

Flexible stepping

1_F9wutKEGROay3Scxu0vP3Q.gif

Use filter to focus

Access to Other Threads

Set of threads are available based on the initial selection

  • Vertex — Primitive of the selected vertex
  • Fragment — Rectangle around the selected pixel
  • Compute — Threadgroup of the selected thread

See Variables in Context

  • Helps you understand your code
  • Important to for comparing good/ bad values
  • Hover for instant access

1_bdY91J_lgqrhsjw-Wt3xBg.gif

Comparing Good and Bad Pixels

  • Quickly compare threads
  • Execution history and variables and updated for the selected thread

1_4SduD0pJq2WoXafRHwJJzA.gif

Understanding Divergence

  • Mask shows which threads executed the same line to help you understand control flow

1_jRqUvmlSr20VO3TR1Pirew.png

Demo

Problem

1_SsQA48y1bJVBp0JLcCc7tA.gif


Finding the Bug

1_kyyAC56C7Ym94EQokluYFA.gif

1_YKvh4MiZI0kDhCql69EQtw.gif


QA

1_J8VXqIu2h3deUk-oZsrcrg.gif

Shader Debugger

  • Specifically designed for debugging Metal shaders
  • Great for
    - Fixing bugs!
    - Understanding your shader
    - Developing your shaders
  • Supports iOS, macOS, and tvOS
  • Available in Xcode 10

Knowing What to Optimized

Profiling tools built into Metal Frame Debugger

  • GPU counters

1_PVe-BZW6ED0GKuyb8Z3MCA.png

  • Pipeline statistics

1_nvqBVduIAn0FBpoBO4qS3Q.png

  • Shader profiler

1_59eLicThvpsl1-TUdkts3w.png

Shader Profiler

  • Provides per-pipeline timing information

1_87kBRktjfvAWRa3lLvtisw.png

  • Per-line execution cost (iOS and tvOS)

1_J8ylItx0P0uQu8IxoUmZfA.png

  • Shader edit and reload
  • Get into shader debugger

Enhanced Shader Profiler for A11

  • Instruction category cost breakdown per line
    - ALU — Float, half, and complex
    - Memory — Sample, load, and store operations
    - Synchronization — Wait memory, barriers, or atomics

1_NpFm2yqOPE-ia_MF5MaeGA.png

  • Visibility into inline function cost

1_UNZ6u9FncoU2tZlbseUNag.png

Demo

1_P_Rz-0jKdprXblOBLZHe_A.gif

Access to Shader Sources

  • New Metal Compiler option
  • Xcode project
    - “Yes, include source code” from build settings
  • Command line
    - “-MO” compiler option

1_4FefxERw-JH2hkm5b2QDIg.png

  • iOS
  • Wwdc 2018
  • Metal
  • Graphics And Games
  • Metal Shader

发表评论

表情:
评论列表 (有 0 条评论,702人围观)

还没有评论,来说两句吧...

相关阅读