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

[question] Reflex support possible? #52

Closed
aufkrawall opened this issue Oct 16, 2021 · 28 comments · Fixed by #66
Closed

[question] Reflex support possible? #52

aufkrawall opened this issue Oct 16, 2021 · 28 comments · Fixed by #66

Comments

@aufkrawall
Copy link

Is Reflex support possible within dxvk-nvapi's scope, or would there be additional work (like the shim DLLs for DLSS by Nvidia) required to make it work on Linux?

@K0bin
Copy link

K0bin commented Oct 16, 2021

What does Reflex even do? I can't find anything specific.

@aufkrawall
Copy link
Author

I don't know anything more than what they state on the Reflex dev site, which unfortunately is not much: https://developer.nvidia.com/reflex/get-started

The interesting part would be the low latency mode, the tooling stuff for latency measurements imho not so much.
E.g. Deathloop is a game with Reflex that can run on Linux. Reflex helps quite a lot for reducing input lag, which is also nice when playing just the single player mode. I have no idea if it even requires the help of the driver to achieve the latency reduction.

@K0bin
Copy link

K0bin commented Oct 16, 2021

On the D3D9-11 side you could reduce the amount of prepared frames which would help to reduce latency. (DXVK has config options for that). I think one mode in the Nvidia Windows driver also synchronizes with the GPU every frame.

No idea about anything else.

@aufkrawall
Copy link
Author

Yeah, we don't have an equivalent in vkd3d-proton. :(
AMD's Anti-Lag on Windows also works with D3D12, whereas Nvidia's driver latency reduction mode does not. But some D3D12 and also Vulkan games have Reflex. According to Battle(non)sense's input to pixel measurements, Reflex is better though than Anti-Lag or Nvidia "NULL", as it reduces latency even further by still having just a moderate performance hit. It really helps a lot in Deathloop, Fortnite or Rainbow Six Siege. I'm not sure if there even is a DLL in the games' folder that can be linked to Reflex.

@K0bin
Copy link

K0bin commented Oct 16, 2021

Yeah, we don't have an equivalent in vkd3d-proton. :(

Because that's up to the application to decide with D3D12 and Vulkan. The concept of prerendered frames doesn't exist in D3D12.

@aufkrawall
Copy link
Author

Because that's up to the application to decide with D3D12 and Vulkan. The concept of prerendered frames doesn't exist in D3D12.

I don't dispute that, yet AMD driver devs somehow managed to implement it for D3D12. I tested Anti-Lag in a bunch of D3D12 games like Hitman 2, Shadow of the Tomb Raider or Horizon Zero Dawn and it worked really well. If this would be doable for vkd3d-proton in a similar fashion? I have no idea. Of course I won't disagree that this by far shouldn't be the top priority. Hopefully Reflex support is more doable. :)

@K0bin
Copy link

K0bin commented Oct 16, 2021

My point is that as long as no one even knows what exactly it does, it can't be implemented.

@SveSop
Copy link
Contributor

SveSop commented Oct 18, 2021

Although seemingly very interesting, i looked at a youtube video i found on nvidia https://www.youtube.com/watch?v=-cXg7GQogAE, i could not immediately find that this was like a "plug-in-dll-that-makes-less-latency" thing... Rather it seemed (to me) it was some sort of "how-to-optimize-your-game" kind of thing that meassure latency and would provide game developers with means to optimize games for this. (was listed some games using this like Fortnite and Apex Legends).

I might have misunderstood the concept ofc, and this being something nVidia has invented that would magically improve latency, but i highly doubt it is that easy. We do not have the concept of "Low Latency Mode" in the Linux driver afaik, and it seems as it is somewhat intended to be used together with games developed for this + possible nVidia gaming monitors that support this feature? nVapi does not seem to have any documented functions for this atm in the public headers, so the guesswork would be reaching pretty far atm.

Certainly interesting, i must admit that, but i think with what we got atm, tweaking dxvk and further optimizing vkd3d and wine is the only thing we can do. Rémi Bernon has contributed many patches towards directinput for Proton/wine, so it is a constant WIP there i would say when it comes to improving stuff especially for latency (wineserver calls and whatnot).

Just my quick 2 cents :)

@aufkrawall
Copy link
Author

