Skip to content

Commit

Permalink
Merge pull request swiftlang#11965 from moiseev/arkit+metal
Browse files Browse the repository at this point in the history
[overlay] Add Metal, MetalKit overlays, and new APIs to ARKit
  • Loading branch information
moiseev authored Sep 22, 2017
2 parents 572bd6f + 1a61ad6 commit 962895b
Show file tree
Hide file tree
Showing 13 changed files with 648 additions and 14 deletions.
27 changes: 27 additions & 0 deletions stdlib/public/SDK/ARKit/ARKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,30 @@ extension ARPointCloud {
return Array(buffer)
}
}

@available(iOS, introduced: 11.0)
extension ARFaceGeometry {
/**
The mesh vertices of the geometry.
*/
@nonobjc public var vertices: [vector_float3] {
let buffer = UnsafeBufferPointer(start: __vertices, count: Int(__vertexCount))
return Array(buffer)
}

/**
The texture coordinates of the geometry.
*/
@nonobjc public var textureCoordinates: [vector_float2] {
let buffer = UnsafeBufferPointer(start: __textureCoordinates, count: Int(__textureCoordinateCount))
return Array(buffer)
}

/**
The triangle indices of the geometry.
*/
@nonobjc public var triangleIndices: [Int16] {
let buffer = UnsafeBufferPointer(start: __triangleIndices, count: Int(triangleCount * 3))
return Array(buffer)
}
}
7 changes: 4 additions & 3 deletions stdlib/public/SDK/Accelerate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ add_swift_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_COMPILE_FLAGS ${STDLIB_SIL_SERIALIZE_ALL} -parse-stdlib
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch Foundation IOKit ObjectiveC os XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC os # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC os # auto-updated
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch Foundation IOKit Metal ObjectiveC XPC # auto-updated
os
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC os # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC os # auto-updated
SWIFT_MODULE_DEPENDS_WATCHOS Darwin CoreFoundation CoreGraphics Dispatch ObjectiveC os # auto-updated

DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_SIMD_OSX}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif()

list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "${STDLIB_SIL_SERIALIZE_WITNESS_TABLES}")

set(all_overlays "Accelerate;AppKit;ARKit;AssetsLibrary;AVFoundation;CallKit;CloudKit;Contacts;CoreAudio;CoreData;CoreFoundation;CoreGraphics;CoreImage;CoreLocation;CoreMedia;CryptoTokenKit;Dispatch;Foundation;GameplayKit;GLKit;HomeKit;IOKit;Intents;MapKit;MediaPlayer;ModelIO;ObjectiveC;OpenCL;os;Photos;QuartzCore;SafariServices;SceneKit;simd;SpriteKit;UIKit;Vision;WatchKit;XCTest;XPC")
set(all_overlays "Accelerate;AppKit;ARKit;AssetsLibrary;AVFoundation;CallKit;CloudKit;Contacts;CoreAudio;CoreData;CoreFoundation;CoreGraphics;CoreImage;CoreLocation;CoreMedia;CryptoTokenKit;Dispatch;Foundation;GameplayKit;GLKit;HomeKit;IOKit;Intents;MapKit;MediaPlayer;Metal;MetalKit;ModelIO;ObjectiveC;OpenCL;os;Photos;QuartzCore;SafariServices;SceneKit;simd;SpriteKit;UIKit;Vision;WatchKit;XCTest;XPC")

