我最近因为我的d3d11应用程序启动缓慢而烦恼,所以我开始调查并发现罪魁祸首是D3D11CreateDeviceAndSwapChain。这一次通话大约需要1.5秒。这对我来说似乎很慢。这也是你的经历吗?
这是设置代码:
DXGI_SWAP_CHAIN_DESC swap_chain_desc = {};
swap_chain_desc.BufferDesc.Width = window->window_width;
swap_chain_desc.BufferDesc.Height = window->window_height;
swap_chain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.BufferCount = 2;
swap_chain_desc.OutputWindow = window->window_handle;
swap_chain_desc.BufferDesc.RefreshRate.Numerator = 60;
swap_chain_desc.BufferDesc.RefreshRate.Denominator = 1;
swap_chain_desc.Windowed = true;
swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
D3D_FEATURE_LEVEL supported_feature_level;
UINT flags = 0;
#ifdef DEBUG
flags = D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, &feature_level, 1, D3D11_SDK_VERSION,
&swap_chain_desc, &context.swapChain, &context.device, &supported_feature_level, &context.context);
答案 0 :(得分:0)
首先,您应该考虑D3D11CreateDeviceAndSwapChain
已弃用,设备应该单独创建,并且您根据应用程序的内容(hwnd vs core window for ex)创建了一些交换链变体。
创建设备速度缓慢没有任何理由,但过去使用设备创建缓慢的经验是由于像Steam这样的应用程序挂起了d3d。最简单的确认方法是对初始化进行性能分析捕获,并查看所涉及的callstacks和DLLs,即设备创建的子代。