"Caching" graphics on the graphics card

BlitzMax Forums/BlitzMax Programming/"Caching" graphics on the graphics card

Grey Alien(Posted 2007) [#1]
Hiya, quick one here, I'm sure I've seen or asked it before but can't remember the answer...

Basically sometimes if you load some graphics into your game and then draw them, the first frame takes a long time to draw due to the graphics being uploaded from RAM to VRAM and if you are running delta time or something you get a visible jerk as the next frame compensates and draws further on in the timescale.

So I wanted to cache my graphics before drawing the first frame but wondered the best way to do this. I thought about:

a) Drawing all the graphics, then drawing a black rect over them (or calling CLS) then flip. So there'd be a black screen. Problem is what if BMax and the Graphics card optimise somehow and go "Hmm, he didn't draw anything so I won't upload any graphics". There may even be a difference between using CLS and drawing a black rect.
b) OR can I just call all the DrawImages I want and then not actually call Flip? Will that upload to the graphics card or is flip required?

Naturally I ought to check the total size of all my textures and aim for a minimum VRAM size of say 32MB or 64MB and make sure I cache only the relevent ones instead of absolutely everything.

But even that makes me think, hmm, do graphics cards try to optimise what is cached based on how often it's used or something else (like size) or will new graphics simply push out old graphics (FIFO).

Another thing I don't know is how graphics cards arrange their memory i.e. can textures all be stored linearly so they exactly fill up 32MB or whatever, OR is any space wasted due to bad tessellation i.e. a small graphic is dropped from VRAM leaving a gap but if the other graphics don't "shuffle up", this will leave a gap that may be too small for new bigger textures so the bigger texture is either split or placed entirely elsewhere (a bit like a fragmented hard drive).

I'm a bit of a gfx card noob so any advice is welcome, thanks!


tonyg(Posted 2007) [#2]
let me know when your tea needs stirring


GfK(Posted 2007) [#3]
Can change his name to Earl Grey Alien then! :D


tonyg(Posted 2007) [#4]
Veeeerrrry good!
<edited to for some extra eee and rrr>
<edit> Some extra information.
Not sure about OGL but Bmax uses DX7 cache algorithim to determine which textures to replace. I did search for the exact rules but never found it. It's going to be something like oldest first.
<edit> and why single-surface is an added advantage.


Grey Alien(Posted 2007) [#5]
tonyg: Thanks for the cuppa :-)

I'll make a proper testbed and see if it works properly.

GfK: That's Baron and later Lord, if my ancestors have anything to do with it. Not quite sure where Earl fits into the hierarchy.


ImaginaryHuman(Posted 2007) [#6]
You dont need to worry, the graphics card does not know that you're drawing black over images that you drew before, it has no intelligence about that. It just carries out your commands. You dont even need to do a flip. Just draw your images and then clear the screen, should be enough.


ImaginaryHuman(Posted 2007) [#7]
I think this is just a DirectX issue, isn't it?


Grey Alien(Posted 2007) [#8]
OK thanks. I would have thought that it would affect OpenGL too as the textures still have to be loaded into VRAM.


anawiki(Posted 2007) [#9]
In Tom's Hen House I draw all required images (for certain stage of the game) and don't flip.

best
Roman


Yan(Posted 2007) [#10]
Function CreateFrames(image:TImage)
	For Local c=0 Until image.frames.length
		image.Frame(c)
	Next
End Function


[edit]
Blimey, that's thrice...
http://www.blitzbasic.com/Community/posts.php?topic=62100#704506
;op
[/edit]


Grey Alien(Posted 2007) [#11]
Roman thx.

Yan: OK handy function thanks (again)


Derron(Posted 2007) [#12]
Hmm...but some graphics-cards relay on the flip-command.

You surely remember on the fact that on some computers the drawimage-commands needed some milliseconds and the flip nearly nothing - and on other computer the drawimage was done in nothing and the flip durates for some more millisecs.

If the flip takes a long time I thought this happens because with this command the gfx-card takes the memory into vram.


bye
MB


Grey Alien(Posted 2007) [#13]
I had thought this too, but it seems that the BMax code uploads to VRam when DrawImage is called (according to Yan)