[PATCH resend 6/6] dinput8: Stop using LL hooks for mouse devices.

Rémi Bernon rbernon at codeweavers.com
Mon Aug 10 04:04:17 CDT 2020


LL hooks are heavy and using them cause performance hit with high
polling rate mice. We don't need them anymore since we now use rawinput
API for mouse device.

This also uses a separate list for rawinput mouse devices.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

Notes:
    The same test as before with injection of 2kHz mouse events this time,
    to better show the difference brings the normal FPS from ~=50fps (the
    missing esync series hurts badly here) down to ~=20fps on average with
    some catch up moments, probably when ll-hooks start to timeout in batch.
    
    Patch #4 helps by doing less work in the ll-hooks and using rawinput
    messages instead, and bring it up to ~=30fps on average, but still with
    the catch up moments.
    
    And with patch #5 it holds the load much better, with a steady ~=45fps
    thanks to the ll-hook removal.

 dlls/dinput/dinput_main.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 1c4a26987f9..45023fc104a 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -104,6 +104,7 @@ static BOOL check_hook_thread(void);
 static CRITICAL_SECTION dinput_hook_crit;
 static struct list direct_input_list = LIST_INIT( direct_input_list );
 static struct list acquired_mouse_list = LIST_INIT( acquired_mouse_list );
+static struct list acquired_rawmouse_list = LIST_INIT( acquired_rawmouse_list );
 static struct list acquired_keyboard_list = LIST_INIT( acquired_keyboard_list );
 static struct list acquired_device_list = LIST_INIT( acquired_device_list );
 
@@ -116,7 +117,7 @@ void dinput_hooks_acquire_device(LPDIRECTINPUTDEVICE8W iface)
 
     EnterCriticalSection( &dinput_hook_crit );
     if (IsEqualGUID( &dev->guid, &GUID_SysMouse ))
-        list_add_tail( &acquired_mouse_list, &dev->entry );
+        list_add_tail( dev->use_raw_input ? &acquired_rawmouse_list : &acquired_mouse_list, &dev->entry );
     else if (IsEqualGUID( &dev->guid, &GUID_SysKeyboard ))
         list_add_tail( &acquired_keyboard_list, &dev->entry );
     else
@@ -657,11 +658,8 @@ static LRESULT WINAPI di_em_win_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPAR
         else if (ri.header.dwType == RIM_TYPEMOUSE)
         {
             EnterCriticalSection( &dinput_hook_crit );
-            LIST_FOR_EACH_ENTRY( dev, &acquired_mouse_list, IDirectInputDeviceImpl, entry )
-            {
-                if (!dev->use_raw_input) continue;
+            LIST_FOR_EACH_ENTRY( dev, &acquired_rawmouse_list, IDirectInputDeviceImpl, entry )
                 dinput_mouse_rawinput_hook( &dev->IDirectInputDevice8A_iface, wparam, lparam, &ri );
-            }
             LeaveCriticalSection( &dinput_hook_crit );
         }
     }
@@ -1720,7 +1718,6 @@ static LRESULT CALLBACK LL_hook_proc( int code, WPARAM wparam, LPARAM lparam )
     EnterCriticalSection( &dinput_hook_crit );
     LIST_FOR_EACH_ENTRY( dev, &acquired_mouse_list, IDirectInputDeviceImpl, entry )
     {
-        if (dev->use_raw_input) continue;
         TRACE("calling dinput_mouse_hook (%p %lx %lx)\n", dev, wparam, lparam);
         skip |= dinput_mouse_hook( &dev->IDirectInputDevice8A_iface, wparam, lparam );
     }
@@ -1764,6 +1761,14 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam
             IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8A_iface );
         }
     }
+    LIST_FOR_EACH_ENTRY_SAFE( dev, next, &acquired_rawmouse_list, IDirectInputDeviceImpl, entry )
+    {
+        if (msg->hwnd == dev->win && msg->hwnd != foreground)
+        {
+            TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev );
+            IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8A_iface );
+        }
+    }
     LIST_FOR_EACH_ENTRY_SAFE( dev, next, &acquired_keyboard_list, IDirectInputDeviceImpl, entry )
     {
         if (msg->hwnd == dev->win && msg->hwnd != foreground)
-- 
2.28.0




More information about the wine-devel mailing list