Go Back   Project64 Forums > Public Version > Project 64 - v2.x - Issues

Reply
 
Thread Tools Display Modes
  #11  
Old 10th May 2017, 02:29 PM
theboy181's Avatar
theboy181 theboy181 is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Aug 2014
Location: Prince Rupert,British Columbia Canada
Posts: 420
Default

@squal_leonheart

Have you tried earlier versions of the plugin? I think that I tested a while back and there was a version that initialized quickly.
__________________
So you think you can TECH!! Watch this!! https://www.youtube.com/watch?v=NAUKPq5QjL0
Reply With Quote
  #12  
Old 11th May 2017, 01:50 PM
squall_leonhart's Avatar
squall_leonhart squall_leonhart is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Mar 2007
Location: Sydney, Australia
Posts: 2,894
Default

Quote:
Originally Posted by theboy181 View Post
@squal_leonheart

Have you tried earlier versions of the plugin? I think that I tested a while back and there was a version that initialized quickly.



older versions that don't have xinput won't have the issue.


Quote:
Originally Posted by Maniac View Post
Thanks for the reply Squall. So taking 30 seconds to initialize is expected? I've tried many games that start faster than that and have controllers detected immediately. It seems something is being done differently for PJ64/nrage.


you must have a lot of hid devices, or particularly weak single core performance for it to take 30 seconds.
__________________
Xfire Profile | VBA-M | XBCD 0.2.7

CPU:Intel i7 920 @ 3.8(D0), Mainboard:Asus Rampage II Gene, Memory:12GB Corsair Vengeance 1600
Video:EVGA Geforce GTX 680+ 4GB, Sound:Creative XFI Titanium Fatal1ty Pro, Monitor:BenQ G2400WD
HDD:500GB Spinpoint F3, 1TB WD Black, 2TB WD Red, 1TB WD Black
Case:NZXT Guardian 921RB, PSU:Corsair 620HX, OS:Windows 7 SP1

Last edited by squall_leonhart; 11th May 2017 at 01:56 PM.
Reply With Quote
  #13  
Old 11th May 2017, 02:17 PM
Maniac Maniac is offline
Junior Member
 
Join Date: Mar 2017
Posts: 19
Default

Quote:
Originally Posted by squall_leonhart View Post
you must have a lot of hid devices, or particularly weak single core performance for it to take 30 seconds.
I'm using this on a GPD Win. It has an Intel Atom z8700, so yes, relatively weak single core performance. It also has 33 HID Devices.

I have not tried this on my desktop (i5 6600K with 27 HID Devices).


So I'm a bit confused why you have to enumerate HID Devices. Are you not able to use XInputGetState for some reason?

Last edited by Maniac; 11th May 2017 at 02:21 PM.
Reply With Quote
  #14  
Old 11th May 2017, 02:38 PM
squall_leonhart's Avatar
squall_leonhart squall_leonhart is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Mar 2007
Location: Sydney, Australia
Posts: 2,894
Default

https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx


all directinput devices must be checked to see if they are xinput devices using WMI to prevent them being enumerated with both apis.


the code used is the same code used by pcsx2 and various games, and most of them don't spin up the wmi provider for a long time.


tbh, Nrage needs all its api related code rewritten.
__________________
Xfire Profile | VBA-M | XBCD 0.2.7

CPU:Intel i7 920 @ 3.8(D0), Mainboard:Asus Rampage II Gene, Memory:12GB Corsair Vengeance 1600
Video:EVGA Geforce GTX 680+ 4GB, Sound:Creative XFI Titanium Fatal1ty Pro, Monitor:BenQ G2400WD
HDD:500GB Spinpoint F3, 1TB WD Black, 2TB WD Red, 1TB WD Black
Case:NZXT Guardian 921RB, PSU:Corsair 620HX, OS:Windows 7 SP1

Last edited by squall_leonhart; 11th May 2017 at 02:50 PM.
Reply With Quote
  #15  
Old 11th May 2017, 03:20 PM
Maniac Maniac is offline
Junior Member
 
Join Date: Mar 2017
Posts: 19
Default

So I looked at the code in the repo... I think I know why this is taking so long:

In NRagePluginV2.cpp, EnumDevices is called with these arguments:
g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY );

DI8DEVCLASS_ALL tells EnumDevices to enumerate *all* devices, not just controllers.

Then in the callback EnumMakeDeviceList in DirectInput.cpp, the first thing it does is call IsXInputDevice in XInputController.cpp.

IsXInputDevice enumerates all devices each time it's called, and it's called for every DirectInput device!

There's a few ways to make this faster... here's a few that I thought of quickly:
1. Only call IsXInputDevice if the dwDevType is DI8DEVTYPE_JOYSTICK, DI8DEVTYPE_GAMEPAD, DI8DEVTYPE_FLIGHT, DI8DEVTYPE_DRIVING (and maybe their subtypes?). I don't think anything else would be a XInput device, right? Also, maybe they only need to be checked if DIDEVTYPE_HID is defined?

2. Cache the HID enumeration for the duration of the EnumDevices call. It doesn't need to be re-enumerated until the next call to EnumDevices. Use a lookup table of some sort with a key of device id and a value flag indicating if it's a XInput device or not.
Reply With Quote
  #16  
Old 12th May 2017, 03:32 PM
squall_leonhart's Avatar
squall_leonhart squall_leonhart is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Mar 2007
Location: Sydney, Australia
Posts: 2,894
Default

Quote:
Originally Posted by Maniac View Post
So I looked at the code in the repo... I think I know why this is taking so long:

In NRagePluginV2.cpp, EnumDevices is called with these arguments:
g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumMakeDeviceList, NULL, DIEDFL_ATTACHEDONLY );

