From db76d9f9807641a5aa9b3e9291b559927bacd374 Mon Sep 17 00:00:00 2001 From: LuckyIYI Date: Mon, 22 Jul 2024 17:14:35 -0400 Subject: [PATCH] vision os target support --- .../Extensions/Metal/MTLDevice/MTLDevice+Features.swift | 4 +++- .../Metal/MTLPixelFormat/MTLPixelFormat+Extensions.swift | 2 +- .../Extensions/Metal/MTLTexture/MTLTexture+Image.swift | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/MetalTools/Extensions/Metal/MTLDevice/MTLDevice+Features.swift b/Sources/MetalTools/Extensions/Metal/MTLDevice/MTLDevice+Features.swift index 85d80fd..50c6b08 100644 --- a/Sources/MetalTools/Extensions/Metal/MTLDevice/MTLDevice+Features.swift +++ b/Sources/MetalTools/Extensions/Metal/MTLDevice/MTLDevice+Features.swift @@ -26,6 +26,8 @@ public extension MTLDevice { return supportsFeatureSet(.iOS_GPUFamily4_v1) #elseif os(macOS) return supportsFeatureSet(.macOS_GPUFamily1_v3) + #elseif os(visionOS) + return false #endif case .tileShaders: return supportsFamily(.apple4) @@ -50,7 +52,7 @@ public extension MTLDevice { var familiesWithReadWriteCubeMapSupport: [MTLGPUFamily] = [ .apple4, .apple5, .apple6, .apple7, .apple8, .mac2 ] - if #available(iOS 16.0, macOS 13.0, *) { + if #available(iOS 16.0, macOS 13.0, visionOS 1.0, *) { familiesWithReadWriteCubeMapSupport.append(.metal3) } for family in familiesWithReadWriteCubeMapSupport where supportsFamily(family) { diff --git a/Sources/MetalTools/Extensions/Metal/MTLPixelFormat/MTLPixelFormat+Extensions.swift b/Sources/MetalTools/Extensions/Metal/MTLPixelFormat/MTLPixelFormat+Extensions.swift index 8b14c79..9785244 100644 --- a/Sources/MetalTools/Extensions/Metal/MTLPixelFormat/MTLPixelFormat+Extensions.swift +++ b/Sources/MetalTools/Extensions/Metal/MTLPixelFormat/MTLPixelFormat+Extensions.swift @@ -335,7 +335,7 @@ public extension MTLPixelFormat { case .a8Unorm: return false case .rgb9e5Float: - #if os(iOS) && !targetEnvironment(macCatalyst) + #if (os(iOS) || os(visionOS)) && !targetEnvironment(macCatalyst) return true #elseif os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) return false diff --git a/Sources/MetalTools/Extensions/Metal/MTLTexture/MTLTexture+Image.swift b/Sources/MetalTools/Extensions/Metal/MTLTexture/MTLTexture+Image.swift index 8f8d5be..5ce0090 100644 --- a/Sources/MetalTools/Extensions/Metal/MTLTexture/MTLTexture+Image.swift +++ b/Sources/MetalTools/Extensions/Metal/MTLTexture/MTLTexture+Image.swift @@ -5,7 +5,7 @@ import MetalKit import MetalPerformanceShaders public extension MTLTexture { - #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) + #if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst) typealias NSUIImage = UIImage #elseif os(macOS) && !targetEnvironment(macCatalyst) typealias NSUIImage = NSImage @@ -174,7 +174,7 @@ public extension MTLTexture { /// This method first converts the texture to a `CGImage` and then creates a `NSUIImage` from it. func image(colorSpace: CGColorSpace? = nil) throws -> NSUIImage { let cgImage = try self.cgImage(colorSpace: colorSpace) - #if os(iOS) + #if (os(iOS) || os(visionOS)) return UIImage(cgImage: cgImage) #elseif os(macOS) return NSImage(