创建交换链时如何解决此多重采样错误?
How to fix this multisampling error when creating a swapchain?
我在创建交换链时收到有关多重采样的 DXGI 错误,在尝试解决此错误数小时后需要一些帮助。
我正在设置一个简单的 window 来学习 Direct3D 11。我已经尝试更改 DXGI_SWAP_CHAIN_DESC1 结构中的 SampleDesc.Count 和 SampleDesc.Quality,但我仍然得到错误。
// 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 渲染目标。
- 创建你的交换链作为一个样本(即没有 MSAA)。
- 创建使用一个或多个样本(即 MSAA)的渲染目标纹理。
- 为您的 MSAA 渲染目标创建渲染目标视图
- 每一帧,渲染到您的 MSAA 渲染目标,然后
ResolveSubresource
到交换链后备缓冲区——或其他一些 single-sample 缓冲区——,然后 Present
。
有关详细的代码示例,请参阅 GitHub。
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.
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.
在 'pre-Directx 12 / Vulkan' 的日子里,DirectX 通过在幕后为您做一些事情使启用 MSAA 变得很容易。它将创建一个用于显示的 non-MSAA 渲染目标,返回一个用于渲染的 MSAA 渲染目标,并作为 Present
的一部分为您完成解析。很简单,但是也有点浪费
使用 DirectX 12 的新 'no magic' 方法,您必须在应用程序中明确执行。在真正的游戏中,无论如何你都想这样做,因为你通常会做很多 post-processing 并且想在 Present
之前做好解决,甚至做其他类型的解决(FXAA、MLAA、SMAA)。例如:
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 是非常愚蠢的,除非是在玩具示例或示例代码中。
To get a sense of just how much of a modern game is doing multiple passes of rendering, see this blog post
的 DirectX 工具包
更新: 我在最近的 blog post
中对此进行了详细介绍
我在创建交换链时收到有关多重采样的 DXGI 错误,在尝试解决此错误数小时后需要一些帮助。
我正在设置一个简单的 window 来学习 Direct3D 11。我已经尝试更改 DXGI_SWAP_CHAIN_DESC1 结构中的 SampleDesc.Count 和 SampleDesc.Quality,但我仍然得到错误。
// 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 渲染目标。
- 创建你的交换链作为一个样本(即没有 MSAA)。
- 创建使用一个或多个样本(即 MSAA)的渲染目标纹理。
- 为您的 MSAA 渲染目标创建渲染目标视图
- 每一帧,渲染到您的 MSAA 渲染目标,然后
ResolveSubresource
到交换链后备缓冲区——或其他一些 single-sample 缓冲区——,然后Present
。
有关详细的代码示例,请参阅 GitHub。
You also can't create it as an
DXGI_FORMAT_*_SRGB
gamma-correcting swapchain with the newDXGI_SWAP_EFFECT_FLIP_*
models. You can create a Render Target View that isDXGI_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.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.
在 'pre-Directx 12 / Vulkan' 的日子里,DirectX 通过在幕后为您做一些事情使启用 MSAA 变得很容易。它将创建一个用于显示的 non-MSAA 渲染目标,返回一个用于渲染的 MSAA 渲染目标,并作为 Present
的一部分为您完成解析。很简单,但是也有点浪费
使用 DirectX 12 的新 'no magic' 方法,您必须在应用程序中明确执行。在真正的游戏中,无论如何你都想这样做,因为你通常会做很多 post-processing 并且想在 Present
之前做好解决,甚至做其他类型的解决(FXAA、MLAA、SMAA)。例如:
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 是非常愚蠢的,除非是在玩具示例或示例代码中。
的 DirectX 工具包To get a sense of just how much of a modern game is doing multiple passes of rendering, see this blog post
更新: 我在最近的 blog post
中对此进行了详细介绍