|
|
View previous topic - View next topic |
Author |
Message |
Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Sat May 23, 2009 12:17 pm Post subject: Optimizing a rasterizer - is it fun? |
[quote] |
|
I think so anyway :D
I dug out an old software renderer I made a while back:
It's not at all fast, as I haven't spent any time optimizing it yet - so far, it's written to be easy to work with and easy to understand. When I run it through the AMD Codeanalyst profiler (which is free and works real well) I get this result (with everything under 1% cut)
At the top we find TransformedVertex (which keeps the data to be interpolated across the triangles, in 16.16 fixed point format) and Rasterizer (which does the scanline-conversion of the triangles), together making up >40% of the CPU-time.
I'm posting this here to maybe get some thoughts and suggestions on optimizing this type of thing, to maybe get an interesting discussion going on optimization in general, so that others can learn a bit from it, and so that those who would like to can get a chance to test their optimization ideas themselves.
So, here's the code, for C++/Visual Studio(which is free, if you don't have it), and includes everything needed to compile, except for DirectX SDK:
http://www.colossusentertainment.com/forumref/sw3d.zip
The code is all free (public domain), as usual, so if you can find a use for any of it, feel free (however, the sample model is not public domain).
But mostly, it would be really fun with a general discussion about low-level optimization. _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|
Back to top |
|
|
Rainer Deyke Demon Hunter
Joined: 05 Jun 2002 Posts: 672
|
Posted: Sun May 24, 2009 2:10 am Post subject: |
[quote] |
|
Let's see...
Functions called in the inner rendering loop, including most TransfomedVertex operations, should be inlined.
In SW3D_Rasterizer.cpp, on line 125, there is an apparently useless conversion from integer to float.
In SW3D_RasterOperations::ProcessFragment, line 12, says "if (texture_)". This check can be factored out to SW3D_Rasterizer::DoScanline before the inner loop.
The 'SW3D_RasterOperations' class carries a lot of state, but only its 'texture_' member is actually used. One level of indirection can be removed by eliminating this class entirely by and moving the texture member to 'SW3D_Rasterizer'.
|
|
Back to top |
|
|
Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Sun May 24, 2009 8:51 am Post subject: |
[quote] |
|
Rainer Deyke wrote: | Functions called in the inner rendering loop, including most TransfomedVertex operations, should be inlined. |
Yes, that's true. But I usually leave that for the last part of the optimization, as it tends to make the profiling results more difficult to read.
Also, I noticed that "Global optimizations" was turned off, for some reason, and enabling that gave a nice boost (framerate up from 30 to 43, Time for rendering 60 frames down from 1400 to 900)
Rainer Deyke wrote: | In SW3D_Rasterizer.cpp, on line 125, there is an apparently useless conversion from integer to float. |
Ah, well spotted, thanks! That one definitely shouldn't be there :P
Rainer Deyke wrote: |
In SW3D_RasterOperations::ProcessFragment, line 12, says "if (texture_)". This check can be factored out to SW3D_Rasterizer::DoScanline before the inner loop. |
Yes, definitely. In fact, as everything has got textures in the sample, I could just remove it altogether for now. And move it out of the loop entirely. In fact, if we're not using textures, we wouldn't need to interpolate vertex coordinates either, so that could go to for that codepath...
Rainer Deyke wrote: | The 'SW3D_RasterOperations' class carries a lot of state, but only its 'texture_' member is actually used. |
Ah, leftovers from old code. Removed now.
Rainer Deyke wrote: | One level of indirection can be removed by eliminating this class entirely by and moving the texture member to 'SW3D_Rasterizer'. |
Yes... I think I structured it like that to make it easier to support different blend modes and other raster operations... worth looking into...
I'm considering trying some SSE to see if that speeds up the vertex data interpolation. We'll see how that goes _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|
Back to top |
|
|
DeveloperX 202192397
Joined: 04 May 2003 Posts: 1626 Location: Decatur, IL, USA
|
Posted: Sun May 24, 2009 9:46 am Post subject: |
[quote] |
|
OOh I'm going to enjoy this thread :D
Its much too late tonight for me to say any more..but when my brain is functioning again tomorrow(later today lol) I'll post more :D
night.... _________________ Principal Software Architect
Rambling Indie Games, LLC
See my professional portfolio
|
|
Back to top |
|
|
|
Page 1 of 1 |
All times are GMT
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|