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

Stuttery input, but perfect frametiming. #995

Open
JustCauseWhyNot opened this issue Oct 19, 2023 · 88 comments
Open

Stuttery input, but perfect frametiming. #995

JustCauseWhyNot opened this issue Oct 19, 2023 · 88 comments

Comments

@JustCauseWhyNot
Copy link

JustCauseWhyNot commented Oct 19, 2023

I'm launching bbr with gamescope -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 8 -S fit --immediate-flips -- strangle 139 gamemoderun %command%. It's doing a good job of upscaling, but despite setting immediate-flip it feels like I'm playing on 60fps. 2023-10-18_21-04. As shown in ss the frametiming is near perfect, and stays that way while I input into the game. But it still feels bad to use. I don't know if it's just a limitation with the compositor, or if there's a options I'm missing.

I am using dwm/x11, and no compositor of my own. And lastly I'm using an gtx 1660 super. I'm not sure what else to write down, but I'd like to have the upscaling while not having to use a compositor. But the pr to merge into proton got closed 😞.

@sharkautarch
Copy link

This probably is only relevant when gamescope is running in nested mode (which I think is the mode that the JustCauseWhyNot is using):
I did some basic profiling by running
gamescope -f -- glxgears
under vktracer, and I saw that there's some periodic gaps in the command buffer which usually seems to begin after the resetFences() command being done after the AcquireNextImageKHR() command

Looking at acquire_next_image() function in rendervulkan.cpp, it seems like resetFences() is always called after WaitForFences() and AcquireNextImageKHR() are successful.