if(DEFINED SWIFT_OVERLAY_TARGETS)
set(overlays_to_build ${SWIFT_OVERLAY_TARGETS})
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/SDK/CoreImage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ add_swift_library(swiftCoreImage ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch Foundation IOKit ObjectiveC XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch Foundation IOKit Metal ObjectiveC XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics Dispatch Foundation Metal ObjectiveC # auto-updated
FRAMEWORK_DEPENDS_OSX QuartzCore
FRAMEWORK_DEPENDS_IOS_TVOS CoreImage

Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/SDK/CoreMedia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ add_swift_library(swiftCoreMedia ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS_OSX Darwin AppKit CoreAudio CoreData CoreGraphics CoreImage Dispatch Foundation IOKit ObjectiveC QuartzCore XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreAudio CoreGraphics Dispatch Foundation ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreAudio CoreGraphics Dispatch Foundation ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_OSX Darwin AppKit CoreAudio CoreData CoreGraphics CoreImage Dispatch Foundation IOKit Metal ObjectiveC QuartzCore XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreAudio CoreGraphics Dispatch Foundation Metal ObjectiveC # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreAudio CoreGraphics Dispatch Foundation Metal ObjectiveC # auto-updated
FRAMEWORK_DEPENDS CoreMedia

DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_COREMEDIA_OSX}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/MediaPlayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_swift_library(swiftMediaPlayer ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_S
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS IOS IOS_SIMULATOR

SWIFT_MODULE_DEPENDS_IOS Darwin AVFoundation CoreAudio CoreFoundation CoreGraphics CoreImage CoreMedia Dispatch Foundation ObjectiveC QuartzCore simd UIKit os CoreData # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin AVFoundation CoreAudio CoreFoundation CoreGraphics CoreImage CoreMedia Dispatch Foundation Metal ObjectiveC QuartzCore simd UIKit os CoreData # auto-updated
FRAMEWORK_DEPENDS_WEAK MediaPlayer

DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_MEDIAPLAYER_IOS}
Expand Down
22 changes: 22 additions & 0 deletions stdlib/public/SDK/Metal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.4.3)
include("../../../../cmake/modules/StandaloneOverlay.cmake")

add_swift_library(swiftMetal ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
Metal.swift

SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch Foundation IOKit ObjectiveC XPC # auto-updated
os
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation Dispatch Foundation ObjectiveC # auto-updated
os
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation Dispatch Foundation ObjectiveC # auto-updated
os

FRAMEWORK_DEPENDS_WEAK Metal

DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_METAL_OSX}
DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_METAL_IOS}
DEPLOYMENT_VERSION_TVOS ${SWIFTLIB_DEPLOYMENT_VERSION_METAL_TVOS}
)
231 changes: 231 additions & 0 deletions stdlib/public/SDK/Metal/Metal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@_exported import Metal // Clang module

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLBlitCommandEncoder {

public func fill(buffer: MTLBuffer, range: Range<Int>, value: UInt8) {
fill(buffer: buffer, range: NSMakeRange(range.lowerBound, range.count), value: value)
}
}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLBuffer {

#if os(OSX)
@available(macOS, introduced: 10.11)
public func didModifyRange(_ range: Range<Int>) {
didModifyRange(NSMakeRange(range.lowerBound, range.count))
}
#endif

@available(macOS 10.12, iOS 10.0, tvOS 10.0, *)
public func addDebugMarker(_ marker: String, range: Range<Int>) {
addDebugMarker(marker, range: NSMakeRange(range.lowerBound, range.count))
}
}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLComputeCommandEncoder {

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func useResources(_ resources: [MTLResource], usage: MTLResourceUsage) {
useResources(resources, count: resources.count, usage: usage)
}

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func useHeaps(_ heaps: [MTLHeap]) {
useHeaps(heaps, count: heaps.count)
}

public func setBuffers(_ buffers: [MTLBuffer?], offsets: [Int], range: Range<Int>) {
setBuffers(buffers, offsets: offsets, with: NSMakeRange(range.lowerBound, range.count))
}

public func setTextures(_ textures: [MTLTexture?], range: Range<Int>) {
setTextures(textures, with: NSMakeRange(range.lowerBound, range.count))
}

public func setSamplerStates(_ samplers: [MTLSamplerState?], range: Range<Int>) {
setSamplerStates(samplers, with: NSMakeRange(range.lowerBound, range.count))
}

public func setSamplerStates(_ samplers: [MTLSamplerState?], lodMinClamps: [Float], lodMaxClamps: [Float], range: Range<Int>) {
setSamplerStates(samplers, lodMinClamps: lodMinClamps, lodMaxClamps: lodMaxClamps, with: NSMakeRange(range.lowerBound, range.count))
}
}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLDevice {

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func getDefaultSamplePositions(sampleCount: Int) -> [MTLSamplePosition] {
var positions = [MTLSamplePosition](repeating: MTLSamplePosition(x: 0,y: 0), count: sampleCount)
getDefaultSamplePositions(&positions, count: sampleCount)
return positions
}
}

