gpt4 book ai didi

c++ - 创建交换链失败

转载 作者:搜寻专家 更新时间:2023-10-31 00:17:46 26 4
gpt4 key购买 nike

我正在关注 DX 示例和 MSDN 引用,但我现在碰壁了。

我从 D3D11CreateDeviceAndSwapChain() 获得 E_InvalidArg 的 HRESULT。我知道这是我传递的 IDXGIAdapter,因为如果我将它更改为 null,它就可以工作。

我无法弄清楚我的初始化有什么问题。也许知识渊博的人知道我做错了什么。在这里:

变量:

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() 调用,所以我只能猜测——您是否注意到 the docs 中的那段内容? ?

If you set the pAdapter parameter to a non-NULL value, you must also set the DriverType parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value, D3D11CreateDeviceAndSwapChain returns an HRESULT of E_INVALIDARG.

很容易被那个困住,因为“嘿,我希望设备使用硬件支持”:-)

关于c++ - 创建交换链失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12618933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com