   [D3D11] Equivalent for glBlitFramebuffer ?
  HiI'm porting some OpenGL code to D3D 11 and stumbled upon an annoying problem:There seems to be no equivalent function for glBlitFramebuffer in D3D. All i want to do is copy/blit a texture into another texture. In D3D11 i found ID3D11DeviceContext::CopyResource, but it neither allows to stretch textures, nor does it work with depth-stencil resources.In my deferred renderer i sometimes need to make a 1:1 copy of depth-stencil textures (mostly the depth-part). And i used glBlitFramebuffer to downsample color-textures into smaller textures (for bloom etc.).The question is, how do i do this in Direct3D 11 ? Bind a pass-through shader and do RTT? And how do i do it with depth-stencil resources?Thanks,Jan.   
  I believe that anything in need of a dimension, scale, or format change will require a full pass.  As you've seen CopyResource() only does a simple copy.D3D10 does have a generate mips function which might fit some down-sampling needs.Copying depth-stencil shouldn't be a problem unless you are changing to a format in a different type group.  I'd need more information about what you're doing here in order to make a suggestion.   ;  I usually only want to make an exact copy of a depth-texture, such that i can make a snapshot of the current depth-buffer and use it for later render-passes as an input-texture. I am a bit surprised, that even an EXACT copy of depth-stencil textures is not supported.The question for me is then: How do i write a shader to copy depth-stencil textures (i am mostly interested in the depth-values) ?Would i bind the destination texture as a depth-stencil target and then sample the source-texture and write the value as "depth" ? Or should i bind the destination texture as a color render-target and then write the sampled depth-value as "red" (ignoring depth-output entirely) ?In the latter case i would need to create a RenderTargetView for the destination-texture. But which format would i use then? DXGI_FORMAT_R24_UNORM_X8_TYPELESS ? DXGI_FORMAT_D24_UNORM_S8_UINT ?This seemingly simple operation (in OpenGL) turns out to be a bit confusing for me.Thanks,Jan.   ;  Working example of using CopyResource to save a depth stencil to a new texture that can be used as an SRV or a DSV.#include <Windows.h>#include <D3D11.h>#include <DxErr.h>#define REPORT_FAILURE(x) if( FAILED(x) ) { DXTrace( __FILE__, __LINE__, x, L"...", FALSE ); }#define SAFE_RELEASE(x) if( x ) { x->Release(); x = nullptr; }int main(){ID3D11Device* pDevice = nullptr;ID3D11DeviceContext* pContext = nullptr;HRESULT hr = S_OK;{D3D_FEATURE_LEVEL fLevels[] = {D3D_FEATURE_LEVEL_11_0,D3D_FEATURE_LEVEL_10_1,D3D_FEATURE_LEVEL_10_0};D3D_FEATURE_LEVEL fLevel; hr = D3D11CreateDevice(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,D3D11_CREATE_DEVICE_DEBUG,fLevels,sizeof(fLevels)/sizeof(fLevels[0]),D3D11_SDK_VERSION,&pDevice,&fLevel,&pContext ); REPORT_FAILURE(hr);}ID3D11Texture2D* pDepthResource1 = nullptr;ID3D11Texture2D* pDepthResource2 = nullptr;if( SUCCEEDED(hr) ){CD3D11_TEXTURE2D_DESC desc( DXGI_FORMAT_R24G8_TYPELESS, 800, 600 );desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;hr = pDevice->CreateTexture2D( &desc, NULL, &pDepthResource1 );REPORT_FAILURE(hr);if( SUCCEEDED(hr) ){desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;hr = pDevice->CreateTexture2D( &desc, NULL, &pDepthResource2 );REPORT_FAILURE(hr);}}ID3D11DepthStencilView* pDepthView1 = nullptr;ID3D11DepthStencilView* pDepthView2 = nullptr;if( SUCCEEDED(hr) ){CD3D11_DEPTH_STENCIL_VIEW_DESC desc( pDepthResource1, D3D11_DSV_DIMENSION_TEXTURE2D, DXGI_FORMAT_D24_UNORM_S8_UINT ); hr = pDevice->CreateDepthStencilView( pDepthResource1, &desc, &pDepthView1 );REPORT_FAILURE(hr);if( SUCCEEDED(hr) ){hr = pDevice->CreateDepthStencilView( pDepthResource2, &desc, &pDepthView2 );REPORT_FAILURE(hr);}}// will let you read the depth values as a shader resource from // the second "saved" depth texture. ID3D11ShaderResourceView* pDepthSRV = nullptr;if( SUCCEEDED(hr) ){CD3D11_SHADER_RESOURCE_VIEW_DESC desc( pDepthResource2, D3D11_SRV_DIMENSION_TEXTURE2D, DXGI_FORMAT_R24_UNORM_X8_TYPELESS );hr = pDevice->CreateShaderResourceView( pDepthResource2, &desc, &pDepthSRV );REPORT_FAILURE(hr);}if( SUCCEEDED(hr) ){pContext->ClearDepthStencilView( pDepthView1, D3D11_CLEAR_DEPTH, 1.0f, 0 );pContext->CopyResource( pDepthResource2, pDepthResource1 );}SAFE_RELEASE(pDepthSRV);SAFE_RELEASE(pDepthView2);SAFE_RELEASE(pDepthView1);SAFE_RELEASE(pDepthResource2);SAFE_RELEASE(pDepthResource1);SAFE_RELEASE(pContext);SAFE_RELEASE(pDevice);};  That's great thank you!So is the documentation incorrect or did i misunderstand it?http://msdn.microsoft.com/en-us/library/ff476392%28VS.85%29.aspxUnder Remarks it says "Immutable, and depth-stencil resources cannot be used as a destination." That was what i was referring to.Thanks again,Jan.   ;  In that sample code the destination isn't a depth-stencil resource, it's only created with D3D11_BIND_SHADER_RESOURCE.   ;  I think that the documentation is wrong.    My resource did have depth stencil bind set, it was ORed with bind shader resource.desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;...desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; [Edited by - DieterVW on June 3, 2010 3:54:30 PM];  Lol. Ignore me!