2

Nvidia Optimus is a major thorn in my side. I just bought a new laptop that is using this on-the-fly gpu switching crap. This means that unless an application starts by querying the GPU for 3D tech or directx, then it uses the intel integrated. This means many applications don't use the GPU (even if you specify it in the Nvidia Control Panel). Some examples: if you run the WEI rating, or dxdiag, or in my case.. xilisoft video converter. Here is a program that can use the GPU to assist in the processing time of the video encoding. Yet since it doesn't try to access the GPU until the encoding starts.. the options to enable the GPU assist are greyed out. It's maddening.

So, I made a very simple DLL in visual basic that initializes directx. I then created another program in visual basic.. a simple window with a single button. When you click this button, it loads the dll file and runs the function that sends an initialization command to directx.

With the "Nvidia Optimus GPU state viewer" running to show which applications are being rendered by the dGPU I run my simple program. Of course it doesn't show up in the viewer. Then, when I press the button, wham, it's now being rendered by the dGPU.

However, this is where my limited programming knowledge ends. The goal here is when you have an app that you can't get running on the Nvidia, I want it to use this dll.

 

DLL INJECTION:

I know about DLL injection.. but I don't know how to do it. After injecting the dll.. how do you get the program to call the specific function INSIDE the dll which starts the directx process?

Wrapper:

Is it possible to make a wrapper/loader that could load the desired application but first run this directx function's code prior to the application starting up.. yet running it AS the application.. so it looks like the application made the call (to Optimus at least).

Assembly:

Perhaps we could make a jump after the entry point of the desired app to a "code cave" which then loads the dll and calls the function. Then create a program which can do this automatically for any desired applications.

Anyway, that's where I am. I'll keep plugging away at this, but any help would be appreciated. thanks.

  • I haven't played much with it, but isn't that right-click menu option "Run on graphics card" supposed to let you choose which card is used? – 0xea Nov 13 '14 at 7:50
  • That right click option still doesn't work for non-3d apps. It's a ridiculously flawed system and maddening to purchase a high end gfx card only to find out you have no true control over what it renders. – OptimusCrime Nov 13 '14 at 17:45
1

In your DLL you simply need to do the following:

And that's all! The library will be injected system wide and all the code you execute in your DLL will be executed in the context of the program it was injected to.

  • 1
    "Because of their early loading, only API functions that are exported from Kernel32.dll are safe to use in the initialization of the AppInit DLLs." will be a problem if the DLL wants to initialize DirectX. – Guntram Blohm Nov 13 '14 at 12:04
  • 1
    and MS would really like people to stop using AppInit_DLLs because it injects system wide and all the code... (etc). The fact that NVidia uses the technique themselves doesn't make it right, and has caused significant compatibility problems including introducing a code-execution vulnerability. – peter ferrie Nov 13 '14 at 16:23
  • Yes, I know the problems and that MS want to get rid of this "feature". But, may work for @OptimusCrime at least this time... – joxeankoret Nov 13 '14 at 17:03
  • Thanks a lot for answering Joxeankoret. As for why vb6? I'm not a strong programmer and that is the only language i ever learned! I've done my fair share of disassembly and code manipulation in ASM, but I'm far from 'great' at it. My problem here is not understanding much about C and dll's. The dll I created in VB6 might not be operating the same as regular dll's. I have the code i want executed in a function (called FUNCTIONCALL) as well as in Dllmain. From what I've read from people about dll injecting, it seems you don't need to call the function, that code should execute upon injection?.. – OptimusCrime Nov 13 '14 at 17:47
  • As for appinit.. I'll give that a shot. but once again, that doesn't specify a function within the dll to be called. I want the target process to call my function very soon after the entrypoint. That way, the target process can establish itself with the Optimus system as a process that needs to be rendered by the dGpu. That way, when (during startup) the application tries to detect which Gpu it is being rendered by, it will detect the dGpu and not the iGpu. – OptimusCrime Nov 13 '14 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.