News:

SMF - Just Installed!

Main Menu

Knights CPU usage

Started by Stephen, May 09, 2012, 06:53:49 PM

Previous topic - Next topic

Stephen

Some have complained recently that Knights uses a lot of CPU.

I suspect that at least some of the problem is caused by SDL. To test this I have created a version of Knights that uses DirectX 11 instead of SDL to do the graphics. On my machine this roughly halves the CPU usage (although it's hard to tell exactly).

It would be good to get some results from other people, as well. This is where you guys come in :) If you want to help, then please do the following:

1) First make sure you are using Windows Vista or Windows 7. The test version of Knights will NOT work on XP or earlier (this is because DX11 requires Vista or above).

2) Download http://www.knightsgame.org.uk/Knights_DX11.exe and place it in your Knights install folder (next to Knights.exe).

3) Run the new Knights version by double clicking Knights_DX11.exe

(At this point you will notice the font looks a bit strange. This is because I haven't converted my TrueType font rendering code to DX11 yet, so Knights will fall back to a basic bitmap font. Do not be alarmed by this :) )

4) Start up a single player game (the default Quest for Gems should be fine) and maximize the Knights window.

5) Open up Task Manager and note what the CPU usage is.

6) Repeat the measurement with the standard Knights.exe so we have something to compare with.

Then report your results here.

Thanks to anyone who decides to help with this. Hopefully we can track down why Knights is using so much CPU.

ImpassIve

My results:

Basic version:
14-17% CPU.

Test version:
CPU is 5-7%.


P.S. To run this test version, I had to update DirectX... O_0
So, if you got message about 'Missing D3DCOMPILER_43.dll', you should download this file from Microsoft's website:
dxwebsetup.exe
and install it.


Stephen

Thank you for that ImpassIve_rus. Your results are fairly consistent with what I get on my machine.

It would be nice to hear from people on slower machines as well... i.e. those where the CPU usage is around 30-50% with the standard Knights version. (Or maybe those older machines are still running XP so can't run the test version?)

K9

I have older slow machine, but as you said running xp.

I don't notice much cause for concern during my gameplay, runs steady, although I wouldn't notice inefficiency because I am not multitasking while I am on my quests.

In the event I upgrade (as being forced by microsoft when they no longer support xp in 2 years), I look forward to using the fastest possible drawing.

Thank you for exploring that Stephen.

Moo

Great improvement!
From 40-50% (one core) with maximized window on old, to 5-20%, usually about 14% or so for new.

Stephen

Hi Moo

Just what I wanted to hear! :)

I think I've fixed the font issue now, here is another exe for you to try:
http://www.knightsgame.org.uk/Knights_DX11_New.exe

Moo


Stephen

Hi Romanio,

I saw that you posted here yesterday. Unfortunately the server crashed last night and I had to restore from an older backup, so your post was lost. Sorry about that.

I can't remember exactly what you said but I think it was something like 15% cpu with the old version and about 10% with the new? So not as dramatic results as some people were seeing, but still an improvement.

--

I'm still undecided how to roll this change out in the full (released) version of Knights. We can't just move everybody over to the new system because people like K9 would be unable to run it. Either there should be an option (i.e. user can choose SDL or DirectX rendering), or perhaps it should be auto-detected (i.e. if DX is detected on the system then use that, otherwise use SDL).

Also, there are some bugs relating to full screen mode in the DirectX version currently. So I recommend sticking to windowed mode if you are using that :)

Romanio(Rus)

Yes, I wrote about that in the old version 15-20% CPU used and in new version 10-13% CPU used
And yet, very sorry that those who use Win XP can not put a new version  :(
And add that some players are much easier to play in full screen mode than in a window (I allude to myself), so thanks for the warning about the bugs  :)

Newk

hi, just succesfully compiled v20 on my linux 12.04 machine... i guess it will stay there in SDL mode in future releases? i hope not :o
what would be an easy way on that platform to get a more direct acces to the graphics hardware? opengl?

http://en.wikipedia.org/wiki/Simple_Directmedia_Layer << here i read something about Xlib

cheers

Newk

ah and speaking of linux: i'm pretty sure this game would attract much more players if it was in the ubuntu repositories.

Stephen

Quote from: Newk on August 13, 2012, 04:21:13 AM
what would be an easy way on that platform to get a more direct acces to the graphics hardware? opengl?

