Video Memory Paging Questions

BlitzMax Forums/BlitzMax Programming/Video Memory Paging Questions

Robert Cummings(Posted 2006) [#1]
Hi all,

Please could you clarify some misconceptions I may have?

* Blitzmax keeps a copy of all textures (images) in system ram as pixmaps

* Blitzmax sends the texture to the video card when it is required so an 8 meg video card would simply discard textures it does not render and page the ones in it does render?

* Images are loaded with a video ram flag so they prefer to be in video ram where possible?

* Images not being drawn can be flushed out of video ram to make room for new images to be drawn, and if this is the case, I can load 100 megs of textures and provided I am drawing less than 8 meg of textures, it will be smooth on the 8 meg card?

The last question is the most important one for me, thanks!


ozak(Posted 2006) [#2]
OpenGL too, keeps a system memory copy on top of that, if it's so ;)


Dreamora(Posted 2006) [#3]
1) True

2) Things like that are handled through drivers and hardware, not the software. But yes, thats how it should work.

3) No. Its commented out in DX for example. If you try to add it, it will end with many MAVs.
OpenGL has no such flagging (the program has to manage that) and on DX side, its better in most cases to let DX manage where the texture is.

4) No it will not be smooth as 8meg cards most likely, as those cards have a far too low bandwidth to send all those data up again and again. As well, those systems will most likely not have 100mb free ram for your textures as well and when they need to go to conventional ram, you could load them from disk nearly as fast as well.
For such systems, creating lower res texture versions (by hijacking BMs own mipmapping code) on startup would definitely be a good idea.


Robert Cummings(Posted 2006) [#4]
Hi,

Thank you for your reply, the last question was more of a what if question

I just wanted to know if I load all the textures I need in my game at startup, they will be intelligently paged to and from the card automatically?


Dreamora(Posted 2006) [#5]
Theoretically yes.
Practically such system that have that less VRAM will most likely not be able to hold the textures in SystemRAM (they exist twice so they need 200MB RAM) so I wouldn't try it ...


ImaginaryHuman(Posted 2006) [#6]
BlitzMax doesn't necessarily KEEP copies of your images as pixmaps. When you load images from an image file it has to put it into a pixmap first, then it uploads it into an image, then it gets rid of the pixmap.

If you want to you can load into a pixmap yourself and then convert the pixmap into an image - which means, taking the pixmap data and placing a copy of it in video ram as an image, so then you have two copies.

Blitzmax does not manage when the textures are kept in video ram or when they get spooled out to main memory or anything else. That is handled by the OpenGL driver or probably by DirectX also. In OpenGL, which requires the images be in video ram for it to work on them, will probably keep the `most used` or `most recently used` images in video ram and put the rest out to main memory if there is no enough vram to hold them all. Then when you use an image, and it's not in video memory, it will spool it back in from main memory and probably swap something else out. That's all managed by the OpenGL driver, for example, not by blitzmax. In OpenGL you can prioritize certain textures or say that some should remain resident in video memory and not be spooled out, but that's not something that I think blitzmax makes use of it addresses or gives you commands for. You'd have to do your own OpenGl programming. No idea about dx.

There is a `prioritize this and keep it in video ram is possible` thing in OpenGL but I don't think max makes use of it at all. I think it just leaves it up to the driver to determing where it keeps the data that it works on.

In order for OpenGL to work on an image or use it as a texture it HAS to be in video ram, or at least has to have been uploaded as a texture/image and spooled off to memory somehow - but all within OpenGL's realm of control. Max does not manage whether or not to transfer pixmaps to video ram based on ram availability or anything like that. You either have a pixmap, or an image, there is no relationship between them. Images are in video ram, pixmaps are in main memory.

As to your last question I think you can just load 100 megs worth and the driver will sort out where to put the various texture data. Then if you use certain textures I presume those will be kept in video ram and others will be shuffled off elsewhere. You'd be better off looking at the Opengl/dx documentation/manuals to be sure of how it is going to do it. If you want CONTROL over that, to prioritize certain textures, then you need to get into doing your own dx/gl programming.

I would hazard a guess that if you only have 8 megs video ram, (not forgetting some of that is taken up with your display and the backbuffer), and you only used a small range of textures, they would just stay in video ram and others would be shuffled off to main memory by the driver. You could just test it and see. If it gets horrendous slowdown you know it's using textures that are spooled to memory rather than in video ram.


Ross C(Posted 2006) [#7]
Why not do this: Have 8 textures/images/ whatever they are, in systemRAM. Keep them there and have everything else loaded in. When you wish to load a new texture/image in, copy the texture/image over the one in VRAM. It would be one way to override dx's system of swapping textures, so you only swap when you need to.

I don't know the real practicalities of this though. Copyrect in blitz3d was fairly quick at doing this. You could even do it in smaller chunks i suppose.

EDIT[ sorry the above was went to mean 8 meg of texture/image. Why not set a limit of textures/aimges, based on the 8 MB divided by the max-size of texture/image.]


ozak(Posted 2006) [#8]
OpenGL's internal texture manager actually does a fine job at this. It usually runs quite smooth, even on lowmem cards :)