Jump to content

Disabling/re-enabling hardware graphics acceleration


Recommended Posts

Posted

I'm installing a new version of ProDesktop which tends to fall over on our kit if hardware graphics acceleration isn't disabled.

 

Ideally I'd like to check hga when the program runs, and disable it if it's enabled. Given that this might affect other applications, I'd like to re-enable it at some point (logoff, shutdown etc).

 

I've tried Googling, I've taken RegShots before and after, and I can't identify what changes I need to make in the background to make it 'just happen'.

 

Can anyone help please?

 

ETA - er, we're running Win2K Pro here

Posted

I asked how to do this on EE some time ago, here is the code I got to do it :

 

Here you go, this function reads the current acceleration value from the registry and returns it. I wrote this code to be usable both in VB and VBScript, since I didn't have VB6 installed on the machine I wrote this on. To 'set' the Acceleration setting, just use a SetDWORDValue call instead of GetDWORDValue near the end of the function (or use DeleteValue if you want to set "full acceleration", since 0 is the default).

 

'********************************

 


Const HKLM = &H80000002

'
' GetAccelerationSetting
'
' Reads current acceleration setting value from the registry.
' Returns 0-5 on success, or -1 if an error occurred reading
' the Device information.
'

Function GetAccelerationSetting()
 GetAccelerationSetting = -1

 Dim objReg, strDevice, intAccelValue, intErr
 Dim strKey, strValueName
 Dim objRegExp, colMatches, objMatch

 ' using WMI's StdRegProv to access the registry (making this code usable
 ' in both VB and VBS)

 On Error Resume Next
 Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")

 If (Err.Number) Then Exit Function

 On Error Goto 0

 strKey = "HARDWARE\DEVICEMAP\VIDEO"
 strValueName = "\Device\Video0"

 intErr = objReg.GetStringValue(HKLM, strKey, strValueName, strDevice)

 If (intErr <> 0) Then Exit Function

 strKey = ""

 Set objRegExp = CreateObject("VBScript.RegExp")
 objRegExp.IgnoreCase = True
 objRegExp.Pattern = "^\\REGISTRY\\Machine\\(.*)$"

 Set colMatches = objRegExp.Execute(strDevice)

 For Each objMatch In colMatches
   strKey = objMatch.SubMatches(0)
 Next

 If (strKey = "") Then Exit Function

 strValue = "Acceleration.Level"

 intErr = objReg.GetDWORDValue(HKLM, strKey, strValue, intAccelValue)

 If (intErr = 0) Then
   GetAccelerationSetting = intAccelValue
 Else
   GetAccelerationSetting = 0
 End If
End Function

 

EE Thread is here :

 

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21646882.html

 

Only thing with this code is that you would after doing this have to some how have to re initliziaze the display driver or something to that effect , short of that reboot it as per the comment here from EE:

 

Note that if you modify the code to SET the acceleration value, you will probably have to reboot the computer to get the changes to take effect. Most of the time, updating the registry directly does not force windows to reinitialize whatever component you're changing (the way updating this setting through the Control Panel does).

Posted
If you alter it or get it to work , would be nice to get a post back and let me know what happens. I did a little bit of testing but never really got it to work without a reboot so would be nice to get an updated version that can do it on the fly :)
Posted

Here is the original version that was posted back with ( a lot harder to implement so your better off sticking with the first one I posted ) but just so that you get the table to see how it is done to set the value , I thought this info would be handy :

 

 

Looks pretty straightforward. From an API perspective, all you need to do is modify a couple of INI files and registry values. The trick is learning the combinations of values which make up the 4 valid conditions (copying and pasting from the PAQ's pseudo-code):

 

 

Lets define 3 parameters:

 

1) P_SAFEMODE

-------------

INIFILE = WIN.INI

SECTION = Windows

KEY = SafeMode

 

REGKEY = 0

REGVALUE= 0

 

MIN = 0

MAX = 2

DEFAULT = 0

 

2) P_ADVANCED

-------------

INIFILE = SYSTEM.INI

SECTION = Display

KEY = Mmio

 

REGKEY = Display\Settings

REGVALUE= Advanced

 

MIN = 0

MAX = 1

DEFAULT = 1

 

3) P_SWCURSOR

-------------

INIFILE = SYSTEM.INI

SECTION = Display

KEY = SwCursor

 

REGKEY = Display\Settings

REGVALUE= SwCursor

 

MIN = 0

MAX = 1

DEFAULT = 0

 

...

 

