Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2020 Developer ToolsGraphics & Games

WWDC20 · 21 min · Developer Tools / Graphics & Games

Debug GPU-side errors in Metal

Track down even the trickiest GPU-side programming errors with enhanced reporting in Xcode 12. While Metal’s API validation layer can catch most problems in a project, GPU errors can cause a host of difficult-to-debug issues. Get an introduction to GPU-side errors and learn how to find and eliminate problems like visual corruption, infinite loop timeouts, out of bounds memory accesses, nil resource access, or invalid resource residency with Xcode 12. Discover how to enable enhanced command buffer error reporting and shader validation, use them effectively as part of your debugging strategy, and automate them in your production pipeline.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 4 snippets

Enable enhanced command buffer errors swift · at 3:40 ↗
let desc = MTLCommandBufferDescriptor()
desc.errorOptions = .encoderExecutionStatus
let commandBuffer = commandQueue.makeCommandBuffer(descriptor: desc)
Processing enhanced command buffer errors swift · at 3:55 ↗
if let error = commandBuffer.error as NSError? {

    if let encoderInfos =
        error.userInfo[MTLCommandBufferEncoderInfoErrorKey]
        as? [MTLCommandBufferEncoderInfo] {

        for info in encoderInfos {
            print(info.label + info.debugSignposts.joined())
            if info.errorState == .faulted {
                print(info.label + " faulted!")
            }
        }
    }
}
Command buffer logs API swift · at 15:39 ↗
commandBuffer.addCompletedHandler { (commandBuffer) in
    for log in commandBuffer.logs {
        let encoderLabel = log.encoderLabel ?? "Unknown Label"
        print("Faulting encoder \"\(encoderLabel)\"")
        guard let debugLocation = log.debugLocation,
              let functionName = debugLocation.functionName
        else {
            return
        }
        print("Faulting function \(functionName):\(debugLocation.line):\(debugLocation.column)")
    }
}
Accessing the log bash · at 15:40 ↗
log stream --predicate "subsystem = 'com.apple.Metal' and category = 'GPUDebug'"

Resources