Skip to content

Commit

Permalink
initial demo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
s1ddok committed Jan 2, 2023
1 parent d185893 commit 72fc817
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 96 deletions.
97 changes: 32 additions & 65 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -18,27 +19,24 @@
/* 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 = "<group>"; };
93BAA7822963774500815D59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
A225ECFF24A4D40000E352C9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
A225ED0124A4D40400E352C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
A225ED0424A4D40400E352C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
A225ED0624A4D40400E352C9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A225ED0724A4D40400E352C9 /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = "<group>"; };
A225ED0D24A4D44C00E352C9 /* Shaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
A225ED0F24A4D46D00E352C9 /* Shaders.metal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shaders.metal.swift; sourceTree = "<group>"; };
A225ED1124A4E7A900E352C9 /* TextureProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextureProcessor.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 */
A225ECF724A4D40000E352C9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3CE5BF14C0A1845E4182C2D3 /* Pods_Demo.framework in Frameworks */,
93BAA781296373FB00815D59 /* Alloy in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -48,26 +46,15 @@
08CF95B3DEFF52EEED03A9D9 /* Frameworks */ = {
isa = PBXGroup;
children = (
BC03861FAD2A4A37B380092F /* Pods_Demo.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
70FF4FF2035421710375C43A /* Pods */ = {
isa = PBXGroup;
children = (
8083BA5C6491A5BC1A6432E6 /* Pods-Demo.debug.xcconfig */,
A8962298E1B295C40B95B0C3 /* Pods-Demo.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
};
A225ECF124A4D40000E352C9 = {
isa = PBXGroup;
children = (
A225ECFC24A4D40000E352C9 /* Demo */,
A225ECFB24A4D40000E352C9 /* Products */,
70FF4FF2035421710375C43A /* Pods */,
08CF95B3DEFF52EEED03A9D9 /* Frameworks */,
);
sourceTree = "<group>";
Expand All @@ -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 = "<group>";
Expand All @@ -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";
Expand Down Expand Up @@ -142,6 +130,9 @@
Base,
);
mainGroup = A225ECF124A4D40000E352C9;
packageReferences = (
93BAA77F296373FB00815D59 /* XCRemoteSwiftPackageReference "Alloy" */,
);
productRefGroup = A225ECFB24A4D40000E352C9 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "alloy",
"kind" : "remoteSourceControl",
"location" : "https://github.com/s1ddok/Alloy",
"state" : {
"branch" : "master",
"revision" : "601ed05dcf89108aaf6f652fd38596228e827e91"
}
}
],
"version" : 2
}
119 changes: 119 additions & 0 deletions Demo/Demo/Shaders.metal.swift
Original file line number Diff line number Diff line change
@@ -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) }
}

}

4 changes: 2 additions & 2 deletions Demo/Demo/TextureProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions Demo/Podfile

This file was deleted.

18 changes: 0 additions & 18 deletions Demo/Podfile.lock

This file was deleted.

1 change: 1 addition & 0 deletions Sources/mtlswift/AST/Node+ContentType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 72fc817

Please sign in to comment.