When switching it on and off, it really makes a lot of a difference for input lag (without any special display device). Especially when fps are lower and games would have CPU prerender of 3 frames otherwise (completely bonkers). Afaik Anti-Lag & "NULL" limit to ~0.5 frames of CPU prerender, whereas Reflex is ~0. Deathloop has an option to reduce latency apart from Reflex, which probably is prenderlimit 1, but Reflex really still makes a noticeable difference on top. I don't know if it also optimizes input processing in some additional way.

Well, hopefully Nvidia can shed some light on Reflex Linux support at some point. :(

@SveSop
Copy link
Contributor

SveSop commented Oct 18, 2021

Is this an ingame option that is "grayed out" when running the game through Wine/Proton? (And thus would somehow require a NvAPI call?)

Just watched Linus https://www.youtube.com/watch?v=aL5YTWRpzoA and it seems that what you use this for - when having the available hardware like mouse, monitor and gpu - is to measure the latency, and then enable/disable various options until you find what gives you the best (least) inputlag. Games having pre-defined "optimum settings" or options, would probably work just aswell for us.. unless ofc it is like i asked above, something unavailable as an option when running under wine/proton. (I don't own any of the games in question, so i cant test this).

I do agree that it would be awesome to be able to view this when playing a game under wine/proton, cos the same settings in windows might need other/different options for Linux... however it very much seems like it is really connected to the driver's overlay functions, something that is not really available for the Linux driver at all. I cannot imagine in any near future where this would be available for Linux tbh.

Just to conclude my (mis)understanding of this:

  1. Reflex is a system to measure latency. Monitor/mouse+++ and display this on-screen
  2. This is a proprietary nVidia thing
  3. Game dev's may use this system to create pre-defined "reflex optimized" setting options for the game (using the SDK)
  4. Enabling/disabling said options DOES make a difference regardless of having the correct monitor/mouse
  5. It is currently nothing available that makes this measure system work when running under wine/proton

The following questions is raised:

  1. Does games with pre-defined Reflex options (ingame settings) not change anything, or are these options unavailable for wine/proton?
  2. Would buying one of these "Reflex enabled monitors" actually make it work in Linux? (USB driver talking to the GPU driver with non-existing game-overlay in Linux atm).
  3. Would it really help much if we get 40-100ms mouselatency added when wineserver is cpu starved anyway? (Sure.. everything would help i suppose)

I tend to get a bit long winded at times, but i can see quite a few elements completely out of scope from what "we" do with DXVK-NVAPI atm tho... Unless ofc the answer to the first question is "It is grayed out, and probably requires a positive NvAPI call to be enabled", cos faking a reply would probably be easy enough if it would mean the options tweaked some game related settings under the hood (that does not require the driver to drastically change something).

@aufkrawall
Copy link
Author

In Deathloop, it just doesn't show up at all in the menu on Linux:
Screenshot_20211018_215559
Deathloop_2021_10_18_22_26_21_373

@SveSop
Copy link
Contributor

SveSop commented Oct 19, 2021

Interesting 😄
Any chance you could post a dxvk-nvapi log by doing DXVK_NVAPI_LOG_LEVEL=info so i can have a look at it? Most likely just a bunch of NvAPI_QueryInterface xxxxx Unknown function ID calls, but still worth looking at i guess.

Atleast it is feasible that it should be a NvAPI call rather than a pure "driver funcion", unless it is yet another one of those "mistaken driver version" things that requires a certain driver that the game just dont get correctly.

@aufkrawall
Copy link
Author

dxvk-nvapi.log

@SveSop
Copy link
Contributor

SveSop commented Oct 19, 2021

Hmm.. That list was a lot shorter than expected.
Got 3 "unknowns" i have no idea what is.. Could be some new NvAPI_GPU_PreRenderQueue or whatever 😉
Got 1 suspect that i am not sure would have anything at all to do with this.. Cant really say if it is only used for a verification for stuff like "if X value is Y - then card is good", but tbh i do not really believe it has anything to do with Reflex. I mean, would having a particular majorSMVersion mean the card is good to go? Or is VariablePixelRateShading support needed? 😄

That leaves my next suspect - the NvAPI_DRS_ system "Nvidia Driver Settings". I kinda thought/believed it was only for loading those gameprofiles (ie. you set Game.exe to run without vsync and whatnot), but it COULD be more involved somehow. Will it "fail" if absolutely NO gameprofiles is found (and the api reports ERROR)?

Thanks tho.. will do some experimentation. I have Escape from Tarkov game, and that got nVidia Reflex support not long ago.. Could enable it on my win10 box with GTX970, but currently dont have it installed on my Linux box due to BattlEye (but that might be close to working now, so maybe i should look into it again).

@jp7677
Copy link
Owner

jp7677 commented Oct 19, 2021

I just added NvAPI_GetPhysicalGPUsFromLogicalGPU since I saw that in the logs, though it probably wont change much.
(That said, please let me know if something has changed :) )

