在什么时候VSync“等待” (块)? [英] At what point does vsync "wait" (block)?

查看:217
本文介绍了在什么时候VSync“等待” (块)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个程序真的很快,如果禁用vsync,将运行> 60fps。 vsync何时强制程序等待?当您清除屏幕或翻转缓冲区时,它阻止吗?

Say I have a program that is really fast and, if vsync were disabled, would run >60fps. When does vsync force the program to wait? Does it block when you clear the screen or when you flip the buffers? Or is it some other time I'm not aware of?

我是指OpenGL,偶然。

I'm referring to OpenGL, incidentally.

奖励问题

鉴于发生阻止的具体时间点不一定,我如何衡量阻塞正在采取多长时间?

Given there's not necessarily a specific point at which the blocking occurs, how would I measure how long the blocking is taking? In other words, how would I work out how fast the program could run?

推荐答案

注释你的答案显示,这仍然是一个有很多误解的话题。

The comments to your answer show, that this remains still a topic with a lot of misconceptions.

要说一个长的故事:没有明确的点,你的程序将阻止。

To make a long story short: There is no explicit point at which your program will block.

交换缓冲区调用立即返回。不相信我?编写一个程序,测量在单个交换缓冲区调用中花费的时间(即不进入渲染循环)。但我听说你说:如果我启用V-Sync并测量我的程序中的帧速率,它显示正确的帧速率,所以它在某处它必须阻止。

The swap buffer call returns immediately. Don't believe me? Write a program that measures the time spent in one single swap buffers call (i.e. don't enter a rendering loop). But I hear you say: If I enable V-Sync and measure the frame rate in my program it shows the right frame rate, so somewhere it has to block.

Whats发生的是,在调用交换缓冲区后,后缓冲区是一种保护;后台缓冲区将在前台缓冲区上显示其调用SwapBuffers的时间。所以下一个操作会在调用SwapBuffers之后改变后台缓冲区块的内容,直到交换发生。

Whats happening is, that after a call to swap buffers the back buffer is kind of "protected"; the back buffer is to be presented on the front buffer with the contents it had the the time of calling SwapBuffers. So the next operation that would alter the contents of the back buffer blocks after a call to SwapBuffers until the swap happened.

但是一个大但是)OpenGL命令队列是异步的。什么块是命令队列的执行,但除非插入同步点或队列最大容量已达到所有OpenGL调用将立即返回。 glFinish 引入了一个同步点。但是,如果你在SwapBuffers之后放置一个glFinish,因为它只对在它自己和以前的SwapBuffers之间发生的任何绘图操作起作用,没有什么可以完成,它也可能立即返回。

BUT (and that's a big but) the OpenGL command queue is asynchronous. What blocks is the execution of the command queue, but unless a synchronization point is inserted or the queue maximum capacity has reached all the OpenGL calls will return immediately. glFinish introduces a synchronization point. But if you place a glFinish right after a SwapBuffers, since it only acts on any drawing operation happening between itself and the previous SwapBuffers, there's nothing to finish yet and it will likely return immediately as well.

所以你处于一个渲染循环,并测量 SwapBuffers 的时间,突然它需要一个V-Sync间隔返回。这是怎么回事?好了, SwapBuffers 意味着 glFlush 。但更重要的是,缓冲区交换使后台缓冲区处于未定义状态,这意味着缓冲区交换操作与修改绘图命令的缓冲区内容处于同一级别。但是因为只有两个缓冲区(前面和后面),如果已经有一个缓冲区交换排队,下面的一个调用一个同步块,直到前面的交换已经执行。这会暂停命令队列,最终最终创建一个OpenGL绘图命令或SwapBuffers命令块。

So you're in a rendering loop and measure the time of SwapBuffers there, and all of a sudden it takes one V-Sync interval to return. What's going on? Well, SwapBuffers implies a glFlush. But more importantly a buffer swap leaves the back buffer in an undefined state, which means, that a buffer swap operation is on the same level of buffer content modification as drawing commands. But because there are only two buffer (front and back) if there's already a buffer swap queued, the following one invokes a synchronization block until the previous swap has been performed. This stalls the command queue and ultimately makes one OpenGL drawing command or the SwapBuffers command block eventually.

这篇关于在什么时候VSync“等待” (块)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