Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: electrojustin on August 03, 2014, 11:36:20 am

Title: ATI mouse/input lag patch
Post by: electrojustin on August 03, 2014, 11:36:20 am
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]
Title: Re: ATI mouse/input lag patch
Post by: Wobble73 on August 04, 2014, 08:01:24 am
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?
Title: Re: ATI mouse/input lag patch
Post by: AdmiralRalwood on August 04, 2014, 08:52:53 am
...If mouse input wasn't experiencing any delay, then it obviously wasn't this problem.
Title: Re: ATI mouse/input lag patch
Post by: Wobble73 on August 04, 2014, 09:15:17 am
But this states "ATI mouse/input lag"? And seeing I have and AMD/ATI graphics chip I thought maybe this could be a solution?
Title: Re: ATI mouse/input lag patch
Post by: electrojustin on August 04, 2014, 01:49:37 pm
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).
Title: Re: ATI mouse/input lag patch
Post by: niffiwan on August 07, 2014, 04:45:44 am
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
 
Title: Re: ATI mouse/input lag patch
Post by: niffiwan on August 08, 2014, 10:34:40 pm
FYI - committed in r10979