TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Apple's CVDisplayLink Doesn't Link to Your Display

110 点作者 jordwalke超过 7 年前

8 条评论

jchb超过 7 年前
If you use OpenGL or Metal with triple buffering (the blog post mentions MTLView which is a Metal view) I believe this doesn&#x27;t matter. You&#x27;ll only be using the CVDisplayLink timer events to generate frames spaced at a even interval - which is equal to the display vsync interval, depending how you configure CVDisplayLink. Then, the actual presentation of those frames <i>will</i> happen in sync with the actual display vsync.<p>See Metal Triple Buffering (<a href="https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;content&#x2F;documentation&#x2F;3DDrawing&#x2F;Conceptual&#x2F;MTLBestPracticesGuide&#x2F;TripleBuffering.html#&#x2F;&#x2F;apple_ref&#x2F;doc&#x2F;uid&#x2F;TP40016642-CH5-SW1" rel="nofollow">https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;content&#x2F;documentation&#x2F;3D...</a>) and MTLCommandBuffer presentDrawable.<p>For OpenGL there are similar mechanisms, eg. NSOpenGLCPSwapInterval.
评论 #15890268 未加载
评论 #15892266 未加载
trishume超过 7 年前
tfw you do a bunch of research you&#x27;re proud of and write an article that reaches the HN front page, and then someone chimes in on Twitter that actually the research is flawed and only applies to multiple displays, and you have to update the post about how wrong you were. :&#x2F;<p>I&#x27;m just sad about all the people that already read it and won&#x27;t see the update so will go away with incorrect knowledge.
评论 #15893511 未加载
评论 #15894169 未加载
Someone超过 7 年前
The documentation (<a href="https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;content&#x2F;documentation&#x2F;GraphicsImaging&#x2F;Conceptual&#x2F;CoreVideo&#x2F;CVProg_Concepts&#x2F;CVProg_Concepts.html" rel="nofollow">https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;content&#x2F;documentation&#x2F;Gr...</a>) doesn’t mention vertical refresh interrupts.<p>It also says <i>”In the past, synchronizing your video frames with the display’s refresh rate was often a problem, especially if you also had audio. You could only make simple guesses for when to output a frame […] which didn’t take into account possible latency from user interactions, CPU loading, window compositing and so on. The Core Video display link can make intelligent estimates for when a frame needs to be output, based on display type and latencies. […] If for some reason the processing takes longer than expected (that is, the display link’s estimate is off), the video graphics card can still drop frames or otherwise compensate for the timing error as necessary.”</i>.<p>So, disassembling the code wasn’t strictly necessary.<p>Combining this with this article, it seems they try to call your program as late as possible, possibly to decrease latency between the time you have influence on what is displayed and the time it is displayed. Could that <i>especially if you also had audio</i> be the reason they do that, as it might make it easier to keep audio in sync with video?
评论 #15892682 未加载
评论 #15892250 未加载
评论 #15891282 未加载
评论 #15892417 未加载
评论 #15892110 未加载
adamnemecek超过 7 年前
There’s quite a few approaches, it’s hard to figure out which one is appropriate for this one. I think that enabling setNeedsDisplay and dispatching commands asynchronously might do the trick? With asynchronous dispatch I’ve actually been getting 120 FPS. But it’s very much case by case basis and I might not be understanding the use case.<p>IIRC this project Gets to 120 when you drag your mouse <a href="https:&#x2F;&#x2F;github.com&#x2F;jtbandes&#x2F;metalbrot-playground" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jtbandes&#x2F;metalbrot-playground</a>
评论 #15889601 未加载
评论 #15890285 未加载
mrpippy超过 7 年前
Bring back VBL tasks.<p><a href="http:&#x2F;&#x2F;mirror.informatimago.com&#x2F;next&#x2F;developer.apple.com&#x2F;documentation&#x2F;mac&#x2F;Processes&#x2F;Processes-74.html" rel="nofollow">http:&#x2F;&#x2F;mirror.informatimago.com&#x2F;next&#x2F;developer.apple.com&#x2F;doc...</a>
评论 #15889805 未加载
评论 #15889819 未加载
danra超过 7 年前
Wow, this is bad. If the author is reading this, is there any chance this is a regression in recent OSes? I remember a WWDC video from quite a few years ago showing exactly why it’s important to use CVDisplayLink which is linked to when your display needs new frames, showing a similar illustration to the one shown above about how otherwise you lose frames.
评论 #15891940 未加载
stmw超过 7 年前
Interesting turnabout from classic MacOS, where the VSync interrupt was both synced and really important. It was the way you got lots of non-graphical processing done, too - lots of event timers &amp; the like went in there.
TwoBit超过 7 年前
You can synchronize to actual vsync on Windows.
评论 #15890170 未加载