我尝试为 d3d12 创建一个交换链,但发现不能对 d3d11 使用相同的函数,但即使正确的函数对我来说也不起作用。
COM<IDXGISwapChain4> swapchain(NULL); {
COM<IDXGISwapChain1> temp(NULL);
LOG(factory->CreateSwapChainForHwnd(queue.ptr, hwnd, (DXGI_SWAP_CHAIN_DESC1[]){{
.Width = 1000, .Height = 600,
.Format = DXGI_FORMAT_R8G8B8A8_UNORM,
.SampleDesc = (DXGI_SAMPLE_DESC){
.Count = 1,
.Quality = 0,
},
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
.BufferCount = 2,
.SwapEffect = DXGI_SWAP_EFFECT_DISCARD,
.Flags = 0
}}, NULL, NULL, &temp.ptr)); d3dmsg();
if(temp.ptr) LOG(temp->QueryInterface(IID_PPV_ARGS(&swapchain.ptr)));
}
我确实使用 _com_error 将错误写入控制台,甚至使用 d3d12debug 来启用调试层。
hresult 的错误消息显示The application made a call that is invalid. Either the parameters of the call or the state of some object was incorrect. Enable the D3D debug layer in order to see details via debug messages.
,但我不明白我到底做错了什么,我也尝试使用正确的结构,但也没有用。
我自己正在处理 d3d 调试消息,但它还没有将任何内容打印到控制台,我不知道是否也失败了。
auto d3dmsg = [&info_queue](){
UINT64 messageCount = info_queue->GetNumStoredMessages();
for (UINT64 i = 0; i < messageCount; ++i) {
SIZE_T messageLength = 0;
info_queue->GetMessage(i, nullptr, &messageLength);
// Allocate space for the message
D3D12_MESSAGE* message = (D3D12_MESSAGE*)malloc(messageLength);
if (message != nullptr) {
// Get the message
info_queue->GetMessage(i, message, &messageLength);
if (message->Severity == D3D12_MESSAGE_SEVERITY_ERROR|D3D12_MESSAGE_SEVERITY_WARNING) {
printf("D3D12 Error: %s\n", message->pDescription);
}
// Free the allocated memory
free(message);
}
}
};
我想了解我做错了什么。我只是想写一个 hello_triangle。
根据您的代码,您正在使用
DXGI_SWAP_EFFECT_DISCARD
。根据文档:DXGI_SWAP_EFFECT 枚举
我建议您可以尝试使用“flip”模型而不是“blt”演示模型。