Performance with DirectX8.1

Discussion regarding the development of CEGUI itself - as opposed to questions about CEGUI usage that should be in the help forums.

Moderators: CEGUI MVP, CEGUI Team

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Performance with DirectX8.1

Postby gcarlton » Tue Aug 23, 2005 23:47

I've been doing some profiling, and came up with a few improvements for the DirectX8.1 renderer. I've already optimised it previously, so it allocs from a custom allocator (avoiding lots of news/frees per frame), and passed in a flag so it doesn't set all the render states - I can do that externally where needed. However, it was still taking in some cases as much time as the rest of the scene altogether.

I found two issues, and fixing them brought the time from 3.1ms per frame down to 0.4ms per frame.

1.)
It locks and unlocks the vertex buffer lots of times per frame. Currently, it does:

Code: Select all

lock,fill,unlock,render,lock,fill,unlock,render,..

It can be changed to do:

Code: Select all

lock,fill,fill,fill,unlock,render,render,render

This requires another vector that stores the texture and vertex offset/size for the draw call. This made a modest improvement.

2.)
In one case, it was swapping textures 32 times per frame. This was due to a very simple problem: Images of alpha 0 were still being rendered. In particular, this means that a series of StaticImages will be broken up with invisible TL frames, chopping and changing the texture.
This is trivial to fix by early outing from the addQuad function.

Code: Select all

   if (0.0f == colours.d_top_left.getAlpha() &&
      0.0f == colours.d_top_right.getAlpha() &&
      0.0f == colours.d_bottom_left.getAlpha() &&
      0.0f == colours.d_bottom_right.getAlpha())
   {
      return;
   }


When it comes to a patch, I'm open to suggestions. I can get a fresh copy and apply 1 or both these changes to it, to make a clean patch. Or I can do a multi-patch that has all 4 changes. Or I can do a patch on top of the previous rotation patch. Or lastly, I can sit back and do nothing. :pint:

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Performance with DirectX8.1

Postby CrazyEddie » Wed Aug 24, 2005 08:23

Hi,

Definately submit a patch :)

Since the entire set of changes are really targetted at a single outcome, feel free so submit a single patch with all the changes.

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Re: Performance with DirectX8.1

Postby gcarlton » Wed Aug 24, 2005 09:43

I'll make up a patch next week. To clarify my question, the four changes I have so far are:
- rotation support
- constructor flag that skips render state setup
- ability to supply a custom allocator
- the above 2 optimisations

I can make up a patch just with the 2 optimisations, or with the lot, or some variation in between.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Performance with DirectX8.1

Postby CrazyEddie » Thu Aug 25, 2005 08:21

Ah, right. I didn't know the rotations would be in there ;) We'll leave that one off then (esp. since it's already on the patch tracker), and everything else just affects the renderer module itself, right?

So the patch would have:
- constructor flag that skips render state setup
- ability to supply a custom allocator
- the above 2 optimisations

Thanks very much :)

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Re: Performance with DirectX8.1

Postby gcarlton » Sat Aug 27, 2005 07:06

Ok, what I did was make up a patch purely with the optimisations, because the allocator changes also need an extra CEGUIAllocator.h file, and it is already part of the resubmitted rotation patch (the one I made up a few weeks ago).

The changes were done for both the dx8 and dx9 renderer. The sample I tested (sample7) had a very modest FPS increase. Real improvement would come in cases where there are lots of non-standard textures that currently thrash the renderer.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Performance with DirectX8.1

Postby CrazyEddie » Sat Aug 27, 2005 18:01

Cool, thanks for the patch.

We seem to be missing some changes to the header files though :?

I tried to extrapolate what was required but I got an exception, so I obviously messed it up :lol:

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Re: Performance with DirectX8.1

Postby gcarlton » Sun Aug 28, 2005 02:22

Ok this patch works, I've actually tested it against a clean copy this time - note to self, should always clean and apply my own patch before submitting it!

I've also investigated things more, and unfortunately, I don't think this patch will help in the general case much.

The saving of the lock/unlock multiple times per frame is minimal - the real gain is avoiding 0 alpha textures. I've tracked down this to something I was doing in the game itself.

In my game's radar, I was creating static images and setting their background colour to 0, rather than using the disable function explicitly. This was the source of the thrashing in my case, as the dozens of radar dots each pulled in an invisible background texture.

The CEGUI samples I have tested do not have any 0 alpha textures rendering in there, so there is no inefficiency to optimise. Whether you think thats good news or not depends on how you look at it! :oops:

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Performance with DirectX8.1

Postby CrazyEddie » Mon Aug 29, 2005 07:57

Ok. I'll have a look at the updated patch later today.

If none of the samples show an improvement, that does not necessarily mean that the patch is of no use - who knows what other people will be doing ;)

User avatar
gcarlton
Just can't stay away
Just can't stay away
Posts: 149
Joined: Wed Jan 12, 2005 12:06

Re: Performance with DirectX8.1

Postby gcarlton » Mon Aug 29, 2005 23:50

Ok, I had one more play with it, and it does offer an improvement even in general cases. To stress it out, I added this snippet of code to sample7. The patch brings it up from 100fps to 150fps or so on dx8.

Code: Select all

   // Add static images
   static const int NUM_EXTRA_IMAGES = 200;
   for (int extra=0; extra<NUM_EXTRA_IMAGES; ++extra)
   {
      StaticImage* newimage = static_cast<StaticImage*>(winMgr.createWindow("TaharezLook/StaticImage"));
      
      // set position and size
      newimage->setPosition(Point(0.1 + 0.5*(float)extra/NUM_EXTRA_IMAGES, 0.1 + 0.5*(float)extra/NUM_EXTRA_IMAGES));
      newimage->setSize(Size(0.1, 0.1));
      // disable frame and standard background
      newimage->setFrameEnabled(true);
      newimage->setBackgroundEnabled(false);
      // set the background image
      newimage->setImage("BackgroundImage", "full_image");

       background->addChildWindow(newimage);
   }

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Performance with DirectX8.1

Postby CrazyEddie » Tue Aug 30, 2005 08:44

Awesome. Hopefully I'll get this patch sorted today :)


Return to “CEGUI Library Development Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests