DirectX12 E_NOINTERFACE error while trying to get IDXGIDevice*

26 Views Asked by At

I'm trying to initialize Direct3D and Direct2D in my code, but I'm encountering an issue when trying to obtain the IDXGIDevice interface from my ID3D12Device8 interface. When I attempt to query the interface, it returns the HRESULT E_NOINTERFACE, indicating that the interface is not supported. However, I need the IDXGIDevice interface to create a Direct2D device.

Here's a snippet of my code:

        ID3D12Device8* device = nullptr;
    IDXGIDevice* dxgiDevice = nullptr;

    ID2D1Device* d2dDevice = nullptr;
    ID2D1DeviceContext* d2dContext = nullptr;

    IDXGIFactory7* dxgiFactory = nullptr;
    ID2D1Factory* d2dFactory = nullptr;
    IDXGIAdapter4* dxgiAdapter = nullptr;
    DXGI_ADAPTER_DESC1 g_adapterDesc{};

    DescriptorHeap g_rtvHeap;
    DescriptorHeap g_dsvHeap;
    DescriptorHeap g_srvHeap;
    DescriptorHeap g_uavHeap;

    void Initialize()
    {
        THROW_IF_FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED));
        THROW_IF_FAILED(MFStartup(MF_VERSION) == S_OK);
#ifdef _DEBUG
        {
            ID3D12Debug* debugController;
            D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
            debugController->EnableDebugLayer();
        }
#endif
        if (device)
            Shutdown();
        {
            // Create factory
            THROW_IF_FAILED(CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory)));
            // Enumerate adapters and find suitable
            IDXGIAdapter1* adapter1 = nullptr;
            for (UINT i = 0; dxgiFactory->EnumAdapters1(i, &adapter1) != DXGI_ERROR_NOT_FOUND; ++i)
            {
                // Check if adapter supports d3d12
                if (SUCCEEDED(D3D12CreateDevice(adapter1, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device))))
                {       
                    THROW_IF_FAILED(adapter1->QueryInterface(IID_PPV_ARGS(&dxgiAdapter))); // Get adapter
                    break;
                }
            }
        }
        //auto ii = GetDXGIDevice(device);

        SET_NAME(device, L"MAIN_DEVICE");

        new (&g_rtvHeap) DescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 128);
        new (&g_dsvHeap) DescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_DSV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 128);
        new (&g_srvHeap) DescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 128);
        new (&g_uavHeap) DescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 128);

        THROW_IF_FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &d2dFactory));
        D2D1_CREATION_PROPERTIES d2dCreationProps = { D2D1_THREADING_MODE_SINGLE_THREADED, D2D1_DEBUG_LEVEL_INFORMATION };
                device->QueryInterface(IID_PPV_ARGS(&dxgiDevice));
        D2D1CreateDevice(dxgiDevice, &d2dCreationProps, &d2dDevice);
    }

I've verified that the ID3D12Device8 interface is successfully created and that the DXGI factory and adapter are also obtained without any errors. However, when I call QueryInterface on the adapter to obtain the IDXGIDevice interface, it fails with the E_NOINTERFACE HRESULT.

I would appreciate any insights into why I'm unable to retrieve the IDXGIDevice interface from the ID3D12Device8 interface and how I can resolve this issue. Thank you!

0

There are 0 best solutions below