mac/vulkan: log colorspace changes of metal layer

since we have a mapping layer between vulkan and metal (MoltenVK) we
don't actually know which colorspace is used/mapped to.

log colorspace changes to actually see which colorspace was chosen.
This commit is contained in:
der richter
2025-11-02 20:33:42 +01:00
parent 5cfdbc24d9
commit 83d9de42bc
2 changed files with 26 additions and 0 deletions

View File

@@ -136,3 +136,17 @@ extension MTLPixelFormat {
return "raw pixel format " + String(self.rawValue)
}
}
extension CGColorSpace {
public var longName: String {
let description = String(describing: self)
guard let colorSpaceName = self.name as? String,
let regex = try? NSRegularExpression(pattern: ".*\\((.*)\\)", options: .caseInsensitive),
let result = regex.firstMatch(in: description, options: [], range: NSRange(location: 0, length: description.count)),
let range = Range(result.range(at: 1), in: description) else { return description }
let nameList = description[range].components(separatedBy: "; ").filter { !$0.hasPrefix("kCGColorSpace") }
let simpleName = colorSpaceName.replacingOccurrences(of: "kCGColorSpace", with: "")
return "\(simpleName) (\(nameList.joined(separator: ", ")))"
}
}

View File

@@ -41,11 +41,23 @@ class MetalLayer: CAMetalLayer {
}
}
// workaround for nil to none-nil values, oldValue is same as current in those cases
var previousColorspace: CGColorSpace?
override var colorspace: CGColorSpace? {
didSet {
if colorspace != previousColorspace {
log.verbose("Metal layer colorspace changed: \(colorspace?.longName ?? "nil")")
}
previousColorspace = colorspace
}
}
init(common com: MacCommon) {
common = com
super.init()
pixelFormat = .rgba16Float
previousColorspace = colorspace
backgroundColor = NSColor.black.cgColor
}