ID3D11ShaderResourceView save to file

Started by
16 comments, last by unbird 10 years, 7 months ago

How I can save to a file a ID3D11ShaderResourceView and also with the same format (DXGI_FORMAT_R16G16B16A16_FLOAT) ?

Advertisement
  1. Create texture with D3D11_USAGE_STAGING flag
  2. Use CopyResource method to copy texture from ID3D11SRV to newly created texture
  3. Use Map to read texture data on CPU
  4. Figure how to write DDS files or use IWICImagingFactory interface

Not sure how to use the thing with the Map to read texture data.

Have you taken a look at the DirectXTK library? I believe this method is already implemented for you, or at least it can provide you with a reference implementation to start from...

Have you taken a look at the DirectXTK library? I believe this method is already implemented for you, or at least it can provide you with a reference implementation to start from...

This is exactly what I need from the DirectXTK library:


HRESULT SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext,
                                  _In_ ID3D11Resource* pSource,
                                  _In_z_ LPCWSTR fileName );

however this library need Windows 8 SDK(that needs w8, and I don't have). It looks like only for this method I only missing <DirectXMath.h> and <wrl.h>, any suggestion ?

edit: I currently use DirectX SDK (June 2010)

The Windows 8 SDK can be installed on Win 7. Haven't tried myself, but one can even use it with VS 2010 as it seems. (Edit, corrected link).

Since you're using the June 2010 DX SDK, you can take a look at the D3DX legacy library, in particular D3DX11SaveTextureToFile.

The Windows 8 SDK can be installed on Win 7. Haven't tried myself, but one can even use it with VS 2010 as it seems. (Edit, corrected link).

Since you're using the June 2010 DX SDK, you can take a look at the D3DX legacy library, in particular D3DX11SaveTextureToFile.

"D3DX11SaveTextureToFile" was the first thing I did before trying anything else, but it didn't work, it just writes an empty file(16mb size).


ID3D11ShaderResourceView* my_ID3D11ShaderResourceView ;
ID3D11Resource* tempResource;
my_ID3D11ShaderResourceView->GetResource(&tempResource);
D3DX11SaveTextureToFile(m_D3D->GetDeviceContext(), tempResource, D3DX11_IFF_DDS, L"file.dds");
I'm currently not at home to test this, but maybe you need a temporary staging texture still, like Zaoshi Kaba suggests. Things to try:

- What HRESULT do you get from that call ?
- Compile with the debug library (d3dx11d.lib)

Also, don't forget to tempResource->Release() when you're done.

I'm currently not at home to test this, but maybe you need a temporary staging texture still, like Zaoshi Kaba suggests. Things to try:

- What HRESULT do you get from that call ?
- Compile with the debug library (d3dx11d.lib)

Also, don't forget to tempResource->Release() when you're done.

HRESULT gives S_OK

I have try everything i can with the "D3DX11SaveTextureToFile" but still cant get it working, and i don't want/need to migrate from June 2010 DX SDK to Windows 8 SDK to use the "SaveDDSTextureToFile".

Strange. That function should work fine even for non-staging textures (IIRC it will create a temporary automatically). Fire up PIX and see what's going on.

Edit: How do you actually populate the texture in the first place ? Load it ? Fill it manually with Map/Update or at creation ? Is it also a render target ?

This topic is closed to new replies.

Advertisement