I thought .DDS files should be loaded quickly?

Ok, so I'm trying to weigh pro and con using various texture compression methods. I spend 99.999% of my time programming 2D sprites for Windows machines using DirectX.

So far I have looked at the alpha-trim texture packaging (SpriteSheets), and this seems like a decent way to get a bit more performance. Now I'm starting to look at the texture format in which they are stored; currently everything is stored as * .PNG.

I heard that * .DDS files are good, especially when they are used with DXT5 compression (/ 3/1 depending on the task), because the texture remains compressed in VRAM? People also say that since they are already DirectDraw Surfaces, they load much faster and faster.

So, I created an application to test this; I call the line below 20 times, freeing the texture between each call.

for (int i = 0; i < 20; i++) { if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"Test.dds", &g_pTexture ) ) ) { return E_FAIL; } g_pTexture->Release(); g_pTexture = NULL; } 

Now, if I try this with the DXT5 texture, it will take 5 times longer than when loading into a simple * .PNG. I heard that if you do not create Mipmaps, it may go slower, so I double-checked it. Then I changed the program that I used to generate the * .DDS file, switching to my own NVIDIA nvcompress.exe, but none of them had any effect.

EDIT: I forgot to mention that files (both * .png and * .dds) are the same image, just saved in different formats. (Same size, amount of alpha, that's it!)

EDIT 2: Using the following options, it loads almost 2.5 times faster AND consumes LOT less VRAM!

  D3DXCreateTextureFromFileEx( g_pd3dDevice, L"Test.dds", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL, NULL, &g_pTexture ) 

However, now I am losing all my transparency in the texture, I was looking at the texture of DXT5, and it looks great in Paint.NET and DirectX DDS Viewer. However, when loaded in full transparency, it turns into a solid black color. Problem with ColorKey?

EDIT 3: Ignore this last bit, I was an idiot and in my quick response quickly forgot to turn on Alpha-Blending on D3DXSprite-> Begin (). Doh!

+4
source share
2 answers

You need to distinguish between the format in which your files are stored on disk and the format that textures ultimately use in video memory. Compressed DXT textures provide a good balance between memory usage and quality in video memory, but other compression methods, such as PNG or Jpeg compression, usually result in smaller files and / or higher quality on disk.

DDS files have the advantage that they support DXT formats directly and are placed on disk in the same way that DirectX expects data to be laid out in memory, so the minimum processor time is required after downloading to convert it to a format that hardware can use. They also support pre-generated mipmap chains, which formats, such as PNG, are not supported. Compressing an image in DXT formats is quite a time-consuming process, so you usually want to avoid it when downloading, if possible.

A DDS file with pre-generated mipmaps that is the same size and uses the same format as the video memory texture that you plan to create from it will use the least processor time of any standard format. You must ensure that D3DX does not allow scaling, filtering, format conversion, or creating mipmap to guarantee this. D3DXCreateTextureFromFileEx allows D3DXCreateTextureFromFileEx to specify flags that prevent any internal conversions ( D3DX_DEFAULT_NONPOW2 for the width and height of the image, if your equipment supports the weakness of two textures, D3DFMT_FROM_FILE to prevent the creation of a mipmap or format conversion, D3DX_FILTER_NONE ).

CPU time is only half the story. Processors are pretty fast these days, and hard drives are relatively slow, so sometimes the total download time can be shorter if you download a smaller compressed file format like PNG or JPG and then do a lot of work with the CPU to convert it than if you load a larger file like DDS, and just make memcpy in the video memory. A common approach that gives good results is DDS zip files and unzip them for quick download from disk and the minimum cost of the processor to convert the format.

Compression formats such as PNG and JPG will compress some images more efficiently than others. DDS - fixed compression ratio - the specified image resolution and format will always be compressed to the same size (which is why it is more suitable for decompression in hardware). If you use simple non-representative images for testing (for example, a uniform color or a simple template), your PNG file is likely to be very small, and therefore it will load from disk faster than a typical game image.

+14
source

Compare the download of the standard PNG and then compress it to the time required to download the DDS file.

However, I cannot understand why PNG will load faster than the same compressed DXT5 textures. For one, it will be a fair bit smaller, so it should load the disk form faster! Is this DXt5 texture the same as PNG texture? those. Do they have the same size?

Have you tried playing with D3DXCreateTextureFromFileEx? You have much more control over what is happening. It can help you.

+1
source

All Articles