nDisplay Nvidia Sync: SetMaximumLatency returns an error, missing Swaptchain flag DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT

Summary

When running nDisplay with the Nvidia Sync Policy (Swap/Present barrier), the engine throws an error when trying to call SetMaximumFrameLatency (e.g. in this line)

There is a further comment on the nDisplay.sync.nvidia.ForceLatencyUpdateEveryFrame Cvar which reads:

// In the recent logs (Nov-Dec, 2023), we see GetMaximumFrameLatency() and SetMaximumFrameLatency() don't work
// properly. This is something weird and may indicate there is an issue outside of UE. Those methods are called
// once during the policy initialization. To better understand the issue and probably see some correlation,
// this cvar allows to focribly call set/get frame latency every frame, and log the results.

Looking into the actual DXGI documentation, there is this remark:
This method is only valid for use on swap chains created with DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT. Otherwise, the result will be DXGI_ERROR_INVALID_CALL.

I’ve added the DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT flag to swapchain creation (unfortunately this happens outside of nDisplay and is completely hardcoded) here and the error goes away.

I would put up a PR, but as this actually adjusts the whole engine swapchain I’m not sure how to resolve this none-intrusively.

What Type of Bug are you experiencing?

Virtual Production

Steps to Reproduce

Use nDisplay with the Nvidia Sync Policy, check the logs. It should always happen.

Expected Result

No error in logs and the call succeeds.

Observed Result

An error is printed in the logs.

Affects Versions

5.7

Platform(s)

Windows