Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [D3D11] Difference between UpdateSubresource and mapping/unmapping

[D3D11] Difference between UpdateSubresource and mapping/unmapping 2 years 1 month ago #519


  • Posts:20
  • OE's Avatar
  • OE
  • Junior Boarder
  • OFFLINE
What is the difference between:
  1. DeviceContext1.UpdateSubresource(ref bufferStruct, constantBuffer, 0);

and
  1. DataStream mappedResource;
  2. DeviceContext1.MapSubresource(...)
  3.  
  4. mappedResource.Write(data);
  5.  
  6. DeviceContext1.UnmapSubresource(...);
The administrator has disabled public write access.

Re: [D3D11] Difference between UpdateSubresource and mapping/unmapping 2 years 1 month ago #527


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
There are 3 things to carefully know on resource/mapping management on msdn: Basically, UpdateSubresource is mainly used to update a resource that was declared with the Usage.Default and is not frequently updated.. Technically, as explained in the UpdateSubresource doc, when you call UpdateSubresource, the buffer is more likely (when there are resource contention, which is mostly the case) to be copied to a temporary buffer accessible from the GPU command buffer. Then, the GPU will copy the content of the temp buffer to the GPU memory. UpdateSubresource is also able to update a part of a buffer, which can be handy in some situations.

Map/UnMap has more combination allowed (you can update staging buffers, dynamic buffers), most of the time, we are using MapMode.WriteDiscard. In this case, the resource must have been created with a Usage.Dynamic and a CpuAccessFlags.Write (There is also the special case of MapMode.WriteNoOverWrite where you could use it to write a part of a resource - except for constant buffers). It is mainly recommended for dynamic scenarios, where a resource is updated once per frame. It is also the only way to update a buffer and be performance friendly when you are using d3d11 multithreading features (this is measure here). The pointer returned by Map can be a mapped GPU memory (meaning that you are writing directly to the GPU memory).
The administrator has disabled public write access.

Re: [D3D11] Difference between UpdateSubresource and mapping/unmapping 2 years 1 month ago #536


  • Posts:20
  • OE's Avatar
  • OE
  • Junior Boarder
  • OFFLINE
So if I understood you correctly, UpdateSubresource is nothing more than short form for the Map/Unmap routine with the ResourceUsage.Default flag? As in, there is nothing magical behind it?
Last Edit: 2 years 1 month ago by xoofx. Reason: Remove unnecessary quote
The administrator has disabled public write access.

Re: [D3D11] Difference between UpdateSubresource and mapping/unmapping 2 years 1 month ago #537


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
I don't fully understand your question. What's this "magical" thing you are expecting from UpdateSubresource? If you mean by "short form", that the code is a bit shorter to update a resource, than using Map/UnMap, yes, but again, UpdateSubresource should not be used for intensive update unless the resource is declared with Usage.Default.
The administrator has disabled public write access.

Re: [D3D11] Difference between UpdateSubresource and mapping/unmapping 2 years 1 month ago #538


  • Posts:20
  • OE's Avatar
  • OE
  • Junior Boarder
  • OFFLINE
xoofx wrote:
I don't fully understand your question. What's this "magical" thing you are expecting from UpdateSubresource? If you mean by "short form", that the code is a bit shorter to update a resource, than using Map/UnMap, yes, but again, UpdateSubresource should not be used for intensive update unless the resource is declared with Usage.Default.

Yep, short form is what I meant. That answered the question :)
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.280 seconds