Here is the second part of the answer - how to set hardware acceleration setting.

 

Accel value

0 1 2 3 Default (3)

----------------------------------

safeMode 2 1 0 0 0

isAdvanced 0 0 1 1 1

isSwCursor 1 1 1 0 0

 

 

 

The "Accel value" is a made up number, used to define the 4 valid conditions. For each Accel value, you need to set the proper combination of safeMode, isAdvanced, and isSwCursor in their respective INI file / registry key. The VB code for this will look nearly identical to the C code in the PAQ (other than syntax differences.... Class versus typedef struct, etc). Unfortunately I don't have time to write and test the VB version right now. Note that this PAQ may be only applicable for Win9x or NT4 systems... it's fairly old, and I noticed in my Display control panel (on a Windows XP system) that there were actually SIX options on the Acceleration slider, not 4. Even if you convert the algorithm to VB as-is, it may no longer be appropriate for recent operating systems.

 

Obviously you will have to alter the vbscript to your needs but its a reasonable start :)

 

At least I thought so :)

Posted

Thanks very much for your help on this wet and grey half term Monday :)

 

I have used the script to set and report on various levels of hardware acceleration, all well and good.

 

The reinitialisation is a bit trickier, I agree. I cast around fora means of testing the level of acceleration without looking at the registry or the advanced display settings tabs (which just report the reg settings) and gave dxdiag a go.

 

I used the test buttons on the Display tab, and the 3D test failed on all 3 stages when I had disabled acceleration. I re-enabled using the script, then ran it again. It failed on stage 1 but succeeded on stages 2 and 3, so suspect it must have reinitialised somewhere in there. I haven't used dxdiag before, so need to work out if I can use it programatically in some way to do the reinitialisation for me.

 

Will report back!

 

Thanks

Posted

Here is a step by step on how it works:

 

I have tested the solution to work on Windows 2000 with a Matrox G450 DH and on Windows XP with some ATI graphics adapter. No warranty, but it looks like it is a general solution for XP/2K.

 

It works as follows:

 

(1) Find out the position of the current video device, information on this may be found in the registry, here:

\\HKLM\HARDWARE\DEVICEMAP\VIDEO\Device\Video0

There you will find a LPSTR type of entry, pointing to a registry key for the current video device, e.g.

"\Registry\Machine\System\ControlSet001\Services\G400\Device0"

(2) Parse that string, replacing "\Registry\Machine" with HKLM (HKEY_LOCAL_MACHINE) and open the corresponding registry key,

(3) Look for a DWORD value "Acceleration.Level". If the value does not exists, hardware acceleration is set to "Full". Otherwise, "Acceleration.Level" may be one of 0x1 to 0x5, 0x5 meaning "No Acceleration", and 0x1 meaning "All but cursor acceleration" (see "Extended Display Settings").

(4) Set the desired acceleration level, or delete the entry to set "Full" acceleration mode.

(5) Let Windows reload the display settings by using the following code:

 

DEVMODE devMode;

BOOL success = ::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode);

if (success == TRUE)

{

LONG result = ::ChangeDisplaySettings(&devMode, CDS_RESET);

printf("ChangeDisplaySettings() returned: %d\n", result);

}

 

First, the current display settings are loaded into the devMode variable, and then, the displayed is forced to perform a reset; at this occasion, the "Acceleration.Level" value is read out from the registry and the new acceleration level is set.

 

Not sure if that helps any with regards to refreshing it.

 

From that it looks like its step 5 ( or an altered version of that ) that you need to some how implement in vbs.

 

Just so you are aware the code in step 5 is originally in delphi ( not sure what version ) but that will defintly help when it comes to trying to port it to vbs, if thats even possible.

 

Maybe ICT NUT or someone like that can help with that part :)

Posted
Just a handy hint RE Pro Desktop, don't forget to complete and Extrusion as an Administrator before you let the kids use it otherwise it will just crash and burn when they try and extrude. You only need to draw a shape, hit the Extrude button on the bottom taskbar and drag the yellow square up to make it a cube / cylinder (or whatever 3D shape it becomes from your flat shape) and then hit ok to make it stick, then anyone can extrude etc.
Posted

really stupid thought here .... but what about just for testing purposes if you used F5 after you use that script and then tried dxdiag to see if it gets the graphics card to re initialize itself after you press F5.

 

If it does then you just need to figure out how to get the screen to refresh without using send keys, might be able to get iexplorer to do it for you ( possibly ) not sure on that though.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...