Skip to content

Commit

Permalink
Fixed filtered twice output
Browse files Browse the repository at this point in the history
  • Loading branch information
yangKJ committed Apr 28, 2024
1 parent 0fa511e commit 02647e9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Harbeth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Harbeth'
s.version = '1.1.9'
s.version = '1.2.0'
s.summary = 'About image and video add filter for metal.'

# This description is used to generate tags and improve search results.
Expand Down
12 changes: 11 additions & 1 deletion Sources/Basic/Core/TextureLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,18 @@ extension TextureLoader {
/// - height: The texture height, must be greater than 0, maximum resolution is 16384.
/// - options: Configure other parameters about generating metal textures.
public static func emptyTexture(width: Int, height: Int, options: [TextureLoader.Option: Any]? = nil) throws -> MTLTexture {
let options = options ?? [TextureLoader.Option: Any]()
var usage: MTLTextureUsage = [.shaderRead, .shaderWrite]
var pixelFormat = MTLPixelFormat.rgba8Unorm
var storageMode = MTLStorageMode.shared
var allowGPUOptimizedContents = true
#if os(macOS)
// Texture Descriptor Validation MTLStorageModeShared not allowed for textures.
// So macOS need use `managed`.
storageMode = MTLStorageMode.managed
#endif
var sampleCount: Int = 1
for (key, value) in (options ?? [TextureLoader.Option: Any]()) {
for (key, value) in options {
switch (key, value) {
case (.texturePixelFormat, let value as MTLPixelFormat):
pixelFormat = value
Expand All @@ -172,6 +174,8 @@ extension TextureLoader {
storageMode = value
case (.textureSampleCount, let value as Int):
sampleCount = value
case (.textureAllowGPUOptimizedContents, let value as Bool):
allowGPUOptimizedContents = value
default:
break
}
Expand All @@ -187,6 +191,9 @@ extension TextureLoader {
descriptor.storageMode = storageMode
descriptor.sampleCount = sampleCount
descriptor.textureType = sampleCount > 1 ? .type2DMultisample : .type2D
if #available(iOS 12.0, macOS 10.14, *) {
descriptor.allowGPUOptimizedContents = allowGPUOptimizedContents
}
guard let texture = Device.device().makeTexture(descriptor: descriptor) else {
throw HarbethError.makeTexture
}
Expand Down Expand Up @@ -304,4 +311,7 @@ extension TextureLoader.Option {
/// The number of samples in the texture to create. The default value is 1.
/// When creating Buffer textures sampleCount must be 1. Implementations may round sample counts up to the next supported value.
public static let textureSampleCount: TextureLoader.Option = .init(rawValue: 1 << 4)

/// Allow GPU-optimization for the contents of this texture. The default value is true.
public static let textureAllowGPUOptimizedContents: TextureLoader.Option = .init(rawValue: 1 << 5)
}
6 changes: 5 additions & 1 deletion Sources/Basic/Extensions/MTLTexture+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ extension MTLTexture {

public struct MTLTextureCompatible_ {

public let target: MTLTexture
weak var target: MTLTexture!

init(target: MTLTexture) {
self.target = target
}

public var size: MTLSize {
.init(width: target.width, height: target.height, depth: target.depth)
Expand Down
9 changes: 1 addition & 8 deletions Sources/Basic/Outputs/Destype.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ public protocol Destype {
/// Asynchronous quickly add filters to sources.
/// - Parameter complete: The conversion is complete of adding filters to the sources asynchronously.
func transmitOutput(complete: @escaping (Result<Element, HarbethError>) -> Void)

/// Asynchronous convert to texture and add filters.
/// - Parameters:
/// - texture: Input metal texture.
/// - complete: The conversion is complete.
func filtering(texture: MTLTexture, complete: @escaping (Result<MTLTexture, HarbethError>) -> Void)
}

extension Destype {
Expand All @@ -43,8 +37,7 @@ extension Destype {

public func filtered() -> Element {
do {
let dest = HarbethIO.init(element: element, filters: filters)
return try dest.output()
return try self.output()
} catch {
return element
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Basic/Outputs/HarbethIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public typealias BoxxIO<Dest> = HarbethIO<Dest>
}
}

/// Convert to texture and add filters.
/// Asynchronous convert to texture and add filters.
/// - Parameters:
/// - texture: Input metal texture.
/// - complete: The conversion is complete.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Basic/Setup/DisplayLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

#if os(macOS)

#if __MAC_14_0 || __MAC_14_1 || __MAC_14_2
#if __MAC_14_0 || __MAC_14_1 || __MAC_14_2 || __MAC_14_3 || __MAC_14_4
import QuartzCore
public typealias CADisplayLink = QuartzCore.CADisplayLink
#else
Expand Down

0 comments on commit 02647e9

Please sign in to comment.