There are several options:

  • OpenGL
  • The latest SDL (1.3) supposedly uses OpenGL and is a big improvement. However, they haven't officially released it yet. (It seems to have been that way for a long time.) Also it's incompatible with SDL 1.2 so would need some changes to the Knights code.
  • SFML (http://www.sfml-dev.org/), this is meant to be an alternative to SDL that uses OpenGL under the hood. Haven't really looked into it though.

The thing with DirectX is that I happened to have some DirectX code lying around that I could easily integrate into Knights. Unfortunately I don't have the same for OpenGL...

Quote from: Newk on August 13, 2012, 04:33:25 AM
ah and speaking of linux: i'm pretty sure this game would attract much more players if it was in the ubuntu repositories.

I don't know much about Debian packaging though. We really need a Debian packaging expert to come forward and help with this.

Evropi

Sorry for the necro, but there forums don't move much anyway!

SDL 1.3 AFAIK will be released as SDL 2.0 and is meant to be an almost-complete rewrite. You should probably stick to SDL; it seems to have more of a future. Emphasis on the simple, by the way. Anyone who has tried to work directly with DirectX or OpenGL knows what I mean, as they all know that feeling of wanting to slit your wrists with rage at the respective libraries' complexity.

It's definitely a problem of your implementation. I've run loads of SDL games like Battle for Wesnoth on my Windows machine and they run much better. Also, the CPU usage (as seen in the Task Manager's processes tab in XP) seems quite low.

I wouldn't recommend mixing DirectX code as it would confuse people who try to compile under Linux a very great deal. Alternatively, you can look into a build system. I'd recommend CMake, though Waf is very capable too (though not supported under Debian). I'm not a C/C++ programmer but I have heard from them and they all seem to hate GNU Autotools (which is not cross-platform) and prefer CMake to the popular slightly more SCons.

Stephen

Hi Evropi, thanks for the comments.

Quote from: Evropi on November 04, 2012, 12:19:04 AM
SDL 1.3 AFAIK will be released as SDL 2.0 and is meant to be an almost-complete rewrite. You should probably stick to SDL; it seems to have more of a future. Emphasis on the simple, by the way. Anyone who has tried to work directly with DirectX or OpenGL knows what I mean, as they all know that feeling of wanting to slit your wrists with rage at the respective libraries' complexity.

Once SDL 2.0 is released I should probably move to that, yes.

Unfortunately SDL 2.0 is not backwards compatible with SDL 1.2, which means I would have to rewrite the Knights rendering backend code to use it. I estimate that would take about 3-4 days. But we can cross that bridge when we come to it...

DirectX is not too bad by the way, at least not since version 10. (DirectX 9 and earlier were a bit painful to use, I'll give you that.)

Quote
It's definitely a problem of your implementation. I've run loads of SDL games like Battle for Wesnoth on my Windows machine and they run much better. Also, the CPU usage (as seen in the Task Manager's processes tab in XP) seems quite low.

Well, the point is that SDL (1.2) uses software rendering so is going to be a lot slower than other methods (such as DirectX or OpenGL) that use hardware rendering.

I'll be the first to admit that my implementation is unoptimized, but the point is, it is not worth optimizing the Knights code, because it's much easier simply to switch to hardware rendering. All the evidence so far (from people who have used the DirectX build under Windows) is that Knights runs "fast enough" when using hardware rendering.

The long term solution is probably to switch to SDL 2.0 (as discussed above).

Quote
I wouldn't recommend mixing DirectX code as it would confuse people who try to compile under Linux a very great deal.

I don't think there's much risk of that; the DirectX code is kept in its own folder so there is not much chance of it being confused with the main Knights code. (The same goes for the SDL code.)

Quote
Alternatively, you can look into a build system. I'd recommend CMake, though Waf is very capable too (though not supported under Debian). I'm not a C/C++ programmer but I have heard from them and they all seem to hate GNU Autotools (which is not cross-platform) and prefer CMake to the popular slightly more SCons.

I keep hearing good things about CMake so maybe I should look into it.

At the moment I do all my development on Windows (using Visual Studio) and then I have a little script that generates a Linux Makefile from the Visual Studio project files. This suits me just fine but I suppose it is not ideal for people who want to do development on Linux.

I need to prioritize though; it's probably more important to work on new modding features at the moment (e.g. getting the map editor working again), rather than messing about with the build system.

P.S. Sorry it took me so long to reply; I've been a bit busy over the last few days.