Jump to content
  • Advertisement
Sign in to follow this  
codingsolo

D3DXCreateTextureFromFileEx creating alarmingly high memory footprint

This topic is 4170 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

	D3DXCreateTextureFromFileEx(m_pDevice, 
		szFileName, 
		D3DX_DEFAULT, 
		D3DX_DEFAULT, 
		D3DX_DEFAULT, 
		0,  
		D3DFMT_UNKNOWN,
		D3DPOOL_MANAGED,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		NULL,
		NULL,
		NULL,
		&pImage->pTexture);
With a 2.25 MB 24-bit .PNG file of dimensions of 1440x900 and 99dpi, the D3DXCreateTextureFromFileEx function is increasing the memory footprint of the application by ~12 megabytes! If I set the MIP level to 1, it does indeed shave off 3 megs, but yet this is still suprisingly high. Any insights on how to reduce this or explanation why the memory is so high? Thanks, Brandon

Share this post


Link to post
Share on other sites
Advertisement
I don't know if I would consider it alarming - 1440x900 is a rather large texture. At least as far as I know the png isn't compressed in memory when it's loaded, so it will be larger in memory than on disk.

Also, it is a really good idea to keep your textures a power of two (eg: 1024x1024).

Share this post


Link to post
Share on other sites
It might be rounding the texture dimensions up:

2048x1024x4 = 8388608
1024x512x4 = 2097152
512x256x4 = 524288
256x128x4 = 131072

SUM: 11,141,120

(any smaller mip levels probably don't make much of a difference at that point.

Share this post


Link to post
Share on other sites
Hey,

PNG's are compressed so it would need them in the raw format. Plus, there is a possibility (as Nypyren suggested) that it's simply rounding them up to the next power-of-2 square dimension. I wouldn't worry though!

Share this post


Link to post
Share on other sites
You are both correct, png is compressed on disk and then uncompressed in memory. also it looks about right for losing 3 megs if you turn off the mips according Nypyren's stats.

that is a massive texture :)

Share this post


Link to post
Share on other sites
You should be able to load it into a DXT1 texture which is 4 bits per pixel/texel if the quality is good enough (don't do it for normal maps though!). This results in significant memory footprint reductions.

Share this post


Link to post
Share on other sites
good point - codingsolo, if you don't know, then dxt1-5 are compression formats (standardised by microsoft, ripped off s3 originally) which can be compressed in memory and are handled by the graphics card natively.

dxt1 is the most compressed but is rather lossy, especially in the alpha channel area (it doesn't actually store alpha data, the pixel is either "on" with a colour (alpha=1), or off entirely.

dxt2-5 give more alpha information, at a compression ratio of 4:1 - dxt2/3 is faster but gives sharper alpha edges, while dxt5 is slower to decompress but gives more alpha information

you can convert pngs to dds at runtime (by settings the format parameter of D3DXCreateTextureFromFileEx to D3DFMT_DXTx) or you can download various tools (e.g. http://developer.nvidia.com/object/nv_texture_tools.html ) to do it offline.

hope this helps :)

Share this post


Link to post
Share on other sites
Quote:
Original post by honnyjopper
dxt1 is the most compressed but is rather lossy, especially in the alpha channel area (it doesn't actually store alpha data, the pixel is either "on" with a colour (alpha=1), or off entirely.


It's worth noting that the colour in DXT1 is no more or less lossy than DXT2-5, however there is one small caveat: any texels where alpha=0 are always automatically considered to have a colour of black (r,g,b=0); for 1:1 mapping this isn't a problem, but if the texture is magnified/stretched with bilinear filtering enabled, you can get black 'fringes' in between the a=0 and a=1 areas.


Quote:
dxt2-5 give more alpha information, at a compression ratio of 4:1 - dxt2/3 is faster but gives sharper alpha edges, while dxt5 is slower to decompress but gives more alpha information


Small correction: DXT5 is slower on some but not all graphics hardware. On said hardware, DXT1-4 textures can be used directly by the rasterizer in their compressed form but DXT5 needs to be 'decompressed' into the texture cache and used in its expanded form, thus losing the texture cache benefits of using DXT compression.


The way I'd explain the difference between the DXT formats to people like artists is:

DXT1 : everything that doesn't need alpha, UI textures, otherwise see me.
DXT3 : if it has an alpha channel and the alpha is 'noisy'/random.
DXT5 : if it has an alpha channel and the alpha has smooth gradients.
DXT2 : pre-multiplied alpha version of DXT3*.
DXT4 : pre-multiplied alpha version of DXT5*.

* for discussion of pre-multiplied alpha, take a look at TomF's excellent blog: http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BPremultiplied%20alpha%5D%5D

DXT5 also has a special use for compressed normal maps (when better formats aren't available or suitable) where the green from the colour is treated as one element of the normal and alpha is treated as a second element of the normal and the third element of the normal is derived mathematically in the shader (normals are usually unit length so its easy).


Quote:
you can convert pngs to dds at runtime (by settings the format parameter of D3DXCreateTextureFromFileEx to D3DFMT_DXTx) or you can download various tools (e.g. http://developer.nvidia.com/object/nv_texture_tools.html ) to do it offline.


Yep. The NVIDIA texture tools are the most fully featured of all the libraries out there, though the ATI tools give slightly better results (comparing RMS error with like-for-like options, probably something to do with Seth who used to be at S3 now writing the ATI tools).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!