Jump to content
  • Advertisement
Sign in to follow this  
Volgogradetzzz

[D3D12] Synchronization on resources creation. Need a fence?

This topic is 835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

 

In D3D12HelloTriangle example there's an interesting synchronization in LoadAssets() function. They call WaitForPreviousFrame() function. I understand why we need it during a rendering. But in this particular example I can't get the purpose of a such synchronization. They are not submitting anything to the gpu (or they do???). They're using an upload heap for the single resource here - vertex buffer. As I understand the upload resource exists on the cpu side and the data is transferred every time the gpu needs it. So no need a fence here. They also create a root signature, pso, fence object itself. So maybe for this objects we need a synchronization? Is it somewhere in documentation?

Share this post


Link to post
Share on other sites
Advertisement
The upload heap is being used as a copy source, and the actual copy operation is performed in a command list. The command queue that the command list is being run on is what needs to be synchronized, so you know when the copy operation has actually finished -- putting the command list into the queue only means the operation is pending.

Share this post


Link to post
Share on other sites

They're just doing a map and a memcopy. The map returns a pointer into the heap, and unmap doesn't do anything, no GPU operations occur and I think the creation actually does a wait for residency so I don't see anywhere where synchronization should be required.

Share this post


Link to post
Share on other sites

The synchronization is happening because they don't want to leave the memory in the upload heap and there's no other way to know when the copy from upload to default happens.

 

E: WAIT I'm totally wrong they are leaving it in upload. This might be a bug? I bet they moved it to default originally and then later thought the code would be easier to read if they didn't, but forgot to remove the sync.

Edited by Dingleberry

Share this post


Link to post
Share on other sites

Yeah, there's no need to wait for commands to finish executing because they don't actually issue any commands. If you look at some of the other samples, they all have a wait at the end of LoadAssets. They do this so that they can ensure that any GPU copies finish before they destroy upload resources. So for instance if you look at the HelloTexture sample, it goes like this:

 

  • Create upload resource
  • Map upload resource, and fill it with data
  • Issue GPU copy commands on a direct command list
  • Submit the direct command list
  • Wait for the GPU to finish executing the command list
  • ComPtr destructor calls Release on the upload resource, destroying it

Share this post


Link to post
Share on other sites

That makes way more sense, but that wait where they create the fence the first time isn't necessary right? The upload heap isn't some magical resource that uploads memory to the gpu lol. It's just a normal video memory allocation that's cpu visible and probably has some caching flags that makes it more suitable for cpu operations.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!