Documentation Archive Developer
Search

Metal Changes for Swift

Metal

Added MTLCommandBufferError.init(_nsError: NSError)
Added MTLLibraryError.init(_nsError: NSError)
Added MTLRenderPipelineError [struct]
Added MTLRenderPipelineError.init(_nsError: NSError)
Added MTLRenderPipelineError.internal
Added MTLRenderPipelineError.invalidInput
Added MTLRenderPipelineError.unsupported
Declaration
From
protocol MTLCommandBuffer : NSObjectProtocol {
    var device: MTLDevice { get }
    var commandQueue: MTLCommandQueue { get }
    var retainedReferences: Bool { get }
    var label: String? { get set }
    func enqueue()
    func commit()
    func addScheduledHandler(_ block: Metal.MTLCommandBufferHandler)
    func present(_ drawable: MTLDrawable)
    func present(_ drawable: MTLDrawable, atTime presentationTime: CFTimeInterval)
    func waitUntilScheduled()
    func addCompletedHandler(_ block: Metal.MTLCommandBufferHandler)
    func waitUntilCompleted()
    var status: MTLCommandBufferStatus { get }
    var error: Error? { get }
    func makeBlitCommandEncoder() -> MTLBlitCommandEncoder
    func makeRenderCommandEncoder(descriptor renderPassDescriptor: MTLRenderPassDescriptor) -> MTLRenderCommandEncoder
    func makeComputeCommandEncoder() -> MTLComputeCommandEncoder
    func makeParallelRenderCommandEncoder(descriptor renderPassDescriptor: MTLRenderPassDescriptor) -> MTLParallelRenderCommandEncoder
}
To
protocol MTLCommandBuffer : NSObjectProtocol {
    var device: MTLDevice { get }
    var commandQueue: MTLCommandQueue { get }
    var retainedReferences: Bool { get }
    var label: String? { get set }
    func enqueue()
    func commit()
    func addScheduledHandler(_ block: @escaping Metal.MTLCommandBufferHandler)
    func present(_ drawable: MTLDrawable)
    func present(_ drawable: MTLDrawable, atTime presentationTime: CFTimeInterval)
    func waitUntilScheduled()
    func addCompletedHandler(_ block: @escaping Metal.MTLCommandBufferHandler)
    func waitUntilCompleted()
    var status: MTLCommandBufferStatus { get }
    var error: Error? { get }
    func makeBlitCommandEncoder() -> MTLBlitCommandEncoder
    func makeRenderCommandEncoder(descriptor renderPassDescriptor: MTLRenderPassDescriptor) -> MTLRenderCommandEncoder
    func makeComputeCommandEncoder() -> MTLComputeCommandEncoder
    func makeParallelRenderCommandEncoder(descriptor renderPassDescriptor: MTLRenderPassDescriptor) -> MTLParallelRenderCommandEncoder
}

Declaration
From
func addCompletedHandler(_ block: Metal.MTLCommandBufferHandler)
To
func addCompletedHandler(_ block: @escaping Metal.MTLCommandBufferHandler)

Declaration
From
func addScheduledHandler(_ block: Metal.MTLCommandBufferHandler)
To
func addScheduledHandler(_ block: @escaping Metal.MTLCommandBufferHandler)

Declaration
From
enum MTLCommandBufferErrorDomain : UInt {
    case none
    case `internal`
    case timeout
    case pageFault
    case blacklisted
    case notPermitted
    case outOfMemory
    case invalidResource
    case memoryless
}
To
enum Code : UInt {
        typealias _ErrorType = MTLCommandBufferError
        case none
        case `internal`
        case timeout
        case pageFault
        case blacklisted
        case notPermitted
        case outOfMemory
        case invalidResource
        case memoryless
    }

