Sign in to follow this  
Ivan Peric

SlimDX (D3D10) Texture2PNG

Recommended Posts

Ivan Peric    105

I have a performance problem with converting Texture2D to PNG. Since I am a total noob at DirectX, I used the Texture2D.ToStream method to map texure data to png data, and it looks kinda slow to me.

 

All application does is draws 1000 random lines to texture and then exports that texture to stream (byte array is the final product). The proces is repeated many times (~100) to get a collection of different images and exporting texture to stream takes ~98% of application run time.

Is there an alternative way to map texture data to image data that will be faster?


 

Share this post


Link to post
Share on other sites
tonemgub    2008

Image format conversion is not supposed to be a real-time operation (maybe except for the DXT format?), if that's what you're expecting. This conversion is also done on the CPU, which means that the texture is first copied from video memory to system memory, making it even slower. Even without the compression, copying the texture to a stream in system-memory or in a file is going to be slow.

Video games usually have special algorithms to predict when they have to pre-load extra textures from disk or from cached memory. You have to do the reverse of that: delay copying all of your data to memory/disk, until you know that somethign has actually changed. Combine that with saving your data as DXT, and you might get some speed improvements, though I can't promise anything spectacular.

Share this post


Link to post
Share on other sites
Ivan Peric    105

Thank you for your answer,

but I managed to speed things up on my own by writing my own method which does the following:

1) Creates Staging resource with CPU Read access
2) Copies resource from original Default resource to staging resource

3) Maps Staging resource and uses it's DataPointer to create BitmapResource

4) Creates the png with PngBitmapEncoder and created Bitmap resource.

This improved application run time ~60%.

 

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