我们正在使用我们的C ++应用程序,在使用Nvidia显卡的某些系统上使用WGL进行窗口创build(和OpenGL进行渲染)时遇到严重的性能问题。 只要调用ChoosePixelFormat或SetPixelFormat ,一旦创build了窗口,或者更确切地说,一旦窗口被调用,内存分配在整个生命周期内就会显着变慢。 这发生在我们可以访问的许多不同的系统上,但对于Windows 8.1 Pro 64位和Windows 10 Enterprise 64位上的Quadro M6000 12 GB(驱动程序版本385.69)和Titan XP (驱动程序版本387.92)最为明显。 在较低的程度上,对于GeForce显卡和Windows 7 Professional 64位,这种效果也是可以测量的。
我已经做了一个小testing应用程序来certificate这个问题。 我们运行一个昂贵的作业,涉及大量的内存分配,然后用WGL创build一个窗口,调用ChoosePixelFormat,删除窗口,然后再次运行相同的昂贵内存分配。 内存分配被定时并输出到控制台。 在我们testing过的所有系统上(六个不同的卡,三个操作系统),在调用ChoosePixelFormat之后,内存分配的可测量性(5%到20%)要慢一些。 但是,当我们将Quadro或Titan Xp放入系统时,ChoosePixelFormat之后的内存分配占用了以前的300%以上。
一些testing结果(我们在系统之间交换了卡片来覆盖几乎所有的组合,但是我们没有保留所有的基准,但这是一个有意义的子集):
Titan Xp, Windows 8.1 Pro 64 bit Before Window Creation Testing memory allocation performance 1 / 3: 5.20743 seconds Testing memory allocation performance 2 / 3: 5.60933 seconds Testing memory allocation performance 3 / 3: 5.4247 seconds After Window Creation Testing memory allocation performance 1 / 3: 18.0398 seconds Testing memory allocation performance 2 / 3: 17.9902 seconds Testing memory allocation performance 3 / 3: 17.9052 seconds GTX 770, Windows 7 Professional 64 bit Before Window Creation Testing memory allocation performance 1 / 3: 4.66427 seconds Testing memory allocation performance 2 / 3: 4.65927 seconds Testing memory allocation performance 3 / 3: 4.62726 seconds After Window Creation Testing memory allocation performance 1 / 3: 5.69533 seconds Testing memory allocation performance 2 / 3: 5.71333 seconds Testing memory allocation performance 3 / 3: 5.72833 seconds GTX 1080, Windows 8.1 Pro 64 bit Before Window Creation Testing memory allocation performance 1 / 3: 5.35666 seconds Testing memory allocation performance 2 / 3: 5.37008 seconds Testing memory allocation performance 3 / 3: 5.36607 seconds After Window Creation Testing memory allocation performance 1 / 3: 5.7112 seconds Testing memory allocation performance 2 / 3: 5.69939 seconds Testing memory allocation performance 3 / 3: 5.71902 seconds
我记得一个古老的把戏,我会拉我的Optimus笔记本电脑,使自我写的应用程序自动使用分立的Nvidia GPU:重命名可执行文件为wow.exe 。 我试过这个,当然,它的工作。 性能问题在我们的实际应用程序和testing应用程序中都没有了。 在Titan Xp上,调用ChoosePixelFormat之后的内存分配比调用之前的奇迹更快。 我非常确定这是因为“魔兽世界”的video驱动程序中的特殊分支,它避开了一些使我们的生活变得艰难的“特征”。 所以现在我们可以在一天之内打电话给我们的软件,名为wow.exe,但是在某些时候,客户可能会问这个名字代表什么,我们将不得不提出一个聪明的缩写或重新命名。 这不是一个永久的解决scheme,而是一个非常奇怪的debugging结果。 (“什么显卡供应商不希望你知道:用这个简单的技巧提高3D应用程序的性能!”)
在debugging链接的testing应用程序时,可以看到,在窗口创build期间,一个或多个线程由窗口销毁后生活的video驱动程序产生。 我们怀疑他们在某种程度上参与了这一切。 但是,我们没有时间和预算来进一步调查。
除了命名我们的软件wow.exe,降级到GTX 1080,或等待Nvidia回答我们的支持查询 – 他们在四年内还没有完成 – 我们现在有什么select? 有没有人遇到过,并成功地克服了这个问题? 在Windows 7 / 8.1 / 10上使用WGL创build窗口和OpenGL(4.5核心)上下文时,有没有办法绕过ChoosePixelFormat和SetPixelFormat? (我们也尝试用GLFW设置窗口,但是我敢肯定,这是在引擎盖下调用WGL的 – 结果是一样的。)另外,我们会对Maxwell或Pascal Quadro卡的任何评论感兴趣或者不会遇到这些问题的Titan Xp。 也许在我们的设置一个小的变化可以做的伎俩。
PS:虽然这个问题听起来有些离奇,但我们并不是第一个遇到这个问题的人。 之前已经描述过 ,但显然Nvidia没有时间回复或解决问题。