1

我在调用 CreateSwapChain 时收到 DXGI_ERROR_INVALID_CALL。这是我创建命令队列的代码。

D3D12_COMMAND_QUEUE_DESC cqDesc = {};
cqDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
cqDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;

hr = g_pDevice->CreateCommandQueue(&cqDesc, IID_PPV_ARGS(&g_pCommandQueue));
if (FAILED(hr)) {
    return false;
}

这就是我调用 CreateSwapChain 的地方。

DXGI_MODE_DESC bBuffDesc = {}; //To describe the display model.
SecureZeroMemory(&bBuffDesc, sizeof(bBuffDesc));
bBuffDesc.Height = Height; // ** Might have to give condition for windowed mode
bBuffDesc.Width = Width;
bBuffDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bBuffDesc.RefreshRate.Denominator = Denominator;
bBuffDesc.RefreshRate.Numerator = Numerator;
bBuffDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bBuffDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
DXGI_SAMPLE_DESC sampleDesc; //To describe multi-sampling preference. 
sampleDesc.Count = 1; //We are not using multi-sampling. We take 1 sample per pixel.
sampleDesc.Quality = 0; // no antialiasing
DXGI_SWAP_CHAIN_DESC swapChainDesc = {}; //To describe the swap chain.
swapChainDesc.BufferCount = g_cnFrameBufferCount;
swapChainDesc.BufferDesc = bBuffDesc;
swapChainDesc.SampleDesc = sampleDesc;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //Tells the pipeline that this is a remder target and not a shader input.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; //Discard the buffer after calling present.
swapChainDesc.OutputWindow = hwnd;
//swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY;
//swapChainDesc.Windowed = false;

if (g_bWindowed) { // Windowed mode
    swapChainDesc.Windowed = true;
}
else { //Full-Screen mode
    swapChainDesc.Windowed = false;
}


IDXGISwapChain * tempSwapChain = nullptr;

hr = dxgiFactory->CreateSwapChain(g_pCommandQueue, &swapChainDesc, &tempSwapChain);

我的hr返回上述错误。任何帮助,将不胜感激。

更新(问题仍然存在)

  • 删除了亚当在评论中指出的对 SecureZeroMemory 的不必要使用
  • 发现 hr 返回 S_OK 窗口模式。似乎问题与全屏模式有关
4

1 回答 1

3

首先,您应该打开调试层以获得更有意义的消息,并在创建工厂时D3D12GetDebugInterface设置标志。DXGI_CREATE_FACTORY_DEBUG

您也应该尝试一下,CreateSwapChainForHwnd因为CreateSwapChain它已接近弃用。对于全屏模式,它有一个单独的参数。在这两种情况下,您需要标志DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH才能成功。推荐的做法是创建一个窗口化的交换链,然后使用SetFullScreenState,因为 Windows 无论如何都会拒绝你的切换,这必须处理。

于 2016-03-02T18:38:37.837 回答