本文介绍了如何在DirectX 11上使用MultiSample Texture和ResourceView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎多重采样纹理进行多重采样,因此反锯齿。

我想使用多重采样纹理。

和这样的CreateTexture。

但是ID3D11ShaderResourceView创建失败。

It seems that multisample texture do multisampling, so Anti-Aliased.
I want to use multisample texture.
And CreateTexture like this.
But ID3D11ShaderResourceView create fail.



  // 我像这样创建了SwapChain。

  HRESULT hr;

  DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};

  swapChainDesc.Width = static_cast< UINT>(m_d3dRenderTargetSize.cx); //匹配窗口的大小。

  swapChainDesc.Height = static_cast< UINT>(m_d3dRenderTargetSize.cy);

  swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; //这是最常见的交换链格式。

  swapChainDesc.Stereo = false;

  swapChainDesc.SampleDesc.Count = 8;

  swapChainDesc.SampleDesc.Quality = 0;

  swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;

  swapChainDesc.BufferCount = 2; //使用双缓冲来最小化延迟。

  swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; //所有Windows应用商店应用必须使用此SwapEffect。

  swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; //启用GetFrameLatencyWaitableObject()。

  swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; //使用XAML互操作时,此值不能为DXGI_ALPHA_MODE_PREMULTIPLIED。

  swapChainDesc.Scaling = DXGI_SCALING_STRETCH;

  swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

  swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

  hr = dxgiFactory-> CreateSwapChainForHwnd(m_d3dDevice,m_hWindow,& swapChainDesc,nullptr,nullptr,& m_swapChain);


 //  I Created the SwapChain like this.
 HRESULT hr;
 DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
 swapChainDesc.Width = static_cast<UINT>(m_d3dRenderTargetSize.cx); // Match the size of the window.
 swapChainDesc.Height = static_cast<UINT>(m_d3dRenderTargetSize.cy);
 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swap chain format.
 swapChainDesc.Stereo = false;
 swapChainDesc.SampleDesc.Count = 8;
 swapChainDesc.SampleDesc.Quality = 0;
 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
 swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
 swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // Enable GetFrameLatencyWaitableObject().
 swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; // When using XAML interop, this value cannot be DXGI_ALPHA_MODE_PREMULTIPLIED.
 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
 swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
 hr=dxgiFactory->CreateSwapChainForHwnd(m_d3dDevice, m_hWindow, &swapChainDesc, nullptr, nullptr, &m_swapChain);



  //创建纹理。

  ID3D11Texture2D *  m_pResource;

  D3D11_TEXTURE2D_DESC TestDesc ; $
  ZeroMemory(& TestDesc,sizeof(D3D11_TEXTURE2D_DESC));

  TestDesc.ArraySize = 1;

  TestDesc .BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;

  TestDesc.Usage = D3D11_USAGE_DEFAULT;

  TestDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

  TestDesc.Width = m_nSize。 x;

  TestDesc.Height = m_nSize.y;

  TestDesc.MipLevels = 1;

  TestDesc.SampleDesc。 Count = 8;

  TestDesc.SampleDesc.Quality = 0;

  hr = pd3dDevice-> CreateTexture2D(& TestDesc,NULL,& m_pResource) ;


 // Create Texture.
 ID3D11Texture2D* m_pResource;
 D3D11_TEXTURE2D_DESC TestDesc;
 ZeroMemory(&TestDesc, sizeof(D3D11_TEXTURE2D_DESC));
 TestDesc.ArraySize = 1;
 TestDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
 TestDesc.Usage = D3D11_USAGE_DEFAULT;
 TestDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
 TestDesc.Width = m_nSize.x;
 TestDesc.Height = m_nSize.y;
 TestDesc.MipLevels = 1;
 TestDesc.SampleDesc.Count = 8;
 TestDesc.SampleDesc.Quality = 0;
 hr = pd3dDevice->CreateTexture2D(&TestDesc, NULL, &m_pResource);

  //创建ShaderResource。

  ID3D11ShaderResourceView *  m_pView;

  D3D11_SHADER_RESOURCE_VIEW_DESC TestDescRV;

  ZeroMemory(& TestDescRV,sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));

  TestDescRV.Format = TestDesc.Format;

  TestDescRV。 ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;

  TestDescRV.Texture2D.MipLevels = 1;

  TestDescRV.Texture2D.MostDetailedMip = 0;

  hr = pd3dDevice-> CreateShaderResource查看(m_pResource,& TestDescRV,& m_pView);

 // Create ShaderResource.
 ID3D11ShaderResourceView* m_pView;
 D3D11_SHADER_RESOURCE_VIEW_DESC TestDescRV;
 ZeroMemory(&TestDescRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
 TestDescRV.Format = TestDesc.Format;
 TestDescRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
 TestDescRV.Texture2D.MipLevels = 1;
 TestDescRV.Texture2D.MostDetailedMip = 0;
 hr = pd3dDevice->CreateShaderResourceView(m_pResource, &TestDescRV, &m_pView);



CreateShaderResourceView()函数错误代码'E_INVALIDARG一个或多个参数无效。'

是否有任何样本使用多重采样纹理?


CreateShaderResourceView() function Error Code 'E_INVALIDARG One or more arguments are invalid.'
Is there any sample use multisample texture?

推荐答案

使用此标志指定翻转演示模型并指定DXGI持久保存内容调用
IDXGISwapChain1 :: Present1 后的后台缓冲区。
此标记不能用于多重采样。

Use this flag to specify the flip presentation model and to specify that DXGI persist the contents of the back buffer after you callIDXGISwapChain1::Present1. This flag cannot be used with multisampling.

最后一句很重要。

但首先要做的是启用调试层。您可以在
,如果你将D3D11_CREATE_DEVICE_DEBUG放在flags参数中,那么它将启用调试运行时。当您的应用程序附加调试器时,调试运行时将提供有关错误的更多信息。如果您使用Visual Studio作为调试器是
,那么您可以在输出窗口中看到此信息。

But the first thing you should do is to enable the debug layer. You can do this in the call toD3D11CreateDevice, if you put D3D11_CREATE_DEVICE_DEBUG in the flags parameter then it will enable the debug runtime. When you have a debugger attached to your application, the debug runtime will provide more information about what went wrong. If you are using Visual Studio as the debugger, then you can see this information in the output window.


这篇关于如何在DirectX 11上使用MultiSample Texture和ResourceView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 20:48