delphi - 强制配备 nVidia Optimus 的系统为我的应用程序使用真正的 GPU?

标签 delphi opengl nvidia

我希望我的应用程序始终使用 nVidia Optimus 笔记本电脑上的真实 GPU 运行。

来自“在 Optimus 系统上启用高性能图形渲染”,( http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf ):

Global Variable NvOptimusEnablement (new in Driver Release 302) Starting with the Release 302 drivers, application developers can direct the Optimus driver at runtime to use the High Performance Graphics to render any application–even those applications for which there is no existing application profile. They can do this by exporting a global variable named NvOptimusEnablement. The Optimus driver looks for the existence and value of the export. Only the LSB of the DWORD matters at this time. A value of 0x00000001 indicates that rendering should be performed using High Performance Graphics. A value of 0x00000000 indicates that this method should be ignored. Example Usage:

extern "C" {   _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; }

问题是我想使用 Delphi 来完成此操作。据我所知,即使存在一些黑客行为,Delphi 也不支持变量导出。我确实尝试了其中一些,但无法使其发挥作用。

在同一个 nvidia 文档中,我读到可以通过静态链接到少数列出的 dll 之一来强制使用正确的 GPU。但我不想链接到我不使用的 dll。 (为什么 opengl.dll 不是其中之一,我无法理解。)一个简单的导出变量看起来更干净。

最佳答案

From what I've read Delphi does not support export of variables.

这个说法是不正确的。下面是展示如何从 Delphi DLL 导出全局变量的最简单示例:

library GlobalVarExport;

uses
  Windows;

var
  NvOptimusEnablement: DWORD;

exports
  NvOptimusEnablement;

begin
  NvOptimusEnablement := 1;
end.

我认为你的问题是你这样写的:

library GlobalVarExport;

uses
  Windows;

var
  NvOptimusEnablement: DWORD=1;

exports
  NvOptimusEnablement;

begin
end.

编译失败并出现以下错误:

E2276 Identifier 'NvOptimusEnablement' cannot be exported

我不明白为什么编译器不喜欢第二个版本。这可能是一个错误。但第一个版本中的解决方法很好。

关于delphi - 强制配备 nVidia Optimus 的系统为我的应用程序使用真正的 GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15372931/

相关文章:

delphi - 如何将格式化为以下格式的字符串转换为TDateTime:15h44m28s?

performance - Delphi 6 应用程序在 Windows 7 上运行缓慢

delphi - 如何记录导致异常的源行并添加自定义信息?

image - OpenGL 与 GLUT——malloc 错误

gpu - GPU共享内存很小-我该怎么办?

德尔福: Handling the fact that Strings are not Objects

c++ - libGL 堆使用

c++ - OpenGL 顶点从侧面被剪切

python - 对 nvidia triton 使用字符串参数

cuda - 用 CUDA 求解二维扩散(热)方程