Modified MTLDevice
Declaration
From
protocol MTLDevice : NSObjectProtocol {
    var name: String? { get }
    var maxThreadsPerThreadgroup: MTLSize { get }
    var isLowPower: Bool { get }
    var isHeadless: Bool { get }
    var recommendedMaxWorkingSetSize: UInt64 { get }
    var isDepth24Stencil8PixelFormatSupported: Bool { get }
    func makeCommandQueue() -> MTLCommandQueue
    func makeCommandQueue(maxCommandBufferCount maxCommandBufferCount: Int) -> MTLCommandQueue
    func heapTextureSizeAndAlign(descriptor desc: MTLTextureDescriptor) -> MTLSizeAndAlign
    func heapBufferSizeAndAlign(length length: Int, options options: MTLResourceOptions = []) -> MTLSizeAndAlign
    func makeHeap(descriptor descriptor: MTLHeapDescriptor) -> MTLHeap
    func makeBuffer(length length: Int, options options: MTLResourceOptions = []) -> MTLBuffer
    func makeBuffer(bytes pointer: UnsafeRawPointer, length length: Int, options options: MTLResourceOptions = []) -> MTLBuffer
    func makeBuffer(bytesNoCopy pointer: UnsafeMutableRawPointer, length length: Int, options options: MTLResourceOptions = [], deallocator deallocator: (@escaping (UnsafeMutableRawPointer, Int) -> Swift.Void)? = nil) -> MTLBuffer
    func makeDepthStencilState(descriptor descriptor: MTLDepthStencilDescriptor) -> MTLDepthStencilState
    func makeTexture(descriptor descriptor: MTLTextureDescriptor) -> MTLTexture
    func makeSamplerState(descriptor descriptor: MTLSamplerDescriptor) -> MTLSamplerState
    func newDefaultLibrary() -> MTLLibrary?
    func makeDefaultLibrary(bundle bundle: Bundle) throws -> MTLLibrary
    func makeLibrary(filepath filepath: String) throws -> MTLLibrary
    func makeLibrary(data data: __DispatchData) throws -> MTLLibrary
    func makeLibrary(source source: String, options options: MTLCompileOptions?) throws -> MTLLibrary
    func makeLibrary(source source: String, options options: MTLCompileOptions?, completionHandler completionHandler: Metal.MTLNewLibraryCompletionHandler)
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor) throws -> MTLRenderPipelineState
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedRenderPipelineReflection?>?) throws -> MTLRenderPipelineState
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, completionHandler completionHandler: Metal.MTLNewRenderPipelineStateCompletionHandler)
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewRenderPipelineStateWithReflectionCompletionHandler)
    func makeComputePipelineState(function computeFunction: MTLFunction) throws -> MTLComputePipelineState
    func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedComputePipelineReflection?>?) throws -> MTLComputePipelineState
    func makeComputePipelineState(function computeFunction: MTLFunction, completionHandler completionHandler: Metal.MTLNewComputePipelineStateCompletionHandler)
    func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
    func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedComputePipelineReflection?>?) throws -> MTLComputePipelineState
    func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
    func makeFence() -> MTLFence
    func supportsFeatureSet(_ featureSet: MTLFeatureSet) -> Bool
    func supportsTextureSampleCount(_ sampleCount: Int) -> Bool
}
To
protocol MTLDevice : NSObjectProtocol {
    var name: String? { get }
    var maxThreadsPerThreadgroup: MTLSize { get }
    var isLowPower: Bool { get }
    var isHeadless: Bool { get }
    var recommendedMaxWorkingSetSize: UInt64 { get }
    var isDepth24Stencil8PixelFormatSupported: Bool { get }
    func makeCommandQueue() -> MTLCommandQueue
    func makeCommandQueue(maxCommandBufferCount maxCommandBufferCount: Int) -> MTLCommandQueue
    func heapTextureSizeAndAlign(descriptor desc: MTLTextureDescriptor) -> MTLSizeAndAlign
    func heapBufferSizeAndAlign(length length: Int, options options: MTLResourceOptions = []) -> MTLSizeAndAlign
    func makeHeap(descriptor descriptor: MTLHeapDescriptor) -> MTLHeap
    func makeBuffer(length length: Int, options options: MTLResourceOptions = []) -> MTLBuffer
    func makeBuffer(bytes pointer: UnsafeRawPointer, length length: Int, options options: MTLResourceOptions = []) -> MTLBuffer
    func makeBuffer(bytesNoCopy pointer: UnsafeMutableRawPointer, length length: Int, options options: MTLResourceOptions = [], deallocator deallocator: ((UnsafeMutableRawPointer, Int) -> Swift.Void)? = nil) -> MTLBuffer
    func makeDepthStencilState(descriptor descriptor: MTLDepthStencilDescriptor) -> MTLDepthStencilState
    func makeTexture(descriptor descriptor: MTLTextureDescriptor) -> MTLTexture
    func makeSamplerState(descriptor descriptor: MTLSamplerDescriptor) -> MTLSamplerState
    func newDefaultLibrary() -> MTLLibrary?
    func makeDefaultLibrary(bundle bundle: Bundle) throws -> MTLLibrary
    func makeLibrary(filepath filepath: String) throws -> MTLLibrary
    func makeLibrary(data data: __DispatchData) throws -> MTLLibrary
    func makeLibrary(source source: String, options options: MTLCompileOptions?) throws -> MTLLibrary
    func makeLibrary(source source: String, options options: MTLCompileOptions?, completionHandler completionHandler: @escaping Metal.MTLNewLibraryCompletionHandler)
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor) throws -> MTLRenderPipelineState
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedRenderPipelineReflection?>?) throws -> MTLRenderPipelineState
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, completionHandler completionHandler: @escaping Metal.MTLNewRenderPipelineStateCompletionHandler)
    func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewRenderPipelineStateWithReflectionCompletionHandler)
    func makeComputePipelineState(function computeFunction: MTLFunction) throws -> MTLComputePipelineState
    func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedComputePipelineReflection?>?) throws -> MTLComputePipelineState
    func makeComputePipelineState(function computeFunction: MTLFunction, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateCompletionHandler)
    func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
    func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, reflection reflection: AutoreleasingUnsafeMutablePointer<MTLAutoreleasedComputePipelineReflection?>?) throws -> MTLComputePipelineState
    func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
    func makeFence() -> MTLFence
    func supportsFeatureSet(_ featureSet: MTLFeatureSet) -> Bool
    func supportsTextureSampleCount(_ sampleCount: Int) -> Bool
}

