Guides and Sample Code Developer
Search

Metal Changes for Swift

Metal

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)

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)

Feedback