Looking at https://themaister.net/blog/2019/08/14/yet-another-blog-explaining-vulkan-synchronization/
and the code the author wrote for handling fences around AcquireNextImageKHR in https://github.com/Themaister/Granite/blob/master/vulkan/wsi.cpp#L508
Perhaps there is way this can be handled better?
(older version of it: https://github.com/Themaister/Granite/blob/141259365a2b837edf0966e8507e45ff4f97cc15/vulkan/wsi.cpp)

image

image

image

@JustCauseWhyNot
Copy link
Author

I'd like to add that based off of some testing I did if I set -r 139 it kinda helped with at least perceived frame pacing, but if there was any slowing down below the set frame limit it'd chug a lot even if it only went down a frame or two. It seemed as though it wouldn't tear, and I couldn't notice any tearing.

Kinda separately -r seemed to be a frame limit which I thought based off of gamescope --help description -r it'd just be setting what the frame rate should be not a limit. But I also found the --frame-limit option to not have any effect at all for capping frames.

@sharkautarch
Copy link

sharkautarch commented Oct 25, 2023

A couple of things you could try:

  • you can try setting gamescope to use vulkan mailbox vsync mode... also either don't use strangle, or if you run into tearing and don't want tearing, set strangle to cap the framerate of gamescope instead of capping the framerate of the game

I also suggest you first try running the game w/o a framerate cap, and without the --immediate-flips flag:
MESA_VK_WSI_PRESENT_MODE=mailbox gamescope -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 8 -S fit -- env MESA_VK_WSI_PRESENT_MODE=immediate gamemoderun %command%
or, if you want to set both gamescope and the game to use mailbox:
MESA_VK_WSI_PRESENT_MODE=mailbox gamescope -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 8 -S fit -- gamemoderun %command%

or if you need to use strangle: (btw, with strangle, you can set a decimal fps cap. I suggest you go to https://www.testufo.com/refreshrate using google chrome/chromium/chromium-based browser to get a fps rate close to your display's refresh rate)
STRANGLE_FPS=<fps-cap-can-be-decimal> STRANGLE_VSYNC=1 STRANGLE_VKONLY=1 ENABLE_VK_LAYER_TORKEL104_libstrangle=1 LD_PRELOAD=libstrangle.so MESA_VK_WSI_PRESENT_MODE=mailbox gamescope -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 8 -S fit -- env LD_PRELOAD="" VK_LOADER_LAYERS_ENABLE="VK_LAYER_FROG_gamescope_wsi" MESA_VK_WSI_PRESENT_MODE=immediate gamemoderun %command%

there is also another vulkan vsync mode: MESA_VK_WSI_PRESENT_MODE=relaxed which is supposed to dynamically switch between vsync and non-vsync behavior in a way that would feel smoother than pure vsync. Tho IMHO, the relaxed mode doesn't seem to work that well with gamescope

Oh and, this may or may not be compatible with your gpu, but you can also try running gamescope in embedded mode
tho the catch with embedded mode is that display scaling w/ -W -H -w -h can't be used with it (tho I think it will still try to scale the output to fit the screen)
(less overhead compared to nested mode) by switching to a console tty [pressing ctrl+alt+f] (so no x11/wayland display on the current screen ), and then running gamescope with steam integration:
gamescope -e -w -F nis --sharpness 8 -S fit -- steam -tenfoot -steamos
oh and btw, --frame-limit only works in this embedded mode. You'd use it like this:
gamescope --frame-limit 139 -r <your-monitor's-refresh-rate-but-rounded-to-whole-number> -e -F nis --sharpness 8 -S fit -- steam -tenfoot -steamos

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Oct 27, 2023

I tried out what you sent. For the embedded session I got (EE) Failed to read Wayland events: broken pipe. When running the other 2 top commands I didn't really notice much of a difference. I think I better can articulate what I'm noticing when running gamescope. I'm noticing that I actually believe I'm running at 138 fps(in game cap), but with gamescope It's either not tearing or something else which is resulting in it feels like there's just a bunch of tiny micro stutters or something. When using mangohud I can't measure a difference in frame times when using gamescope vs not using it. I know gamescope has some performance overhead, but I wouldn't expect it to make the input and output just feel bad (I don't know how else to say it).

@sharkautarch
Copy link

sharkautarch commented Oct 28, 2023

try setting -r to double your refresh rate
See: #734
You can also try:

  • running su
  • running setcap 'CAP_SYS_NICE=eip' $(which gamescope)
  • running echo -1 > /proc/sys/kernel/sched_rt_runtime_us
  • running exit to exit out of root privilege
  • running gamescope with --rt

Lastly, if you're using the gamescope package installed from your repo, you can try building and installing gamescope from the git repository. The only catch is that there seems to be a nvidia driver bug that causes issues on the git version of gamescope.
However, I was able to get the git version to work on nvidia for me after reverting a commit that seemed to introduce the regression.
See my fork here: https://github.com/sharkautarch/gamescope/tree/nvidia-fix
if you clone the fork using git, make sure to do cd gamescope; git checkout nvidia-fix so you're on the nvidia-fix branch
After you build and install from the fork, you'll have to:

  • Install the vulkan-tools package, if you don't already have it installed
  • get your gpu id by running MESA_VK_DEVICE_SELECT=list vulkaninfo
  • pass the id to gamescope with gamescope --prefer-vk-device <id> [other args]
    EDIT: it turns out that running bbr on gamescope git version causes bbr to crash

@JustCauseWhyNot
Copy link
Author

Lastly, if you're using the gamescope package installed from your repo, you can try building and installing gamescope from the git repository.

I'm using portage, and installed gamescope-3.12.5. I did patch it to include to fix the resizing issue for nvidia gpus which was causing me grief.

diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp
index c508979..8087a8b 100644
--- a/src/rendervulkan.cpp
+++ b/src/rendervulkan.cpp
@@ -488,6 +488,7 @@ private:
        VK_FUNC(MapMemory) \
        VK_FUNC(QueuePresentKHR) \
        VK_FUNC(QueueSubmit) \
+       VK_FUNC(QueueWaitIdle) \
        VK_FUNC(ResetCommandBuffer) \
        VK_FUNC(ResetFences) \
        VK_FUNC(UnmapMemory) \
@@ -2988,7 +2989,7 @@ bool vulkan_make_swapchain( VulkanOutput_t *pOutput )
 bool vulkan_remake_swapchain( void )
 {
        VulkanOutput_t *pOutput = &g_output;
-       g_device.waitIdle();
+       g_device.vk.QueueWaitIdle( g_device.queue() );
 
        pOutput->outputImages.clear();

@JustCauseWhyNot
Copy link
Author

MESA_VK_WSI_PRESENT_MODE=mailbox gamescope -r 310 --rt -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun %command% That's the command I'm passing into steam launch options for bbr. It's still not solving the problem I'm observing.

@JustCauseWhyNot
Copy link
Author

I'm trying it out on a native game outside of steam, and from a quick little testing time. It's feeling a lot more how I'd expect. Close enough I'd almost say it's resolved sorta, and I was also having the same issue in this game as I'm with bbr. Right now I'd say the issue is with steam, or bbr itself. When I pass for instance gamemoderun to bbr in steam on it's own I also have a issue of it not turning on in the game.

@JustCauseWhyNot
Copy link
Author

After more testing for the native linux game if I pass strangle 139 It'll cause the problem to occur. I do wanna cap my frames, but the game doesn't have a native frame limiter. Any suggestions? Since gamescopes framelimiter doesn't really work for me.

@JustCauseWhyNot
Copy link
Author

It seems like anything that brings my frames below 140 cause major stuttering issues, but if I wasn't using gamescope those issues wouldn't occur.

@sharkautarch
Copy link

sharkautarch commented Oct 29, 2023

I have been experimenting with making gamescope's vblanking system more accurate and also have a lower latency.
Tho it still may be a bit buggy, and also it incorporates some busy-waiting which reduces latency but also is less energy efficient.
it is in the nvidia-fix-and-vblank-debug branch of my fork
The only catch is that it is based off of the latest git version of gamescope, with a workaround for one of the nvidia bugs that causes gamescope to crash.

HOWEVER, all branches of my fork still crash w/nvidia when running games like bbr on gamescope.

I might make another branch based off of an older working version of gamescope that incorporates my vblanking experimentations

Note that if you want to test out my nvidia-fix-and-vblank-debug branch, I would recommend you not to pass an -r to my version of gamescope

@JustCauseWhyNot
Copy link
Author

I'll try out your branch. Thanks for informing me about it, and putting in the work.

@sharkautarch
Copy link

oh yea btw for some reason, it seems like my branch of gamescope crashes if it is given CAP_SYS_NICE
if you gave it CAP_SYS_NICE, just run:
setcap '' $(which gamescope)
to reset it...

@sharkautarch
Copy link

HOWEVER, all branches of my fork still crash w/nvidia when running games like bbr on gamescope.

...

I'm using portage, and installed gamescope-3.12.5.

Now that I think about it, bbr did manage to run when I turned off an environment variable: ENABLE_GAMESCOPE_WSI=0 ... gamescope ...
I didn't mention it before because it is unideal to run bbr that way, since ENABLE_GAMESCOPE_WSI=1 lets gamescope import frames directly from the game via a vulkan layer.

looking at this commit: 6b6ffcd
I can tell that versions of gamescope newer than v3.12.5 default to ENABLE_GAMESCOPE_WSI=1 instead of ENABLE_GAMESCOPE_WSI=0

I remember that bbr's error window when launching my nvidia-fix branch said something about the game not supporting some window resolution (I think it was whatever gamescope's nested window size was set to).
I think the problem is that gamescope changes the resolution/screen size of the game's launcher/initial loading swapchain (or the d3d equivalent to that is), and for whatever reason, this causes an error.

If bbr crashes when running it w/ v3.12.5 gamescope with ENABLE_GAMESCOPE_WSI=1 gamescope <other params> %command%
then that would support my hypothesis.

@JustCauseWhyNot
Copy link
Author

Running Exec=env __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=mailbox gamescope --rt -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/launcher with your branch launches the launcher, but when I press enter to launch the game it insta crashes. I don't even see anything I can just tell because of the title saying WT: crash report. I ran doas setcap '' $(which gamescope) also, but didn't seem to make any difference.

@sharkautarch
Copy link

Try running it with ENABLE_GAMESCOPE_WSI=0

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Oct 31, 2023

That fixed auto crashing 👍, but I'm still noticing significant latency or what feels like it no matter the framerate.

@sharkautarch
Copy link

sharkautarch commented Nov 1, 2023

That fixed auto crashing 👍, but I'm still noticing significant latency or what feels like it no matter the framerate.

Try out my new branch: nvidia-fix-and-vblank-debug-extra-experimental
might still give you momentary periods of stutter, but hopefully it will be an improvement in framepacing

EDIT: also I think sometimes this new branch crashes when starting, but should work after trying to launch it a couple times

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Nov 1, 2023

Exec=env __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 ENABLE_GAMESCOPE_WSI=1 MESA_VK_WSI_PRESENT_MODE=mailbox gamescope --rt -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces
2023-11-01_11-30
And if I use ENABLE_GAMESCOPE_WSI=0 I get broken pipe over and over.

output
./.local/share/applications/gamescope-wt.desktop: 1: [Desktop: not found
./.local/share/applications/gamescope-wt.desktop: 3: War: not found
wlserver: [backend/headless/backend.c:68] Creating headless backend
[2023-11-01 11:31:12.436] [MANGOHUD] [info] [blacklist.cpp:68] process 'gamescope' is blacklisted in MangoHud
vulkan: selecting physical device 'NVIDIA GeForce GTX 1660 SUPER': queue family 2
vulkan: physical device supports DRM format modifiers
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x3231564E (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x48344241 (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x48344258 (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x38344241 (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x38344258 (VkResult: 0)
vulkan: supported DRM formats for sampling usage:
vulkan:   AR24 (0x34325241)
vulkan:   XR24 (0x34325258)
vulkan:   AB24 (0x34324241)
vulkan:   XB24 (0x34324258)
vulkan:   RG16 (0x36314752)
vulkan:   AB30 (0x30334241)
vulkan:   XB30 (0x30334258)
vulkan:   AR30 (0x30335241)
vulkan:   XR30 (0x30335258)
vulkan: Creating Gamescope nested swapchain with format 44 and colorspace 0
wlserver: Running compositor on wayland display 'gamescope-0'
wlserver: [backend/headless/backend.c:16] Starting headless backend
wlserver: [xwayland/server.c:108] Starting Xwayland on :1
wlserver: [types/wlr_compositor.c:673] New wlr_surface 0x19d3060 (res 0x1da3bb0)
wlserver: [xwayland/server.c:273] Xserver is ready
pipewire: stream state changed: connecting
pipewire: stream state changed: paused
pipewire: stream available on node ID: 325
x86_64 processor:
   Brand: AuthenticAMD
   Model: AMD Ryzen 7 3700X 8-Core Processor
   Invariant TSC: True
   cpuid leaf 15H is not supported
   From measurement frequency   3.60 GHz => 277.78 ps
   Sanity check against std::chrono::steady_clock gives frequency   3.60 GHz => 277.78 ps
Measured granularity = 1 tick =>   3.60 GHz, 277.78 ps
g_nsPerTick: 0.277779
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms lastDrawTime: 3.00ms lastOffset: 4.65ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
[S_API] SteamAPI_Init(): SteamAPI_IsSteamRunning() did not locate a running instance of Steam.
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
[S_API] SteamAPI_Init(): Loaded '/home/justcausewhynot/.local/share/Steam/linux64/steamclient.so' OK.
[S_API FAIL] SteamAPI_Init() failed; create pipe failed.sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
[S_API] SteamAPI_Init(): SteamAPI_IsSteamRunning() did not locate a running instance of Steam.
[S_API] SteamAPI_Init(): Loaded '/home/justcausewhynot/.local/share/Steam/linux64/steamclient.so' OK.
[S_API FAIL] SteamAPI_Init() failed; create pipe failed.sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
sleep_cycle=1 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 16.67ms - drawTime: 3.00ms offset: 18.32ms
std::exp(-(static_cast<long double>(rollingMaxDrawTime)/10000000.0)) = 0.48572
static_cast<long double>(centered_mean)/(1.0+roll) = 1.12179e+07
sleep_cycle=2 offset clamping: redZone: 1.65ms decayRate: 980% - rollingMaxDrawTime: 11.22ms - drawTime: 3.00ms offset: 12.87ms
(EE) failed to read Wayland events: Broken pipe
Floating point exception
    ~ ❯ [2023-11-01 11:31:13.554] [MANGOHUD] [error] [overlay_params.cpp:815] Unknown option 'io_stats'                          11:31:13

I know you said it'd fail a couple times, but I tried 5-10 times at least.

@sharkautarch
Copy link

sharkautarch commented Nov 2, 2023

Replying to #995 (comment)

I updated the nvidia-fix-and-vblank-debug-extra-experimental branch to fix the issue
Plus also some more improvements to make the framepacing quite smoother.
From my testing, running gamescope with a nested refresh rate set to 120 hz via -r 120 is now pretty smooth for me, which wasn't the case before.
full command I used for testing:
GDK_BACKEND=wayland __GL_SYNC_TO_VBLANK=0 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 120 -o 120 -f -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit --prefer-vk-device 10de:25a0 -- env vblank_mode=0 vrrtest

Tho I will say running it with -r 140 was less smooth, but idk if that is just because my actual laptop display is 60hz, so maybe thats just because 120 is a multiple of 60hz, but 140 isn't

Make sure to run git pull to download the new commits to the branch

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Nov 2, 2023

full command I used for testing: GDK_BACKEND=wayland __GL_SYNC_TO_VBLANK=0 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 120 -o 120 -f -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit --prefer-vk-device 10de:25a0 -- env vblank_mode=0 vrrtest

Is that what you're recommending I use?

It did boot when I used the previous command I pasted here, but I'm getting gamescope: ../gamescope-9999/src/wlserver.cpp:1659: void wlserver_key(uint32_t, bool, uint32_t): Assertion `wlserver.wlr.virtual_keyboard_device != nullptr' failed. now. It now keeps prompting a crash report. And here is the command I ran Exec=env __GL_SYNC_TO_VBLANK=0 __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 310 -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces.

@sharkautarch
Copy link

full command I used for testing: GDK_BACKEND=wayland __GL_SYNC_TO_VBLANK=0 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 120 -o 120 -f -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit --prefer-vk-device 10de:25a0 -- env vblank_mode=0 vrrtest

Is that what you're recommending I use?

No, that was just the command I used to run a program which I find helpful to quickly test the framepacing behavior of gamescope

It did boot when I used the previous command I pasted here, but I'm getting gamescope: ../gamescope-9999/src/wlserver.cpp:1659: void wlserver_key(uint32_t, bool, uint32_t): Assertion `wlserver.wlr.virtual_keyboard_device != nullptr' failed. now. It now keeps prompting a crash report. And here is the command I ran Exec=env __GL_SYNC_TO_VBLANK=0 __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 310 -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces.

make sure to add ENABLE_GAMESCOPE_WSI=0 for vulkan/proton games
For some vulkan, non-proton, apps, it may just work without needing to set ENABLE_GAMESCOPE_WSI=0 if you switch MESA_VK_WSI_PRESENT_MODE=immediate to MESA_VK_WSI_PRESENT_MODE=mailbox
hopefully there'll be an nvidia driver update at some point that'll fix whatever bug is breaking the gamescope WSI layer.
For now, you'll have to set ENABLE_GAMESCOPE_WSI=0 to disable the WSI layer

also, check that you recompiled gamescope with the latest commits I put out:
you can check by doing:

  • cd gamescope
  • git branch -> make sure the star is next to nvidia-fix-and-vblank-debug-extra-experimental
  • press q to quit from git branch
  • git log -> check that you see commit 51f18962804c37adbbba1672627b7206524c351e <... other text>

if you did set ENABLE_GAMESCOPE_WSI=0 and the game still crashed, then I think MESA_VK_WSI_PRESENT_MODE needs to be MESA_VK_WSI_PRESENT_MODE=mailbox instead of MESA_VK_WSI_PRESENT_MODE=immediate

So try either of these commands: (not sure if setting -r to double your refresh will make it more or less stuttery)

Exec=env ENABLE_GAMESCOPE_WSI=0 vblank_mode=0 __GL_SYNC_TO_VBLANK=0 __GL_SHARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces

Exec=env ENABLE_GAMESCOPE_WSI=0 vblank_mode=0 __GL_SYNC_TO_VBLANK=0 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 MESA_VK_WSI_PRESENT_MODE=immediate gamescope --immediate-flips -r 310 -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces
^ I'm assuming 310 is double your refresh rate

@JustCauseWhyNot
Copy link
Author

No crashing, and it actually feels way better. But I still am having issues. I do thank you for all you've done to help and contribute.

@sharkautarch
Copy link

No crashing, and it actually feels way better. But I still am having issues. I do thank you for all you've done to help and contribute.

Another update:
check out a newer version of my fork w/ my new
nvidia-fix-and-vblank-debug-extra-experimental-v2 branch

if the nvidia-fix-and-vblank-debug-extra-experimental-v2 branch behaves worse for you,
you can always go back to the nvidia-fix-and-vblank-debug-extra-experimental branch, which has remained unchanged

Notable difference in terms of usage are a couple switches I added to the new branch:
--vblank-never-spin Vblank thread: Never busywait to send the next vblank
--vblank-sometimes-spin Vblank thread: Sleep for most of the waiting time ~(3/4),
then wakeup and busywait the quarter remaining time to reduce latency. (Default)

--vblank-always-spin Vblank thread: Busywait the period between sending the next vblank as much as possible.

@JustCauseWhyNot
Copy link
Author

I'll 100% give this a try!

@sharkautarch
Copy link

I'll 100% give this a try!

Update: I just fixed a bug I had made which was causing random crashing.
Run git pull if you had already downloaded from the nvidia-fix-and-vblank-debug-extra-experimental-v2

@JustCauseWhyNot
Copy link
Author

On portage I've made a local ebuild of gamescope where I've set it to a live version which when built will always pull the latest commit, and in the ebuild I've set it to your repo & branch. So I can just update gamescope through portage. All I've gotta do is change the branch name for the correct branch in your repo. I just like portage so I figured I'd share how I update gamescope with you, and anyone else who reads this.

@JustCauseWhyNot
Copy link
Author

If I try and build your branch it fails to compile. Here's my build.log

@sharkautarch
Copy link

sharkautarch commented Nov 19, 2023

If I try and build your branch it fails to compile. Here's my build.log

FAILED: layer/libVkLayer_FROG_gamescope_wsi_x86_64.so.p/VkLayer_FROG_gamescope_wsi.cpp.o
x86_64-pc-linux-gnu-g++ -Ilayer/libVkLayer_FROG_gamescope_wsi_x86_64.so.p -Ilayer -I../gamescope-9999/layer -Iprotocol -I/usr/lib64/libffi/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c++20 -DWLR_USE_UNSTABLE -Wno-unused-parameter -Wno-missing-field-initializers -Wno-invalid-offsetof -Wno-unused-const-variable -Wno-volatile -Wno-ignored-qualifiers -Wno-missing-braces -ffast-math -DHAVE_PIPEWIRE=1 -DHAVE_OPENVR=0 '-DHWDATA_PNP_IDS="//usr/share/hwdata/pnp.ids"' -march=native -O2 -pipe -fPIC -MD -MQ layer/libVkLayer_FROG_gamescope_wsi_x86_64.so.p/VkLayer_FROG_gamescope_wsi.cpp.o -MF layer/libVkLayer_FROG_gamescope_wsi_x86_64.so.p/VkLayer_FROG_gamescope_wsi.cpp.o.d -o layer/libVkLayer_FROG_gamescope_wsi_x86_64.so.p/VkLayer_FROG_gamescope_wsi.cpp.o -c ../gamescope-9999/layer/VkLayer_FROG_gamescope_wsi.cpp
../gamescope-9999/layer/VkLayer_FROG_gamescope_wsi.cpp: In static member function ‘static void GamescopeWSILayer::VkInstanceOverrides::GetPhysicalDeviceFeatures2(const vkroots::VkInstanceDispatch*, VkPhysicalDevice, VkPhysicalDeviceFeatures2*)’:
../gamescope-9999/layer/VkLayer_FROG_gamescope_wsi.cpp:504:54: error: ‘FindInChainMutable’ is not a member of ‘vkroots’
504 | auto pSwapchainMaintenance1Features = vkroots::FindInChainMutable<VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT, VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT>(pFeatures);
| ^~~~~~~~~~~~~~~~~~
../gamescope-9999/layer/VkLayer_FROG_gamescope_wsi.cpp: In function ‘uint32_t GamescopeWSILayer::gamescopeFrameLimiterOverride()’:
../gamescope-9999/layer/VkLayer_FROG_gamescope_wsi.cpp:128:10: warning: ignoring return value of ‘ssize_t pread(int, void*, size_t, __off64_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
128 | pread(fd, &overrideValue, sizeof(overrideValue), 0);

hmmm I think that must of have been the result of me merging in newer commits from upstream gamescope...

On the otherhand... looks like that same exact compiler error was posted about recently here:
#1015 (comment)

It looks like it includes /usr/include/vkroots.h when you have older version installed.
$ pkgfile /usr/include/vkroots.h
extra/gamescope
I have the same problem while compiling it locally and having older gamescope version installed by pacman.
Adding vkroots to force_fallback_for in meson.build solved the problem.
In your case it might be enough to remove old version before installing new one.

I guess I can just edit my branch's meson.build file to force the fallback for vkroots...

EDIT: I just pushed a new commit to the nvidia-fix-and-vblank-debug-extra-experimental-v2 branch to force the fallback for vkroots
@JustCauseWhyNot let me know if that helps

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Nov 30, 2023

Ok Here's output

`Exec=env __GL_SYNC_TO_VBLANK=0 __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17 ENABLE_GAMESCOPE_WSI=0 gamescope -r 308 -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- env MESA_VK_WSI_PRESENT_MODE=mailbox gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces`
❯  Exec=env __GL_SYNC_TO_VBLANK=0 __GL_SARPEN_ENABLE=1 __GL_SHARPEN_VALUE=50 __GL_SHARPEN_IGNORE_FILP_GRAIN=17  ENABLE_GAMESCOPE_WSI=0  gamescope  -r 308 -w 1970 -h 1108 -W 1440 -H 2560 -F nis --sharpness 10 -S fit -- env MESA_VK_WSI_PRESENT_MODE=mailbox gamemoderun /home/justcausewhynot/Games/WarThunder/linux64/aces
No CAP_SYS_NICE, falling back to regular-priority compute and threads.
Performance will be affected.
wlserver: [backend/headless/backend.c:67] Creating headless backend
[2023-11-30 11:49:55.337] [MANGOHUD] [info] [blacklist.cpp:68] process 'gamescope' is blacklisted in MangoHud
vulkan: selecting physical device 'NVIDIA GeForce GTX 1660 SUPER': queue family 2
vulkan: physical device supports DRM format modifiers
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x3231564E (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x38344241 (VkResult: 0)
vulkan: vkGetPhysicalDeviceFormatProperties2 returned zero modifiers for DRM format 0x38344258 (VkResult: 0)
vulkan: supported DRM formats for sampling usage:
vulkan:   AR24 (0x34325241)
vulkan:   XR24 (0x34325258)
vulkan:   AB24 (0x34324241)
vulkan:   XB24 (0x34324258)
vulkan:   RG16 (0x36314752)
vulkan:   AB4H (0x48344241)
vulkan:   XB4H (0x48344258)
vulkan:   AB30 (0x30334241)
vulkan:   XB30 (0x30334258)
vulkan:   AR30 (0x30335241)
vulkan:   XR30 (0x30335258)
vulkan: Creating Gamescope nested swapchain with format 44 and colorspace 0
wlserver: Running compositor on wayland display 'gamescope-0'
wlserver: [backend/headless/backend.c:17] Starting headless backend
wlserver: [xwayland/server.c:108] Starting Xwayland on :1
The XKEYBOARD keymap compiler (xkbcomp) reports:
> Warning:          Could not resolve keysym XF86CameraAccessEnable
> Warning:          Could not resolve keysym XF86CameraAccessDisable
> Warning:          Could not resolve keysym XF86CameraAccessToggle
> Warning:          Could not resolve keysym XF86NextElement
> Warning:          Could not resolve keysym XF86PreviousElement
> Warning:          Could not resolve keysym XF86AutopilotEngageToggle
> Warning:          Could not resolve keysym XF86MarkWaypoint
> Warning:          Could not resolve keysym XF86Sos
> Warning:          Could not resolve keysym XF86NavChart
> Warning:          Could not resolve keysym XF86FishingChart
> Warning:          Could not resolve keysym XF86SingleRangeRadar
> Warning:          Could not resolve keysym XF86DualRangeRadar
> Warning:          Could not resolve keysym XF86RadarOverlay
> Warning:          Could not resolve keysym XF86TraditionalSonar
> Warning:          Could not resolve keysym XF86ClearvuSonar
> Warning:          Could not resolve keysym XF86SidevuSonar
> Warning:          Could not resolve keysym XF86NavInfo
Errors from xkbcomp are not fatal to the X server
wlserver: [types/wlr_compositor.c:692] New wlr_surface 0x5610ffb41110 (res 0x5610ffb1c420)
wlserver: [xwayland/server.c:273] Xserver is ready
pipewire: stream state changed: connecting
pipewire: stream state changed: paused
pipewire: stream available on node ID: 193
[S_API] SteamAPI_Init(): SteamAPI_IsSteamRunning() did not locate a running instance of Steam.
[S_API] SteamAPI_Init(): Loaded '/home/justcausewhynot/.local/share/Steam/linux64/steamclient.so' OK.
[S_API FAIL] SteamAPI_Init() failed; create pipe failed.[2023-11-30 11:49:56.322] [MANGOHUD] [error] [overlay_params.cpp:815] Unknown option 'io_stats'
[2023-11-30 11:49:56.322] [MANGOHUD] [error] Unrecognized graph type: custom_Latency
wlserver: [types/wlr_compositor.c:692] New wlr_surface 0x5610ff9c7c90 (res 0x5610ffb1fad0)
xwm: Unhandled initial NET_WM_STATE property: _NET_WM_STATE_FOCUSED
The XKEYBOARD keymap compiler (xkbcomp) reports:
> Warning:          Unsupported maximum keycode 708, clipping.
>                   X11 cannot support keycodes above 255.
> Warning:          Could not resolve keysym XF86CameraAccessEnable
> Warning:          Could not resolve keysym XF86CameraAccessDisable
> Warning:          Could not resolve keysym XF86CameraAccessToggle
> Warning:          Could not resolve keysym XF86NextElement
> Warning:          Could not resolve keysym XF86PreviousElement
> Warning:          Could not resolve keysym XF86AutopilotEngageToggle
> Warning:          Could not resolve keysym XF86MarkWaypoint
> Warning:          Could not resolve keysym XF86Sos
> Warning:          Could not resolve keysym XF86NavChart
> Warning:          Could not resolve keysym XF86FishingChart
> Warning:          Could not resolve keysym XF86SingleRangeRadar
> Warning:          Could not resolve keysym XF86DualRangeRadar
> Warning:          Could not resolve keysym XF86RadarOverlay
> Warning:          Could not resolve keysym XF86TraditionalSonar
> Warning:          Could not resolve keysym XF86ClearvuSonar
> Warning:          Could not resolve keysym XF86SidevuSonar
> Warning:          Could not resolve keysym XF86NavInfo
Errors from xkbcomp are not fatal to the X server
vulkan: Creating Gamescope nested swapchain with format 44 and colorspace 0
vulkan: Creating Gamescope nested swapchain with format 44 and colorspace 0
pipewire: renegotiating stream params (size: 1276x700)
xwm: Rejecting WM_CHANGE_STATE to ICONIC for window 0x600002
vulkan: Creating Gamescope nested swapchain with format 44 and colorspace 0
pipewire: renegotiating stream params (size: 2560x1440)
gamescope: Received Terminated signal, forwarding to child!
gamescope: Received Terminated signal, attempting shutdown!
(EE) failed to read Wayland events: Broken pipe

I did get 4.6 to build locally through meson.

It's actually really awesome right now. No flickering, and using mangohuds framerate limiter reeally helps helps alleviate any stuttering. My one issue is if the frames drop below the frame limit of 154 the game will be very jerky. It's like it can't decide which frame to show. Even if the frames drop by a few it can cause major jerking.

@sharkautarch
Copy link

sharkautarch commented Dec 3, 2023

Replying to #995 (comment)

I just pushed out yet another new version:
nvidia-fix-and-vblank-debug-extra-experimental-v4.7

you may want to just use -r 155 instead of -r 308 with this new version, because it seems like with v4.7, the best result is when you set the refresh rate to the whole number closest to your display refresh rate

@JustCauseWhyNot
Copy link
Author

I'll try that out in a few hours. Thank you.

@JustCauseWhyNot
Copy link
Author

I tried it out. It may be a bit better, but honestly I don't know. It's an issue with screen tearing. I don't believe gamescope is letting the game tear. It's like shows a new frame jumps back a frame and shows another frame. It's weird. Let me know if you want output.

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Dec 4, 2023

Not whole output, but I was getting
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.01ms
dispatch_vblank(int): VBlankTimeInfo_t receive latency: 0.00ms

That printed a lot.

@sharkautarch
Copy link

sharkautarch commented Dec 4, 2023

Not whole output, but I was getting

...
> ```

That printed a lot.

Yeah I had added a bit of code to check the latency of each vblank imported into the steamcompmgr thread

Are all of the lines just .01ms or .00ms? I was worried it would be higher
I'll remove the code that prints that out if it turns out not to be higher than .01ms ever

I tried it out. It may be a bit better, but honestly I don't know.

Anyhow I'll definitely going to have to tweak my code more...

I don't believe gamescope is letting the game tear.

I think there was a draft pr for trying to allow xwayland to tear or something, I might take a look at it at some point
EDIT: oh yeah it was this PR: #679

EDIT EDIT:

It's like shows a new frame jumps back a frame and shows another frame.

OHHH I just been thinking more about it, and now I think I know a reason for why that might be happening...
I think I might be able to add some more code to try to reduce that sort of effect

@JustCauseWhyNot
Copy link
Author

I'd just like to add that its only "choppy" when the frames drop below my fps cap of 154.

@misyltoad
Copy link
Collaborator

I did a port of vblankmanager to timerfd here: #1053 Still needs testing

@KagoraTheGrindcoreAddict
Copy link

KagoraTheGrindcoreAddict commented Dec 7, 2023

Did a quick test with Borderlands 3 and #1053 does seem to be smoother and have better frame pacing for me with gamescope -f -W 3840 -H 2160 -r 240 -- mangohud %command%.

Mangohud vsync set to adaptive in the config, used the in game fps limit to lock 120fps.

EDIT: Put a lot more time into it and frame times do feel much more consistent and inline with what mangohud shows.

@anthr76
Copy link

anthr76 commented Feb 14, 2024

Hey @sharkautarch which nvidia driver do you recommend for your revert/patches in https://github.com/sharkautarch/gamescope

@sharkautarch
Copy link

Hey @sharkautarch which nvidia driver do you recommend for your revert/patches in https://github.com/sharkautarch/gamescope

supposedly the newer nvidia driver versions should of had these issues fixed and thus not necessitate my patches, but if you still have issues w/ gamescope on nvidia, I recommend using the nvidia dkms 535 version

@anthr76
Copy link

anthr76 commented Feb 14, 2024

Yeah on gamescope 3.13.19 I face issues starting gamescope on all nvidia drivers (535.154.05,550.40.07,535.43.25) I will give 535.154.05 and the tip of nvidia-fix a try

@anthr76
Copy link

anthr76 commented Feb 14, 2024

Gamescope just hangs on stable :/ trying Gamescope-session from a tty. The closest I got was using Vulkan-beta but navigating the menus is flickering and feels like 15fps

@sharkautarch
Copy link

Gamescope just hangs on stable :/ trying Gamescope-session from a tty. The closest I got was using Vulkan-beta but navigating the menus is flickering and feels like 15fps

So are you saying that the nvidia-fix branch hangs for you when running in nested?
What command do you run it with, and what does gamescope print when running from the command line?

@AlexFolland
Copy link

There are multiple issue tickets in which users (including me) have reported this relatively new freezing / hanging behavior with Nvidia drivers 545 and later and the latest gamescope:

Is it possible that this freezing / hanging is the same issue?

@sharkautarch
Copy link

sharkautarch commented Feb 14, 2024

...

Is it possible that this freezing / hanging is the same issue?

It's very hard to tell, since the interaction between gamescope and the nvidia driver might appear different depending on if you're using X11 or wayland.
I myself am on X11/xfce w/ hybrid graphics using nvidia dkms 535. It's been a while since I've run gamescope w/ the nvidia gpu, but last time it was working for me when using my gamescope nvidia-fix branch (I had to run gamescope w/ ENABLE_GAMESCOPE_WSI=0 gamescope --prefer-vk-device <nvidia-dev-id>)
Then add ontop of that:

  • there was a bug w/ nvidia driver on wayland that only appears w/ hybrid graphics computers. Tho that should be fixed by now in stable versions of the nvidia driver (I think it was discussed in this issue )
  • Separate from the above I've noticed on hybrid graphics that I would have to run gamescope nvidia-fix branch w/ --prefer-vk-device <nvidia-dev-id> for it to work for me.
  • I'm not sure if all of the driver-side fixes for nvidia have made it into the stable version yet

users (including me) have reported this relatively new freezing / hanging behavior with Nvidia drivers 545 and later and the latest gamescope:

Does this new 'freezing' behavior also occur when running with: ENABLE_GAMESCOPE_WSI=0 gamescope ...?
Since anthr76 mentioned that gamescope crashed on nvidia 545 on wayland session, but runs (slowly but surely) in tty, maybe this could be related to one (or some combination of) these issues in nvidia/egl-wayland (I'm kinda shooting in the dark here):

Since distro beta packages for nvidia drivers can sometimes be slightly older than the latest nvidia beta, you could try installing the nvidia 545/550 beta driver directly from nvidia's website

@anthr76
Copy link

anthr76 commented Feb 14, 2024

This is new hardware/system so I'm having a hard time finding a workable baseline but you can find my config here if you can navigate Nix

Below is combinations I've tried to no avail:

Kernel: 6.1.52 / 6.7.4
Nvidia Driver: 545.29.06 / 545.29.06 / 550.40.07
Gamescope: https://github.com/sharkautarch/gamescope/commits/nvidia-fix / https://github.com/sharkautarch/gamescope/commits/nvidia-fix-and-vblank-debug-extra-experimental-v4.8 (both had stuttery flickering output)

I'm launching gamescope from a tty with gamescope session

With driver 545.29.06 with Kernel 6.1.52 and gamescope https://github.com/sharkautarch/gamescope/commits/nvidia-fix I am at least able to see gamescope work but it works at about 15 fps with occasional stutters

Current output of Nvidia-smi

nvidia-smi 
Wed Feb 14 20:13:30 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.06              Driver Version: 545.29.06    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 4090        Off | 00000000:01:00.0  On |                  Off |
| 30%   30C    P0              16W / 450W |     13MiB / 24564MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A     10356      G   gamescope                                     6MiB |
+---------------------------------------------------------------------------------------+

I'm happy to provide any relevant helpful information.

I've also tried all the variants of nvidia drivers with gamescope 3.13.19

@sharkautarch
Copy link

With driver 545.29.06 with Kernel 6.1.52 and gamescope https://github.com/sharkautarch/gamescope/commits/nvidia-fix I am at least able to see gamescope work but it works at about 15 fps with occasional stutters

Did you have to run gamescope with ENABLE_GAMESCOPE_WSI=0?

@anthr76
Copy link

anthr76 commented Feb 14, 2024

No I didn't, doesn't seem like it's set in gamescope-session.

@sharkautarch
Copy link

Hmm
Try using my nvidia-fix-latest-upstream that I made today
Not sure if it’ll work, but it might be less flickery

@JustCauseWhyNot
Copy link
Author

I tried compiling your branch, but it failed. Here's the build.log

@sharkautarch
Copy link

I tried compiling your branch, but it failed. Here's the build.log

Do you have a git submodule update somewhere in your build script?
Also add this meson flag:
-Dforce_fallback_for=stb,wlroots,vkroots,wayland,libliftoff

@JustCauseWhyNot
Copy link
Author

Do you have a git submodule update somewhere in your build script?

Honestly I don't know. I'm guessing no since it's just pulling from your repo at time of build so it's always updated.

@sharkautarch
Copy link

sharkautarch commented Apr 11, 2024

Do you have a git submodule update somewhere in your build script?

Honestly I don't know. I'm guessing no since it's just pulling from your repo at time of build so it's always updated.

Yeah make sure to put a git submodule update somewhere in it

also btw, you might also want to try my nvidia-fix-latest-upstream-plus-extra-tweaks branch out, which simply adds some slight performance tweaks and what not

@sharkautarch
Copy link

@JustCauseWhyNot do note that people have recently been reporting that regular gamescope (version >= 3.14.2) has been working on the 550.67 nvidia driver
#948 (comment)

@JustCauseWhyNot
Copy link
Author

JustCauseWhyNot commented Apr 11, 2024

I'm using 3.14.2, but I'm having tons of flickering. With 550:67 nvidia drivers.

@sharkautarch
Copy link

sharkautarch commented Apr 11, 2024

I'm using 3.14.2, but I'm having tons of flickering. With 550:67 nvidia drivers.

Hmmm maybe try the new release version
https://github.com/ValveSoftware/gamescope/tree/3.14.3

also what full command are you running gamescope with?

@JustCauseWhyNot
Copy link
Author

Exec=env ENABLE_GAMESCOPE_WSI=0 gamescope -H 2560 -- /home/justcausewhynot/Games/WarThunder/linux64/aces. I can try to manually update it to the latest release.

@sharkautarch
Copy link

Exec=env ENABLE_GAMESCOPE_WSI=0 gamescope -H 2560 -- /home/justcausewhynot/Games/WarThunder/linux64/aces. I can try to manually update it to the latest release.

Yeah try that, also check if you are able to run gamescope without the ENABLE_GAMESCOPE_WSI=0

@JustCauseWhyNot
Copy link
Author

Sorry I've yet to update it, but I built it with no wsi support, and you ENABLE_GAMESCOPE_WSI=0, and it had no effect. I'll update it soon.

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

No branches or pull requests

6 participants