[Linux] Mouse sluggish? Try this code mod.

Discuss your new mods and themes here

Moderator: Defcon moderators

User avatar
bert_the_turtle
level5
level5
Posts: 4795
Joined: Fri Oct 13, 2006 6:11 pm
Location: Cologne
Contact:

[Linux] Mouse sluggish? Try this code mod.

Postby bert_the_turtle » Wed May 16, 2007 2:49 pm

Background: Defcon does not call the function glFinish() every frame; according to spec, this function makes sure all graphics operations are executed before it returns. Not calling it will, on some systems, cause lag between input and graphics because there may be several already computed frames in a queue waiting to be rendered, and by the time they finally appear on screen, they are a bit out of date. glFinish() flushes this queue.

If the UI of Defcon is already smooth for you and there is no feelable delay between your real mouse movement and the movement of the pointer on the screen, you don't have to read on. You won't profit from this mod.

Luckily for the rest, Defcon is linked dynamically against SDL in Linux. While you can't (easily) modify Defcon's code on your own, SDL is open source and you can modify SDL's code and replace the version of SDL that comes with Defcon with your own version.

Step by step instructions to do so, smuggling in a glFinish() call:
1. Get SDL from here. Defcon comes with version 1.2.11, and that's what I use in the instructions; you'll probably get away with later versions as well.
2. Get this patch. It modifies the SDL function that Defcon does call every frame to include the glFinish() call.
3. Upack SDL (in the following, the lines starting with $ are the ones you need to enter without the $ sign, the rest is the expected output):

Code: Select all

$ tar -xzf <path to SDL download>/SDL-1.2.11.tar.gz
$ cd SDL-1.2.11/

4. apply the patch:

Code: Select all

$ patch < <path to patch>/defcon_glfinish.patch -p 1
patching file src/video/SDL_video.c

5. compile regularly:

Code: Select all

$ ./configure
<output snipped>
$ make -k
<output snipped>

6. copy the resulting library into the defcon library folder:

Code: Select all

$ cp build/.libs/libSDL-1.2.so.0.11.0 <path to defcon>/lib/libSDL-1.2.so.0.11.0

7. launch defcon and enjoy!

If this is too complicated or you don't have the required tools installed and you trust me (you shouldn't!), here is the bzipped result of the operations above. Just unbzip it and put it into Defcon's lib directory.

Effect for me on my work PC with a crappy NVidia FX 5200 card: input lag reduction of one or two frames, which is an easily feelable improvement when you only get 20 FPS.

Edit: on my home PC with an NVidia 6800, there is no effect, although there is feelable mouse lag in the menu. It goes away either way in a multiplayer game.

The downside: on NVidia cards (and I hear ATI cards as well), calling glFinish() blocks the CPU and makes the calling program use 100% of its time. Boo for NVidia. I think ATI is no better. On SOME systems, replacing glFinish() with glFlush() in the patch works just as well without this drawback. YMMV.
User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6254
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Re: [Linux] Mouse sluggish? Try this code mod.

Postby NeoThermic » Wed May 16, 2007 4:57 pm

bert_the_turtle wrote:The downside: on NVidia cards (and I hear ATI cards as well), calling glFinish() blocks the CPU and makes the calling program use 100% of its time. Boo for NVidia. I think ATI is no better. On SOME systems, replacing glFinish() with glFlush() in the patch works just as well without this drawback. YMMV.


Well, yeah, glFinish is a blocking function (the OpenGL spec also notes that); it waits for everything else to finish before it then passes the info to the GPU. glFlush just forces the program to flush everything that has been previously done, regardless of if it has finished or not. I'd almost suggest to use glFlush outright as then you avoid any blocking issues :)

NeoThermic
User avatar
bert_the_turtle
level5
level5
Posts: 4795
Joined: Fri Oct 13, 2006 6:11 pm
Location: Cologne
Contact:

Postby bert_the_turtle » Wed May 16, 2007 6:07 pm

I probably picked the wrong word. That part of the blocking, that the function does not return before all work is done, is perfectly fine, it's the desired effect. But the other effect, that the CPU is running in circles, is a waste of resources. The blocking network functions (socket read waiting for data to arrive), for example, don't do that. Now, I don't know what issues the driver has to fight, so I'm not complaining too loudly :)
User avatar
bert_the_turtle
level5
level5
Posts: 4795
Joined: Fri Oct 13, 2006 6:11 pm
Location: Cologne
Contact:

Postby bert_the_turtle » Tue May 22, 2007 7:22 am

Results have been mixed so far. The little mouse lag on my home laptop and desktop, which was only present when no game was running anyway, didn't improve. Some fellow I met on IRC also tried this saw no improvement on his ATI card. Depending on how you count (I wouldn't count my home PCs, as they don't have this problem), that's a 50% or 25% success rate. Anyone else tried this?
User avatar
snwcrsh
level2
level2
Posts: 106
Joined: Mon May 14, 2007 6:00 pm

Postby snwcrsh » Tue May 22, 2007 8:43 pm

dont know if you meant me by "the guy on irc" .. but i tried it without success (after you pointed out that i need some GL package to compile). I have a ATI Radeon R250 (FireGL 9000) in a thinkpad t41 and defcon works perfectly smooth on w2k.
User avatar
bert_the_turtle
level5
level5
Posts: 4795
Joined: Fri Oct 13, 2006 6:11 pm
Location: Cologne
Contact:

Postby bert_the_turtle » Tue May 22, 2007 9:22 pm

Yep, I meant you. I'm terrible with names, especially on the net if I can't connect them with faces.
rimbaud
level1
level1
Posts: 36
Joined: Mon Feb 01, 2010 10:37 pm

Postby rimbaud » Mon Feb 01, 2010 11:11 pm

Thanks, this made a big difference for me. Turning the Comms box off is the big one though, jeez.

Card: GeForce Go 7600 on a dual core machine with 2GB

Return to “Mod Projects”

Who is online

Users browsing this forum: No registered users and 1 guest