title: Is it possible to combine HDR with MSAA in a DirectX 12 desktop application?
body: <p>Using the DirectX Tool Kit for DirectX 12, I'm able to successfully compile and run the individual MSAA and HDR tutorial samples.
  When I combined the relevant code for the MSAA and HDR components together into a single <strong>Game.cpp</strong> file however, compilation fails with the debug layer message:</p>
  <p><em>D3D12 ERROR : ID3D12CommandList::ResolveSubresource : The specified format is not compatible with the source resource.Format : R10G10B10A2_UNORM, Source Resource Format : R16G16B16A16_FLOAT [RESOURCE_MANIPULATION ERROR #878: RESOLVESUBRESOURCE_INVALID_FORMAT]</em></p>
  <p>I am using the HDR sample code for an SDR display monitor, and therefore need to apply tone mapping. With respect to the order in which calls are made, I make a call to end the HDR scene before attempting to resolve the MSAA render target:</p>
  <pre><code>// 3d rendering completed
  m_hdrScene-&gt;EndScene(commandList);
  
  if (m_msaa)
  {
      // Resolve the MSAA render target.
      //PIXBeginEvent(commandList, PIX_COLOR_DEFAULT, L&quot;Resolve&quot;);
  
      auto backBuffer = m_deviceResources-&gt;GetRenderTarget();
      ...
  </code></pre>
  <p>Then following the MSAA resolve block, I place the tone mapping statement as follows:</p>
  <pre><code>// Unbind depth/stencil for sprites (UI)
  auto rtvDescriptor = m_deviceResources-&gt;GetRenderTargetView();
  commandList-&gt;OMSetRenderTargets(1, &amp;rtvDescriptor, FALSE, nullptr);
  
  // set texture descriptor heap in prep for sprite drawing
  commandList-&gt;SetDescriptorHeaps(static_cast&lt;UINT&gt;(std::size(heaps)), heaps);
  
  // apply tonemapping to hdr scene
  switch (m_deviceResources-&gt;GetColorSpace())
  {
  default:
      m_toneMap-&gt;Process(commandList);
      break;
  ...
  </code></pre>
  <p>I found that attempting to tone map <em>before</em> setting the descriptor heap for drawing 2D sprites (over the 3D scene) would result in the error:</p>
  <p><em>D3D12 ERROR: CGraphicsCommandList::SetGraphicsRootDescriptorTable: The descriptor heap (0x0000025428203230:'DescriptorHeap') containing handle 0x80000253a82ff205 is different from currently set descriptor heap 0x0000025428203540:'EffectTextureFactory'. [ EXECUTION ERROR #708: SET_DESCRIPTOR_TABLE_INVALID]
  D3D12: <strong>BREAK</strong> enabled for the previous message, which was: [ ERROR EXECUTION #708: SET_DESCRIPTOR_TABLE_INVALID ]</em></p>
  <p>I admit this was a rather naive first attempt to combine HDR and MSAA, but I'm concerned that these features could be incompatible and/or mutually exclusive in DirectX 12. I understand why a resource compatibility issue arises during MSAA resolve, as we need to use floating point render targets for HDR. I should note that my program will run and render correctly with HDR if I skip the MSAA code blocks by setting my <strong>m_msaa</strong> boolean to <em>false</em>.</p>
  <p>Looking forward to any advice anyone may have. If sufficient code or other details about the program are required, I'll be happy to update my post.</p>