Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

D3D12: Copy Queue and ResourceBarrier

This topic is 976 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

I'm looking at creating queues for each of the following command list types:

 

  • D3D12_COMMAND_LIST_TYPE_DIRECT
  • D3D12_COMMAND_LIST_TYPE_COMPUTE
  • D3D12_COMMAND_LIST_TYPE_COPY

I've created a setup that uses a DIRECT queue and primarily just renders geometry.  Now I want to set up a queue for copying data from Upload Heaps to Default Heaps.  This works fine as long as I only make copy calls with the queue (CopyBufferRegion or CopyTextureRegion).  But if I try to call ResourceBarrier on it, the program crashes.  This seems to jibe with the sparse documentation on COPY queues: "COPY queues and command lists accept only copy commands."

 

So... say I'm copying vertex data.  Should I transition the resource from D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER to D3D12_RESOURCE_STATE_COPY_DEST on the DIRECT queue, then use the COPY queue to do the copy, and then transition back on the DIRECT queue?  Is the COPY queue even optimized for copies anyway?  I'm guessing that it is, since it has its own type, but the documentation on it is a bit thin.  And having to transition the resource on 2 separate queues seems cumbersome...

Share this post


Link to post
Share on other sites
Advertisement
The copy queue 'could' be optimised; it is a bit hardware specific.

For example on Intel I doubt you'd get any pay back, AMD however have dedicated DMA hardware on their GPU so copying can be handled separately from other operations. (Same with compute queues; GCN has up to 8 hardware queues each servicing up to 8 software queues - although if memory serves currently you can only create one unique queue per type with D3D12.)

Share this post


Link to post
Share on other sites
I have the exact same problem as you!

The documentation is super sparse with regards to this. It says that to execute copy commands on the copy queue, the resource needs to be in different states compared to submitted the copy through the 3D/compute queues. All the resource states need to start in D3D12_RESOURCE_STATE_COMMON. Here's a link to the documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/dn899217(v=vs.85).aspx -- have a look at "Multi-Queue resource access".

Once again, I'm doing what that documentation says but I'm still getting a crash ont the resource barrier command too...

And yes, the copy queue is supposed to be optimised for copying. At least with regards to CPU overhead -- except for on the Intel integrated graphics chips

Share this post


Link to post
Share on other sites

That is a much more informative page than anything I'd found, thanks!  Interestingly, I don't get a crash on ResourceBarrier.  I get an error when I call Close on the command list I tried to use for the copy, with it returning E_INVALIDARG.  This only happens if I put a ResourceBarrier in the commands though.

Share this post


Link to post
Share on other sites

That is a much more informative page than anything I'd found, thanks!  Interestingly, I don't get a crash on ResourceBarrier.  I get an error when I call Close on the command list I tried to use for the copy, with it returning E_INVALIDARG.  This only happens if I put a ResourceBarrier in the commands though.

 

Copy queue doesn't seem to support all resource states. I found it is safe to use COMMON, COPY_SOURCE and COPY_DEST states in copy queue. Also, if I'm correctly understand "promotable flags" part of the MSDN article, then resource barrier isn't necessary on copy queue if resources are in COMMON state.

Share this post


Link to post
Share on other sites

I still can't get it to work.  I'm attempting to use it to upload vertex data.  I created a committed resource, in a DEFAULT heap, initialized as a COPY_DEST.

 

Then I created a second resource, in an UPLOAD heap, initialized as a COPY_SOURCE (or as GENERIC_READ, or COMMON, it didn't make a difference).

 

I made the call to CopyBufferRegion, but as soon as I add a resource barrier to transition from COPY_DEST to VERTEX_AND_CONSTANT_BUFFER, I get the error when I close the list.  I tried transitioning to COMMON (so that I'm only using COPY_SOURCE, COPY_DEST, and COMMON), and I get the same error.

Edited by Funkymunky

Share this post


Link to post
Share on other sites


. I found it is safe to use COMMON, COPY_SOURCE and COPY_DEST states in copy queue

 

Are you sure? In the MSDN article it states that, "The COPY flags (COPY_DEST and COPY_SOURCE) used as initial states represent states in the 3D/Compute type class. To use a resource initially on a Copy queue it should start in the COMMON state". So I assume both resources that are involved in a copy must start in D3D12_RESOURCE_STATE_COMMON.

 

I never really read that part on promotion of resource state that thoroughly, but having a look at it now, does it mean the resource barrier command is not necessary at all (as per your post)? When I try to access this resource on the 3D/copy queue, it'll implicitly be promoted to the required state (if it's supported)?

Share this post


Link to post
Share on other sites

 


. I found it is safe to use COMMON, COPY_SOURCE and COPY_DEST states in copy queue

 

Are you sure? In the MSDN article it states that, "The COPY flags (COPY_DEST and COPY_SOURCE) used as initial states represent states in the 3D/Compute type class. To use a resource initially on a Copy queue it should start in the COMMON state". So I assume both resources that are involved in a copy must start in D3D12_RESOURCE_STATE_COMMON.

 

 

Sloppy phrasing on my side. I meant these states are safe in resource barriers on copy queue.

 

 

 

I never really read that part on promotion of resource state that thoroughly, but having a look at it now, does it mean the resource barrier command is not necessary at all (as per your post)? When I try to access this resource on the 3D/copy queue, it'll implicitly be promoted to the required state (if it's supported)?

 

 

I just compiled and tested my program without any resource barriers on copy queue, it still works fine without warnings from debug layer. Then I tried to transition texture to UNORDERED_ACCESS (just to check that this portion of code gets executed), it failed with E_INVALIDARG, as expected. So it seems promotion works as advertised.

 

EDIT: I tested the program on GTX 980, HD 4600, R7 360, Microsoft Basic Render Driver.

Edited by red75prime

Share this post


Link to post
Share on other sites

Thanks, red75prime, I was able to get my copy queue working!

 

FunkyMonkey, try the resource barrier command but transition from D3D12_RESOURCE_STATE_COMMON to D3D12_RESOURCE_STATE_COPY_DEST (you need to initialise the default heap with the D3D12_RESOURCE_STATE_COMMON state)

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!