Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AMD AntiLag 2 support #96991

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

frabert
Copy link

@frabert frabert commented Sep 14, 2024

Adds support for AMD AntiLag 2.

Requires some intermingling between the rendering device and input polling, I'm open to suggestion as to whether there's a better way than what I've got right now.

@frabert frabert requested review from a team as code owners September 14, 2024 10:16
@AThousandShips

This comment was marked as resolved.

@mrjustaguy
Copy link
Contributor

IIRC this requires core integration to function correctly, and is likely one of the main reasons why there's no Nvidia Reflex support in Godot (as it's not license compatible with Godot and has to be in core)

There are probably ways to expose the required internals properly to addons (like is required for DLSS and SMAAT2x, but those just require fairly simple things to be exposed and by no means require any deep integration with the internals)

@frabert
Copy link
Author

frabert commented Sep 14, 2024

AFAICT the integration is pretty simple as it only requires calling a specific function before input polling. The SDK license is MIT -- I believe there should be no problem on that side.

@mrjustaguy
Copy link
Contributor

Only two reasons for rejecting this would be:

  1. There's a way to modify core to allow this to be made as an addon (which in turn would allow for Nvidia's Reflex to be added as an addon as well despite Godot License being incompatible, as Addon's can be released under more restrictive licenses)
  2. Only a small part of Godot's user base benefits from this feature

I'm unsure how likely and/or how complex the First option would be to implement
The Second option I disagree with as this is one of those hardware specific features, and not AMD's fault that their competitor's aren't licensing their stuff with Godot compatible licenses (Nvidia's Reflex in this case)

Disclaimer - I'm an AMD user that benefits from this feature, but I'd be supporting this all the same if it were Nvidia's Reflex which wouldn't benefit me as such

@frabert
Copy link
Author

frabert commented Sep 15, 2024

Given the comments in the proposal issue, I've decided I'll also try supporting this on Vulkan using the official AMD extension.

Any suggestions as to what the config setting would be? rendering/rendering_device/d3d12/amd_antilag2_enabled obviously doesn't fit anymore

@fire
Copy link
Member

fire commented Sep 17, 2024

Does this work on all vulkan graphics cards or only amd gpus?

@mrjustaguy
Copy link
Contributor

AMD only I'm afraid.

@KeyboardDanni
Copy link
Contributor

Cool to see more folks tackling latency issues!

I do have a couple concerns with this PR:

  • This seems to change when inputs are read based on frame timing information. This could cause issues with applications like rhythm games where input timing should ideally remain consistent. Thus anything that could introduce input jitter or timing drift should have that spelled out either in the documentation or the settings/API.
  • The proposed project setting path is vendor-specific. I think it'd be better to have something like rendering/rendering_device/d3d12/low_latency_backend and have that be an enum or string that includes AMD Anti-Lag 2 as an option, similar to how FSR is currently implemented. There's two good reasons for this. First, it should help with the necessary infrastructure to allow other antilag technologies as plugins. Second, it helps make sure that only one antilag technology is active at a time. I could see a scenario where AMD Anti-Lag becomes available for nVidia in the future, and a project tries to use both AMD Anti-Lag and nVidia Reflex at the same time which would cause Problems™.

Right now I'm currently looking into establishing a broader low latency mode. Please let me know what you think of this proposal.

