Coder Social home page Coder Social logo

NVIDIA Optimus enablement about mage-v0 HOT 2 CLOSED

matt77hias avatar matt77hias commented on June 8, 2024
NVIDIA Optimus enablement

from mage-v0.

Comments (2)

matt77hias avatar matt77hias commented on June 8, 2024

Quick workaround: explicitly require NVIDIA GPU for FPS.exe (4x, for all configuration and platform combinations) in the NVIDIA Control Panel

from mage-v0.

matt77hias avatar matt77hias commented on June 8, 2024

This could be a promising solution:

#include <windows.h>
#include <sal.h>
#include "nvapi.h"
#include "NvApiDriverSettings.h"

namespace mage {

    // When NvOptimusEnablement fails, we both link NVApi (also supposed to enable it) 
    // and specifically enable it in the driver settings.
    class nVidia
    {
    public:
        nVidia( void )
        {
            NvAPI_Status status;
            // (0) Initialize NVAPI. This must be done first of all
            status = NvAPI_Initialize();
            if (status != NVAPI_OK) 
            {
                return;
            }
            // (1) Create the session handle to access driver settings
            NvDRSSessionHandle hSession = 0;
            status = NvAPI_DRS_CreateSession(&hSession);
            if (status != NVAPI_OK) 
            {
                return;
            }
            // (2) load all the system settings into the session
            status = NvAPI_DRS_LoadSettings(hSession);
            if (status != NVAPI_OK) 
            {
                return;
            }
            // (3) Obtain the Base profile. Any setting needs to be inside
            // a profile, putting a setting on the Base Profile enforces it
            // for all the processes on the system
            NvDRSProfileHandle hProfile = 0;
            status = NvAPI_DRS_GetBaseProfile(hSession, &hProfile);
            if (status != NVAPI_OK) 
            {
                return;
            }
            NVDRS_SETTING drsSetting1 = {0};
            drsSetting1.version = NVDRS_SETTING_VER;
            drsSetting1.settingId = SHIM_MCCOMPAT_ID;
            drsSetting1.settingType = NVDRS_DWORD_TYPE;
            NVDRS_SETTING drsSetting2 = {0};
            drsSetting2.version = NVDRS_SETTING_VER;
            drsSetting2.settingId = SHIM_RENDERING_MODE_ID;
            drsSetting2.settingType = NVDRS_DWORD_TYPE;
            NVDRS_SETTING drsSetting3 = {0};
            drsSetting3.version = NVDRS_SETTING_VER;
            drsSetting3.settingId = SHIM_RENDERING_OPTIONS_ID;
            drsSetting3.settingType = NVDRS_DWORD_TYPE;
            drsSetting1.u32CurrentValue = SHIM_MCCOMPAT_ENABLE;
            drsSetting2.u32CurrentValue = SHIM_RENDERING_MODE_ENABLE;
            drsSetting3.u32CurrentValue = SHIM_RENDERING_OPTIONS_DEFAULT_RENDERING_MODE;
            status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting1);
            if (status != NVAPI_OK) 
            {
                return;
            }
            status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting2);
            if (status != NVAPI_OK) 
            {
                return;
            }
            status = NvAPI_DRS_SetSetting(hSession, hProfile, &drsSetting3);
            if (status != NVAPI_OK) 
            {
                return;
            }
            // (5) Now we apply (or save) our changes to the system
            status = NvAPI_DRS_SaveSettings(hSession);
            if (status != NVAPI_OK) 
            {
                return;
            }
            // (6) We clean up. This is analogous to doing a free()
            NvAPI_DRS_DestroySession(hSession);
            hSession = 0;
            NvAPI_Unload();
        }
        ~nVidia()
        {
        }
    };

    // Global, so this gets instantiated with no other outside code.
    nVidia gNvApi;

}

It is however not GPU independent.

from mage-v0.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.