Skip to content

Commit 02647e9

Browse files
committed
Fixed filtered twice output
1 parent 0fa511e commit 02647e9

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

Harbeth.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'Harbeth'
11-
s.version = '1.1.9'
11+
s.version = '1.2.0'
1212
s.summary = 'About image and video add filter for metal.'
1313

1414
# This description is used to generate tags and improve search results.

Sources/Basic/Core/TextureLoader.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,18 @@ extension TextureLoader {
153153
/// - height: The texture height, must be greater than 0, maximum resolution is 16384.
154154
/// - options: Configure other parameters about generating metal textures.
155155
public static func emptyTexture(width: Int, height: Int, options: [TextureLoader.Option: Any]? = nil) throws -> MTLTexture {
156+
let options = options ?? [TextureLoader.Option: Any]()
156157
var usage: MTLTextureUsage = [.shaderRead, .shaderWrite]
157158
var pixelFormat = MTLPixelFormat.rgba8Unorm
158159
var storageMode = MTLStorageMode.shared
160+
var allowGPUOptimizedContents = true
159161
#if os(macOS)
160162
// Texture Descriptor Validation MTLStorageModeShared not allowed for textures.
161163
// So macOS need use `managed`.
162164
storageMode = MTLStorageMode.managed
163165
#endif
164166
var sampleCount: Int = 1
165-
for (key, value) in (options ?? [TextureLoader.Option: Any]()) {
167+
for (key, value) in options {
166168
switch (key, value) {
167169
case (.texturePixelFormat, let value as MTLPixelFormat):
168170
pixelFormat = value
@@ -172,6 +174,8 @@ extension TextureLoader {
172174
storageMode = value
173175
case (.textureSampleCount, let value as Int):
174176
sampleCount = value
177+
case (.textureAllowGPUOptimizedContents, let value as Bool):
178+
allowGPUOptimizedContents = value
175179
default:
176180
break
177181
}
@@ -187,6 +191,9 @@ extension TextureLoader {
187191
descriptor.storageMode = storageMode
188192
descriptor.sampleCount = sampleCount
189193
descriptor.textureType = sampleCount > 1 ? .type2DMultisample : .type2D
194+
if #available(iOS 12.0, macOS 10.14, *) {
195+
descriptor.allowGPUOptimizedContents = allowGPUOptimizedContents
196+
}
190197
guard let texture = Device.device().makeTexture(descriptor: descriptor) else {
191198
throw HarbethError.makeTexture
192199
}
@@ -304,4 +311,7 @@ extension TextureLoader.Option {
304311
/// The number of samples in the texture to create. The default value is 1.
305312
/// When creating Buffer textures sampleCount must be 1. Implementations may round sample counts up to the next supported value.
306313
public static let textureSampleCount: TextureLoader.Option = .init(rawValue: 1 << 4)
314+
315+
/// Allow GPU-optimization for the contents of this texture. The default value is true.
316+
public static let textureAllowGPUOptimizedContents: TextureLoader.Option = .init(rawValue: 1 << 5)
307317
}

Sources/Basic/Extensions/MTLTexture+Ext.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ extension MTLTexture {
1919

2020
public struct MTLTextureCompatible_ {
2121

22-
public let target: MTLTexture
22+
weak var target: MTLTexture!
23+
24+
init(target: MTLTexture) {
25+
self.target = target
26+
}
2327

2428
public var size: MTLSize {
2529
.init(width: target.width, height: target.height, depth: target.depth)

Sources/Basic/Outputs/Destype.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ public protocol Destype {
2727
/// Asynchronous quickly add filters to sources.
2828
/// - Parameter complete: The conversion is complete of adding filters to the sources asynchronously.
2929
func transmitOutput(complete: @escaping (Result<Element, HarbethError>) -> Void)
30-
31-
/// Asynchronous convert to texture and add filters.
32-
/// - Parameters:
33-
/// - texture: Input metal texture.
34-
/// - complete: The conversion is complete.
35-
func filtering(texture: MTLTexture, complete: @escaping (Result<MTLTexture, HarbethError>) -> Void)
3630
}
3731

3832
extension Destype {
@@ -43,8 +37,7 @@ extension Destype {
4337

4438
public func filtered() -> Element {
4539
do {
46-
let dest = HarbethIO.init(element: element, filters: filters)
47-
return try dest.output()
40+
return try self.output()
4841
} catch {
4942
return element
5043
}

Sources/Basic/Outputs/HarbethIO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public typealias BoxxIO<Dest> = HarbethIO<Dest>
115115
}
116116
}
117117

118-
/// Convert to texture and add filters.
118+
/// Asynchronous convert to texture and add filters.
119119
/// - Parameters:
120120
/// - texture: Input metal texture.
121121
/// - complete: The conversion is complete.

Sources/Basic/Setup/DisplayLink.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
#if os(macOS)
1111

12-
#if __MAC_14_0 || __MAC_14_1 || __MAC_14_2
12+
#if __MAC_14_0 || __MAC_14_1 || __MAC_14_2 || __MAC_14_3 || __MAC_14_4
1313
import QuartzCore
1414
public typealias CADisplayLink = QuartzCore.CADisplayLink
1515
#else

0 commit comments

Comments
 (0)