Sign in to follow this  
BlackJoker

DX12 Update only portion of data inside constant buffer D3D12

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
      628375
    • Total Posts
      2982310
  • Similar Content

    • By VietNN
      Hi everyone, I am new to Dx12 and working on a game project.
      My game just crash at CreateShaderResourceView with no infomation output in debug log, just: 0xC0000005: Access violation reading location 0x000001F22EF2AFE8.
      my code at current:
      CreateShaderResourceView(m_texture, &desc, *cpuDescriptorHandle);
       - m_texture address is: 0x000001ea3c68c8a0
      - cpuDescriptorHandle address is 0x00000056d88fdd50
      - desc.Format, desc.ViewDimension, Texture2D.MostDetailedMip, Texture2D.MipLevels is initalized.
      The crash happens all times at that stage but not on same m_texture. As I noticed the violation reading location is always somewhere near m_texture address.
      I just declare a temp variable to check how many times CreateShaderResourceView already called, at that moment it is 17879 (means that I created 17879 succesfully), and CreateDescriptorHeap for cpuDescriptorHandle was called 4190, do I reach any limit?
      One more infomation, if I set miplevel of all texture when create to 1 it seem like there is no crash but game quality is bad. Do not sure if it relative or not.
      Anyone could give me some advise ?
    • By VietNN
      Hi all,
      The D3D12_SHADER_RESOURCE_VIEW_DESC has a member Shader4ComponentMapping but I don't really know what is it used for? As several example set its value to D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING. I also read the document on MSDN but still do not understand anything about it.
      https://msdn.microsoft.com/en-us/library/windows/desktop/dn903814(v=vs.85).aspx
      https://msdn.microsoft.com/en-us/library/windows/desktop/dn770406(v=vs.85).aspx
      Anyone could help me, thank you.
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Thanks, 
      Dejay Hextrix 
    • By HD86
      As far as I know, the size of XMMATRIX must be 64 bytes, which is way too big to be returned by a function. However, DirectXMath functions do return this struct. I suppose this has something to do with the SIMD optimization. Should I return this huge struct from my own functions or should I pass it by a reference or pointer?
      This question will look silly to you if you know how SIMD works, but I don't.
    • By lubbe75
      I am looking for some example projects and tutorials using sharpDX, in particular DX12 examples using sharpDX. I have only found a few. Among them the porting of Microsoft's D3D12 Hello World examples (https://github.com/RobyDX/SharpDX_D3D12HelloWorld), and Johan Falk's tutorials (http://www.johanfalk.eu/).
      For instance, I would like to see an example how to use multisampling, and debugging using sharpDX DX12.
      Let me know if you have any useful examples.
      Thanks!
  • Popular Now