diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index aece424..4d2e65e 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -3,11 +3,12 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ - 3CE5BF14C0A1845E4182C2D3 /* Pods_Demo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC03861FAD2A4A37B380092F /* Pods_Demo.framework */; }; + 93BAA781296373FB00815D59 /* Alloy in Frameworks */ = {isa = PBXBuildFile; productRef = 93BAA780296373FB00815D59 /* Alloy */; }; + 93BAA7832963774500815D59 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 93BAA7822963774500815D59 /* Info.plist */; }; A225ECFE24A4D40000E352C9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A225ECFD24A4D40000E352C9 /* AppDelegate.swift */; }; A225ED0024A4D40000E352C9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A225ECFF24A4D40000E352C9 /* ViewController.swift */; }; A225ED0224A4D40400E352C9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A225ED0124A4D40400E352C9 /* Assets.xcassets */; }; @@ -18,19 +19,16 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 8083BA5C6491A5BC1A6432E6 /* Pods-Demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.debug.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"; sourceTree = ""; }; + 93BAA7822963774500815D59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A225ECFA24A4D40000E352C9 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; A225ECFD24A4D40000E352C9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A225ECFF24A4D40000E352C9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; A225ED0124A4D40400E352C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A225ED0424A4D40400E352C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - A225ED0624A4D40400E352C9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A225ED0724A4D40400E352C9 /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = ""; }; A225ED0D24A4D44C00E352C9 /* Shaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = ""; }; A225ED0F24A4D46D00E352C9 /* Shaders.metal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shaders.metal.swift; sourceTree = ""; }; A225ED1124A4E7A900E352C9 /* TextureProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextureProcessor.swift; sourceTree = ""; }; - A8962298E1B295C40B95B0C3 /* Pods-Demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.release.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig"; sourceTree = ""; }; - BC03861FAD2A4A37B380092F /* Pods_Demo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Demo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -38,7 +36,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 3CE5BF14C0A1845E4182C2D3 /* Pods_Demo.framework in Frameworks */, + 93BAA781296373FB00815D59 /* Alloy in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -48,26 +46,15 @@ 08CF95B3DEFF52EEED03A9D9 /* Frameworks */ = { isa = PBXGroup; children = ( - BC03861FAD2A4A37B380092F /* Pods_Demo.framework */, ); name = Frameworks; sourceTree = ""; }; - 70FF4FF2035421710375C43A /* Pods */ = { - isa = PBXGroup; - children = ( - 8083BA5C6491A5BC1A6432E6 /* Pods-Demo.debug.xcconfig */, - A8962298E1B295C40B95B0C3 /* Pods-Demo.release.xcconfig */, - ); - path = Pods; - sourceTree = ""; - }; A225ECF124A4D40000E352C9 = { isa = PBXGroup; children = ( A225ECFC24A4D40000E352C9 /* Demo */, A225ECFB24A4D40000E352C9 /* Products */, - 70FF4FF2035421710375C43A /* Pods */, 08CF95B3DEFF52EEED03A9D9 /* Frameworks */, ); sourceTree = ""; @@ -88,10 +75,10 @@ A225ECFF24A4D40000E352C9 /* ViewController.swift */, A225ED0124A4D40400E352C9 /* Assets.xcassets */, A225ED0324A4D40400E352C9 /* Main.storyboard */, - A225ED0624A4D40400E352C9 /* Info.plist */, A225ED0724A4D40400E352C9 /* Demo.entitlements */, A225ED0D24A4D44C00E352C9 /* Shaders.metal */, A225ED1124A4E7A900E352C9 /* TextureProcessor.swift */, + 93BAA7822963774500815D59 /* Info.plist */, ); path = Demo; sourceTree = ""; @@ -103,17 +90,18 @@ isa = PBXNativeTarget; buildConfigurationList = A225ED0A24A4D40400E352C9 /* Build configuration list for PBXNativeTarget "Demo" */; buildPhases = ( - F6D8D246BDCA4E4D6498391B /* [CP] Check Pods Manifest.lock */, A225ECF624A4D40000E352C9 /* Sources */, A225ECF724A4D40000E352C9 /* Frameworks */, A225ECF824A4D40000E352C9 /* Resources */, - 0E92A1E14702270E294928BA /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); dependencies = ( ); name = Demo; + packageProductDependencies = ( + 93BAA780296373FB00815D59 /* Alloy */, + ); productName = Demo; productReference = A225ECFA24A4D40000E352C9 /* Demo.app */; productType = "com.apple.product-type.application"; @@ -142,6 +130,9 @@ Base, ); mainGroup = A225ECF124A4D40000E352C9; + packageReferences = ( + 93BAA77F296373FB00815D59 /* XCRemoteSwiftPackageReference "Alloy" */, + ); productRefGroup = A225ECFB24A4D40000E352C9 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -158,53 +149,12 @@ files = ( A225ED0224A4D40400E352C9 /* Assets.xcassets in Resources */, A225ED0524A4D40400E352C9 /* Main.storyboard in Resources */, + 93BAA7832963774500815D59 /* Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 0E92A1E14702270E294928BA /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - F6D8D246BDCA4E4D6498391B /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Demo-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ A225ECF624A4D40000E352C9 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -347,7 +297,6 @@ }; A225ED0B24A4D40400E352C9 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 8083BA5C6491A5BC1A6432E6 /* Pods-Demo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Demo/Demo.entitlements; @@ -368,7 +317,6 @@ }; A225ED0C24A4D40400E352C9 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = A8962298E1B295C40B95B0C3 /* Pods-Demo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Demo/Demo.entitlements; @@ -409,6 +357,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 93BAA77F296373FB00815D59 /* XCRemoteSwiftPackageReference "Alloy" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/s1ddok/Alloy"; + requirement = { + branch = master; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 93BAA780296373FB00815D59 /* Alloy */ = { + isa = XCSwiftPackageProductDependency; + package = 93BAA77F296373FB00815D59 /* XCRemoteSwiftPackageReference "Alloy" */; + productName = Alloy; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = A225ECF224A4D40000E352C9 /* Project object */; } diff --git a/Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..0a5ada4 --- /dev/null +++ b/Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "alloy", + "kind" : "remoteSourceControl", + "location" : "https://github.com/s1ddok/Alloy", + "state" : { + "branch" : "master", + "revision" : "601ed05dcf89108aaf6f652fd38596228e827e91" + } + } + ], + "version" : 2 +} diff --git a/Demo/Demo/Shaders.metal.swift b/Demo/Demo/Shaders.metal.swift new file mode 100644 index 0000000..e8fea3c --- /dev/null +++ b/Demo/Demo/Shaders.metal.swift @@ -0,0 +1,119 @@ + +// This file is autogenerated, do not edit it +import Alloy + + +internal class Saturation { + + internal let deviceSupportsNonuniformThreadgroups: Bool + + internal let pipelineState: MTLComputePipelineState + + internal init(library: MTLLibrary, shouldKeepAlpha: Bool) throws { + let constantValues = MTLFunctionConstantValues() + self.deviceSupportsNonuniformThreadgroups = library.device.supports(feature: .nonUniformThreadgroups) + constantValues.set(self.deviceSupportsNonuniformThreadgroups, at: 0) + constantValues.set(shouldKeepAlpha, at: 1) + self.pipelineState = try library.computePipelineState(function: "saturation", constants: constantValues) + } + + internal func callAsFunction(input: MTLTexture, output: MTLTexture, effect: Float, in commandBuffer: MTLCommandBuffer) { + self.encode(input: input, output: output, effect: effect, in: commandBuffer) + } + internal func callAsFunction(input: MTLTexture, output: MTLTexture, effect: Float, using encoder: MTLComputeCommandEncoder) { + self.encode(input: input, output: output, effect: effect, using: encoder) + } + internal func encode(input: MTLTexture, output: MTLTexture, effect: Float, in commandBuffer: MTLCommandBuffer) { + commandBuffer.compute { encoder in + encoder.label = "Saturation" + self.encode(input: input, output: output, effect: effect, using: encoder) + } + } + internal func encode(input: MTLTexture, output: MTLTexture, effect: Float, using encoder: MTLComputeCommandEncoder) { + let _threadgroupSize = self.pipelineState.max2dThreadgroupSize + encoder.setTexture(input, index: 0) + encoder.setTexture(output, index: 1) + encoder.setValue(effect, at: 0) + + if self.deviceSupportsNonuniformThreadgroups { encoder.dispatch2d(state: self.pipelineState, exactly: output.size, threadgroupSize: _threadgroupSize) } else { encoder.dispatch2d(state: self.pipelineState, covering: output.size, threadgroupSize: _threadgroupSize) } + } + +} + + +internal class Contrast { + + internal let deviceSupportsNonuniformThreadgroups: Bool + + internal let pipelineState: MTLComputePipelineState + + internal init(library: MTLLibrary, shouldKeepAlpha: Bool) throws { + let constantValues = MTLFunctionConstantValues() + self.deviceSupportsNonuniformThreadgroups = library.device.supports(feature: .nonUniformThreadgroups) + constantValues.set(self.deviceSupportsNonuniformThreadgroups, at: 0) + constantValues.set(shouldKeepAlpha, at: 1) + self.pipelineState = try library.computePipelineState(function: "contrast", constants: constantValues) + } + + internal func callAsFunction(input: MTLTexture, output: MTLTexture, effect: Float, in commandBuffer: MTLCommandBuffer) { + self.encode(input: input, output: output, effect: effect, in: commandBuffer) + } + internal func callAsFunction(input: MTLTexture, output: MTLTexture, effect: Float, using encoder: MTLComputeCommandEncoder) { + self.encode(input: input, output: output, effect: effect, using: encoder) + } + internal func encode(input: MTLTexture, output: MTLTexture, effect: Float, in commandBuffer: MTLCommandBuffer) { + commandBuffer.compute { encoder in + encoder.label = "Contrast" + self.encode(input: input, output: output, effect: effect, using: encoder) + } + } + internal func encode(input: MTLTexture, output: MTLTexture, effect: Float, using encoder: MTLComputeCommandEncoder) { + let _threadgroupSize = self.pipelineState.max2dThreadgroupSize + encoder.setTexture(input, index: 0) + encoder.setTexture(output, index: 1) + encoder.setValue(effect, at: 0) + + if self.deviceSupportsNonuniformThreadgroups { encoder.dispatch2d(state: self.pipelineState, exactly: output.size, threadgroupSize: _threadgroupSize) } else { encoder.dispatch2d(state: self.pipelineState, covering: output.size, threadgroupSize: _threadgroupSize) } + } + +} + + +internal class Sharpening { + + internal let deviceSupportsNonuniformThreadgroups: Bool + + internal let pipelineState: MTLComputePipelineState + + internal init(library: MTLLibrary, shouldKeepAlpha: Bool, intensity: Float) throws { + let constantValues = MTLFunctionConstantValues() + self.deviceSupportsNonuniformThreadgroups = library.device.supports(feature: .nonUniformThreadgroups) + constantValues.set(self.deviceSupportsNonuniformThreadgroups, at: 0) + constantValues.set(shouldKeepAlpha, at: 1) + constantValues.set(intensity, at: 2) + self.pipelineState = try library.computePipelineState(function: "sharpen", constants: constantValues) + } + + internal func callAsFunction(input: MTLTexture, blurred: MTLTexture, output: MTLTexture, in commandBuffer: MTLCommandBuffer) { + self.encode(input: input, blurred: blurred, output: output, in: commandBuffer) + } + internal func callAsFunction(input: MTLTexture, blurred: MTLTexture, output: MTLTexture, using encoder: MTLComputeCommandEncoder) { + self.encode(input: input, blurred: blurred, output: output, using: encoder) + } + internal func encode(input: MTLTexture, blurred: MTLTexture, output: MTLTexture, in commandBuffer: MTLCommandBuffer) { + commandBuffer.compute { encoder in + encoder.label = "Sharpening" + self.encode(input: input, blurred: blurred, output: output, using: encoder) + } + } + internal func encode(input: MTLTexture, blurred: MTLTexture, output: MTLTexture, using encoder: MTLComputeCommandEncoder) { + let _threadgroupSize = self.pipelineState.max2dThreadgroupSize + encoder.setTexture(input, index: 0) + encoder.setTexture(blurred, index: 1) + encoder.setTexture(output, index: 2) + + if self.deviceSupportsNonuniformThreadgroups { encoder.dispatch2d(state: self.pipelineState, exactly: output.size, threadgroupSize: _threadgroupSize) } else { encoder.dispatch2d(state: self.pipelineState, covering: output.size, threadgroupSize: _threadgroupSize) } + } + +} + diff --git a/Demo/Demo/TextureProcessor.swift b/Demo/Demo/TextureProcessor.swift index ad941b4..08d7120 100644 --- a/Demo/Demo/TextureProcessor.swift +++ b/Demo/Demo/TextureProcessor.swift @@ -68,8 +68,8 @@ class TextureProcessor { let blurredImage = MPSTemporaryImage(commandBuffer: commandBuffer, textureDescriptor: temporaryDescriptor) - self.gaussianBlur(sourceTexture: temporaryImage2.texture, - destinationTexture: blurredImage.texture, + self.gaussianBlur(source: temporaryImage2.texture, + destination: blurredImage.texture, in: commandBuffer) self.sharpen(input: temporaryImage2.texture, diff --git a/Demo/Podfile b/Demo/Podfile deleted file mode 100644 index 670b469..0000000 --- a/Demo/Podfile +++ /dev/null @@ -1,10 +0,0 @@ -# Uncomment the next line to define a global platform for your project -# platform :ios, '9.0' - -target 'Demo' do - # Comment the next line if you don't want to use dynamic frameworks - use_frameworks! - - # Pods for Demo - pod 'Alloy' -end diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock deleted file mode 100644 index bef7d01..0000000 --- a/Demo/Podfile.lock +++ /dev/null @@ -1,18 +0,0 @@ -PODS: - - Alloy (0.14.2): - - Alloy/Core (= 0.14.2) - - Alloy/Core (0.14.2) - -DEPENDENCIES: - - Alloy - -SPEC REPOS: - trunk: - - Alloy - -SPEC CHECKSUMS: - Alloy: b03b3db64505726e491c4b41643d651ee3e766cc - -PODFILE CHECKSUM: 6d0db170179a67672006b118eb8152a768503c32 - -COCOAPODS: 1.9.2 diff --git a/Sources/mtlswift/AST/Node+ContentType.swift b/Sources/mtlswift/AST/Node+ContentType.swift index ba575ea..d4ab145 100644 --- a/Sources/mtlswift/AST/Node+ContentType.swift +++ b/Sources/mtlswift/AST/Node+ContentType.swift @@ -78,6 +78,7 @@ public extension ASTNode { case functionTemplateDecl = "FunctionTemplateDecl" case ifStmt = "IfStmt" case implicitCastExpr = "ImplicitCastExpr" + case importDecl = "ImportDecl" case initListExpr = "InitListExpr" case injectedClassNameType = "InjectedClassNameType" case integerLiteral = "IntegerLiteral" diff --git a/Sources/mtlswift/Encoder Generator/EncoderGenerator.swift b/Sources/mtlswift/Encoder Generator/EncoderGenerator.swift index 40d6607..f91e43b 100644 --- a/Sources/mtlswift/Encoder Generator/EncoderGenerator.swift +++ b/Sources/mtlswift/Encoder Generator/EncoderGenerator.swift @@ -69,7 +69,7 @@ final class EncoderGenerator { currentLevel -= 1 } - guard extractingLevel.1 != "<<>>" + guard extractingLevel.1 != "<<>>" && extractingLevel.1 != "" else { continue } let newChild = try ASTNode(parsingString: extractingLevel.1)