#if os(OSX)
@available(swift 4)
@available(macOS 10.13, *)
public func MTLCopyAllDevicesWithObserver(handler: @escaping MTLDeviceNotificationHandler) -> (devices:[MTLDevice], observer:NSObject) {
var resultTuple: (devices:[MTLDevice], observer:NSObject)
resultTuple.observer = NSObject()
resultTuple.devices = MTLCopyAllDevicesWithObserver(AutoreleasingUnsafeMutablePointer<NSObjectProtocol?>(&resultTuple.observer), handler)
return resultTuple
}
#endif

@available(swift 4)
@available(macOS 10.12, iOS 10.0, tvOS 10.0, *)
extension MTLFunctionConstantValues {

public func setConstantValues(_ values: UnsafeRawPointer, type: MTLDataType, range: Range<Int>) {
setConstantValues(values, type: type, with: NSMakeRange(range.lowerBound, range.count))
}

}

@available(swift 4)
@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
extension MTLArgumentEncoder {

public func setBuffers(_ buffers: [MTLBuffer?], offsets: [Int], range: Range<Int>) {
setBuffers(buffers, offsets: offsets, with: NSMakeRange(range.lowerBound, range.count))
}

public func setTextures(_ textures: [MTLTexture?], range: Range<Int>) {
setTextures(textures, with: NSMakeRange(range.lowerBound, range.count))
}

public func setSamplerStates(_ samplers: [MTLSamplerState?], range: Range<Int>) {
setSamplerStates(samplers, with: NSMakeRange(range.lowerBound, range.count))
}
}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLRenderCommandEncoder {

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func useResources(_ resources: [MTLResource], usage: MTLResourceUsage) {
useResources(resources, count: resources.count, usage: usage)
}

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func useHeaps(_ heaps: [MTLHeap]) {
useHeaps(heaps, count: heaps.count)
}

#if os(OSX)
@available(macOS 10.13, *)
public func setViewports(_ viewports: [MTLViewport]) {
setViewports(viewports, count: viewports.count)
}

@available(macOS 10.13, *)
public func setScissorRects(_ scissorRects: [MTLScissorRect]) {
setScissorRects(scissorRects, count: scissorRects.count)
}
#endif

public func setVertexBuffers(_ buffers: [MTLBuffer?], offsets: [Int], range: Range<Int>) {
setVertexBuffers(buffers, offsets: offsets, with: NSMakeRange(range.lowerBound, range.count))
}

public func setVertexTextures(_ textures: [MTLTexture?], range: Range<Int>) {
setVertexTextures(textures, with: NSMakeRange(range.lowerBound, range.count))
}

public func setVertexSamplerStates(_ samplers: [MTLSamplerState?], range: Range<Int>) {
setVertexSamplerStates(samplers, with: NSMakeRange(range.lowerBound, range.count))
}

public func setVertexSamplerStates(_ samplers: [MTLSamplerState?], lodMinClamps: [Float], lodMaxClamps: [Float], range: Range<Int>) {
setVertexSamplerStates(samplers, lodMinClamps: lodMinClamps, lodMaxClamps: lodMaxClamps, with: NSMakeRange(range.lowerBound, range.count))
}

public func setFragmentBuffers(_ buffers: [MTLBuffer?], offsets: [Int], range: Range<Int>) {
setFragmentBuffers(buffers, offsets: offsets, with: NSMakeRange(range.lowerBound, range.count))
}

public func setFragmentTextures(_ textures: [MTLTexture?], range: Range<Int>) {
setFragmentTextures(textures, with: NSMakeRange(range.lowerBound, range.count))
}

public func setFragmentSamplerStates(_ samplers: [MTLSamplerState?], range: Range<Int>) {
setFragmentSamplerStates(samplers, with: NSMakeRange(range.lowerBound, range.count))
}

public func setFragmentSamplerStates(_ samplers: [MTLSamplerState?], lodMinClamps: [Float], lodMaxClamps: [Float], range: Range<Int>) {
setFragmentSamplerStates(samplers, lodMinClamps: lodMinClamps, lodMaxClamps: lodMaxClamps, with: NSMakeRange(range.lowerBound, range.count))
}

#if os(iOS)

@available(iOS 11.0, *)
public func setTileBuffers(_ buffers: [MTLBuffer?], offsets: [Int], range: Range<Int>) {
__setTileBuffers(buffers, offsets: offsets, with: NSMakeRange(range.lowerBound, range.count))
}

@available(iOS 11.0, *)
public func setTileTextures(_ textures: [MTLTexture?], range: Range<Int>) {
__setTileTextures(textures, with: NSMakeRange(range.lowerBound, range.count))
}

@available(iOS 11.0, *)
public func setTileSamplerStates(_ samplers: [MTLSamplerState?], range: Range<Int>) {
__setTileSamplerStates(samplers, with: NSMakeRange(range.lowerBound, range.count))
}

@available(iOS 11.0, *)
public func setTileSamplerStates(_ samplers: [MTLSamplerState?], lodMinClamps: [Float], lodMaxClamps: [Float], range: Range<Int>) {
__setTileSamplerStates(samplers, lodMinClamps: lodMinClamps, lodMaxClamps: lodMaxClamps, with: NSMakeRange(range.lowerBound, range.count))
}
#endif
}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLRenderPassDescriptor {

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func setSamplePositions(_ positions: [MTLSamplePosition]) {
setSamplePositions(positions, count: positions.count)
}

@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
public func getSamplePositions() -> [MTLSamplePosition] {
let numPositions = getSamplePositions(nil, count: 0)
var positions = [MTLSamplePosition](repeating: MTLSamplePosition(x: 0,y: 0), count: numPositions)
getSamplePositions(&positions, count: numPositions)
return positions
}

}

