Announcement: Be excellent to each other.


Caravel Forum : DROD Boards : Bugs : Slowdown caused by heavy shadow calculations (5.0 and earlier)
New Topic New Poll Post Reply
Poster Message
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Slowdown caused by heavy shadow calculations (+5)  
Not quite a bug, as it does work as it is, but could definitely be improved... I used 4.0, but after a quick test in the editor, it seems the problem is in 5.0 too, and probably 3.0 as well.
My DROD PC isn't the newest or the fastest, and while playing GatEB I had noticeably poor performance in the Skondusk Marshes, amongst other places. Partially this was due to an issue with platforms (which has already been fixed), but the weather effects also contribute to it.
To easiest see the problem I've identified, create a room in the editor and enable Cloud Shadows in the weather settings, and test the room.
I get ~45-50 FPS and ~20-25% CPU usage. Movement feels "rough".
I recompiled with the current floating-point calculations changed to a lookup from a precomputed table.
I now get 60+ FPS and ~5-10% CPU usage. Movement feels "smooth". :)

I changed CBitmapManager::ShadeWithSurfaceMask (no-shadow-mask case). I haven't tried with anything else, but I'm guessing similar simple changes could improve other similar routines.

[Last edited by Moo at 06-23-2014 11:22 PM]
06-23-2014 at 11:22 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
Penwielder
Level: Smitemaster
Rank Points: 628
Registered: 09-12-2009
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Just wanted to chip in that, provided this tests out well on all systems, it's something I'd really appreciate. Even on the best of the computers I DROD on (which has an Intel i5 and the best graphics card I've owned yet, though I have no idea what the latter is) it can get a bit choppy.

In the past I always just assumed you couldn't do anything about this without moving into the use of OpenGL/DirectX/whatever, and I'm glad to hear there might be some easier changes available.

____________________________
Penwielder's Palace, Detention Complex, Archipelago, Cube of Memories
06-23-2014 at 11:36 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Moo wrote:
I get ~45-50 FPS and ~20-25% CPU usage. Movement feels "rough".
I recompiled with the current floating-point calculations changed to a lookup from a precomputed table.
I now get 60+ FPS and ~5-10% CPU usage. Movement feels "smooth". :)

I changed CBitmapManager::ShadeWithSurfaceMask (no-shadow-mask case). I haven't tried with anything else, but I'm guessing similar simple changes could improve other similar routines.
I'm always game for adding optimizations, especially straightforward and localized ones like this. Would you please post your code diff here? I need to make sure I'm clear on what you're proposing. If I can, I'll work on getting this integrated into 5.0 soon, like, this week.

Any additional help on vetting optimizations on any other routines in CBitmapManager would likewise be greatly appreciated.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 06-24-2014 12:16 AM]
06-24-2014 at 12:15 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (+9)  
Here:
Click here to view the secret text


[Last edited by Schik at 06-24-2014 03:24 AM]
06-24-2014 at 12:44 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (+1)  
Thanks!

Hmm...that
shadow[j] = ...
should be
shadow[i][j] = ...
, correct? Maybe I'm just being dense, but how could this have been working for you?


Edit: ah, bad forum formatting to the rescue. Look at the source to this message and guess where the italics came from. False alarm...

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by Schik at 06-24-2014 02:51 AM]
06-24-2014 at 01:39 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Wow! That's exciting. I'm thinking that the multiple references to "shadow[pSrc[0]][...]" can be refactored into a single Uint* assignment, so we don't have to double dereference the array for each RGB value, i.e.,

Uint* shadowSrc = shadow[pSrc[0]];
pDest[0] = shadowSrc[pDest[0]];
pDest[1] = shadowSrc[pDest[1]];
pDest[2] = shadowSrc[pDest[2]];


I'd bet that would be even faster. Can't wait to try this all out. Thanks so much!

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 06-24-2014 01:45 AM]
06-24-2014 at 01:44 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
I added this optimization to all the calculations in this method. It's working nicely. Also added to the two BlitTileShadows* methods, which apply the same calculations.

That's everything that uses fShadowConvFactor. I don't think I can apply these same optimizations to the other methods where the light/shadow value is passed in as an argument. If you can think of a way to do that, please share it.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
06-25-2014 at 02:59 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (+3)  
Similar for CBitmapManager::DarkenRect
Click here to view the secret text

Darkness + outside + water 42-45FPS ~25% -> 55-58FPS ~15%
There's still something else causing slowness in that situation though...
07-02-2014 at 02:12 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Ah, I see. Discretize the possible values. That's nice. I'll try it.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-03-2014 at 03:56 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
As far as I could see, it's only used with 5% (mostly 10%) values already, so limiting it to those values shouldn't cause a problem...
07-03-2014 at 05:26 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Ah, interesting. I'll make sure I comprehend all of this as I make the changes on my end.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-03-2014 at 06:02 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
I've made this change. I also applied it to DarkenTileWithMask and the first half of DarkenWithMask. I see these calculations are used with finer values than 5-10% (see darkMap in RoomWidget.cpp), so I'm going to bump it up from 20 to 100 levels. Thanks again! :)

Applied in 5.0.1.5988.

If you can figure out how to do a similar thing with the second half of DarkenWithMask, or AddMask, AddMaskAdditive, I'll include them too. I'm thinking that one of these explains the remaining slowdown you're experiencing.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 07-03-2014 10:49 PM]
07-03-2014 at 10:48 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Drgamer
Level: Master Delver
Rank Points: 113
Registered: 09-09-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
I think this is related but certain rooms have slowdown when undoing specific parts of them. Sometimes the entire room can have this slowdown. So undoing can get uneven and laggy. The undoing can be done in demos as well, and the same effect happens.

