XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

XInput / XInputGetState Performance Problems

Last post 2/2/2010 8:08 AM by gekko. 1 replies.
  • 1/19/2010 3:42 PM

    XInput / XInputGetState Performance Problems

    This has been mentioned here before, but we are also having problems with XInputGetState performance with code similar to the DX SDK sample code.  I have modified the "XInput Sample: SimpleController" code to profile around the for loop that calls XInputGetState().  This code takes over 1.6ms when less than 4 controllers are plugged in.  I assume this is because it is attempting to enumerate other devices.

    If the code is changed to poll for a single controller that is plugged in, the XInputGetState call takes .08ms.  So it appears that one should *not* call this code the way it is done in the samples.  This should be made clear in the documentation and the sample code if this is the case as 1.6ms is a substantial amount of frame time.

    So if this is not the correct way to poll for controller changes, what are people using to detect that a new controller is available?  It would be nice if it behaved more like the X360 using a callback for detection.  The best I can come up with is to set a flag to only have it call XInputGetState when on a screen that is initially trying to detect a new controller. However, we have seen the controller id change from "1" to "2" or "3" when unplugging a controller.  So if a user accidentally pulls out a controller while playing this could be a problem.

    We have also noticed that with two controllers plugged in, removing one and replugging it will often not detect the reinserted controller.  This happens in the SimpleController sample under 64bit Vista, though I imagine it's a problem on all OSes.

    Thanks for the help,
    -Douglas Cox
    Engine Programming Director
    Vicious Cycle Software, Inc.

  • 2/2/2010 8:08 AM In reply to

    Re: XInput / XInputGetState Performance Problems

    I had similar times to what you posted running under XP.  The solution we use is to use the WM_DEVICECHANGE message.  This will get sent anytime new hardware is connected, among other reasons (consult the docs, of course).  So only check the disconnected controllers if new hardware was found.  You'll still take the performance hit when doing the checks, but it won't happen very often.  Besides, I would imagine your CPU spikes when new hardware is found anyway, so I doubt any performance hiccup will be noticeable.

    Hope that helps!
Page 1 of 1 (2 items) Previous Next