directx-12msaa

dx12 open 4x msaa failed


I am just learning "introduction to 3D game programming with DirectX 12".Running the example code in initialize d3d(chapter 4),when I wanna use 4xmsaa,something wrong was happened,like the follow figure,please help me. wrong figure


Solution

  • In keeping with the DirectX 12 design philosophy of "no magic runtime behavior", you aren't allowed to create a backbuffer as MSAA. This is because the video output hardware can't actually present MSAA backbuffers, so they have to be resolved to a single pixel each at some point in the pipeline. In DirectX 11, this was done 'behind the scenes' when you created an MSAA backbuffer. In DirectX 12, you are responsible for creating the MSAA render target texture yourself, and then perform the resolve to the backbuffer -or- run some other postprocess that does the resolve. The set up is exactly the same, just more verbose and explicit and under application control instead of being 'magic'.

    See the SimpleMSAA12 sample.

    With DirectX 12 you also aren't allowed to create sRGB format backbuffers. You can create sRGB render target views that will perform the gamma while writing to the backbuffer. There were some bugs in the older debug layers and Windows 10 runtime when doing direct resolves of sRGB MSAA render targets to non-sRGB backbuffers. These are also noted in the sample above.

    Note that UWP apps have exactly the same behavior as DirectX 12 for Win32 desktop apps. This is because both UWP apps and DirectX 12 are required to use the DXGI_SWAP_EFFECT_FLIP_* swap effects instead of the legacy DXGI_SWAP_EFFECT_* swap modes.

    BTW, if you had enabled DXGI debugging, you'd have gotten some specific debug diagnostic output when you tried to create the 4x MSAA backbuffer:

    DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (
    DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL
    and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling.
    [ MISCELLANEOUS ERROR #102: ]
    

    Take a look at this blog post for details on enabling DXGI debugging in your project, or take a look at the implementation of DeviceResources.