Author Topic: ATI mouse/input lag patch  (Read 1839 times)

0 Members and 1 Guest are viewing this topic.

ATI mouse/input lag patch
Not sure if this is the right place to put this, but it seemed reasonable enough...

For Linux users with ATI cards, some OpenGL games have an issue where mouse movement stutters or lags. This is particularly prominent in source games like Team Fortress 2, Half Life 2, and Left 4 Dead 2. The issue and potential fixes are described thoroughly here: https://github.com/ValveSoftware/Source-1-Games/issues/765

Upon loading up fs2_open 3.7.2 for the first time, I immediately saw the same issue. Missions gave me serious mouse/joystick lag. Every quarter of a second or so, my angular speed would change dramatically.

So, this patch essentially adds a command line flag that, when set, inserts a call to glFinish() into the rendering cycle, as suggested in the github bug report. Setting this flag may result in a framerate hit, but it makes the game playable for Linux users with ATI cards.

Let me know if there's any trouble with the patch file! The p level should be 0.

[attachment kidnapped by pirates]

 

Offline Wobble73

  • 210
  • Reality is for people with no imagination
Re: ATI mouse/input lag patch
Hmmm, I was playing HL2 last night and noticed when I stopped pressing the "w" key I continued to move forward, sometimes for quite a while. I could still steer myself with the mouse, but I would not stop moving forward. (got myself killed a few times because of this bug). Do you think this would fix it?
Who is General Failure and why is he reading my hard disk?
Early bird gets the worm, but the second mouse gets the cheese
Ambition is a poor excuse for not having enough sense to be lazy.
 
Member of the Scooby Doo Fanclub. And we're not talking a cartoon dog here people!!

 You would be well adviced to question the wisdom of older forumites, we all have our preferences and perversions

  

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: ATI mouse/input lag patch
...If mouse input wasn't experiencing any delay, then it obviously wasn't this problem.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Wobble73

  • 210
  • Reality is for people with no imagination
Re: ATI mouse/input lag patch
But this states "ATI mouse/input lag"? And seeing I have and AMD/ATI graphics chip I thought maybe this could be a solution?
Who is General Failure and why is he reading my hard disk?
Early bird gets the worm, but the second mouse gets the cheese
Ambition is a poor excuse for not having enough sense to be lazy.
 
Member of the Scooby Doo Fanclub. And we're not talking a cartoon dog here people!!

 You would be well adviced to question the wisdom of older forumites, we all have our preferences and perversions

 
Re: ATI mouse/input lag patch
I really did mean pointer input, e.g. mouse, joystick, possibly other controllers, not so much keyboard. The bug is really only with the proprietary ATI drivers and it normally manifests itself as perceptible stutter.

That being said, HL2 is a source engine game and as such experiences the bug. I've never heard of keyboard input getting stuck due to it, but someone on the github thread indicated that the problem was especially bad with newer ATI cards (I currently use an HD 6670, so I'm spared a little bit). Test it by typing gl_finish 1 into the console next time you play HL2; that should fix it for most valve games (expect  for L4D2 which neglected to include that particular command).

 

Offline niffiwan

  • 211
  • Eluder Class
Re: ATI mouse/input lag patch
I had a look at this and it seems fine to me.  I made a few trivial wording changes so that the intended use is a bit clearer.  I don't have the input lag issue myself, but I did test that it doesn't seem to have any adverse effects with my nVidia card.  Unless anyone has any further comments I'll commit the patch below on the weekend.

Code: [Select]
diff --git a/code/cmdline/cmdline.cpp b/code/cmdline/cmdline.cpp
index 51bebda..d5ae196 100644
--- a/code/cmdline/cmdline.cpp
+++ b/code/cmdline/cmdline.cpp
@@ -194,6 +194,7 @@ Flag exe_params[] =
  #endif
  { "-use_gldrawelements","Don't use glDrawRangeElements", true, 0, EASY_DEFAULT, "Troubleshoot", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-use_gldrawelements", },
  { "-old_collision", "Use old collision detection system", true, EASY_DEFAULT, EASY_ALL_ON, "Troubleshoot", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-old_collision", },
+ { "-gl_finish", "Fix input lag on some ATI+Linux systems", true, 0, EASY_DEFAULT, "Troubleshoot", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-gl_finish", },
 
  { "-ingame_join", "Allow in-game joining", true, 0, EASY_DEFAULT, "Experimental", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-ingame_join", },
  { "-voicer", "Enable voice recognition", true, 0, EASY_DEFAULT, "Experimental", "http://www.hard-light.net/wiki/index.php/Command-Line_Reference#-voicer", },
@@ -412,6 +413,7 @@ cmdline_parm no_di_mouse_arg("-disable_di_mouse", "Disable DirectInput mouse cod
 cmdline_parm no_drawrangeelements("-use_gldrawelements", NULL, AT_NONE); // Cmdline_drawelements -- Uses glDrawElements instead of glDrawRangeElements
 cmdline_parm keyboard_layout("-keyboard_layout", "Specify keyboard layout (qwertz or azerty)", AT_STRING);
 cmdline_parm old_collision_system("-old_collision", NULL, AT_NONE); // Cmdline_old_collision_sys
+cmdline_parm gl_finish ("-gl_finish", NULL, AT_NONE);
 
 int Cmdline_load_all_weapons = 0;
 int Cmdline_nohtl = 0;
@@ -428,6 +430,7 @@ int Cmdline_no_glsl_model_rendering = 0;
 int Cmdline_no_di_mouse = 0;
 int Cmdline_drawelements = 0;
 char* Cmdline_keyboard_layout = NULL;
+bool Cmdline_gl_finish = false;
 
 // Developer/Testing related
 cmdline_parm start_mission_arg("-start_mission", "Skip mainhall and run this mission", AT_STRING); // Cmdline_start_mission
@@ -1487,6 +1490,11 @@ bool SetCmdlineParams()
  Cmdline_keyboard_layout = keyboard_layout.str();
  }
 
+ if (gl_finish.found())
+ {
+ Cmdline_gl_finish = true;
+ }
+
  if ( snd_preload_arg.found() )
  {
  Cmdline_snd_preload = 1;
diff --git a/code/cmdline/cmdline.h b/code/cmdline/cmdline.h
index 9e36ed1..117a35c 100644
--- a/code/cmdline/cmdline.h
+++ b/code/cmdline/cmdline.h
@@ -130,6 +130,7 @@ extern int Cmdline_no_glsl_model_rendering;
 extern int Cmdline_no_di_mouse;
 extern int Cmdline_drawelements;
 extern char* Cmdline_keyboard_layout;
+extern bool Cmdline_gl_finish;
 
 // Developer/Testing related
 extern char *Cmdline_start_mission;
diff --git a/code/graphics/gropengl.cpp b/code/graphics/gropengl.cpp
index 8c3888e..abd4ca3 100644
--- a/code/graphics/gropengl.cpp
+++ b/code/graphics/gropengl.cpp
@@ -354,6 +354,8 @@ void gr_opengl_flip()
 #ifdef _WIN32
  SwapBuffers(GL_device_context);
 #else
+ if (Cmdline_gl_finish)
+ glFinish ();
  SDL_GL_SwapBuffers();
 #endif
 
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...

 

Offline niffiwan

  • 211
  • Eluder Class
Re: ATI mouse/input lag patch
FYI - committed in r10979
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...