@available(swift 4)
@available(macOS 10.11, iOS 8.0, tvOS 8.0, *)
extension MTLTexture {

@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)
public func makeTextureView(pixelFormat: MTLPixelFormat, textureType: MTLTextureType, levels levelRange: Range<Int>, slices sliceRange: Range<Int>) -> MTLTexture? {
return makeTextureView(pixelFormat: pixelFormat, textureType: textureType, levels: NSMakeRange(levelRange.lowerBound, levelRange.count), slices: NSMakeRange(sliceRange.lowerBound, sliceRange.count))
}
}
20 changes: 20 additions & 0 deletions stdlib/public/SDK/MetalKit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.4.3)
include("../../../../cmake/modules/StandaloneOverlay.cmake")

add_swift_library(swiftMetalKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
MetalKit.swift

SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR
SWIFT_MODULE_DEPENDS_OSX Darwin AppKit CoreData CoreFoundation CoreGraphics CoreImage Dispatch Foundation IOKit Metal ModelIO ObjectiveC QuartzCore simd XPC # auto-updated
SWIFT_MODULE_DEPENDS_IOS Darwin CoreFoundation CoreGraphics CoreImage Dispatch Foundation Metal ModelIO ObjectiveC QuartzCore simd UIKit # auto-updated
SWIFT_MODULE_DEPENDS_TVOS Darwin CoreFoundation CoreGraphics CoreImage Dispatch Foundation Metal ModelIO ObjectiveC QuartzCore simd UIKit # auto-updated

FRAMEWORK_DEPENDS_WEAK MetalKit
FRAMEWORK_DEPENDS_WEAK Metal

DEPLOYMENT_VERSION_OSX ${SWIFTLIB_DEPLOYMENT_VERSION_METALKIT_OSX}
DEPLOYMENT_VERSION_IOS ${SWIFTLIB_DEPLOYMENT_VERSION_METALKIT_IOS}
DEPLOYMENT_VERSION_TVOS ${SWIFTLIB_DEPLOYMENT_VERSION_METALKIT_TVOS}
)
Loading

0 comments on commit 962895b

Please sign in to comment.