[PATCH] DGA driver buggy and slow

DGA should be the fastest driver on linux, but it currently isn’t (wasn’t).
(with “testsprites -hw -flip 10000”) It is 4 times slower then directfb.

The bug is that after each operation it calls XFlush, which is a slow
network operation (switching context). With many consequent blits or fills
it may slow down the whole application about 4 times.

XFlush needs to be called if we jut do a single operation, and than
do our things for a longer while. But in doublebuffered mode it does not
need to be called after every operation, only before the flip.

So I made up a little patch that does this. I test it with
"SDL_VIDEODRIVER=dga ./testsprites -hw -flip 10000".

Before patch: 5.32 fps
After: 21.43 fps

Now the dga driver is the fastest on linux.
(compared to directfb 21.07 fps).

We can’t get much more out of the dga driver since after rewriting the
whole test without SDL (pure calls to X and XDGA) i got 21.44 fps.
(If anyone wants the nonsdl test source just tell)

Cezary Kaliszyk.–
-------------- next part --------------
diff -urN SDLold/src/video/dga/SDL_dgavideo.c SDLnew/src/video/dga/SDL_dgavideo.c
— SDLold/src/video/dga/SDL_dgavideo.c Wed Oct 30 17:52:34 2002
+++ SDLnew/src/video/dga/SDL_dgavideo.c Fri Nov 1 09:36:35 2002
@@ -816,7 +816,7 @@
printf(“Hardware accelerated rectangle fill: %dx%d at %d,%d\n”, w, h, x, y);
#endif
SDL_NAME(XDGAFillRectangle)(DGA_Display, DGA_Screen, x, y, w, h, color);

  • XFlush(DGA_Display);
  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);
    DGA_AddBusySurface(dst);
    UNLOCK_DISPLAY();
    return(0);
    @@ -856,7 +856,7 @@
    SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen,
    srcx, srcy, w, h, dstx, dsty);
    }
  • XFlush(DGA_Display);

You probably mean

if (!(this->screen->flags & SDL_DOUBLEBUF)) XFlush(DGA_Display);

! has higher precedence than &.On Fri, Nov 01, 2002 at 10:13:15AM +0100, Cezary Kaliszyk wrote:

  • XFlush(DGA_Display);
  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);
    DGA_AddBusySurface(dst);
    UNLOCK_DISPLAY();
    return(0);
    @@ -856,7 +856,7 @@
    SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen,
    srcx, srcy, w, h, dstx, dsty);
    }
  • XFlush(DGA_Display);
  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);


Glenn Maynard

You’re right.
I had the XFlush commented out, and added this if just before sending
Thanks.
Cezary KaliszykOn Fri, Nov 01, 2002 at 04:44:14AM -0500, Glenn Maynard wrote:

On Fri, Nov 01, 2002 at 10:13:15AM +0100, Cezary Kaliszyk wrote:

  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);

You probably mean

if (!(this->screen->flags & SDL_DOUBLEBUF)) XFlush(DGA_Display);

! has higher precedence than &.


Glenn Maynard

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 254 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021101/6633d7ed/attachment.pgp

In fact in this case it doesn’t mater. Although the later is much
clearer way of presenting the test.

Explanation:
Inverse of the flags will reverse the result of the ‘and’ and thus do
exactly the same thing as the other alternative.On Friday 01 November 2002 11:44, Glenn Maynard wrote:

On Fri, Nov 01, 2002 at 10:13:15AM +0100, Cezary Kaliszyk wrote:

  • XFlush(DGA_Display);
  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);
    DGA_AddBusySurface(dst);
    UNLOCK_DISPLAY();
    return(0);
    @@ -856,7 +856,7 @@
    SDL_NAME(XDGACopyArea)(DGA_Display, DGA_Screen,
    srcx, srcy, w, h, dstx, dsty);
    }
  • XFlush(DGA_Display);
  • if (!this->screen->flags & SDL_DOUBLEBUF) XFlush(DGA_Display);

You probably mean

if (!(this->screen->flags & SDL_DOUBLEBUF)) XFlush(DGA_Display);

! has higher precedence than &.

(!(this->screen->flags & SDL_DOUBLEBUF)) XFlush(DGA_Display);

! has higher precedence than &.

In fact in this case it doesn’t mater. Although the later is much
clearer way of presenting the test.

Explanation:
Inverse of the flags will reverse the result of the ‘and’ and thus do
exactly the same thing as the other alternative.

!this->screen->flags is the logical NOT of flags, not the inverse of flags.
The result will be either 0 or 1. So it does matter.On Friday 01 November 2002 07:37 am, you wrote:

I really should think before answering. I completely forget that in c
those operations are achieved with different operators unlike on some
other languages.On Friday 01 November 2002 19:34, j_post wrote:

On Friday 01 November 2002 07:37 am, you wrote:
(!(this->screen->flags & SDL_DOUBLEBUF)) XFlush(DGA_Display);

! has higher precedence than &.

In fact in this case it doesn’t mater. Although the later is much
clearer way of presenting the test.

Explanation:
Inverse of the flags will reverse the result of the ‘and’ and thus
do exactly the same thing as the other alternative.

!this->screen->flags is the logical NOT of flags, not the inverse of
flags. The result will be either 0 or 1. So it does matter.

Hello,

Will this patch be applied to the library source in the CVS ? Such an optimisation
seems to be cool.

JulienOn Fri, 1 Nov 2002 10:13:15 +0100 Cezary Kaliszyk wrote:

DGA should be the fastest driver on linux, but it currently isn’t (wasn’t).
(with “testsprites -hw -flip 10000”) It is 4 times slower then directfb.

The bug is that after each operation it calls XFlush, which is a slow
network operation (switching context). With many consequent blits or fills
it may slow down the whole application about 4 times.

XFlush needs to be called if we jut do a single operation, and than
do our things for a longer while. But in doublebuffered mode it does not
need to be called after every operation, only before the flip.

So I made up a little patch that does this. I test it with
"SDL_VIDEODRIVER=dga ./testsprites -hw -flip 10000".

Before patch: 5.32 fps
After: 21.43 fps

Now the dga driver is the fastest on linux.
(compared to directfb 21.07 fps).

We can’t get much more out of the dga driver since after rewriting the
whole test without SDL (pure calls to X and XDGA) i got 21.44 fps.
(If anyone wants the nonsdl test source just tell)

Cezary Kaliszyk.

Hello,

Will this patch be applied to the library source in the CVS ? Such an optimisation
seems to be cool.

Yes, I’ll check it out and apply it.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

DGA should be the fastest driver on linux, but it currently isn’t (wasn’t).
(with “testsprites -hw -flip 10000”) It is 4 times slower then directfb.

The bug is that after each operation it calls XFlush, which is a slow
network operation (switching context). With many consequent blits or fills
it may slow down the whole application about 4 times.

XFlush needs to be called if we jut do a single operation, and than
do our things for a longer while. But in doublebuffered mode it does not
need to be called after every operation, only before the flip.

So I made up a little patch that does this. I test it with
"SDL_VIDEODRIVER=dga ./testsprites -hw -flip 10000".

Thanks! I’ve added your patch to CVS.

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment