Is there a way to "recache" gfx in VRAM

BlitzMax Forums/BlitzMax Programming/Is there a way to "recache" gfx in VRAM

Grey Alien(Posted 2007) [#1]
Hi, I'm currently using this code by Ian Duff to cache my images in VRAM.

Function ccCreateFrames(image:TImage)
'Use this to cache an image or animimage in VRAM for quicker drawing later.
For Local c=0 Until image.frames.length
image.Frame(c)
Next
End Function

That's fine, but I have a question:

Let's say my video card only had 32MB RAM and I cached around 32MB of graphics on it for the game screen with the above code, then I showed another screen which uploaded another 8Mb to VRAM, I assume it would push out the earlier cached graphics. So if I call the above code AGAIN on returning to the game screen, will it recache the original 32Mb of graphics again, or is that code a "one shot" affair due to the internal workings of BMax (i.e. it's sets some flag or someting)? Anyone know? Hope I've explained this clearly enough...


Dreamora(Posted 2007) [#2]
Upload will be needed whenever the texture is not in VRAM anymore, as the app would just show a white quad if it didn't reupload the needed media.

The behavior on the DX side is automatic. The OpenGL behavior can be seen in the gl driver.
Blitz does NOT know if something isn't in VRAM anymore. so it basically tries to use it and it is uploaded when not present anymore.


Grey Alien(Posted 2007) [#3]
thx. Yep I realise that upload is required if not in VRAM anymore, but why does the above code I posted upload it in the first place (I don't understand what it's doing internally), and if called again will it upload it again if it needs to? I don't want to have to wait until I call Draw() for Blitz to discover that it needs to upload to VRAM again as that would cause a minordelay in the drawing function, I want to precache when the screen is being loaded up.


ImaginaryHuman(Posted 2007) [#4]
It may be spooled off to main memory as the memory overflows which can be a huge slowdown. GL will probably try to keep the most recently used textures in memory, regardless of how you're using them.


MGE(Posted 2007) [#5]
Unless I'm totally wrong, Blitzmax tells the GPU that the textures are in system memory which means they will be pulled into Vram as needed by the app. To eliminate that initial stutter that can accour while images are streamed into Vram, you could render all textures needed for the loop, followed by a black square to cover the screen, do a few flips, etc, etc. Then go ahead and render the actual loop, that should help with the stutter.


Grey Alien(Posted 2007) [#6]
Yeah MGE I know about that one, but I was using the code from my top post to eliminate that because I have all my graphics in a handy list so can iterate through and call that code to cache them all. What I'm wondering is if it works a second time later on or if it's a one shot affair due to Blitz internal mod code (flags being set once done etc)


dmaz(Posted 2007) [#7]
What I'm wondering is if it works a second time later on or if it's a one shot affair due
I would think it would... I think a test is in order ;) if you need a crappy machine to exacerbate the problem, I'd be happy to run a test on my old laptop. hey won't your little background task performance graphing test allow you to see when such a reload happens?


Grey Alien(Posted 2007) [#8]
yeah guess it should do. I've got 256MB of VRAM so it's gonna be hard to test on mine ... well it's not mega urgent I just wondered if anyone knew more...