Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Hardware Acceleration

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Hardware Acceleration
KaBlammyman
Member #455
June 2000
avatar

I want to start using my video cards full potential, how can this be done? Should I use video bitmaps (or whatever they are called)? Page flipping? If I do, isnt this done by using VRAM, not system ram, correct? But isnt VRAM slower than system ram, so how is that acceleration? I just want to use my grafx card power in some way...or any grafx card's power, even if it has only 1 meg of VRAM. Should I go to OpenGL to do this? I started to learn it, but, I know there are some ways in plain allegro to help me in the mean time. Also, if I can use my nice sound card to its full potential, that would also be great...hell, I just dont want the processor to do all the work!
Thanx in advance

->Insert clever quote here<-
http:my website

Korval
Member #1,538
September 2001
avatar

For a video card, accessing its Video RAM is vastly faster than accessing system memory. System memory access, even over AGP, are slow for a video card. And, ignoring location and busses, modern video card RAM is vastly superior to main memory.

Video RAM is slow for the CPU to access. CPU read/write requests to V-RAM typically go through a 33MHz interface, and are uncached. CPU read/write requests to main memory go through a (on modern machines) 100MHz, 133MHz, or better interface that is cached. Ignoring the cache improvement, that's a 3-4x speed up at least.

The basic idea if you're going to be working your video card is to keep everything in video memory. That means 100% of your BITMAPs are video memory bitmaps. Also, you shouldn't touch video BITMAPs. That means no blitting to them, no read/writing, nothing.

There are some limitations to this, however. Allegro's blending (including FBlend) will be very slow. These are software blits, so they work best in main memory.

Also, video memory tends to be small. 32MB on most modern game-quality video cards (though games are starting to demand more). Therefore, you should consider using system BITMAPs. These (presumably) use AGP memory, which is main memory that the video card can access directly through an enhanced DMA bus. They still blit pretty fast, too, so they offer another possibility.

If you want to get hardware blending, you're going to have to use OpenGL.

Quote:

I just want to use my grafx card power in some way...or any grafx card's power, even if it has only 1 meg of VRAM.

If your video card only has 1MB of video RAM... it doesn't have any power worth exploiting. There's no AGP, no accelerated OpenGL, nothing. You'll fill up the video RAM with your framebuffer, leaving precious little left for your BITMAPs.

I think a healthy upgrade ($600-800) is in order.

Steve Terry
Member #1,989
March 2002
avatar

hmm vram -> vram blits seem to be the fastest on my machine, but that doesn't mean the accellerator is doing much than using it's faster memory to get stuff onto the screen.. and in some cases ie. transparency, the video RAM is accessed to bring each pixel into the CPU registers.. which is slower than bringing each pixel from RAM.. since it's closer, and can be cached, etc. So it's kinda up to you.. if you want to do transparency, blit to a temp bitmap, then to your vram screen.

... darn you Korval... beat me to it.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

KaBlammyman
Member #455
June 2000
avatar

Thanx for the replies. I have 2 computers, one is my main machine with 640 megs of system ram and a geforce2 MX 400 with 64 megs of DDR vram (i think its DDR), so memory here aint a problem, but I also have a laptop with 2 megs of vram, and no special videocard and 233mHz processor, so my games run a lot slower. My games do not use any 3D grafx or anything special, so, they should not slow down (considering that everything else but my drawing routines are perfect), hence my question. Any adivce, or any more information would be great.
THANX

->Insert clever quote here<-
http:my website

jcact
Member #2,203
April 2002
avatar

If you use video ram and it fills up won't your program crash? This would increase the minimum system requirements for a game.

Nick Fisk
Member #2,197
April 2002
avatar

When I started using VRAM on my game, the frame rate went up from around 30fps to about 230fps. But it doesn't work on my older pc.

The main thing that was slowing my game down was the tilemap which was being drawn every frame. By storing the double buffer and tiles in VRAM I could do VRAM blits which gave me this speed increase.

On the whole, I think its only worth it if the game is only going to run on newer pc's. Since its only the newer pc's which are going to have a graphics card with enough VRAM and have the hardware acceleration.

Thomas Fjellstrom
Member #476
June 2000
avatar

