Advertisement

Upload buffer timing - when can they be overwritten?

Started by April 08, 2018 10:19 PM
3 comments, last by CortexDragon 6 years, 10 months ago

I'm wondering when upload buffers are copied into the GPU. Basically I want to pool buffers and want to know when I can reuse and write new data into the buffers.

In D3D12? You can use a fence on the copy queue to inform you when your copy commands have been completed. 

Advertisement

Perhaps you know this already (and if so, sorry for rambling on), but upload buffers are not copied into GPU memory unless you manually do it yourself.  On desktop GPU's that have have a separate physical pool of memory on the video card, UPLOAD resources will live in CPU memory that's mapped into both the CPU and GPU's address space. When the GPU access the resource, it will pull it over the PCI-e bus, which may be significantly slower compared to DEFAULT resources that live in GPU memory. So generally you only want to use it for things where the GPU will only access the data once, like a transient constant buffer or a staging buffer whose contents are then copied into DEFAULT memory. 

An UPLOAD resource will be safe to overwrite when the last ExecuteCommandLists batch has finished reading from it. Like Hodgman says, the way to know when a GPU has finished processing a batch of command lists is to have the queue signal a fence, which the CPU can either poll or wait on. Usually you're doing this anyway to avoid overwriting your command buffers, so the simplest approach is to tie your temporary UPLOAD memory to your command buffers. 

 

When the commandlist that is copying from the staging buffer has finished executing, and (as mentioned by the above posters), you know that by a fence on the queue you are using.

 

If you are doing this on the graphics queue, and your program is arranged like many of the basic dx12 samples, and you have frame objects containing commandlists for each of your (for example) 3 frames, you already know when those frame objects are available again due to the wait for the fence that is in your standard game loop (each frame object is available after 3 frames if your framecount is 3).

 

This topic is closed to new replies.

Advertisement