I know that in SceneKit, you can enable a banner on the side of the SKView
to look at real time frame rates and other useful debugging information. But what about MTKView
? I don't seem to find such a property to enable, or how I can query the current frame rate. (Because I am rendering something that have a frame rate of 0.5fps or so)
I don't think there is simple flag for you. Because you control the complete rendering pipeline when creating a command buffer, Metal can't know where to inject a rendering pass with some custom text.
You could inject your own rendering pass (based on a flag like var showDebugInformation = true
) in your pipeline, but that sounds like a bit of work.
I would probably monitor frame times manually in the draw
method and update a label every draw. A rough outline could look like this:
var previousFrameAtTime: Date
let lastFrameTime = CurrentValueSubject<TimeInterval, Never>(.infinity)
func draw(in view: MTKView) {
lastFrameTime.send(Date().timeIntervalSince(previousFrameAtTime))
previousFrameAtTime = Date()
// ...
}
Then you can observe this value in your view, something like this:
import Combine
class MyViewController: UIViewController {
let label = UILabel()
var cancellables: [AnyCancellable] = []
func subscribeToFrameTime() {
renderer.lastFrameTime
.sink { label.text = "\($0 * 1000) ms." }
.store(in: &cancellables)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With