c++ - 在 Windows 10/DirectX 上仅在全屏模式下使用 VSYNC 撕裂(窗口模式工作正常)

标签 c++ directx directx-11 dwm vsync

我认为我的 DirectX 11 应用程序在以前的系统上运行良好(我有大约 70% 的把握)。但是现在,在 Windows 10(笔记本电脑)中我只在全屏模式下有撕裂问题(窗口模式下没有任何撕裂)。

该场景相当“繁重”(它应该针对我的应用程序进行性能测试)。当 DirectX 渲染“较重”的部分时,它会在短时间内下降到大约 50fps(我的测量可能有点不准确),然后又回到 60-61fps。奇怪的是,我没有看到“较重”部分(约 50fps)出现撕裂。

我听说它可能与 DWM 有某种关系,DWM 为窗口应用程序提供自己的同步(这就是我的程序在窗口模式下运行良好的原因?)。

我该怎么办?

交换链:

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = width;
sd.BufferDesc.Height = height;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = numerator;
sd.BufferDesc.RefreshRate.Denominator = denominator;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = *hwnd;
sd.SampleDesc.Count = sampleCount; //1 (and 0 for quality) to turn off multisampling
sd.SampleDesc.Quality = maxQualityLevel;
sd.Windowed = fullScreen ? FALSE : TRUE;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; //allow full-screen switchin

// Set the scan line ordering and scaling to unspecified.
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// Discard the back buffer contents after presenting.
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

其中numeratordenominator是根据this tutorial计算的:

...
numerator = displayModeList[i].RefreshRate.Numerator;
denominator = displayModeList[i].RefreshRate.Denominator;

它返回两个非常高的值,当彼此相除时给出大约 60(如果将它们设置为 601,我会得到相同的效果吗?):

enter image description here

我还渲染:

if(VSYNC){
    swapChain->Present(1, 0); //lock to screen refresh rate
}else{
    swapChain->Present(0, 0); //present as fast as possible
}

我错过了什么吗?还是我做错了什么?

最佳答案

我的评论作为回答:

Did you try to zero out the numerator and denominator? The DXGI will then calculate proper values automatically. (doc) The link also covers, why 60/1 shouldn't be hardcoded (can lead to problems on some systems).

关于c++ - 在 Windows 10/DirectX 上仅在全屏模式下使用 VSYNC 撕裂(窗口模式工作正常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31761790/

相关文章:

c++ - 根据模板参数选择 union 成员

C++ 通用类链接错误

c++ - 如何将表(数字列表)从 Lua 传递到 C 并访问它

c++ - 如何使 QMdiArea 子窗口小部件不可调整大小?

c# - .NET 的 3D 图形库

directx - 如何在 DirectX 11 中创建犹他茶壶?

c++ - 针对 March09SDK 编译 DX 9.0c 应用程序 => 无法与较旧的 DX 9.0c DLL 一起运行 => 问题 :)

c++ - 管道中的 DirectX11 像素着色器丢失

C++ 和 directx 11 错误没有为 dxgi.dll 加载符号

c++ - 错误 : ID3D11Texture2D is not defined.