D3D12 bug:从 .net48 更新到 .net7 后尝试在 D3D12 中创建设备 (D3D12CreateDevice) 时出现 Poco::NotFoundException

Sol*_*eil 5 .net c# c++ directx-12

我遇到了一个异常,我不知道如何解决/理解。它来自D3D12CreateDevice,我没有来源和控制权。

语境

我有一个带有 WPF (.net7) 和 c 代码的应用程序,它创建一个 D3D12 资源(窗口),该资源被注入到 XAML 对象(例如,矩形)中,并且它们可以互操作。代码工作正常,直到我从 .net48 更新到 .net5+(确切地说是 .net7)。

我没有更改代码,而是更改了项目文件。

我重新安装了GPU驱动(使用RTX4090),但没有解决问题。

D3D12 代码可以很好地与其他 WPF 上下文配合使用,但不能与其他上下文配合使用,此外,互操作代码似乎不涉及这种情况,因为我们离它还很远;所以我真的很困惑。

我的问题:

  1. 怎么解决这个问题?
  2. 我是否应该考虑 .net5+ 不适合这种互操作性并考虑恢复到 .net48 ?

更多细节:

ShutterModeler.exe 中的 0x00007FF8A6EECD29 处抛出异常:Microsoft C++ 异常:内存位置 0x0000006DE436E670 处的 Poco::NotFoundException。

// Helper function for acquiring the first available hardware adapter that supports Direct3D 12.
// If no such adapter can be found, *ppAdapter will be set to nullptr.
_Use_decl_annotations_
void DX12CudaSample::GetHardwareAdapter(IDXGIFactory2* pFactory, IDXGIAdapter1** ppAdapter)
{
    ComPtr<IDXGIAdapter1> adapter;
    *ppAdapter = nullptr;

    for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != pFactory->EnumAdapters1(adapterIndex, &adapter); ++adapterIndex)
    {
        DXGI_ADAPTER_DESC1 desc;
        adapter->GetDesc1(&desc);
        bool isSoftwareGPU = desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE;
        if (isSoftwareGPU)
            continue;

        auto uuidDev = _uuidof(ID3D12Device);
        auto currentAdapter = adapter.Get();
        auto status = D3D12CreateDevice(currentAdapter, D3D_FEATURE_LEVEL_11_0, uuidDev, nullptr); //this line throws
        //if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_11_0, _uuidof(ID3D12Device), nullptr)))
        if(SUCCEEDED(status))
            break;
    }

    *ppAdapter = adapter.Detach();
}
Run Code Online (Sandbox Code Playgroud)

看来找到了正确的改编:

  desc    {Description=0x0000006de437c3b0 L"NVIDIA GeForce RTX 4090" VendorId=4318 DeviceId=9860 ...} DXGI_ADAPTER_DESC1
Run Code Online (Sandbox Code Playgroud)

更多细节:

  Description 0x0000006de437c3b0 L"NVIDIA GeForce RTX 4090"   wchar_t[128]
  VendorId 4318   unsigned int
  DeviceId    9860    unsigned int        SubSysId    375066846   unsigned int
  Revision    161 unsigned int
  DedicatedVideoMemory    25329401856 unsigned __int64
  DedicatedSystemMemory   0   unsigned __int64
  SharedSystemMemory  68674734080 unsigned __int64
  AdapterLuid {LowPart=14177306 HighPart=0 }  _LUID       Flags   0   unsigned int
Run Code Online (Sandbox Code Playgroud)

和:

当前适配器 = 0x000002a4dcfd3f50

从我的代码到异常的调用堆栈:

KernelBase.dll!RaiseException() Unknown
MessageBus.dll!00007fffa447cb4d()   Unknown
MessageBus.dll!00007fffa427af4e()   Unknown
MessageBus.dll!00007fffa41fe097()   Unknown
MessageBus.dll!00007fffa4210919()   Unknown
MessageBus.dll!00007fffa420ac95()   Unknown
MessageBus.dll!00007fffa42085d0()   Unknown
MessageBus.dll!00007fffa420fe91()   Unknown
nvwgf2umx.dll!00007fff876e8da7()    Unknown
nvwgf2umx.dll!00007fff876ea202()    Unknown
nvwgf2umx.dll!00007fff876d9e64()    Unknown
nvwgf2umx.dll!00007fff878dc16b()    Unknown
nvwgf2umx.dll!00007fff87bb8a70()    Unknown
nvwgf2umx.dll!00007fff88c9725b()    Unknown
D3D12Core.dll!NDXGI::CUMDAdapter::OpenAdapter<0>(void)  Unknown
D3D12Core.dll!NDXGI::CUMDAdapter::CUMDAdapter(struct IDXCoreAdapterFactory *,struct IDXCoreAdapter *,struct _LUID)  Unknown
D3D12Core.dll!CCreateDeviceCache::LoadUMD(void) Unknown
D3D12Core.dll!CCreateDeviceCache::ResolveUMDAndVersion(class std::vector<struct SupportedVersion,class std::allocator<struct SupportedVersion> > &,class std::shared_ptr<class NDXGI::CUMDAdapter> &,unsigned __int64 *)    Unknown
D3D12Core.dll!D3D12CoreCreateDevice()   Unknown
D3D12Core.dll!D3D12ValidateAndCreateDevice()    Unknown
D3D12.dll!D3D12CreateDeviceImpl(struct IUnknown *,enum D3D_FEATURE_LEVEL,struct _GUID const &,void * *) Unknown
D3D12.dll!D3D12CreateDevice()   Unknown
D3D12CudaUpdate.dll!DX12CudaSample::GetHardwareAdapter(IDXGIFactory2 * pFactory, IDXGIAdapter1 * * ppAdapter) Line 56   C++
Run Code Online (Sandbox Code Playgroud)

来源

我无法分享确切的代码,因为我找不到用较小的项目重现错误的方法,但我正在使用此解决方案中的 D3D12 代码:

https://github.com/mprevot/CudaD3D12Update/blob/master/DX12CudaSample.cpp

获取第一个 D3D12 适配器的代码与 MSFT 中的代码相同:

https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-d3d12createdevice

小智 1

看起来这是 Nvidia 驱动程序目前的一个已知问题:https://forums.developer.nvidia.com/t/poco-notfoundexception- thrown-in-driver-version-531-18/245285

可悲的是,我认为当前唯一可行的解​​决方案是回滚驱动程序。