1

我创建了两个通过 PBO 渲染视频的 OpenGL 窗口。我想不通的是为什么第二个窗口或第二个渲染的窗口总是比第一个窗口花费更长的时间?我意识到这可能是特定于供应商的,因为我只在 nVidia Quadro 产品上观察到过。

一些伪代码:

pixels[]

for (num_windows)
{
  gettimeofday(t0)
  window.display(pixels)
  gettimeofday(t1)
  delta = t1 - t0
}

第一个窗口的 delta 通常小于 5 ms,而大多数时候第二个窗口的 delta 大于 10 ms。为什么是这样?

4

1 回答 1

2

This is not an appropriate method for timing how long something takes to render, since the CPU and GPU are asynchronous and blocking may occur during buffer swaps and/or the command queue becomes full. If you're on a newer OpenGL implementation, you should use Timer Queries.

Without seeing your implementation of display (...) and how each of these windows differs, I can only surmise that something like VSYNC is to blame (especially when the two times you mention add up very nearly to 60 Hz). Swapping buffers with VSYNC enabled will block the calling thread until the appropriate time. You can potentially have a shorter wait the first time you do this than the second because the second will start immediately at the beginning of a VSYNC interval.

You may wish to do something useful with the CPU in-between drawing to one window and the other so that the time spent blocking is not completely wasted. Or, you might consider using multi-threaded rendering, with one thread driving each window's buffer swap. This is one case where multi-threaded rendering really does make sense.

于 2013-09-05T18:27:37.830 回答