创建交换链时如何解决此多次采样错误? [英] How to fix this multisampling error when creating a swapchain?

查看:117
本文介绍了创建交换链时如何解决此多次采样错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建交换链时,我收到有关多重采样的DXGI错误,尝试解决该错误数小时后需要一些帮助.

I'm getting an DXGI ERROR about multisampling when creating a swapchain and need some help after hours of trying to resolve this error.

我正在设置一个用于学习Direct3D 11的简单窗口.我尝试更改DXGI_SWAP_CHAIN_DESC1结构中的SampleDesc.Count和SampleDesc.Quality,但是仍然出现错误.

I'm setting up a simple window for learning Direct3D 11. I have tried changing the SampleDesc.Count and SampleDesc.Quality in the DXGI_SWAP_CHAIN_DESC1 structure, but I still get the error.

// dxgiFactory is using interface IDXGIFactory7
// d3dDevice5 is using interface ID3D11Device5

ComPtr<IDXGISwapChain1> dxgiSwapChain1;

DXGI_SWAP_CHAIN_DESC1 desc;
desc.Width = 800;
desc.Height = 400;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Stereo = FALSE;
desc.SampleDesc.Count = 0;
desc.SampleDesc.Quality = 0;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.BufferCount = 3;
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
desc.AlphaMode = DXGI_ALPHA_MODE_STRAIGHT;
desc.Flags = 0;

hr = dxgiFactory->CreateSwapChainForHwnd(d3dDevice5.Get(), hWnd, &desc, nullptr, nullptr, &dxgiSwapChain1);

调试输出:

DXGI ERROR: IDXGIFactory::CreateSwapChain: Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) do not support multisampling.

如何解决此错误?

推荐答案

TL; DR 可以将翻转模型更改为较旧的 DXGI_SWAP_EFFECT_DISCARD 或创建一个MSAA渲染目标您会明确解决.

TL;DR Either change your flip model to the older DXGI_SWAP_EFFECT_DISCARD or create an MSAA render target that you explicitly resolve.

  1. 将交换链创建为一个示例(即无MSAA).
  2. 创建使用一个或多个样本(即MSAA)的渲染目标纹理.
  3. 为MSAA渲染目标创建渲染目标视图
  4. 每个帧,先渲染到您的MSAA渲染目标,然后再 ResolveSubresource 到交换链后备缓冲区(或其他一些单样本缓冲区),然后再进行 Present .
  5. li>
  1. Create your swap chain as one sample (i.e. no MSAA).
  2. Create a render target texture that is using one or more samples (i.e. MSAA).
  3. Create your render target view for your MSAA render target
  4. Each frame, render to your MSAA render target, then ResolveSubresource to the swapchain backbuffer--or some other single-sample buffer--, then Present.

有关详细的代码示例,请参见 GitHub .

For a detailed code example, see GitHub.

您也无法使用新的 DXGI_SWAP_EFFECT_FLIP _ * 模型将其创建为 DXGI_FORMAT _ * _ SRGB 伽马校正交换链.您可以为不是sRGB的交换链创建 DXGI_FORMAT _ * _ SRGB 的渲染目标视图,以获得相同的效果.在MSAA和sRGB以及Windows 10 Fall Creators Update(16299)或更高版本中修复的新翻转模型上,有些麻烦.

You also can't create it as an DXGI_FORMAT_*_SRGB gamma-correcting swapchain with the new DXGI_SWAP_EFFECT_FLIP_* models. You can create a Render Target View that is DXGI_FORMAT_*_SRGB for a swapchain that is not sRGB to get the same effect. There's a little bit of a gotcha doing both MSAA and sRGB together with the new flip models that is fixed in Windows 10 Fall Creators Update (16299) or later.

如果您使用的是DirectX 12,则不能选择使用较早的交换效果,因此必须直接实现MSAA渲染目标.再次,请参见 GitHub .

If you were using DirectX 12, you don't have the option of using the older swap effects, so you have to implement the MSAA render target directly. Again, see GitHub.

在"Directx 12之前的版本/Vulkan"时代,DirectX可以通过在幕后为您做很多事情来轻松启用MSAA.它将创建一个非MSAA渲染目标进行显示,将您带回的MSAA渲染目标进行渲染,并作为 Present 的一部分为您解决问题.这很容易,但是也有点浪费.

In the 'pre-Directx 12 / Vulkan' days, DirectX made it easy to enable MSAA by doing a bunch of stuff behind the scenes for you. It would create a non-MSAA render target for display, give you back an MSAA render target for rendering, and do the resolve for you as part of the Present. It was easy, but it was also a bit wasteful.

使用DirectX 12的新无魔术"方法,您必须在应用程序中显式地执行此操作.在真实游戏中,您无论如何都要这样做,因为您通常要进行很多后处理,并且希望在 Present 之前做好解析,甚至要进行其他类型的解析(FXAA,MLAA,SMAA).例如:

With the new 'no magic' approach of DirectX 12, you have to do it explicitly in the application. In real games you want to do this anyhow because you usually do a lot of post-processing and want do the resolve well before Present or even do other kinds of resolve (FXAA, MLAA, SMAA). For example:

Render 3D scene to a floating-point MSAA render target
->
Resolve to a single-sample floating-point render target
->
Perform tone-mapping/color-grading/blur/bloom/etc.
->
Render UI/HUD
->
Perform HDR10 signal generation/gamma-correction/color-space warp
->
Present

从该流程中可以看到,除了玩具示例或示例代码之外,使交换链成为MSAA是很愚蠢的.

As you can see from that flow, it's pretty silly to ever have the swapchain be MSAA except in toy examples or sample code.

要了解现代游戏中有多少次渲染需要经过多次渲染,请参见有关 DX 11 更新:我在最近的博客文章

这篇关于创建交换链时如何解决此多次采样错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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