fix(macos): guard MoltenVK heaps

This commit is contained in:
edde746
2026-05-18 17:37:46 +02:00
parent 68e27fdbb3
commit e9c93415a8
@@ -7,6 +7,7 @@ import QuartzCore
import UIKit
#elseif os(macOS)
import Cocoa
import Metal
#endif
protocol MpvPlayerDelegate: AnyObject {
@@ -278,6 +279,7 @@ class MpvPlayerCoreBase: NSObject {
func setupMpv() -> Bool {
#if os(macOS)
guard let renderLayer = metalLayer else { return false }
configureMoltenVKPlacementHeaps()
#else
guard let renderLayer = videoLayer else { return false }
#endif
@@ -597,6 +599,16 @@ class MpvPlayerCoreBase: NSObject {
checkError(mpv_set_option_string(mpv, "target-colorspace-hint", "yes"))
}
#if os(macOS)
private func configureMoltenVKPlacementHeaps() {
guard let device = MTLCreateSystemDefaultDevice() else { return }
let supportsPlacementHeaps = device.supportsFamily(.apple2) || device.supportsFamily(.mac2)
if !supportsPlacementHeaps {
setenv("MVK_CONFIG_USE_MTLHEAP", "0", 1)
}
}
#endif
private func isManagedRendererProperty(_ name: String) -> Bool {
name == "vo" || name == "wid" || name == "gpu-api" || name == "gpu-context"
|| name == "avfoundation-composite-osd"