@@ -2761,6 +2761,9 @@
<member name="rendering/rendering_device/d3d12/agility_sdk_version" type="int" setter="" getter="" default="613">
Version code of the [url=https://devblogs.microsoft.com/directx/directx12agility/]Direct3D 12 Agility SDK[/url] to use ([code]D3D12SDKVersion[/code]). This must match the [i]minor[/i] version that is installed next to the editor binary and in the export templates directory for the current editor version. For example, if you have [code]1.613.3[/code] installed, you need to input [code]613[/code] here.
</member>
<member name="rendering/rendering_device/d3d12/amd_antilag2_enabled" type="bool" setter="" getter="" default="true">
If [code]true[/code], enables AMD AntiLag 2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth an external link documenting what this is, a short summary, and the pros and cons of enabling this feature.

@KeyboardDanni
Copy link
Contributor

@frabert Would you be willing to test these changes using my latency tester? I am trying to narrow down the cause of RenderingDevice apparently having an additional frame of lag over OpenGL, so more datapoints here would be very helpful.

@frabert
Copy link
Author

frabert commented Nov 27, 2024

@KeyboardDanni
WhatsApp Image 2024-11-27 at 19 46 59_b080889f

WhatsApp Image 2024-11-27 at 19 46 59_5333eba2

One was taken with AntiLag on and the other one with it off. I don't think it matters which is which because if I understand your test correctly, the result is the same in both :)

@KeyboardDanni
Copy link
Contributor

KeyboardDanni commented Nov 27, 2024

Hmm, disappointing results for sure. Just to double check, you ran this on the D3D12 renderer, right? On nVidia, the Vulkan renderer has five frames of lag max on defaults settings whereas D3D12 has four.

Edit: Also would like to know what your results are in windowed vs fullscreen.

Edit 2: I'm not sure what the extent of this PR is, so if it only affects input timing, that won't be reflected in the latency tester, as it's strictly checking swapchain/frame queue lag.

@frabert
Copy link
Author

frabert commented Nov 27, 2024

Correct. Running using Vulkan has less latency, I think one or two frames less.

EDIT: no difference between windowed and fullscreen

@KeyboardDanni
Copy link
Contributor

Well that's interesting. On nVidia, latency is worse on Vulkan fullscreen unless you disable layered DXGI, then it's the same as D3D12. Do you know if Vulkan is running using native presentation or layered DXGI on the AMD drivers? I believe AMD added support for layered DXGI in their more recent drivers, but I'm unsure what the method to enable this is (it might be automatic). Either way, PresentMon should be able to tell you how it's being presented.

I'd also like to see the effects of setting frame_queue_size = 1 and swapchain_image_count = 2 (the former will require code changes).

@frabert
Copy link
Author

frabert commented Nov 27, 2024

PresentMon says

godot.windows.editor.x86_64.exe[35584]:
    0000020B5359F180 (DXGI): SyncInterval=1 Flags=0 CPU=16.668ms (60.0 fps) Display=16.667ms (60.0 fps) GPU=0.648ms Latency=99.355ms Composed: Flip

The latency with those changes worsened lol

WhatsApp Image 2024-11-27 at 22 16 30_25b593f8
WhatsApp Image 2024-11-27 at 22 16 30_021fa2a5

@KeyboardDanni
Copy link
Contributor

PresentMon says Composed: Flip which means it's not being displayed using the hardware planes, but going through DWM, which will either add latency or frame stutter due to the extra layer of indirection. If this is Vulkan, what results do you get in fullscreen mode? Ideally you should get Hardware: Legacy Flip (OpenGL/Vulkan in Native presentation, fullscreen mode) or Hardware Composed: Independent Flip (DXGI swapchain with hardware planes).

If you still can't get either of these two presentation modes, check to make sure that you have windowed/fullscreen optimizations and MPO (multi-plane overlay) enabled in Windows, and on Windows 10 make sure the application is the foreground window with no overlays on top (on Windows 11 it shouldn't matter due to some under-the-hood improvements).

@frabert
Copy link
Author

frabert commented Nov 27, 2024

I get Hardware: Independent Flip when fullscreen with both Vulkan and D3D12

@KeyboardDanni
Copy link
Contributor

KeyboardDanni commented Nov 27, 2024

How's latency in fullscreen? Better or worse? And does your hardware configuration have anything that might cause additional indirection, such as hybrid graphics?

Surprised that D3D12 isn't showing Hardware Composed: Independent Flip. Are fullscreen optimizations/MPO disabled, or is this just related to Windows 10 or a driver quirk?

@frabert
Copy link
Author

frabert commented Nov 27, 2024

I think my hardware config is pretty straightforward? It's a single discrete GPU, no integrated GPUs.

Fullscreen D3D12 does show Hardware: Independent Flip when fullscreen

@frabert
Copy link
Author

frabert commented Nov 27, 2024

if it only affects input timing, that won't be reflected in the latency tester, as it's strictly checking swapchain/frame queue lag

Only now read this edit: as far as I understand, AMD AntiLag2 indeed only seems to affect input latency by strategically waiting until the very last moment before presenting before polling for input.

@KeyboardDanni
Copy link
Contributor

Fullscreen D3D12 does show Hardware: Independent Flip when fullscreen

Hardware: Independent Flip is not quite the same thing as Hardware Composed: Independent Flip. The latter means multiple hardware planes are in use, which should still be available on Windows 10. Can you provide test results for Vulkan full-screen with MPO enabled?

@frabert
Copy link
Author

frabert commented Nov 27, 2024

I understand MPO is normally enabled, and I have never disabled it before. Checking the registry I don't see any setting that would suggest it is currently disabled.

@KeyboardDanni
Copy link
Contributor

KeyboardDanni commented Nov 27, 2024

...Make that both Vulkan and D3D12. The more datapoints I have, the better I can diagnose latency issues and assess the effectiveness of lag fixes. Ideally I'd like that following:

  • Vulkan windowed
  • Vulkan full-screen
  • D3D12

All with the following combinations:

  • frame_queue_size = 2, swapchain_image_count = 3
  • frame_queue_size = 2, swapchain_image_count = 2
  • frame_queue_size = 1, swapchain_image_count = 2

All with fullscreen optimizations and MPO enabled in Windows.

Edit: Didn't see your post about MPO. Perhaps this issue isn't a great place for realtime communication :) Would you mind hopping on the Godot Contributors Chat? https://chat.godotengine.org/channel/rendering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for AMD Anti-Lag 2
6 participants