链接 Cuda (cudart.lib) 使 DXGI DuplicateOutput1() 失败

Linking Cuda (cudart.lib) makes DXGI DuplicateOutput1() fail

在我的项目中添加 cudart.lib 后,我对 IDXGIOutput5::DuplicateOutput1() 的调用失败,错误为 0x887a0004 (DXGI_ERROR_UNSUPPORTED)。

我在 Visual Studio 2019 工作,我的监视器复制代码是经典的:

hr = output5->DuplicateOutput1(this->dxgiDevice, 0, sizeof(supportedFormats) / sizeof(DXGI_FORMAT), supportedFormats, &this->dxgiOutputDuplication);

目前我尝试用 cuda 做的唯一一件事就是简单地列出 Cuda 设备:

 int nDevices = 0;

 cudaError_t error = cudaGetDeviceCount(&nDevices);

 for (int i = 0; i < nDevices; i++) {

            cudaDeviceProp prop;
            cudaGetDeviceProperties(&prop, i);

            LOG_FUNC_DEBUG("Graphic adapter : Descripion: %s, Memory Clock Rate : %d kHz, Memory Bus Width : %u bits",
                prop.name,
                prop.memoryClockRate,
                prop.memoryBusWidth
            );
}

此外,这段代码之后很晚才被调用我尝试使用 DXGI 开始监视器复制。

我的应用程序中的每件事似乎都是正确的:我调用了 SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2),但我没有 运行 在离散 GPU 上(参见 [https://support.microsoft.com/en-us/help/3019314/error-generated-when-desktop-duplication-api-capable-application-is-ru][1]

顺便说一句,它曾经有效,如果我只是从链接器输入中删除 "so simple" Cuda 调用和 cudart.lib,它就会再次有效!

我真的不明白是什么导致了这种奇怪的行为,知道吗?

...after I added cudart.lib in my project

当您 link CUDA 库时,您会强制您的应用程序在独立 GPU 上 运行。你已经知道应该避免这种情况,但你仍然通过这个 link 来强制它。

...and I'm not running on e discrete GPU...

你是,静态 link 到 CUDA 是提示使用 dGPU 的特定情况。

有些系统的桌面复制对 dGPU 不起作用,而您的系统似乎就是其中之一。即使不明显,您也会看到 [NVIDIA] 设计的行为。

(但是也有其他系统,其中桌面复制针对 dGPU 而不是针对 iGPU)。

您的潜在解决方案是 this line:

Application is not directly linked against cuda.lib or cudart.lib or LoadLibrary to dynamically load the nvcuda.dll or cudart*.dll and uses GetProcAddress to retrieve function addresses from nvcuda.dll or cudart*.dll.