Revert "fix: temporary fix for fps drop issue when starting stream with graph disabled"

This reverts commit d72930877a.
This commit is contained in:
Acaki committed 2025-08-08 01:51:09 +08:00
1 parent 69026cbcd6
commit 1442495c9e
2 files changed
+14 -39

No files matched your search

-1
View File
@@ -20,7 +20,6 @@ typedef void (^MetricsHandler)(int plotId, CFTimeInterval value);
@property (nonatomic) FloatBuffer * _Nonnull frametimes; @property (nonatomic) FloatBuffer * _Nonnull frametimes;
@property (nonatomic) BOOL enableGraphs; @property (nonatomic) BOOL enableGraphs;
@property (nonatomic) float graphOpacity; @property (nonatomic) float graphOpacity;
@property (nonatomic) int streamFps;
@property (nonatomic) BOOL imguiRunning; @property (nonatomic) BOOL imguiRunning;
@property (nonatomic) MetricsHandler _Nonnull metricsHandler; @property (nonatomic) MetricsHandler _Nonnull metricsHandler;
+14 -38
View File
@@ -30,7 +30,6 @@
_enableGraphs = enableGraphs; _enableGraphs = enableGraphs;
_graphOpacity = (float)(graphOpacity / 100.0); _graphOpacity = (float)(graphOpacity / 100.0);
_bounds = bounds; _bounds = bounds;
_streamFps = streamFps;
_device = MTLCreateSystemDefaultDevice(); _device = MTLCreateSystemDefaultDevice();
_commandQueue = [_device newCommandQueue]; _commandQueue = [_device newCommandQueue];
@@ -84,46 +83,34 @@
self.mtkView.device = self.device; self.mtkView.device = self.device;
self.mtkView.delegate = self; self.mtkView.delegate = self;
self.mtkView.preferredFramesPerSecond = _streamFps; // Match the stream frame rate for proper display sync self.mtkView.preferredFramesPerSecond = 60; // ImGui overlay will always render at this rate
self.mtkView.opaque = NO; self.mtkView.opaque = NO;
self.mtkView.enableSetNeedsDisplay = NO; self.mtkView.enableSetNeedsDisplay = NO;
if (_enableGraphs) { if (_enableGraphs) {
[self ImGui_Init]; [self ImGui_Init];
self.mtkView.paused = NO; self.mtkView.paused = NO;
self.mtkView.hidden = NO;
} }
else { else {
// Keep Metal view running for display sync but don't initialize ImGui self.mtkView.paused = YES;
self.mtkView.paused = NO;
self.mtkView.hidden = YES; // Hide but keep running for display sync
} }
} }
// start & stop are used to show/hide graphs when swiping stats in or out // start & stop are used to show/hide graphs when swiping stats in or out
-(void)start { -(void)start {
if (_enableGraphs) {
[self ImGui_Init]; [self ImGui_Init];
self.mtkView.hidden = NO; if (_enableGraphs) {
} else {
// Keep running for display sync but stay hidden
self.mtkView.hidden = YES;
}
self.mtkView.paused = NO; self.mtkView.paused = NO;
} }
}
-(void)show { -(void)show {
if (_enableGraphs) {
[self.mtkView setHidden:NO]; [self.mtkView setHidden:NO];
} }
}
-(void)hide { -(void)hide {
if (_enableGraphs) {
[self.mtkView setHidden:YES]; [self.mtkView setHidden:YES];
} }
// When graphs are disabled, ImGui stays hidden but keeps running for display sync
}
-(void)stop { -(void)stop {
self.mtkView.paused = YES; self.mtkView.paused = YES;
@@ -133,15 +120,6 @@
// Only called when mtkView.paused is false // Only called when mtkView.paused is false
- (void)drawInMTKView:(MTKView *)view - (void)drawInMTKView:(MTKView *)view
{ {
id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
MTLRenderPassDescriptor* renderPassDescriptor = view.currentRenderPassDescriptor;
if (renderPassDescriptor == nil) {
[commandBuffer commit];
return;
}
if (_enableGraphs) {
#if !defined(IMGUI_DISABLE) #if !defined(IMGUI_DISABLE)
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.DisplaySize.x = view.bounds.size.width; io.DisplaySize.x = view.bounds.size.width;
@@ -150,6 +128,14 @@
CGFloat framebufferScale = view.window.screen.scale ?: UIScreen.mainScreen.scale; CGFloat framebufferScale = view.window.screen.scale ?: UIScreen.mainScreen.scale;
io.DisplayFramebufferScale = ImVec2(framebufferScale, framebufferScale); io.DisplayFramebufferScale = ImVec2(framebufferScale, framebufferScale);
id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
MTLRenderPassDescriptor* renderPassDescriptor = view.currentRenderPassDescriptor;
if (renderPassDescriptor == nil) {
[commandBuffer commit];
return;
}
// Start the Dear ImGui frame // Start the Dear ImGui frame
ImGui_ImplMetal_NewFrame(renderPassDescriptor); ImGui_ImplMetal_NewFrame(renderPassDescriptor);
ImGui::NewFrame(); ImGui::NewFrame();
@@ -175,25 +161,15 @@
ImGui_ImplMetal_RenderDrawData(draw_data, commandBuffer, renderEncoder); ImGui_ImplMetal_RenderDrawData(draw_data, commandBuffer, renderEncoder);
[renderEncoder popDebugGroup]; [renderEncoder popDebugGroup];
[renderEncoder endEncoding]; [renderEncoder endEncoding];
#endif
} else {
// When graphs are disabled, just render a transparent frame for display sync
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 0.0);
id <MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor]; // Present
[renderEncoder pushDebugGroup:@"Display sync frame"];
// Don't render anything, just clear
[renderEncoder popDebugGroup];
[renderEncoder endEncoding];
}
// Present (always with timing for display sync)
#if TARGET_OS_SIMULATOR #if TARGET_OS_SIMULATOR
[commandBuffer presentDrawable:view.currentDrawable]; [commandBuffer presentDrawable:view.currentDrawable];
#else #else
[commandBuffer presentDrawable:view.currentDrawable afterMinimumDuration:1.0 / view.preferredFramesPerSecond]; [commandBuffer presentDrawable:view.currentDrawable afterMinimumDuration:1.0 / view.preferredFramesPerSecond];
#endif #endif
[commandBuffer commit]; [commandBuffer commit];
#endif
} }
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size