This is the error

D3D11 ERROR: ID3D11Device::CreateRenderTargetView: A RenderTargetView cannot be created of a Resource that did not specify the RENDER_TARGET BindFlag. [ STATE_CREATION ERROR #138: CREATERENDERTARGETVIEW_INVALIDRESOURCE]
D3D11 ERROR: ID3D11Device::CreateRenderTargetView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #140: CREATERENDERTARGETVIEW_INVALIDARG_RETURN]

So as i see here i need to set the BindFlag of the backBuffer to D3D11_BIND_RENDER_TARGET, but in all the tutorial i saw nobody is doing it, they all create the render target view by using this code

hr=m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&m_backBuffer)); 
if (FAILED(hr)) MessageBox(0, L"Failed get buffer", 0, 0); 
hr=m_device->CreateRenderTargetView(m_backBuffer, NULL, &m_renderTargetView); 
if (FAILED(hr)) MessageBox(0, L"Failed to create rendertargetview", 0, 0);

And nobody, nowhere is doing as the msdn site says, that the render target view must be created with this specific flag: D3D11_BIND_RENDER_TARGET

So I tried doing it by myself.

I created a texture2d desc like this for the back buffer:

D3D11_TEXTURE2D_DESC backBufferDescription;
    backBufferDescription.BindFlags = D3D11_BIND_RENDER_TARGET;
    backBufferDescription.ArraySize = 1;
    backBufferDescription.CPUAccessFlags = 0;
    backBufferDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    backBufferDescription.Height = 600;
    backBufferDescription.Width = 800;
    backBufferDescription.MipLevels = 1;
    backBufferDescription.MiscFlags = 0;
    backBufferDescription.SampleDesc.Quality = 0;
    backBufferDescription.SampleDesc.Count = 1;
    backBufferDescription.Usage = D3D11_USAGE_DEFAULT;
    m_device->CreateTexture2D(&backBufferDescription, NULL, &m_backBuffer);
    if (FAILED(hr))
        MessageBox(0, L"Fallito back buffer desc", 0, 0);

And it doesn't work the same.

Help please

  • \$\begingroup\$ Can you show us how you create the swapchain? \$\endgroup\$ – Stefan Agartsson Jan 15 '17 at 22:42
  • \$\begingroup\$ The first method gets the back buffer so I think your problem will be with your swapchain setup as that's where the back buffer RT comes from the second method is used to set up a RT for rendering into and is independent from the back buffer that's why that one is not working. \$\endgroup\$ – Justin William Stanley Bryant Jan 15 '17 at 23:09

The code you are referring to from MSDN is using the Texture2D resources created for the swap chain, which are only usable as render targets (i.e. D3D11_BIND_RENDER_TARGET is implicit).

In this DirectX Tool Kit tutorial, I'm creating my own render target textures that can also be used as a texture.

// Full-size render target for scene
CD3D11_TEXTURE2D_DESC sceneDesc(backBufferFormat, backBufferWidth, backBufferHeight,
DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D(&sceneDesc, nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView(m_sceneTex.Get(), nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateShaderResourceView(m_sceneTex.Get(), nullptr,

// Half-size blurring render targets
CD3D11_TEXTURE2D_DESC rtDesc(backBufferFormat, backBufferWidth / 2, backBufferHeight / 2,
Microsoft::WRL::ComPtr<ID3D11Texture2D> rtTexture1;
DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D(&rtDesc, nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView(rtTexture1.Get(), nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateShaderResourceView(rtTexture1.Get(), nullptr,

Microsoft::WRL::ComPtr<ID3D11Texture2D> rtTexture2;
DX::ThrowIfFailed(m_d3dDevice->CreateTexture2D(&rtDesc, nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateRenderTargetView(rtTexture2.Get(), nullptr,
DX::ThrowIfFailed(m_d3dDevice->CreateShaderResourceView(rtTexture2.Get(), nullptr,

See this link for the full source example.

Of course the key thing to note is that you can't see or Present render targets that are not part of the swap chain. You have to copy them to the swapchain buffer or render with them into the swapchain render target at some point.

  • \$\begingroup\$ Chuck Walbourn thanks a lot for the explanation, is solved the error already but the code you provided me will be very useful, thank you \$\endgroup\$ – Emanuele Jan 19 '17 at 21:49
  • \$\begingroup\$ Stefan Agartsson Justin William Stanley Bryant thanks for your time i solved the error, thanks \$\endgroup\$ – Emanuele Jan 19 '17 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.