c# – 强制硬件加速渲染
我有一个用C编写的OpenGL库,它使用C#应用程序使用C/C++LI适配器.我的问题是,如果将应用程序用于使用Nvidia Optimus技术的笔记本电脑,该应用程序将不会使用硬件加速并失败.
我试图使用在Nvidias文档http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf中找到的信息 对于我们来说,使用配置文件不是一个好选择,因为我们需要确保使用nvidia硬件. 有没有一些C#应用程序可以强制Optimus使用Nvidia芯片组而不是集成的英特尔芯片组? 解决方法
如果您的软件在Intel上失败,那么您将无法在50%的笔记本电脑上运行它.所以我建议修改这个.
不如说,您可以通过代码完美地创建配置文件.只需使用NvAPI. NvAPI_Status status; // (0) Initialize NVAPI. This must be done first of all status = NvAPI_Initialize(); if (status != NVAPI_OK) PrintError(status,__LINE__); // (1) Create the session handle to access driver settings NvDRSSessionHandle hSession = 0; status = NvAPI_DRS_CreateSession(&hSession); if (status != NVAPI_OK) PrintError(status,__LINE__); // (2) load all the system settings into the session status = NvAPI_DRS_LoadSettings(hSession); if (status != NVAPI_OK) PrintError(status,__LINE__); // (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) PrintError(status,__LINE__); 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; if( ForceIntegrated ){ drsSetting1.u32CurrentValue = SHIM_MCCOMPAT_INTEGRATED; drsSetting2.u32CurrentValue = SHIM_RENDERING_MODE_INTEGRATED; drsSetting3.u32CurrentValue = SHIM_RENDERING_OPTIONS_DEFAULT_RENDERING_MODE | SHIM_RENDERING_OPTIONS_IGPU_TRANSCODING; }else{ 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) PrintError(status,__LINE__); status = NvAPI_DRS_SetSetting(hSession,&drsSetting2); if (status != NVAPI_OK) PrintError(status,&drsSetting3); if (status != NVAPI_OK) PrintError(status,__LINE__); // (5) Now we apply (or save) our changes to the system status = NvAPI_DRS_SaveSettings(hSession); if (status != NVAPI_OK) PrintError(status,__LINE__); // (6) We clean up. This is analogous to doing a free() NvAPI_DRS_DestroySession(hSession); hSession = 0; 在启动时,测试您的个人资料是否存在.如果没有,创建它(你可能也必须重新启动自己). 编辑:看起来有一个更简单的方法.来自GLFW 3源代码: // Applications exporting this symbol with this value will be automatically // directed to the high-performance GPU on nVidia Optimus systems // GLFWAPI DWORD NvOptimusEnablement = 0x00000001; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |