`创建DirectX 10设备和交换链时E_FAIL`-_com_error



我正在学习一些简单的DX教程,并且遇到了早期的障碍。我正在使用一台旧笔记本电脑和一台新电脑,所以我使用d3d10_1.lib,它可以让我使用9功能集。然而,PC确实一直支持DX11,所以那里应该没有什么问题。

因此,以下是它失败的功能:

bool DirectX9Renderer::Initialise(HWND* handle)
{
    //window handle
    hWnd = handle;
    //get window dimensions
    RECT rc;
    GetClientRect( *hWnd, &rc );
    UINT width = rc.right - rc.left;
    UINT height = rc.bottom - rc.top;
    DXGI_SWAP_CHAIN_DESC swapChainDesc;
    ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
    //set buffer dimensions and format
    swapChainDesc.BufferCount = 2;
    swapChainDesc.BufferDesc.Width = width;
    swapChainDesc.BufferDesc.Height = height;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;;
    //set refresh rate
    swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
    swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
    //sampling settings
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.SampleDesc.Count = 1;
    //output window handle
    swapChainDesc.OutputWindow = *hWnd;
    swapChainDesc.Windowed = true;    
    HRESULT result = D3D10CreateDeviceAndSwapChain1( // this is line 57
        NULL, 
        D3D10_DRIVER_TYPE_HARDWARE,
        NULL, 
        D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG,
        D3D10_FEATURE_LEVEL_9_1,
        D3D10_1_SDK_VERSION,
        &swapChainDesc, 
        &pSwapChain,
        &pD3DDevice
    );
    if(FAILED(result))
    {
        return FatalError("D3D device creation failed");
    }
            // there's more stuff after this, but I don't get that far
    }

因此,对D3D10CreateDeviceAndSwapChain1的调用失败,并返回帮助较小的错误代码E_FAIL

调试输出中也有一行:

First-chance exception at 0x770f56c4 in TileTest.exe: Microsoft C++ exception: _com_error at memory location 0x00b6e8d4..

我尝试过使用D3D10_DRIVER_TYPE_REFERENCE和不同的D3D10_FEATURE_LEVEL_xx值,但似乎不起作用。

我认为问题可能与我发送的D3D10_CREATE_DEVICE_FLAG有关。我将D3D10_CREATE_DEVICE_SINGLETHREADED | D3D10_CREATE_DEVICE_DEBUG更改为0,现在它可以工作了。

我尝试在VMware虚拟机中创建设备。它失败了(设备保持为NULL),直到我将请求的FEATURE_LEVEL从D3D10_FEATURE_LEVEL_10_1更改为D3D10_FEATURE_LEVEL_9_3。我听说这也有助于其他电脑使用真正的硬件。

相关内容

最新更新