3

Im trying to load a bitmap in order to render it on the screen,to do so im using loadSurfaceFromFile. the images that i want to load are 1280*1024, it takes about 35ms to load these images. it seems to me that it should load a lot faster(something like 5ms) what im i doing wrong?

edited code:

QueryPerformanceCounter(&liStart2);
int size = load_file_to_memory(s.c_str(),&content);
QueryPerformanceCounter(&liStop2);
QueryPerformanceCounter(&liStart);
D3DXLoadSurfaceFromFileInMemory(surface,NULL,NULL,content,size,NULL,D3DX_DEFAULT,0,NULL);
QueryPerformanceCounter(&liStop);
LONGLONG llTimeDiff = liStop.QuadPart - liStart.QuadPart;
double dftDuration = (double) llTimeDiff * 1000.0 / (double) Frequency.QuadPart;
LONGLONG llTimeDiff2 = liStop2.QuadPart - liStart2.QuadPart;
double dftDuration2 = (double) llTimeDiff2 * 1000.0 / (double) Frequency.QuadPart;
meirrav
  • 761
  • 1
  • 9
  • 27
  • 5ms seems too fast, the average seek time on a hard disk of that order of time. Then you are loading 4MB or so of data from your bmp file, which at a typical hard disk rate of 200MB/s will take 20ms or so. And that's before any processing is done on the data itsself... – jcoder Sep 05 '12 at 10:22
  • 5ms is the time that i think it should take for loading from the memory to the surface and not from the hard disk.is there a better way the render an image from a file (maybe with something else then surface)? – meirrav Sep 05 '12 at 10:56
  • Right, although your example loads from a file... Erm, preload everything you want into texture objects and draw them quickly when you need them? – jcoder Sep 05 '12 at 10:57
  • Thats what im doing now(loading to a surface array),but since i have usually around 1000 images to load you need to wait a long time... – meirrav Sep 05 '12 at 11:04

1 Answers1

1

What you want to do is to hide the load latency using multiple loader threads. Here's a discussion on the performance of loading textures from disk. I myself have utilized the last method outlined in the article there (by Jon Watte) with excellent results.

Hope this helps!

Ani
  • 10,826
  • 3
  • 27
  • 46
  • hiding the latency is a possible solution, but i still don't understand why does the surface/texture loading takes so long(20ms to load from memory to the device) – meirrav Sep 06 '12 at 14:12
  • Have you profiled the code to see which part is the bottleneck? Is it the PNG decoding? The reading itself? The discussion I pointed to has many helpful hints on what to do depending on what is slow. – Ani Sep 06 '12 at 14:15
  • I'm sorry - I don't understand what you mean by "this is my update code". Could you clarify, please? – Ani Sep 06 '12 at 14:27
  • sorry,i edited the code,the bottleneck is in the D3DXLoadSurfaceFromFileInMemory call – meirrav Sep 06 '12 at 14:32
  • Then, it seems to me that the bottleneck is decoding/decompression. Have you tried different file formats (I believe the supported formats are bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga) to see if that helps? Perhaps uncompressed PNGs? – Ani Sep 06 '12 at 14:49
  • isn't bmp an uncompressed format?, anyway i tried the others with no luck, they seem to work slower – meirrav Sep 09 '12 at 06:02
  • Yes, the most common 24 bpp BMP is not compressed. In this case, it is possible that you might become read bottlenecked. If performance is critical for you, take a look at this (http://stackoverflow.com/questions/11313251/fastest-png-decoder-for-net) other answer of mine related to GPU-based PNG decompression. – Ani Sep 10 '12 at 12:51
  • i decided to use multiple loaders and preload some of the data, its not ideal but nothing else seems to work.thanks anyway – meirrav Sep 11 '12 at 12:27