DI8DEVCLASS_ALL tells EnumDevices to enumerate *all* devices, not just controllers.

Then in the callback EnumMakeDeviceList in DirectInput.cpp, the first thing it does is call IsXInputDevice in XInputController.cpp.

IsXInputDevice enumerates all devices each time it's called, and it's called for every DirectInput device!

There's a few ways to make this faster... here's a few that I thought of quickly:
1. Only call IsXInputDevice if the dwDevType is DI8DEVTYPE_JOYSTICK, DI8DEVTYPE_GAMEPAD, DI8DEVTYPE_FLIGHT, DI8DEVTYPE_DRIVING (and maybe their subtypes?). I don't think anything else would be a XInput device, right? Also, maybe they only need to be checked if DIDEVTYPE_HID is defined?

2. Cache the HID enumeration for the duration of the EnumDevices call. It doesn't need to be re-enumerated until the next call to EnumDevices. Use a lookup table of some sort with a key of device id and a value flag indicating if it's a XInput device or not.

a quick fucking around with the source, we need DI8DEVCLASS_ALL to include keyboard support, but DI8DEVCLASS_GAMECTRL on its own resolves the issue.


it seems that much of the time spent in wmi is on enumerating the keyboard and mouse.
__________________
Xfire Profile | VBA-M | XBCD 0.2.7

CPU:Intel i7 920 @ 3.8(D0), Mainboard:Asus Rampage II Gene, Memory:12GB Corsair Vengeance 1600
Video:EVGA Geforce GTX 680+ 4GB, Sound:Creative XFI Titanium Fatal1ty Pro, Monitor:BenQ G2400WD
HDD:500GB Spinpoint F3, 1TB WD Black, 2TB WD Red, 1TB WD Black
Case:NZXT Guardian 921RB, PSU:Corsair 620HX, OS:Windows 7 SP1

Last edited by squall_leonhart; 12th May 2017 at 04:08 PM.
Reply With Quote
  #17  
Old 12th May 2017, 03:59 PM
Maniac Maniac is offline
Junior Member
 
Join Date: Mar 2017
Posts: 19
Default

Quote:
Originally Posted by squall_leonhart View Post
a quick fucking around with the source, we need DI8DEVCLASS_ALL to include keyboard support, but DI8DEVCLASS_GAMECTRL on its own resolves the issue.
Yeah, I don't think you'd want to change the enumeration. I think EnumMakeDeviceList would need to have a condition regarding when it calls IsXInputDevice. I think you can't just check for DI8DEVCLASS_GAMECTRL though? From what I read, the dwDevType value in DIDEVICEINSTANCE should have a DI8DEVTYPE* value, not a DI8DEVCLASS* value (if I'm wrong, cool, that's more simple).
Code:
	switch (GET_DIDEVICE_TYPE(lpddi->dwDevType)) {
	case DI8DEVTYPE_JOYSTICK:
	case DI8DEVTYPE_GAMEPAD:
	case DI8DEVTYPE_FLIGHT:
	case DI8DEVTYPE_DRIVING:
		if (IsXInputDevice(&lpddi->guidProduct))		// Check if is XInput device --tecnicors
			return DIENUM_CONTINUE;
		break;
	default:
		break;
	}

On a possibly related note:
http://stackoverflow.com/questions/1...painfully-slow
Reply With Quote
  #18  
Old 12th May 2017, 05:23 PM
Maniac Maniac is offline
Junior Member
 
Join Date: Mar 2017
Posts: 19
Default

My post went to moderation, so I'm going to try again... but putting this at the top of EnumMakeDeviceLists to replace the call to IsXInputDevice should help:


Code:
	switch (GET_DIDEVICE_TYPE(lpddi->dwDevType)) {
	case DI8DEVTYPE_JOYSTICK:
	case DI8DEVTYPE_GAMEPAD:
	case DI8DEVTYPE_FLIGHT:
	case DI8DEVTYPE_DRIVING:
		if (IsXInputDevice(&lpddi->guidProduct))		// Check if is XInput device --tecnicors
			return DIENUM_CONTINUE;
		break;
	default:
		break;
	}
Reply With Quote
  #19  
Old 12th May 2017, 06:21 PM
squall_leonhart's Avatar
squall_leonhart squall_leonhart is offline
Alpha Tester
Project Supporter
Senior Member
 
Join Date: Mar 2007
Location: Sydney, Australia
Posts: 2,894
Default

good change, does the job.


I have committed the change to the nrage repo and posted a change-issue to pj64's github.


This was also a possible working change
Code:
    switch (GET_DIDEVICE_TYPE(lpddi->dwDevType)) {
    case DI8DEVCLASS_GAMECTRL:
        if (IsXInputDevice(&lpddi->guidProduct))        // Check if is XInput device --tecnicors
            return DIENUM_CONTINUE;
        break;
    default:
        break;
    }
__________________
Xfire Profile | VBA-M | XBCD 0.2.7

CPU:Intel i7 920 @ 3.8(D0), Mainboard:Asus Rampage II Gene, Memory:12GB Corsair Vengeance 1600
Video:EVGA Geforce GTX 680+ 4GB, Sound:Creative XFI Titanium Fatal1ty Pro, Monitor:BenQ G2400WD
HDD:500GB Spinpoint F3, 1TB WD Black, 2TB WD Red, 1TB WD Black
Case:NZXT Guardian 921RB, PSU:Corsair 620HX, OS:Windows 7 SP1

Last edited by squall_leonhart; 12th May 2017 at 06:31 PM.
Reply With Quote
  #20  
Old 12th May 2017, 06:38 PM
Maniac Maniac is offline
Junior Member
 
Join Date: Mar 2017
Posts: 19
Default

Great, thanks!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 09:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.