[D3D12] Number of queued frames and swapchain buffers

Started by
6 comments, last by nbertoa 7 years, 9 months ago

Hi community

I read the following in a NVIDIA link about DirectX12 recommendations.

https://developer.nvidia.com/dx12-dos-and-donts

"Don’t forget that there's a per swap-chain limit of 3 queued frames before DXGI will start to block in Present()"

I was doing something similar in my architecture (basically, I match the number of queued frames with the number of swap chain buffers)

Should the number of queued frames be the same than the number of swap chain buffers? I think the answer is YES, because If you send 3 groups of command lists that will output to 3 different final render targets, then there should be a correspondence between your final render targets and swap chain buffers, because you can end with barriers problems at Present (You can be trying to present a resource that is going to be used as render target by an unprocessed command list in the GPU).

Am I missing something?

Thanks!

Advertisement

At a high level, no it's not really that relevant. Since the frames are (probably) all submitted to the same command queue, there's no GPU parallelism going on here, so the number of buffers doesn't really matter.

For a full answer on why you might want more buffers, check out this other topic:

http://www.gamedev.net/topic/679050-how-come-changing-dxgi-swap-chain-descbuffercount-has-no-effect/

I just read your post. Thanks for the information.

The reason why I am using 3 buffers in swap chain instead of 2 is because as I am queuing 3 frames, I was getting errors because DirectX complained about writing operation in current displayed back buffer. I think that is something you mentioned in that post.

You should have one more buffer than the number of frames that you queue, since one of the buffer is the one that it's been presented. So for a 3 buffer swap chain, you should queue up to 2 frames. That being said, queuing 2 frames should be more than enough (you want to keep your GPU busy but also to have a reasonable latency).

And for that error, if you are requesting each frame the right buffer, it should not happen.

The only reason for more buffers is to queue completed frames. And the only time you can queue completed frames is when using VSync. If you're submitting all of your frames serially, then buffer 0 gets off screen the same time buffer 1 gets on screen, and frame 2 can start writing to buffer 0 with no delay.

Though if you're using FLIP_SEQUENTIAL/FLIP_DISCARD (which you are since you're asking about D3D12), using sync interval 0, and not using the ALLOW_TEARING flag, then it makes sense to have more buffers, since you want to be able to queue completed frames here too.

@Sergio J. De Los Santos:
I will check about your recommendation of having N swap chain buffers ans N - 1 queued frames in my code. Currently, both have the same number and I did not see any problems in the app, but what you says makes sense.

Why the latency could change according the number of queued frames?

@Jesse Natalie:
Where do you set the sync interval to be 0? When you create the swap chain?

In Present(). It's the first parameter.

Ohh you are right. And yes, I use exactly the same configuration you described. Then I will try your suggestion and Sergio J. De Los Santos suggestion too.

Where did you learn about this stuff and the stuff you described in the post you recommended me to read (in your first answer to this post)

This topic is closed to new replies.

Advertisement