Declaration
From
func makeBuffer(bytesNoCopy pointer: UnsafeMutableRawPointer, length length: Int, options options: MTLResourceOptions = [], deallocator deallocator: (@escaping (UnsafeMutableRawPointer, Int) -> Swift.Void)? = nil) -> MTLBuffer
To
func makeBuffer(bytesNoCopy pointer: UnsafeMutableRawPointer, length length: Int, options options: MTLResourceOptions = [], deallocator deallocator: ((UnsafeMutableRawPointer, Int) -> Swift.Void)? = nil) -> MTLBuffer

Declaration
From
func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
To
func makeComputePipelineState(descriptor descriptor: MTLComputePipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)

Declaration
From
func makeComputePipelineState(function computeFunction: MTLFunction, completionHandler completionHandler: Metal.MTLNewComputePipelineStateCompletionHandler)
To
func makeComputePipelineState(function computeFunction: MTLFunction, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateCompletionHandler)

Declaration
From
func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)
To
func makeComputePipelineState(function computeFunction: MTLFunction, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewComputePipelineStateWithReflectionCompletionHandler)

Declaration
From
func makeLibrary(source source: String, options options: MTLCompileOptions?, completionHandler completionHandler: Metal.MTLNewLibraryCompletionHandler)
To
func makeLibrary(source source: String, options options: MTLCompileOptions?, completionHandler completionHandler: @escaping Metal.MTLNewLibraryCompletionHandler)

Declaration
From
func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, completionHandler completionHandler: Metal.MTLNewRenderPipelineStateCompletionHandler)
To
func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, completionHandler completionHandler: @escaping Metal.MTLNewRenderPipelineStateCompletionHandler)

Declaration
From
func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: Metal.MTLNewRenderPipelineStateWithReflectionCompletionHandler)
To
func makeRenderPipelineState(descriptor descriptor: MTLRenderPipelineDescriptor, options options: MTLPipelineOption, completionHandler completionHandler: @escaping Metal.MTLNewRenderPipelineStateWithReflectionCompletionHandler)

Declaration
From
enum MTLLibraryErrorDomain : UInt {
    case unsupported
    case `internal`
    case compileFailure
    case compileWarning
    case functionNotFound
    case fileNotFound
}
To
enum Code : UInt {
        typealias _ErrorType = MTLLibraryError
        case unsupported
        case `internal`
        case compileFailure
        case compileWarning
        case functionNotFound
        case fileNotFound
    }

Modified MTLRenderPipelineError.Code [enum]
Declaration
From
enum MTLRenderPipelineErrorDomain : UInt {
    case `internal`
    case unsupported
    case invalidInput
}
To
enum Code : UInt {
        typealias _ErrorType = MTLRenderPipelineError
        case `internal`
        case unsupported
        case invalidInput
    }