title: Texture streaming in DirectX11, Immutable vs Dynamic
body: <p>We often have the case where we need to stream textures to the graphics card (in game case: terrains, in my case image from different input sources like cameras/capture cards/videos)</p>
  
  <p>Of course in camera case, I receive my data in a separate thread, but still need to upload that data to the GPU for display.</p>
  
  <p>I know 2 models for it.</p>
  
  <ul>
  <li><p>Use a dynamic resource:
  You create a dynamic texture which has the same size and format as your input image, when you receive a new image you set a flag that tells you need upload, and then use map in the device context to upload the texture data (with eventual double buffer of course).</p>
  
  <p>Advantage is you have a single memory location, hence you don't have memory fragmentation over time.</p>
  
  <p>Drawback is you need to upload in immediate context, so your upload had to be in your render loop.</p></li>
  <li><p>Use immutable and load/discard
  In that case you upload in the image receiving thread, by creating a new resource, push the data and discard the old resource.</p>
  
  <p>Advantage is you should have a stall free upload (no need for immediate context, you can still run your command list while texture is uploading), resource can be used with a simple trigger once available (to swap SRV).</p>
  
  <p>Drawback is you can fragment memory over time (by allocating and freeing resources in a constant manner (30 fps for a standard camera as example).</p>
  
  <p>Also you have to deal with throttling yourself (but that part is not a big deal).</p></li>
  </ul>
  
  <p>So is there something I missed in those techniques, or is there an even better way to handle this?</p>