使用MSAA创建交换链失败 [英] Creating a swap chain with MSAA fails

查看:224
本文介绍了使用MSAA创建交换链失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试设置支持MSAA的交换链时,出现 DXGI_ERROR_INVALID_CALL 错误-这是创建交换链的代码:

When I try to setup a swap chain with MSAA support I get an DXGI_ERROR_INVALID_CALL error - here is the code that creates the swap chain:

// Describe and create the swap chain.
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
swapChainDesc.BufferCount = frameCount_;
swapChainDesc.Width = static_cast<UINT>(rsd.width);
swapChainDesc.Height = static_cast<UINT>(rsd.height);
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;

if (rsd.enableMSAA) {
    swapChainDesc.SampleDesc = findBestMSAASetttings(swapChainDesc.Format);
}

ComPtr<IDXGISwapChain1> swapChain;

HRESULT hr = factory_->CreateSwapChainForHwnd(commandQueue_.Get(), // Swap chain needs the queue so that it can force a flush on it.
                                                  hWnd, &swapChainDesc, nullptr, nullptr, &swapChain);

找到最佳可用MSAA设置的方法如下:

The method to find the best available MSAA settings looks like this:

DXGI_SAMPLE_DESC D3D12RenderSystem::findBestMSAASetttings(DXGI_FORMAT format)
{
    HRESULT hr = S_FALSE;

    // The default sampler mode, with no anti-aliasing, has a count of 1 and a quality level of 0.
    UINT maxQualityLevel = 0;
    UINT respectiveSampleCount = 1;

    // If anti-aliasing is activated the best possible sample and quality level is chosen.
    // Find highest available sample count and quality level
    for (UINT sampleCount = 1; sampleCount <= D3D12_MAX_MULTISAMPLE_SAMPLE_COUNT; sampleCount++) {
        D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaQualityDesc{};
        msaaQualityDesc.SampleCount = sampleCount;
        msaaQualityDesc.Format = format; // DXGI_FORMAT_R8G8B8A8_UNORM;
        msaaQualityDesc.Flags = D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE;
        msaaQualityDesc.NumQualityLevels = 0;

        hr = device_->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaQualityDesc, sizeof(msaaQualityDesc));
        if (hr != S_OK) {
            BLUE_LOG(error) << "CheckMultisampleQualityLevels failed.";
        }
        if (msaaQualityDesc.NumQualityLevels > 0) {
            BLUE_LOG(trace) << "MSAA with sampleCount " << msaaQualityDesc.SampleCount << " and qualtiy level " << msaaQualityDesc.NumQualityLevels << " supported.";

            if (maxQualityLevel <= msaaQualityDesc.NumQualityLevels) {
                maxQualityLevel = msaaQualityDesc.NumQualityLevels;
                respectiveSampleCount = sampleCount;
            }
        }
    }

    BLUE_ASSERT(hr == S_OK, "find best MSAA setting failed.")

    DXGI_SAMPLE_DESC sd;
    sd.Count = respectiveSampleCount;
    sd.Quality = maxQualityLevel;

    return sd;
}

rsd.enableMSAA false 一切正常。

我的设备是这样创建的(我使用的是warp适配器,因为我没有硬件支持):

My device is created like this (I am using the warp adapter, since I have no hardware support):

throwIfFailed(factory_->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
            throwIfFailed(D3D12CreateDevice(warpAdapter.Get(), featureLevel_, IID_PPV_ARGS(&device_)));

我的日志说:

trace | D3D12RenderSystem::findBestMSAASetttings | MSAA with sampleCount 1 and qualtiy level 1 supported.
trace | D3D12RenderSystem::findBestMSAASetttings | MSAA with sampleCount 2 and qualtiy level 1 supported.
trace | D3D12RenderSystem::findBestMSAASetttings | MSAA with sampleCount 4 and qualtiy level 1 supported.
trace | D3D12RenderSystem::findBestMSAASetttings | MSAA with sampleCount 8 and qualtiy level 1 supported.
trace | D3D12RenderSystem::findBestMSAASetttings | MSAA with sampleCount 16 and qualtiy level 1 supported.


推荐答案

https://github.com/Microsoft/DirectXTK12/wiki/Simple-rendering 说:


Direct3D 12不支持创建MSAA交换链-尝试
使用SampleDesc.Count> 1创建交换链将失败。相反,您
创建自己的MSAA渲染目标,并明确解析为DXGI
后台缓冲区以进行呈现,如下所示。

Direct3D 12 don't support creating MSAA swap chains--attempts to create a swap chain with SampleDesc.Count > 1 will fail. Instead, you create your own MSAA render target and explicitly resolve to the DXGI back-buffer for presentation as shown here.

这篇关于使用MSAA创建交换链失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