@aufkrawall
Copy link
Author

The Reflex option now is available in the game's menu. :)
However, I think it doesn't do anything, as I can't notice any difference regarding input lag (unlike on Windows). Here is a new log:
dxvk-nvapi.log

@SveSop
Copy link
Contributor

SveSop commented Oct 20, 2021

Hmm.. i see 3 new calls now:

NvAPI_QueryInterface NvAPI_D3D_SetSleepMode: Not implemented method
NvAPI_QueryInterface NvAPI_D3D_SetLatencyMarker: Not implemented method
NvAPI_QueryInterface NvAPI_D3D_Sleep: Not implemented method

From the headers, these absolutely seem related, as the text indicates stuff like LowLatencyBoost and other stuff.

//! The bLowLatencyBoost will request the GPU run at max clocks even in
//! scenarios where it is idle most of the frame and would normally try
//! to save power. This can decrease latency in CPU-limited scenarios.

Worth investigating, but i would think this controls some driver aspect of things - that i thought would be negated when running in "performance mode", but these days "performance mode" might be more involved (powerlimits+++) than just running at full gpu clock.
Interesting.. Would guaranteed require usage of nvml tho, since NvAPI dont directly control any hardware settings.

@SveSop
Copy link
Contributor

SveSop commented Oct 20, 2021

This was slightly harder then expected to "test". It may be that i need the IUnknown or ID3D12Device id's we get from dxvk or vkd3d when an actual D3D device has been "created"... so just writing a test to read or enable these values seems to end in a error message when doing it on windows. Naturally enough, since my hacky "function tests proggy" does not create a actual d3d device when run.

I still lean a wee bit towards this being a "hardware driver control" kind of thing, and since nvml does not really have anything looking like this, i do not think it is directly possible to implement atm. However, it is kind of hard (as previously said) to figure out if any benefits is to be gained from this in the first place.. Playing through wine/proton is likely adding latency anyway, and i am unsure if it would help much.

Until there is a way to actually measure this latency (ref. earlier post about driver overlay stuff and whatnot), for all we know Linux is doing a much better job at this than windows does natively already 😏 I do not really play any competitive games anymore, and have not gamed on anything new when it comes to hardware in years, so cant really compare perceived latency from windows <-> Linux.

You are most likely bound to be loosing fps from any sort of translation (dxvk/vkd3d -> vulkan) and you will loose latency and fps from wine anyway.

I will keep digging around more for this, but i am sad to say "Don't hold your breath" 😄

@aufkrawall
Copy link
Author

I don't notice any additional lag when playing on Xorg without vsync vs. Windows. I'm pretty sure ~90% of lag is caused by the games themselves, i.e. stupid CPU prerender of 3 frames or even more (limiting to 1 in DXVK usually makes a hell of a difference). If Reflex on Linux would be limited to keeping CPU prerender queue emtpy to short, it should already be a major benefit. Well, just guessing here, as we don't really know in detail what Reflex does...

@SveSop
Copy link
Contributor

SveSop commented Oct 21, 2021

Yeah, it is quite unknown so far since no public headers with the functions is released.
I think as you pointed out - so far the "best we can do" when gaming in Linux is:

  1. dxgi.maxFrameLatency = 1 in dxvk.conf
  2. Some games also can benefit from dxvk.halveNvidiaHVVHeap = True
  3. Enable nVidia persistenced mode (daemon) or maybe sudo nvidia-smi -pm 1
  4. Set performance mode nvidia-settings -a "[gpu:0]/GPUPowerMizerMode=1"

Stuff similar to this will atleast seemingly make sure we limit as much as possible pre-rendered frames, and should avoid as much as possible throttling gpu unnecessary (within limits of temp and power). You can also increase powerlimit for the gpu with sudo nvidia-smi -pl XX (where XX is the max powerlimit for the GPU).

