Archived

This topic is now archived and is closed to further replies.

performance problems

This topic is 6360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem: I wanted to implement some alphablending-effects in my 2d-game. So I''ve programmed some functions to create a lookup-table that is really fast (my opinion). I''ve also created a structure named "Alphabitmap" that holds the numbers of the alphablend-table (extracted from a bitmap). Look at the "firework-demo" of DirectX SDK (6.1) to see which effects I want to reach. My problem is the performance. The program only reaches 4fps when blending fullscreen (on an Athlon500 !) with this function: (I''m using Visual C++ 5 and DirectDraw) ---------------------------------------------- //16bit-565 USHORT b1=Alphabitmap->b; //get color USHORT g1=Alphabitmap->g; USHORT r1=Alphabitmap->r; USHORT b2; //colors on screen USHORT g2; USHORT r2; USHORT*dest_ptr = dest_buffer+(x+y*lpitch); //pointer to backbuffer (destination) USHORT dest_ptr_end=dest_buffer+((x+Alphabitmap->width)+y*lpitch); int *table_ptr = Alphabitmap->alpha; //pointer to alphatable USHORT dest =*dest_ptr; int table =*table_ptr; int loopend=(Alphabitmap->width*Alphabitmap->height); for(index=0; index>11; g2=(dest & 0x7E0)>>6; r2= dest & 0x1F; //tlut is the Alphablend-Lookup-Table: dest = ( tlut[table].color[b1][b2] | tlut[table].color[g1][g2]<<6 | tlut[table].color[r1][r2]<<11 ); *dest_ptr=dest; if(dest_ptr == dest_ptr_end) { dest_ptr+=(lpitch-Alphabitmap->width); dest_ptr_end+=lpitch; } //advance pointers dest_ptr++; table_ptr++; dest=*dest_ptr; //this seems to be the slowest operation in the loop (why??) table=*dab_aptr; } ---------------------------------------------- Have you an idea how this could be faster ??

Share this post


Link to post
Share on other sites
Well I''m going for the same effect (and looked at the same DX demo) however I''ve heard lookup tables are only fast on certain computers and cause cache thrashing. So I''ve implemented an assembler version, take a look at MMX enhanced Alpha Blending in the programming resources area here on game dev, I modelled my code after that (Already 95% asm) it also explains the idea''s behind the code and some other more primitive forms of alphablitting and he can do a 320x200 alphablit (he''s logo I think?) and hold 60fps on my machine which is a PIII 533b, I think it should handle more though cause I get 60fps with all of his methods including the primitive ones, so you should be able to use that and run a game at 60fps and still make it.
Hope that helps!
See ya,
Ben

Share this post


Link to post
Share on other sites
cyberben, I was wondering if you had a website or anything where we can see some of your work?!?! You seem to be only saying, I know ASM, I know ASM, but haven''t showed us anything to prove your knowledge... well? it''s about time you do so... maybe you do have knowledge, but please.. show us.. dont just say i did that in ASM, and i did this... in 100% pure ASM.. wow... it seems impossible....

Share this post


Link to post
Share on other sites
I''ve tried the MMX enhanced code.
It''s really fast but the effect isn''t that
good as I wanted it to be...but there''s no choice.

There''s already a thing I can''t understand:
why does this take so much time:
dest=*dest_ptr; //(dest_ptr is the backbuffer)
I mean it''s only getting the value of where
the backbuffer-pointer points.
If I clear this operation I get 20fps or more.

And I don''t think that the lookup table in this code
causes cache thrashing, because it''s only 20*32*32 USHORTS.

But still thanks cyberben.

Share this post


Link to post
Share on other sites