问题描述
我正在跟踪DX示例& MSDN引用,但我现在打了墙。
I am following a DX sample & MSDN reference, but I hit a wall now.
我从D3D11CreateDeviceAndSwapChain()获取E_InvalidArg的HRESULT。
我知道这是IDXGIAdapter我传递,因为它工作,如果我改变为null。
I get the HRESULT of E_InvalidArg from D3D11CreateDeviceAndSwapChain().I know it is the IDXGIAdapter I passed, since it works if I change it to null.
我不知道什么是我的初始化错了。也许有更好的知识的人知道我做错了什么。这是:
I cannot figure out what is wrong with my initialization. Maybe someone with better knowledge knows what I did wrong. Here it is:
vars:
vector<IDXGIAdapter1*> vAdapters;
IDXGIAdapter1* selectedVAdapter; // Constructor inits this to null
方法:
void refreshVideoAdapters(){
IDXGIAdapter1* pAdapter;
IDXGIFactory1* pFactory=NULL;
uint lastID=0;
if(selectedVAdapter){
DXGI_ADAPTER_DESC1* desc=NULL;
selectedVAdapter->GetDesc1(desc);
lastID=desc->DeviceId;
releaseVideoAdapter();
}
if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))) return;
for(uint i=0; pFactory->EnumAdapters1(i, &pAdapter)!=DXGI_ERROR_NOT_FOUND; i++){
vAdapters.push_back(pAdapter);
if(lastID){
DXGI_ADAPTER_DESC1* desc=NULL;
pAdapter->GetDesc1(desc);
if(lastID==desc->DeviceId){
selectedVAdapter=pAdapter;
lastID=0;
}
}
}
if(pFactory) pFactory->Release();
}
void releaseVideoAdapter(){
for(uint i=0; i<vAdapters.size(); i++){
vAdapters[i]->Release();
vAdapters[i]=NULL;
}
vAdapters.clear();
selectedVAdapter=NULL;
}
IDXGIAdapter1* getVideoAdapter(){return selectedVAdapter;}
bool setVideoAdapter(uint num=0){
if(num<vAdapters.size()){
selectedVAdapter=vAdapters[num];
return 1;
}
return 0;
}
呼叫的相关部分:
...
D3D_FEATURE_LEVEL featureLevels[]={
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_9_3,
};
uint featuresSize=ARRAYSIZE(featureLevels);
D3D_DRIVER_TYPE driverTypes[]={
D3D_DRIVER_TYPE_HARDWARE,
D3D_DRIVER_TYPE_WARP,
D3D_DRIVER_TYPE_REFERENCE,
};
uint driversSize=ARRAYSIZE(driverTypes);
refreshVideoAdapters();
setVideoAdapter();
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory( &sd, sizeof( sd ) );
sd.BufferCount = 1;
sd.BufferDesc.Width = 42;
sd.BufferDesc.Height = 42;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
HRESULT success=D3D11CreateDeviceAndSwapChain(
selectedVAdapter, driver, NULL, flag, featureLevels, featuresSize,
D3D11_SDK_VERSION, &sd, &swapChain, &deviceInterface,
&selectedFeatureLevel, &deviceContext);
...
推荐答案
你没有显示整个D3D11CXreateDeviceAndSwapChain()调用,所以我可以猜测 - 你是否注意到?
You didn't show the entire D3D11CXreateDeviceAndSwapChain() call, so I can just guess -- did you heed that paragraph from the docs?
很容易陷入困境,因为嘿,我想让设备使用硬件支持: - )
Easy to get trapped by that one, since "hey, I want the device to use hardware support" :-)
这篇关于创建交换链失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!