Since the render target view (that views the texture to render into) and depth stencil view (the corresponding depth buffer) have different multi-sampling settings, above error message have been shown. 


When using multi-sampling, every pixel needs to store extra data for the sub-samples. Each texture resource is prepared for one certain multi-sampling setting and to make them work together, both the color texture and the depth buffer (after all, it’s just another texture) need the same setting. You can have resources with different settings, but you can only bind them together, if their settings coincide.



Example code) 



HRESULT hr = S_OK;

// Setup the render target texture description.

D3D11_TEXTURE2D_DESC rtTextureDesc;

rtTextureDesc.Width = 1280;

rtTextureDesc.Height = 960;

rtTextureDesc.MipLevels = 1;

rtTextureDesc.ArraySize = 1;

rtTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;

rtTextureDesc.SampleDesc.Count = 1;

rtTextureDesc.SampleDesc.Quality = 0;

rtTextureDesc.Usage = D3D11_USAGE_DEFAULT;

rtTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;

rtTextureDesc.CPUAccessFlags = 0;

rtTextureDesc.MiscFlags = 0;


// Create the render target texture.

V_RETURN(pd3dDevice->CreateTexture2D(&rtTextureDesc, NULL, &m_renderTargetTexture));


// Setup the description of the render target view.

D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;

renderTargetViewDesc.Format = rtTextureDesc.Format;

renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;

renderTargetViewDesc.Texture2D.MipSlice = 0;


// Create the render target view.

V_RETURN(pd3dDevice->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView));


//Setup the depth stencil texture description. 

D3D11_TEXTURE2D_DESC dsTextureDesc;

dsTextureDesc.Width = 1280;

dsTextureDesc.Height = 960;

dsTextureDesc.MipLevels = 1;

dsTextureDesc.ArraySize = 1;

dsTextureDesc.SampleDesc.Count = 1;

dsTextureDesc.SampleDesc.Quality = 0;

dsTextureDesc.Format = DXGI_FORMAT_D32_FLOAT;

dsTextureDesc.Usage = D3D11_USAGE_DEFAULT;

dsTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;

dsTextureDesc.CPUAccessFlags = 0;

dsTextureDesc.MiscFlags = 0;

V_RETURN(pd3dDevice->CreateTexture2D(&dsTextureDesc, NULL, &m_depthTexture));


// Create the depth stencil view

D3D11_DEPTH_STENCIL_VIEW_DESC DescDS;

DescDS.Format = dsTextureDesc.Format;

DescDS.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;

DescDS.Texture2D.MipSlice = 0;

DescDS.Flags = NULL;

V_RETURN(pd3dDevice->CreateDepthStencilView(m_depthTexture, &DescDS, &m_depthView));


pd3dImmediateContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthView);

return hr;

Posted by Cat.IanKang
,