Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » fastest bliting method

Credits go to Billybob, Chris Katko, decsonic, Gnatinator, Kris Allen, Krzysztof Kluczek, ReyBrujo, Richard Phipps, and Steve Terry for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
fastest bliting method
lucaz
Member #4,194
January 2004

what is the fast method?, 1)use iterative loops 2)memcpy 3)other.

Steve Terry
Member #1,989
March 2002
avatar

Direct memory line access? Depends really what depth you are running at, you can use block memory access in 8bpp, or 32-bit words at a time in 16-bpp, etc.

___________________________________
[ 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

lucaz
Member #4,194
January 2004

direct line access is the first option right?.
When Im mean iterative loops is:

for(int x=0; x<bmp1->w ;x++)
 for(int y=0; y<bmp1->h ;y++)
  bmp1->line[x][y] = bmp2->line[x][y];

Steve Terry
Member #1,989
March 2002
avatar

Right...

___________________________________
[ 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

Chris Katko
Member #1,881
January 2002
avatar

3) MMX.

But then again, you didn't specify video/memory/system bitmaps and the destination, and also any blending. :)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

lucaz
Member #4,194
January 2004

this is the fastest method?, ¬_¬ ....

Steve Terry
Member #1,989
March 2002
avatar

Depends on how much time you want to spend on your custom blitter ;D MMX is great but it is kinda complex.

___________________________________
[ 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

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Quote:

for(int x=0; x<bmp1->w ;x++)
for(int y=0; y<bmp1->h ;y++)
bmp1->line[x][y] = bmp2->line[x][y];

Bitmap line array works as line[y][x], but remember about different bits per pixel count in different formats. Also you should blit in rows, not in columns, to make better use of cache. Using memory pointers can help a bit too.

int y,*s,*d,*e;
for(y=0; y<bmp1->h ;y++)
{
  s = bmp1->line[y];
  e = s + (bmp1->w*bpp+3)/4;  // bpp = bytes per pixel
  d = bmp2->line[y];
  while(s<e)
    *d++ = *s++;
}

:)

And MMX is completely useless in blitting unless you are doing blending in 24/32bpp, since it just gives additional math operations and none are required here. :)

lucaz
Member #4,194
January 2004

are you sure this is the fastest method?, memcpy seems more useful, it dont iterate... just take a block of memory a copy it to another-

Steve Terry
Member #1,989
March 2002
avatar

I'm not saying memcpy wouldn't work however that will only allow you to copy a bitmap, not manipulate it or make a custom blitter, why not just use blit instead? :P

___________________________________
[ 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

ReyBrujo
Moderator
January 2001
avatar

You can move 8 blocks of data using the MMX movq operators, instead of the one block at each time with memcpy. Problems: target machine should be MMX enabled, the addresses should be aligned, and the array should be 4x multiple. I have the code at home, will check it out later.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Gnatinator
Member #2,330
May 2002
avatar

Just blitting straight to the screen is extremley fast (I can pull thousands of frames per second). Its putting that data into memory first, then to the screen thats slow :P (ie double buffer)

ReyBrujo
Moderator
January 2001
avatar

Faster way will always be using DRS instead of updating the whole screen.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Kris Allen
Member #4,639
May 2004
avatar

of course memcpy iterates, how else would it move more than one piece of data?

- Kris

lucaz
Member #4,194
January 2004

I dont know its code. but at least it just does one for(), not 2

Steve Terry
Member #1,989
March 2002
avatar

What exactly are you trying to accomplish, we may find the best method for what you want to implement.

___________________________________
[ 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

ReyBrujo
Moderator
January 2001
avatar

Kris, There is a difference between manually iterating (using a loop and jump) and letting the processor iterate for you (like, in example, using repnz movsb):

1; this is looping
2xor ecx, ecx
3mov esi, source_string
4mov edi, target_string
5begin_loop:
6 mov eax, [esi+ecx] ; fetch a byte from the source string
7 mov [edi+ecx], eax ; put the byte in the target string
8 inc ecx
9 test ecx, string_length
10jnz begin_loop
11 
12; this must be memcpy way
13mov ecx, string_length
14mov esi, source_string
15mov edi, target_string
16repnz movsb ; keep repeating movbs (take a byte from
17 ; esi, put it in edi, decrease ecx) until
18 ; esi is 0 (end of string) or ecx is 0.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Kris Allen
Member #4,639
May 2004
avatar

ah cool, didnt know about that, no wonder it's so fast :B

- Kris

Krzysztof Kluczek
Member #4,191
January 2004
avatar

I'm not sure, but I think that my method and any other which should be faster than it will be memory bus limited anyway.

And of course fastest blitting method is to use HW acceleration. :)

decsonic
Member #4,150
December 2003

Wouldnt bother writing your own blitting methods unless blending is applied tho, if even then.

Programmer's paranoia: Don't trust anybody's code, not even your own.

Human Modeling Tutorials

Richard Phipps
Member #1,632
November 2001
avatar

I really don't think it's worth spending the time trying to optimise things like this. Doing the rest of the program is more important.. :)

lucaz
Member #4,194
January 2004

who likes to optimise blit?

ReyBrujo
Moderator
January 2001
avatar

Well, first optimize your game fully. You don't try optimizing printf, you try optimizing your program so that it won't use that many first.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Richard Phipps
Member #1,632
November 2001
avatar

Quote:

who likes to optimise blit?

Er.. your thread title is 'fastest blitting method' ???

(And I didn't say blit, I said things like this..)

decsonic
Member #4,150
December 2003

read my sig ;D

Programmer's paranoia: Don't trust anybody's code, not even your own.

Human Modeling Tutorials

 1   2 


Go to: