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

Started by
4 comments, last by afroviking 8 years ago

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?

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.

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.

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.

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

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.

This topic is closed to new replies.

Advertisement