• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
xlope01

ID3D11ShaderResourceView save to file

17 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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

2

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites
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 [tt]tempResource->Release()[/tt] when you're done.
1

Share this post


Link to post
Share on other sites

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 [tt]tempResource->Release()[/tt] 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".

0

Share this post


Link to post
Share on other sites
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
1

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites
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
1

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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. 

1

Share this post


Link to post
Share on other sites

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.

2

Share this post


Link to post
Share on other sites

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 [b]Edit[/b]: 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
1

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0