Game Development Community

Pre-loading textures into VRAM?

by Manoel Neto · in Torque 3D Professional · 05/18/2010 (6:01 am) · 2 replies

I have a scene with a couple dozen different characters, and when starting the game for the first time there's a small freeze whenever a new character needs to be rendered for the first time. I assume the textures are being loaded into VRAM for the first time.

Is there an elegant way to pre-load textures into VRAM so my game runs smoothly all the time? Maybe something in the texture profiles? I really want to avoid having to setup a dummy cutscene where all characters are in the same place with some black GUI covering them up ;)

#1
05/18/2010 (9:48 am)
Someone more versed in modern rendering techniques will have to answer your specific question. I'm not really familiar with the idea that loading textures to VRAM will cause a freeze, but I would suggest that with so many character models, you may be exceeding your RAM or VRAM capacity entirely.

In many engines preloading (ie, from disk to system RAM) is a concern, however that should be happening automatically in Torque (sound effects profiles are the only datablocks where you might accidentally not be preloading, as they need to have preload = true; set manually).

One thing you'll want to be certain about is that you're using only compressed textures. Raw bitmaps of any type (including compressed to disk formats like PNG and JPG) are going to take up massive chunks of VRAM, and with 24+ character models, it would be fairly easy to fill up the memory on many modern video cards. Getting these textures into DDS format (see: en.wikipedia.org/wiki/S3_Texture_Compression) will massively decrease your VRAM overhead. Photoshop will save to DDS in various DXT compression methods these days, and there are a number of whatever->DDS converters out there if your image editor doesn't. I believe DXT3 is basically the standard method right now. If my understanding is correct you should be able to cut your VRAM use (for textures) down to 25% of what it is without DXT compression.

Beyond compression, you may need to make some sacrifices to the size or number of textures these models are using. I would suggest that, like many modern games with this many characters, you could get significant performance boosts from using fewer models and a more robust model customizations system, but this sort of thing is probably too complex to really explore seriously.

Good luck. Hopefully someone will be able to provide the more technical answers you're looking for, but I figured I'd give you a couple things to consider.
#2
05/18/2010 (10:18 am)
The entire scene is budgeted to fit into the VRAM of our target spec without need of paging out anything. There's no uncompressed textures anywhere either. However, I'm sure that depending on D3D resource settings, textures aren't readily loaded into VRAM until they are needed.

I got around the freezes by using a hack: by manipulating mGlobalBounds and doing a few changes to prepRenderImage() I managed to force my characters to go through rendering regardless of culling on the first frame, which gets them loaded into VRAM.