gpt4 book ai didi

c++ - Direct3D 12 窗口模式强制 vsync

转载 作者:搜寻专家 更新时间:2023-10-31 01:37:15 29 4
gpt4 key购买 nike

我正在编写一个简单的 Direct3D 12 应用程序来为 Vulkan 的发布做准备,它在所有方面都按预期工作,除了一个:在带边框的窗口中运行将帧速率限制为 60fps,即使禁用了 vsync。让我感到困惑的是:全屏窗口中的同一个程序以将近 4000fps 的速度运行。

使用肮脏的自制分析器,我发现挂起发生在我的代码的这一部分,它一直等到最后一帧完成,然后才开始处理下一帧。

if (m_fence->GetCompletedValue() < endFenceValue)
{
result = m_fence->SetEventOnCompletion(endFenceValue, m_fenceEvent);
if (result != S_OK) return false;
WaitForSingleObject(m_fenceEvent, INFINITE); //Program stalls here
}
//m_fence is a pointer to an ID3D12Fence object
//endFenceValue is an unsigned long long
//m_fenceEvent is a HANDLE

用于呈现渲染帧的代码很普通:

if (m_vsync)
{
result = m_swapChain->Present(1, 0);
if (result != S_OK) return 0;
}
else
{
result = m_swapChain->Present(0, 0);
if (result != S_OK) return 0;
}

//Increase the fence value
result = m_commandQueue->Signal(m_fence, m_fenceValue);
if (result != S_OK) return 0;

return m_fenceValue++;
//m_swapChain is a pointer to an IDXGISwapChain3 object
//m_commandQueue is a pointer to an ID3D12CommandQueue object
//m_fenceValue is a HANDLE

注意:第一段代码使用上述函数的返回值作为endFenceValue

我使用的交换链是这样设置的:

swapChainDesc.BufferCount = 2; //Double buffered
swapChainDesc.BufferDesc.Width = width; //Set width
swapChainDesc.BufferDesc.Height = height; //Set height
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //32-bit back buffers
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; //Set the back buffers to be used as render targets
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; //Throw out old back buffer contents after getting a new frame
swapChainDesc.OutputWindow = window;
swapChainDesc.Windowed = !fullscreen;
//Auto-detect the refresh rate
swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 0;

//No multisampling for now
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
//Set the scan line ordering and scaling to unspecified
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
//Allow to switch between windowed and fullscreen modes
//Also changes the monitor resolution to match the width and height of the window in fullscreen mode
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

对于那些感兴趣的人,我正在使用 SDL 创建窗口,但是编写我自己的 WinMain 并没有解决问题。我还尝试在 nVidia 控制面板中检查我的 vsync 设置,退出 fl.ux(但不卸载它),并在系统属性中更改我的性能设置。

任何人都可以为此提供解释或解决方案吗?

最佳答案

Windows 10 构建版本 10586 中删除了窗口交换链的刷新率上限。

更新您的 windows,它应该会自行解决。

关于c++ - Direct3D 12 窗口模式强制 vsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34407705/

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