Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


ID3D11ShaderResourceView save to file


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 31 August 2013 - 07:21 AM

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



Sponsor:

#2 Zaoshi Kaba   Crossbones+   -  Reputation: 4410

Like
2Likes
Like

Posted 31 August 2013 - 09:49 AM

  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


#3 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 01 September 2013 - 12:38 PM

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



#4 Jason Z   Crossbones+   -  Reputation: 5147

Like
2Likes
Like

Posted 02 September 2013 - 07:43 PM

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...



#5 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 03 September 2013 - 02:59 PM

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)


Edited by xlope01, 03 September 2013 - 03:00 PM.


#6 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 03 September 2013 - 03:59 PM

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.



#7 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 04 September 2013 - 09:13 AM

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");

Edited by xlope01, 04 September 2013 - 09:14 AM.


#8 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 04 September 2013 - 09:32 AM

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.

#9 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 05 September 2013 - 11:14 AM

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".



#10 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 05 September 2013 - 11:57 AM

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 ?

Edited by unbird, 05 September 2013 - 01:39 PM.


#11 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 06 September 2013 - 03:46 AM

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 ?

 

It is a render target(2048x2048).

As for PIX I can't get it to work for some reason.



#12 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 06 September 2013 - 04:12 AM

Read here and especially here. Use at your own risk, but uninstalling that platform update worked fine for me.

Edit: Ah yeah, what did you mean by "empty file" ? All zeroes (so no valid dds file at all) ? Black texture ? How did you check that ?

Edited by unbird, 06 September 2013 - 04:51 AM.


#13 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 06 September 2013 - 09:19 AM

if i open the dds file with a text editor the first line is this

DDS |             0                                                            DX10                                          
 

and after that it is filled with spaces until the end of the file. (size16MB for a 2048x2048 render target)

of course I can not open the file in any photo/paint editor, it says error etc



#14 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 06 September 2013 - 02:02 PM

That doesn't mean it's a bad file. Maybe your tools just can't cope with half-floats.

 

Try to load it in the DirectX texture tool: You find it in the SDK folder under \Utilities\bin\x86\DxTex.exe. 



#15 MJP   Moderators   -  Reputation: 11565

Like
2Likes
Like

Posted 06 September 2013 - 05:01 PM

That tool won't load it. The D3DX11 functions will save out DDS files using the newer DX10 DDS format, and there's almost no applications that will open it. In fact the only one I know of is Visual Studio 2012.



#16 unbird   Crossbones+   -  Reputation: 5464

Like
1Likes
Like

Posted 06 September 2013 - 05:37 PM

Strange. I tried something similar before suggesting: I saved (using SlimDX, which uses the above function under the hood) the backbuffer texture 1920x1080 with four channel half-floats. DxTex - both the 32 and 64 bit - load them fine. I don't see such a DX10 marker with a raw/hex viewer though. Is there some trigger (say, size) which "makes" it a DX10 DDS only?

 

Anyway: xlope01, could you upload this file somewhere, please ?

 

Also: you can "test" it with the corresponding loading function D3DX11CreateTextureFromFile and render it. Maybe first try a non-DDS format.

 

Edit: Update: Could go up to 4096^2 and again both DxTex load them fine. @xlope: Something is still off at your side I think. A 2048^2 texture should be 32 MB in size (2048*2048*4*2 = 33'554'432). And another Edit: Wait, maybe I'm silly now, I don't know if DDS does support compression. But a 2048^2 texture saves to approximately 32 MB on my side.


Edited by unbird, 06 September 2013 - 06:19 PM.


#17 xlope01   Members   -  Reputation: 174

Like
0Likes
Like

Posted 07 September 2013 - 03:50 AM

IT is actually working if I load with D3DX11CreateShaderResourceViewFromFile from the dds file that I make with D3DX11SaveTextureToFile (not sure why i can not open it with any photo/paint editor or  DxTex)

2048^2 is 32MB with R16G16B16A16, and with R11G11B10 is 16MB



#18 unbird   Crossbones+   -  Reputation: 5464

Like
0Likes
Like

Posted 07 September 2013 - 04:09 AM

Aaaah, there's the problem. R11G11B10_FLOAT is a newer format. Tried it, suddenly I've got this DX10 marker. Jep, DxTex doesn't cope with that.
 
Pity that. I think you have to live with it, unfortunately. Neither can I name you a tool which supports it, sorry.
 
Just as an aside: Make sure to get PIX working. Here's a screenshot from the image save call.
82a105274537842.gif

One can see clearly what's happening, namely the exact sequence Zaoshi Kaba described (the last couple of events in the list). The temporary texture also gets a nice debug name.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS