SlimDX (D3D10) Texture2PNG

Started by
1 comment, last by Ivan Peric 9 years, 11 months ago

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?


Advertisement

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.

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

This topic is closed to new replies.

Advertisement