It does appear to mainly be in rather dark levels, so that's why I think it has to do with the shadow calculations.

Fast fowarding the demos doesn't appear to be a problem, however.

One of the easy to access levels is
Click here to view the secret text


It seems to still happen up to 5.0.1.5973.
07-04-2014 at 12:00 AM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged

File: BitmapManager.cpp (137.6 KB)
Downloaded 41 times.
License: Public Domain
icon Re: Slowdown caused by heavy shadow calculations (0)  
Moo, I just realized you probably don't have all these routines on-hand. Here's the current BitmapManager.cpp.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.

[Last edited by mrimer at 07-04-2014 05:01 AM]
07-04-2014 at 05:00 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged

File: BitmapManager.h (13.4 KB)
Downloaded 40 times.
License: Public Domain
icon Re: Slowdown caused by heavy shadow calculations (0)  
And .h file.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-04-2014 at 05:01 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Rabscuttle
Level: Smitemaster
Avatar
Rank Points: 2460
Registered: 09-10-2004
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (+1)  
Drgamer wrote:
I think this is related but certain rooms have slowdown when undoing specific parts of them. Sometimes the entire room can have this slowdown. So undoing can get uneven and laggy. The undoing can be done in demos as well, and the same effect happens.

It does appear to mainly be in rather dark levels, so that's why I think it has to do with the shadow calculations.

Fast fowarding the demos doesn't appear to be a problem, however.

One of the easy to access levels is
Click here to view the secret text


It seems to still happen up to 5.0.1.5973.

This is most likely due to scripted characters - when you undo the game replays all your moves except the last one*, and scripted monsters take longer to process than regular creatures, which becomes noticable after some amount of moves.

I noticed some ridiculously slow undos in some of the larger puzzles in the central station place. (movecount was well over 1000). Going to the demo screen was not speedy either :/

*Actually, I think I remember reading that the game stored snapshots at various points, so it's probably not really all your moves.

[Last edited by Rabscuttle at 07-04-2014 05:52 AM]
07-04-2014 at 05:51 AM
View Profile Send Private Message to User Show all user's posts High Scores This architect's holds Quote Reply
Tuttle
Level: Smitemaster
Avatar
Rank Points: 1545
Registered: 02-22-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Rabscuttle wrote:
*Actually, I think I remember reading that the game stored snapshots at various points, so it's probably not really all your moves.
I think you're right. I was playing an ugly horde room with UU the other day, and undoing had a definite rhythm of being really slow, speeding up over the course of a few hundred moves and then going back to being slow.
07-04-2014 at 06:24 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Tuttle wrote:
Rabscuttle wrote:
*Actually, I think I remember reading that the game stored snapshots at various points, so it's probably not really all your moves.
I think you're right. I was playing an ugly horde room with UU the other day, and undoing had a definite rhythm of being really slow, speeding up over the course of a few hundred moves and then going back to being slow.
Yes, I think you are both right. That, as you likely know, is a different issue than what we are addressing here, which is low frame rate, even when no moves are being made.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-04-2014 at 06:29 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
mrimer wrote:
I'm thinking that one of these explains the remaining slowdown you're experiencing.
Seems not. With all the recent fixes, the remaining major cause in that case is BlitWrappingSurface for the water, and there's not a lot that can be done there.
One thing that may help (although it didn't seem to make an obvious difference for me) is enabling SSE2 (or even just SSE) instructions (Enable Enhanced Instruction Set in Code Generation settings in VS). It modifies those 3 functions you listed, at least. This will break compatibility with pre-pentium-4 processors, but really does anyone still use any? Perhaps you could release a separate build with that option (just the exe)...
I also notice there's some light/dark calculations in RoomWidget that could possibly be optimized similarly to how we have been doing, but it's perhaps not worth it. Filling a room with ceiling lights made the editor slow, and pretty much broke the rendering, but didn't make playing slow.
07-04-2014 at 03:30 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Moo wrote:
I also notice there's some light/dark calculations in RoomWidget that could possibly be optimized similarly to how we have been doing, but it's perhaps not worth it. Filling a room with ceiling lights made the editor slow, and pretty much broke the rendering, but didn't make playing slow.
I'd like to optimize these light/dark calculations. If you can point out some sections and code you'd use to replace it, I'd surely use it!

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-04-2014 at 11:32 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
Moo
Level: Master Delver
Rank Points: 224
Registered: 10-14-2006
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
CRoomWidget::AddLightInterp "Reduce light by darkness factor" could use an array like the previous darken stuff. Looks like it's called with a value from darkMap... Using 100 or however many values could work, but probably better to set up the array using those floats, then pass an int to the function rather than the float.
Those 3 lines could also be skipped entirely if there's no darkening needed.
07-07-2014 at 07:19 PM
View Profile Send Private Message to User Show all user's posts Quote Reply
mrimer
Level: Legendary Smitemaster
Avatar
Rank Points: 5056
Registered: 02-04-2003
IP: Logged
icon Re: Slowdown caused by heavy shadow calculations (0)  
Moo wrote:
Looks like it's called with a value from darkMap...
Not exactly, but that is a factor in fDark.
Using 100 or however many values could work, but probably better to set up the array using those floats, then pass an int to the function rather than the float.
Mmm, I'm not quite understanding what you mean here. Would you please clarify?
Those 3 lines could also be skipped entirely if there's no darkening needed.
Agreed.

____________________________
Gandalf? Yes... That's what they used to call me.
Gandalf the Grey. That was my name.
I am Gandalf the White.
And I come back to you now at the turn of the tide.
07-12-2014 at 03:11 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD Boards : Bugs : Slowdown caused by heavy shadow calculations (5.0 and earlier)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.