Hey!
I am trying to get MSAA rendering to work in DX12, but I am having issues. My setup is like this:
I have a render target that I am rendering all my stuff into, it is generally used for UI and some parts of the game.
I have another separate render target, that I am rendering the shapes with MSAA to, mostly containing lines as they look very bad without anti aliasing. But when I call ResolveSubresource with destination being main render target and source being MSAA render target, my screen goes to black and I can only see the MSAA drawings, because this operation overwrites the render target's contents.
So I researched and found out I have to make a intermediate buffer to copy the msaa, then render it (blend??) to my main render target, but I can't figure out how to do this or find any examples, as the codes i found usually enable msaa for the whole render pipeline instead of only specific places, here is my current code:
auto barrier = CD3DX12_RESOURCE_BARRIER::Transition(
current_buffer.msaa_resource,
D3D12_RESOURCE_STATE_RESOLVE_SOURCE, // this is the initial state
D3D12_RESOURCE_STATE_RENDER_TARGET);
command_list->ResourceBarrier(1, &barrier);
// clear msaa target
constexpr FLOAT clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
command_list->ClearRenderTargetView(current_buffer.msaa_target, clear_color, 0, nullptr);
// render to msaa target
command_list->OMSetRenderTargets(1, ¤t_buffer.msaa_target,
FALSE, nullptr);
// render shapes into msaa target
// for example, render lines / circles or any other stuff you want with msaa.
...
// resolve msaa
barrier = CD3DX12_RESOURCE_BARRIER::Transition(current_buffer.msaa_resource,
D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
command_list->ResourceBarrier(1, &barrier);
command_list->ResolveSubresource(current_buffer.msaa_intermediate_resource,
0, current_buffer.msaa_resource, 0, rtv_format_);
// now can render stuff without MSAA, original render target
command_list->OMSetRenderTargets(1, ¤t_buffer.main_target, FALSE, nullptr);
...
// TODO HOW TO COPY current_buffer.msaa_intermediate_resource into current_buffer.main_target without overwriting its contents?
...
// present