I suspect that this Reflex thing does a bit more too.. like setting maxFrameLatency < 1 perhaps, something dxvk cant do atm. For D3D12, this option does nothing i think, since it is a wee bit different for D3D12, so it could be some NvAPI function for D3D12 for this function alone maybe?

Unless we can get a direct comparison between windows (+reflex) <-> wine/proton for latency, it is kinda hard to determine how great the difference is. The video i linked a few posts up from Linux tech tips, he was showing some type of gear that they used "before Reflex", that was wired up to the mouse, and possibly some camera thing that detected something on the screen to measure this. Not sure if that is something that would work in Linux at all, but would be interesting to see if one could meassure something similar?

@jp7677
Copy link
Owner

jp7677 commented Oct 21, 2021

Yeah, it is quite unknown so far since no public headers with the functions is released.

All three methods are in the public headers.

@SveSop
Copy link
Contributor

SveSop commented Oct 21, 2021

Yeah, it is quite unknown so far since no public headers with the functions is released.

All three methods are in the public headers.

Assuming this actually IS related to "Reflex"...? 😏
Maybe one could get a better understanding of the requirements of "Reflex" by downloading the SDK? Not sure...

EDIT: "SleepMode"? Is not exactly self-explanatory that it is the same as "Reflex" (was more or less my meaning).

@SveSop
Copy link
Contributor

SveSop commented Oct 21, 2021

Do i understand the dxvk-nvapi testsuite so that it creates a D3D device (via dxgi) when testing some of the NvAPI_D3D12_ calls? If so.. i wonder if a test for those 3 "suspected" calls could be written that would provide SOME useful reply when run in windows?

It would fail (for now) when run with wine/proton, but perhaps it could be used for figuring out how they work in windows with the actual nvapi lib?

@jp7677
Copy link
Owner

jp7677 commented Oct 21, 2021

Do i understand the dxvk-nvapi testsuite so that it creates a D3D device (via dxgi) when testing some of the NvAPI_D3D12_ calls? If so.. i wonder if a test for those 3 "suspected" calls could be written that would provide SOME useful reply when run in windows?

No, the unit-tests use mocks, those instances just pretend to be d3d12devices and are only useful to validate which methods have been called by the tests itself.

If you want a test that uses actual d3d12devices, I guess you could look at the vkd3d-proton tests.

@ishitatsuyuki
Copy link
Contributor

For anyone who is interested in Reflex support on Linux, please take a look at my project https://github.com/ishitatsuyuki/LatencyFleX, hooked up into games through NvAPI. It can be installed by replacing and adding a few wine libraries, including DXVK-NVAPI.

It does not use any NVIDIA SDK or proprietary code apart from the binding interface. It's possible that it's better or worse than Reflex, but so far as it has been providing satisfactory results for me. (I'm testing on an AMD graphics card with DXVK vendor ID overrides, so let me know if there are any NVIDIA specific issues.)

@jp7677
Copy link
Owner

jp7677 commented Dec 30, 2021

For anyone who is interested in Reflex support on Linux, please take a look at my project https://github.com/ishitatsuyuki/LatencyFleX, hooked up into games through NvAPI. It can be installed by replacing and adding a few wine libraries, including DXVK-NVAPI.

It does not use any NVIDIA SDK or proprietary code apart from the binding interface. It's possible that it's better or worse than Reflex, but so far as it has been providing satisfactory results for me. (I'm testing on an AMD graphics card with DXVK vendor ID overrides, so let me know if there are any NVIDIA specific issues.)

Thanks a lot. This looks certainly promising, I’ll keep your project in the back of my mind!

@jp7677 jp7677 linked a pull request Jan 15, 2022 that will close this issue
@jp7677 jp7677 closed this as completed in #66 Feb 9, 2022
@jp7677
Copy link
Owner

jp7677 commented Feb 9, 2022

The LatencyFlex PR is merged, enabling Reflex should now make a difference when LatencyFlex (https://github.com/ishitatsuyuki/LatencyFleX) is properly set up.

@jp7677
Copy link
Owner

jp7677 commented Feb 9, 2022

All credits to @ishitatsuyuki !

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

Successfully merging a pull request may close this issue.

5 participants