I disagree. even if you have an older card, 2MB is still enough for the screen @ 640x480x32bpp and for 868kb of sprites. And plus, older gfx cards have better 2d exceleration... (my Mach64 was way faster for allegro's accelerated 2d functions than my TNT2, and Rage128 Pro) hehe, the Mach64 was an integrated delie with 8MB of sgram... (It actually had its own memory if I remember correctly)

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Thomas Harte
Member #33
April 2000
avatar

I agree mostly with Mr. Fjellstrom, except that if you want to page flip (which you almost certainly do . . .), then you can't use 640x480x32bit mode with just 2mb of RAM, since 640*480*4*2 = 2,457,600. Maybe switch down to 16bit colour?

Anyway, I have a machine of a similar age to the Mach64, but instead fitted with a 2mb S3 Virge. This also is a very good 2d card and using it provides a much better frame rate than the CPU can alone. One game where I can definitely notice the difference is DX-Ball 2.

KaBlammyman
Member #455
June 2000
avatar

Cool, so it looks like as long as my games are 2D simple, 8 bit, and using 32x32 sprites (or somthing similar), then using VRAM on just about any machine is okay? I though so, but I had to make sure. So, in order to do some grafx accel, should I use page flipping with video bitmaps? Any considerations when using vram? any code will be helpful. Thanx for all the input thus far.

->Insert clever quote here<-
http:my website

Steve Terry
Member #1,989
March 2002
avatar

double buffering would be faster since page flipping/triple buffering wait for a screen refresh.. limiting yoru FPS to 75 - 80 fps.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Thomas Fjellstrom
Member #476
June 2000
avatar

faster yes. for an FPS counter :) but all that time can be eaten up by the prog before vsync is called (if it even works on your card).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

KaBlammyman
Member #455
June 2000
avatar

Cool, double buffering it is! I will try using my same style, but using video bitmaps instead. When I test this out, I'll let you know how it goes. I'm pretty sure I'm not the only one who wants to know about this. Anybody reading this should feel free to give any advice or help in the mean time, thanx!

->Insert clever quote here<-
http:my website

da_flo
Member #1,907
February 2002
avatar

Quote:

double buffering would be faster since page flipping/triple buffering wait for a screen refresh.. limiting yoru FPS to 75 - 80 fps.

It is quite weird... I have just implemented page flipping in my game and vsync seems to be called only in fullscreen mode !
When I run the game in windowed mode I get nearly 200 fps whereas in fullscreen it's stuck at 75 fps ( quite normal though ::) )

white_door
Member #202
April 2000
avatar

double buffering with vram would be slower on slower systems but faster on faster systems, since you have an extra blit that is totally unneeded. Only on faster machines would there be extra fps gaining from not having to wait for a vsync make any difference. And even then does > 999 fps vs caped at 60 fps make any difference at all to gameplay in 2d games? as far as memory goes you need the exact same amount of ram for either method.

if are on a newer machine and you have some extra ram you could optional switch from page flipping to triple buffering with very little code changes and then you would have all the speed of page flips + no waiting for a vsync.

Korval
Member #1,538
September 2001
avatar

Quote:

I disagree. even if you have an older card, 2MB is still enough for the screen @ 640x480x32bpp and for 868kb of sprites.

868KB. That's not a lot. Allow me to demonstrate:

You have a 32x32 sprite. You give him a walk cycle of 8 frames (we want decent animation, right?). 8 more frames for the run cycle. We give him 8 directions of motion. That's 128 frames just for movement. At 32x32x32bits-per-pixelx128frames = 524288 bytes. That's well over half of the memory for a subset of the animations for one high-quality sprite.

Granted, if you're going to live in the realm of 3-frame walking animations and so forth, this may be fine.

bozokadafi
Member #2,070
March 2002
avatar

Quote:

If you use video ram and it fills up won't your program crash?

create_video_bitmap() returns NULL when there's no space in vram for the bitmap. your program should put the bitmap in system ram if this happens.

Steve Terry
Member #1,989
March 2002
avatar

hehe a simple program ie. my GUI test program runs at 400+fps memory double buffered 640x480x16, and with vram->vram blits it's at 1600+fps... of course I have some bad A$$ hardware to push those numbers so high.. but I will also say it's completely unnessesary to have that high of fps in any 2D game.. unless you just want to show off.

Well one solution is to call a function that returns the amount of available Video memory and check it against the total size of all sprites, if it's less than needed, either send a message saying "unsupported video card", or force memory blits.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Thomas Harte
Member #33
April 2000
avatar

Quote:

You have a 32x32 sprite. You give him a walk cycle of 8 frames (we want decent animation, right?). 8 more frames for the run cycle. We give him 8 directions of motion. That's 128 frames just for movement. At 32x32x32bits-per-pixelx128frames = 524288 bytes.

Except, as already discussed, 32bpp is not really an option on a 2mb card. So we're talking 16bpp. Then, of course, most people don't store all 8 directions, but they use h_flip and v_flip. Which divides the number of directions you need to store by 4. Giving 32x32x16bppx32 = 65536 - a paltry 7.5% of memory, and allowing room for 13 such creatures and 16 other 32x32x16bpp tiles for things like mouse cursors and so on. Or say, 10 animated beings and a tileset for the map and cursor and so on of 104 elements.

Quote:

double buffering would be faster since page flipping/triple buffering wait for a screen refresh.. limiting yoru FPS to 75 - 80 fps

