diff --git a/Sources/UsdView/Hydra/Hydra+RenderEngine.swift b/Sources/UsdView/Hydra/Hydra+RenderEngine.swift index fdb7c52cd..f1cb33a9d 100644 --- a/Sources/UsdView/Hydra/Hydra+RenderEngine.swift +++ b/Sources/UsdView/Hydra/Hydra+RenderEngine.swift @@ -13,6 +13,11 @@ import Foundation import PixarUSD +#if canImport(Metal) && !os(visionOS) + import Metal + import MetalKit +#endif // canImport(Metal) && !os(visionOS) + public enum Hydra { public class RenderEngine @@ -51,5 +56,10 @@ public enum Hydra engine.render(root: stage.getPseudoRoot(), params: params) } + + public var hydraDevice: MTLDevice + { + hgi.device + } } } diff --git a/Sources/UsdView/Hydra/Hydra+View.swift b/Sources/UsdView/Hydra/Hydra+View.swift index b342b20b5..f2d80222f 100644 --- a/Sources/UsdView/Hydra/Hydra+View.swift +++ b/Sources/UsdView/Hydra/Hydra+View.swift @@ -36,9 +36,8 @@ public extension Hydra.Viewport init(engine: Hydra.RenderEngine, rgba: (Double, Double, Double, Double)) { #if canImport(Metal) && !os(visionOS) - let device = MTLCreateSystemDefaultDevice()! - let renderer = Hydra.MTLRenderer(device: device)! - self.init(hydra: engine, device: device, renderer: renderer, rgba: rgba) + let renderer = Hydra.MTLRenderer(device: engine.hydraDevice)! + self.init(hydra: engine, renderer: renderer, rgba: rgba) #endif // canImport(Metal) && !os(visionOS) } } diff --git a/Sources/UsdView/Hydra/MTL/Hydra+MTLView.swift b/Sources/UsdView/Hydra/MTL/Hydra+MTLView.swift index 0484269d9..ad4f15ac3 100644 --- a/Sources/UsdView/Hydra/MTL/Hydra+MTLView.swift +++ b/Sources/UsdView/Hydra/MTL/Hydra+MTLView.swift @@ -40,10 +40,10 @@ import PixarUSD var rgba: (Double, Double, Double, Double) - public init(hydra: Hydra.RenderEngine, device: MTLDevice, renderer: MTLRenderer, rgba: (Double, Double, Double, Double)) + public init(hydra: Hydra.RenderEngine, renderer: MTLRenderer, rgba: (Double, Double, Double, Double)) { self.hydra = hydra - self.device = device + self.device = hydra.hydraDevice self.renderer = renderer self.rgba = rgba }