首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DirectX 12设备在创建后立即挂起

DirectX 12设备在创建后立即挂起
EN

Stack Overflow用户
提问于 2016-02-13 12:49:19
回答 1查看 1.5K关注 0票数 1

在创建DirectX 12命令队列时,遇到了一个奇怪的错误。其他DX12应用程序能够在同一台计算机上成功启动。

我的计算机使用D3D_FEATURE_LEVEL_11_0 if块。测试用的图形卡是NVIDIA GT 740,有361.75个驱动程序。

这是正在使用的代码(最小化):

代码语言:javascript
复制
#include <Windows.h>
#include <d3d12.h>
#include <dxgi1_4.h>
#include <comdef.h>
#include <D3d12sdklayers.h>
#include <string>

#pragma comment(lib,"d3d12.lib")
#pragma comment(lib,"dxgi.lib")
#pragma comment(lib,"d3dcompiler.lib")
using namespace std;

LRESULT WINAPI WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine, int nCmdShow) {
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(nCmdShow);
    UNREFERENCED_PARAMETER(lpCmdLine);

    wchar_t* WindowClass = L"Papergate";
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
    wc.lpszClassName = WindowClass;

    if (!RegisterClassEx(&wc))
    {
        return 1;
    }

    HWND hwnd = CreateWindowEx(NULL, wc.lpszClassName, WindowClass,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL, hInstance, NULL);

    if (!hwnd)
    {
        UnregisterClass(WindowClass, hInstance);
        return 1;
    }
    ShowWindow(hwnd, SW_SHOWDEFAULT);
    UpdateWindow(hwnd);

    ID3D12Device* device;
    HRESULT result = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_12_1,
        __uuidof(ID3D12Device), (void**)&device);
    if (FAILED(result))
    {
        result = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_12_0,
            __uuidof(ID3D12Device), (void**)&device);
        if (FAILED(result))
        {
            result = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0,
                __uuidof(ID3D12Device), (void**)&device);
            if (FAILED(result)) {
                _com_error error(result);
                MessageBox(hwnd, error.ErrorMessage(),
                    (wstring(L"Error: ") + to_wstring(__LINE__)).c_str(),
                    MB_OK);
                return 2;
            }
        }
    }

    ID3D12Debug* debugInterface;
    if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugInterface))))
    {
        debugInterface->EnableDebugLayer();
    }

    D3D12_COMMAND_QUEUE_DESC commandQueueDesc;
    commandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
    commandQueueDesc.NodeMask = 0;
    commandQueueDesc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
    commandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
    ID3D12CommandQueue* commandQueue;
    result = device->CreateCommandQueue(&commandQueueDesc, __uuidof(ID3D12CommandQueue), (void**)&commandQueue);
    if (FAILED(result)) {
        _com_error error(result);
        MessageBox(hwnd, error.ErrorMessage(),
            (wstring(L"Error: ") + to_wstring(__LINE__)).c_str(), MB_OK);
        result = device->GetDeviceRemovedReason();
        error = _com_error(result);
        MessageBox(hwnd, error.ErrorMessage(),
            (wstring(L"Error: ") + to_wstring(__LINE__)).c_str(), MB_OK);
        debugInterface->Release(); device->Release(); return 2;
    }

    MSG msg;
    ZeroMemory(&msg, sizeof(MSG));
    while (GetMessage(&msg, NULL, 0, 0) && msg.message != WM_QUIT)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    commandQueue->Release();
    device->Release();
    UnregisterClass(WindowClass, hInstance);
    return 0;
}

我在第97行和第102行分别得到以下错误:

代码语言:javascript
复制
The GPU device instance has been suspended. Use GetDeviceRemovedReason to determine the appropriate action.

第二个错误:

代码语言:javascript
复制
The GPU will not respond to more commands, most likely because some other application submitted invalid commands.
The calling application should re-create the device and continue.
EN

回答 1

Stack Overflow用户

发布于 2016-02-13 18:16:10

这似乎很可能是某种类型的驱动程序错误。检查硬件是否有更新的驱动程序。您应该尝试在这个Direct3D12中使用VSIX游戏模板,看看它们是否遇到了相同的问题(有关模板的更多细节,请参见这篇博客文章)。

您为不同功能级别调用D3D12CreateDevice的级联模式是不寻常的,也不是必要的。如果您的应用程序可以在Direct3D功能级别11.0或更高级别上运行,那么只需使用D3D_FEATURE_LEVEL_11_0一次。您应该将所支持的最低功能级别传递给此函数。

如果Direct3D 12设备确实支持更高的功能级别,则可以通过检查各个特性或使用D3D12_FEATURE_FEATURE_LEVELS来使用CheckFeatureSupport来发现这一点。

代码语言:javascript
复制
// Create the DX12 API device object.
DX::ThrowIfFailed(D3D12CreateDevice(
    adapter.Get(),
    m_d3dMinFeatureLevel,
    IID_PPV_ARGS(&m_d3dDevice)
    ));

// Determine maximum supported feature level for this device
static const D3D_FEATURE_LEVEL s_featureLevels[] =
{
    D3D_FEATURE_LEVEL_12_1,
    D3D_FEATURE_LEVEL_12_0,
    D3D_FEATURE_LEVEL_11_1,
    D3D_FEATURE_LEVEL_11_0,
};

D3D12_FEATURE_DATA_FEATURE_LEVELS featLevels =
{
    _countof(s_featureLevels), s_featureLevels, D3D_FEATURE_LEVEL_11_0
};

HRESULT hr = m_d3dDevice->CheckFeatureSupport(D3D12_FEATURE_FEATURE_LEVELS,
    &featLevels, sizeof(featLevels));
if (SUCCEEDED(hr))
{
    m_d3dFeatureLevel = featLevels.MaxSupportedFeatureLevel;
}
else
{
    m_d3dFeatureLevel = m_d3dMinFeatureLevel;
}

请记住,D3D_FEATURE_LEVEL_12_0D3D_FEATURE_LEVEL_12_1本质上只是D3D_FEATURE_LEVEL_11_1,一些可选特性是强制性的。如果您的应用程序已经在11.x检查它们,那么就没有理由“要求”12.0或12.1。见MSDN

对于绝大多数Direct3D 12游戏和应用程序来说,D3D_FEATURE_LEVEL_11_0D3D_FEATURE_LEVEL_11_1都是不错的选择。请记住,虽然AMD/ATI支持功能级别11.1非常早,NVIDIA DirectX 11部件只支持11.0与一些可选的功能一段时间。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35380051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档