M2 Max MacBook Pro全屏Metal渲染(MTKView/CAMetalLayer)卡顿异常
M2 Max MacBook Pro全屏Metal渲染60Hz帧率波动问题
问题现象
在M2 Max款MacBook Pro的全屏模式下,无论使用MTKView还是直接调用CAMetalLayer进行Metal渲染,均无法稳定输出60Hz帧率:帧率在过快与过慢间波动,伴随可见微卡顿(例如渲染白色背景上匀速移动的黑条时),Metal Performance HUD也显示帧更新节奏不一致。
仅全屏模式触发该问题;当鼠标悬停在系统菜单栏,或调出CMD+Tab切换界面(即有其他UI元素覆盖全屏视图)时,卡顿现象会暂时消失。此问题未出现在2020款Intel MacBook Air上,仅发生在M2系列MacBook Pro设备。
已尝试的排查/修复操作
- 调整系统ProMotion相关设置
- 组合配置MTKView的
preferredFramesPerSecond和displaySyncEnabled属性 - 放弃MTKView,改用CVDisplayLink搭配CAMetalLayer实现渲染,问题依旧
推测问题根源可能是displayLink与CAMetalLayer后端的时序逻辑冲突。
疑问与求助
- 该问题是个例还是M2系列MacBook Pro的普遍问题?
- 是否存在我未注意到的操作失误导致该现象?
- 若确为硬件/系统层面的问题,能否通过调整渲染更新时序来规避?
最小复现代码
无需复杂渲染逻辑,仅提交drawable即可触发问题:
#import <Metal/Metal.h> #import <MetalKit/MetalKit.h> @interface ViewController() <MTKViewDelegate> @property (nonatomic, weak) IBOutlet MTKView *mtkView; @property (nonatomic) id<MTLDevice> device; @property (nonatomic) id<MTLCommandQueue> commandQueue; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _device = MTLCreateSystemDefaultDevice(); _mtkView.device = _device; _mtkView.preferredFramesPerSecond = 60; _mtkView.delegate = self; _commandQueue = [_device newCommandQueue]; } - (void)drawInMTKView:(MTKView *)view { MTLRenderPassDescriptor *viewRPD = view.currentRenderPassDescriptor; if(viewRPD) { id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer]; [commandBuffer presentDrawable:view.currentDrawable]; [commandBuffer commit]; } } - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size { } @end
内容的提问来源于stack exchange,提问作者Jakob
相关产品推荐
相关产品推荐

