Jump to content
  • Advertisement
Sign in to follow this  
BlackJoker

DX12 Update only portion of data inside constant buffer D3D12

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

Hi.

I started to learn DX12 and I have a question regarding constant buffer update.

 

I need to write only to the certain parts of my constant buffer by offset.

In D3D11 I could do like that:

 

BackingBuffer is type of DataBuffer and I could write there my data separately by offsets like this:

BackingBuffer.Set(offset, ref value);

And then update my constant buffer:

// Setup the dest region inside the buffer
            if ((this.Description.BindFlags & BindFlags.ConstantBuffer) != 0)
            {
               device.UpdateSubresource(new DataBox(BackingBuffer.Pointer, 0, 0), constantBuffer);
            }
            else
            {
               var destRegion = new ResourceRegion(offsetInBytes, 0, 0, offsetInBytes + BackingBuffer.Size, 1, 1);
               device.UpdateSubresource(new DataBox(BackingBuffer.Pointer, 0, 0), constantBuffer, 0, destRegion);
            }

How can I do the same in D3D12?

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Advertisement

Since D3D10 the advice has always been to think about splitting Constant Buffers according to update frequency. If you have a single constant buffer within which there are some parts that needed to be updated at a higher frequency than others, think about splitting the constant buffer into two and avoid this situation entirely.

Share this post


Link to post
Share on other sites

I dont know exactly which data will be updated often and which not, so I cannot split anything. 

@Dingleberry

That method copying resource in resource, but I want to copy data to my resource without creating new constant buffer each time.

Is it possible? Or is there any solution for this in D3D12?

Share this post


Link to post
Share on other sites

You create a buffer on an upload heap and then map it. In D3D12 you can leave the buffer mapped forever, write to the mapped memory, and use it as a copy source. You copy from that buffer to other buffers, or whatever. See: https://msdn.microsoft.com/en-us/library/windows/desktop/dn899125(v=vs.85).aspx

 

You potentially need to use fences to ensure the gpu doesn't copy a buffer that isn't finished being written to though. 

 

Using fences and upload buffers you could make something nearly identical to D3D11 behavior that just needs a little bookkeeping work.

Edited by Dingleberry

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!