But it wouldn't be visibly smoother, since you wouldn't be able to see more frames. In fact it would, as has been pointed out, be less smooth for some users who have machines which could have kept up with page flipping, but can't quite keep up with double buffering.

bozokadafi
Member #2,070
March 2002
avatar

i just want to add this also. there is nothing wrong with porting your game to use many/all of the different techniques of updating the screen using vram. that way you can find out yourself which will run faster on a machine like the one you test on.

Steve Terry
Member #1,989
March 2002
avatar

for example my video program.. it allows mode switching for the best mode in a game.. so it's up to the user to select which mode is best for the game.. and I'd have to disagree on the pageflipping/triple buffering being less smooth.. it runs the smoothest on my machine.. with double buffering I get tearing.. even if I set vsync.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

bozokadafi
Member #2,070
March 2002
avatar

Quote:

with double buffering I get tearing.. even if I set vsync

Now that's something right there that has never worked for me... double buffering with vsync(). :-/

[addition] let me back that up. vsync() with double buffering and locked FPS never looked smooth on my inferior computer.[/addition]

Korval
Member #1,538
September 2001
avatar

Quote:

Except, as already discussed, 32bpp is not really an option on a 2mb card. So we're talking 16bpp.

Does hardware allow 16-bit blits to a 32-bit framebuffer? I figured the hardware blitter would require the use of the same bitdepth for blitting.

Quote:

Then, of course, most people don't store all 8 directions, but they use h_flip and v_flip. Which divides the number of directions you need to store by 4.

First, v_flip isn't going to give you a reasonable result at all unless your sprites are designed to be viewed from directly top-down (top-down shooters). Most games that allow the user to move up/down look at sprites at an angle (Zelda, virtually all RPGs, etc). v_flip can't help them.

Secondly, h_flip causes an annoying problem. It flips handedness. Sure, if it has no handedness, then you can get away with it, but one of the things that annoyed me about Zelda et. al. is that you always switch handedness when you face a certain way. You can choose to ignore this, but I prefer to bump up the memory requirements. Of course, my personal minimum memory requirements are 32MB of video or better, but that's just me.

Third, is h_flip supported in hardware?

Thomas Harte
Member #33
April 2000
avatar

Quote:

Does hardware allow 16-bit blits to a 32-bit framebuffer? I figured the hardware blitter would require the use of the same bitdepth for blitting.

Well, a lot of hardware can convert, but my point was that when Thomas Fjellstrom he said that you could use 640x480x32bit he didn't allow for the probably requirement to allocate two buffers of that size, and not one. Two buffers of that size will not fit into 2mb, so it is more likely a game will use 16bit colour in this instance than 32bit. Sorry, I should have been more clear!

Quote:

Third, is h_flip supported in hardware?

Most hardware supports arbitrary scaling, including stretched blits that effectively swap orientation, so I'd say so. When I say most hardware, I mean that my S3 Virge definitely does, and I'd imagine nothing newer than that (i.e. last 5 or 6 years) does not, and that quite a few older things do.

Quote:

First, v_flip isn't going to give you a reasonable result at all unless your sprites are designed to be viewed from directly top-down
...
Secondly, h_flip causes an annoying problem

Obviously, this is all impossible to find a counter argument for - I was just trying to make the point that when you know from the start that you have only 2mb to work in, you can adapt your game plans to fit.

Perhaps another idea might be to produce all your artwork at a high standard, poll Allegro for available video RAM, and if the user doesn't have enough allow them to chose between a software implementation and one with downscaled graphics (in resolution and/or bit depth)? Then you 32mb people can play at, say, 1024x768x32bpp, and us 2mb people can play at, say, 320x240x16bpp - I've just done the maths, and a 320x240x16bpp buffer requires less than 1/16th the storage of a 1024x768x32bpp buffer, so this is a quite valid suggestion. In fact you can use the largest graphics display the card allows less than ~362x271, or 98304 pixels.

KaBlammyman
Member #455
June 2000
avatar

Well, I tried using video bitmaps with my standard double buffering methods, and things did get smoother. I didnt put any tiles or animation in VRAM, just my buffers. I will try those other options soon, but I didnt have time to try them yet. The reason why I wanted to use some hardware accel. is because my games ran kinda slow (only Super Grand Prix auctually). I didnt know why becuase it is not complex enuff to run slow! So, I did some optimizations (includeing hardware accel) and now its a little better. I got more work to do in a little amount of time...but thanx everybody for the VRAM info.

->Insert clever quote here<-
http:my website

Nick Fisk
Member #2,197
April 2002
avatar

You've got to put the tiles in VRAM. When I was trying to speed up mine. i found that just putting the double buffer in VRAM didn't help that much. I found that its not the size of the blit operation that really slows it down, but the amount of blits. Ie a tilemap is really slow. By putting the tiles in VRAM I got a 200fps increase.

 1   2 


Go to: