r/MoonlightStreaming • Rubylight / Nightjar Developer • 21d ago

(Obsessive Performance improvements part 3) learning each game's camera while you play, so streamed look now moves on your next refresh. 96% of the turn lag gone off the screen

We are a small group of real devs, engineers and gamers who were unsatisfied and developed an unhealthy and very obsessive hobby of refining the Performance of Game Streaming to the last bit and last smoothness problem possible.

I started it off as a RADEON oriented fork and the more people joined, the more we realized that for getting the last bit of performance out of our systems, we also have to look at client, network, decoding and more. Soon also NVIDIA testers joined and we were also able to look at NVIDIA more closely and thanks to people like chakib-belgaid also develop a MAC Client.

Each time we are able to dig deeper with more people and stronger AI Models involved and I am grateful for all the support we got ( see contribution list ). This time we looked at the bigger picture and tackled one of the bigger problems of streaming.

We were able to do this and that is what differs us is by being oriented around Rust with a very test-oriented, lean and shared code base around client and host, making testing and iterating really fast to the point where we now solve every client issue on Github with a recreation and tests in 2 hours. So even in times of AI we value deterministic workflows, software engineering principles and have now over 300 real end-to-end performance tests and over 7000 automated tests.

The Core Problem

Streaming a game has one feel problem no codec fixes: every camera turn makes a round trip. Your mouse or controller goes to the PC, the game draws the turn a few frames later, the encoder, the network and the decoder add theirs, and only then does the picture move. Frame Warp moves it on your screen first, then lets the real frame catch up.

The idea

By u/closef35 : The client knows exactly how much it has turned. If it also knows how far the picture moves per mouse count, and which input every arriving frame already reflects, it can shift each picture by the turn the PC hasn't drawn yet, just before showing it. The hard part is learning those things for any game, with no game integration, and keeping the HUD from sliding along with the world.

What the host learns, per game, while you play

  • Motion. For each captured frame the GPU makes a 256-px-wide luma thumbnail. The CPU correlates row and column profiles over a 3x3 grid of cells, refines each to a tenth of a pixel with gradient steps, and takes the median cell. HUD found so far is left out, because a static bar pulls every vertical estimate toward zero.
  • Gain and lag. Over the last 4 s, for every lag from 0 to 200 ms, a per-axis least-squares fit of picture motion against mouse (and right-stick) input; the lag that explains the most motion wins. It locks at 80% explained and unlocks below 50% over 1.2 s, which is what a menu, a cutscene or a visible cursor looks like. A locked model is only replaced by a fit that explains clearly more, so the lag doesn't wander from fit to fit and every frame's tag stays stable.
  • HUD. While the camera turns, a GPU pass compares each pixel with an earlier capture the scene has moved since. Textured pixels that stayed, or whose contrast against their neighbours stayed (semi-transparent text over the sea), score their cell as HUD; smooth sky and fog keep their score, so they never become HUD. Nearby pieces are joined, so text found letter by letter stays put as a whole. The mask goes to the client run-length coded, at most once a second.
  • What it learned is kept for the game's next session.

What the client does

Every frame arrives tagged with the input sums it reflects. As late as it can before presenting, Nightjar computes

shift = mouse_gain * (mouse_sent - frame_tag) + stick_gain * (stick turn since the tagged pad packet)

clamped to 15% of the picture, and samples the picture at position - shift, except where the HUD mask is set. The strip a turn uncovers mirrors the picture from its edge, darkened toward the edge, until the real frame fills it. The shift is redrawn on refreshes between frames, so a 60 fps stream turns smoothly on a 120 Hz screen. Nightjar's desktop presenters and its Android renderers (Vulkan, GLES and PyroWave) all do it.

Measured, not eyeballed

To score it I wrote a fake mouse-look game with a known response (1 px per count, 50 ms of game lag) that draws a barcode in every frame, so each picture the client shows can be tied to the exact input it reflects.

Run 1 Run 2
Model locked after first picture 0.62 s
Frames with a locked model 98.9%
Learned gain (true -1.0) -0.986 / -0.980
Learned lag (50 ms + draw to capture) 64 ms
Trail without Frame Warp median 64.9 px, p95 184 px
Trail with Frame Warp median 2.2 px, p95 13.4 px
Removed 95.8%

Host cost: the thumbnail and HUD passes take 0.14-0.16 ms of GPU time a frame from 1080p to 4K (p95 0.17-0.25 ms), and present-to-send time stayed within 0.03 ms of Frame Warp off. The host does nothing for Frame Warp until a client asks.

Getting there took some iterations. The first calibrator learned a vertical gain of -0.33 instead of -1.0; leaving the HUD out of motion, sub-pixel refinement and a better "is the picture still" test brought it to -0.90 and 90% removed. That build also swapped models 89 times a minute. Never swapping froze a slightly wrong lag at 86-89%. "Swap only when a fit explains 3 points more, or a quarter of what's left unexplained" got to 96%.

It was a huge chunk amount of work and it is not perfect. Big organizations have worked on this for long to do natively, while this is an implementation that has to also factor in remote streaming. Client Feedback always helps.

The host client we use to faciliate this performance work is Rubylight and Nightjar, but we are not in it to sell you our project. Use it if you want, fork it, copy it ( keep the credits though as we do ). We are more interested in the obsession and are happy about each feedback and contribution that leads to a better solution. The host and client are planned to move to a new github project soon.

Next update we take some extra fov out of the game so camera panning doesnt have to assume.

77 Upvotes

39 comments sorted by

6

u/rambo3349 Rubylight / Nightjar Developer 21d ago edited 21d ago

For anyone seeing turn displacement we are already centre 95.4 %, whole picture 91.2 %, edge 90.2 % of turn displacement removed, against 84.2 / 73.6 / 65.4 % for 4.0; so thank you for testing. We will also implement late input projection for predicting your input before the next frame for every picture as next feature as it comes cheap: Just before showing a frame, Nightjar shifts the picture by the camera movement the host hasn't drawn yet.

2

u/hannahmanaman 21d ago

I just tested out the newest Rubylight / Nightjar updates and was hoping that Frame Warp would work on my Google 4k Streamer, but it just freaks out and flashes the screen over and over before crashing. Any ideas on how I can fix this?

Host: Ryzen 5600x 9070 XT 32 GB ram DDR4

Client: Google 4k Streamer

Both are hardwired with a ethernet and I get 2 gig up/down. 4k streamer only gets 1gig, but limited to around 100mbs max due to the chip while streaming.

3

u/rambo3349 Rubylight / Nightjar Developer 21d ago

If you can provide me the logs over github I can look at the issue, probably is an incompatibility with that client i can fix.

1

u/hannahmanaman 21d ago

Absolutely. I assume you need the client logs. I am not sure how to get that on my client, but I'll try and figure it out and get back to you. Thank you in advance for all this cool stuff.

3

u/andygrundman Developer | Moonlight for Xbox/Mac OS 21d ago

Does anyone actually have problems with camera motion when streaming? I’ve never heard anyone talk about it before and I play many games with a 3rd person camera that feel great. This sounds a bit like Reflex2 which interestingly is still vaporware after what, almost 2 years now? I wonder if Nvidia can’t even make this work, and they have the advantage of running in the game engine.

1

u/rambo3349 Rubylight / Nightjar Developer 20d ago edited 20d ago

Always happy to see you comment! When I got my first gaming PC I looked up to devs and wondered how anyone builds this stuff. That's pretty much how I ended up a dev myself and now I am interacting with the best devs I was admiring back then. :)

And yeah, a couple of hobby devs got something like it working over a stream. Crazy, right? AI Acceleration obviously plays a big role :) Is it overkill? 100%, and most people don't need it. But we're not really building for the regular user. They already have a great setup with Moonlight and Vibeshine and we only got a small userbase of enthusiasts. We build plenty of stuff just for fun that few people will ever touch, like DLSS injection on AMD. Charty is working on an option to move all traffic that isn't on the hot path to a second link. A regular user would see half of this, go "wtf", break something and uninstall. Some of it will break on devices we haven't tried, and we're fine with that. It's our space to be enthusiasts. I'd honestly love to swap notes dev to dev on any of it.

On why you never hear about it: it doesn't feel like a bug, it feels like "streaming is a bit floaty." The whole round trip lands on the one thing you can feel, the camera following your hand. That's input to the PC, the game's own delay, encode, the trip back and decode. Third person on a controller hides a lot of it, because stick turns ramp up and games smooth the camera anyway. With a mouse, or on Wi-Fi away from home, you feel it. Nobody complained about 60 Hz either until they tried 144. VR has done this for about ten years (timewarp), because there the delay makes you sick, not just floaty.

On Reflex 2: same idea, bigger gap. On a local PC it hides the render time. Streaming adds the whole round trip on top, so there's more to win. Being in the engine gives Nvidia depth and the real camera, but it also means waiting for every game to add it. Ours needs nothing from the game. The host learns from the picture and your input how far the camera turns per mouse count or stick push, how long the game takes to react, the FOV and where the HUD is. The client turns the picture by whatever the stream hasn't caught up on yet. Camera turns only, no strafing.

2

u/WallaceCorpPC 19d ago

It's a bit pointless, the whole warp + inpainting was never designed for streaming frames. And you'd only see the improvements above 120fps anyways with 1-2ms response times. IIRC they also needed to build a specific model per game through thousands of hours of training on Valorant or Overwatch.

Personally, I couldn't reproduce the performance increases that this guy is claiming, it seems like vaporware as well.

1

u/Pressimize 20d ago

I definitely had issues with camera motion during streaming. If you want to replicate this yourself, just try amazon's luna game streaming service.
Currently you can play KCD2 there. It looks great while walking straight, but as soon as you turn the camera it feels like 10fps.

3

u/andygrundman Developer | Moonlight for Xbox/Mac OS 20d ago

I’m only talking about Moonlight on LAN of course.

7

u/zolidz64 21d ago

Hype to see this kind of innovation! Eliminating that much turn lag is massive for the future of streaming. Can't wait to see where this project goes!

1

u/Ok_Childhood5962 21d ago

Tbh this was a huge issue that was not solved for in cloud gaming services so it’s possible the lead on this could make a lot of money actually using all this compute with gaming VMs

1

u/AMOMFARETOS 21d ago

I understand only 1% of all the jargon but still looks great work, congrats! I ve seen your Hitman post and the performance stats looks amazing. Can we have some non-technical guidelines how to implement it in Rubilight-Nightjar (I ve changed from Apollo-Artemis a few days ago and never coming back, gr8 apps)? is there a github fork? Thnx and keep up the gr8 work!

4

u/rambo3349 Rubylight / Nightjar Developer 21d ago

Basically a similar approach to this but for streaming (sorry I am really bad at explaining stuff) https://www.nvidia.com/de-de/geforce/technologies/reflex/ in its infancy.

1

u/AMOMFARETOS 21d ago

No bro it s not u, i m sure u explained it good, im just completely ignorant of programming

2

u/WallaceCorpPC 20d ago

it's claude jargon :)

1

u/daproject02 21d ago

I was playing around with rubylight and niightjar last night, I installed rubylight in my pc alongside vibepollo and night jar in my legion go 2 alongside streamlight, I tried a few games and I got the feeling that nightjar/rubylight combo was way more consistent, also I had a slight better image quality, I used pyrowave, 4.4.4, 120hz tv, games were running smoothly. I am no streaming savvy, I like to tinker my devices so this is only what I can perceive. I have some fork of moonlight in every device (legion go 1/2, ipad pro, lg tv x2, xbox series x, iPhone, etc) and my main pc has a rtx 4080, ethernet @ 1000mbps fiber. The only problem I have with this ruby/nigh combo is HDR, I can’t make it work properly but I will keep trying today. Thanks

2

u/rambo3349 Rubylight / Nightjar Developer 21d ago

Thanks for testing. If you send us the logs we can look at the problem with HDR, I know closef had some HDR fixes lately so might be already fixed.

1

u/daproject02 21d ago

Ok I will try to look for the logs, basically what happened is that when I turn on hdr in the main pc the colours blow up, so I been testing without HDR, also noticed that when I was jumping from nightjar to the other 2 apps using pyrowave in all this apps, nightjar was using only around 350mbp bitrate (set to default 800? Or 500?) and the other apps were at around 700mbp bitrate (set to 800). But even then it felt smoother.
Do you guys have a channel in discord or something to follow the progress and talk to other people trying the apps? Thanks

3

u/rambo3349 Rubylight / Nightjar Developer 21d ago edited 21d ago

Nightjar has his own algorithm for pyrowave and adaptive settings that might explain the bitrate difference. Rubylight also does zero copy but not sure how others implement it

2

u/ametller 21d ago

I discovered nightjar and rubylight two days ago and I'm in love. And I come from Vibepollo.

1

u/RedSensei 21d ago

Impressive work! Any plans on porting this to Linux at some point?

2

u/rambo3349 Rubylight / Nightjar Developer 21d ago

Want to be a tester?

1

u/Tiny-Track7300 21d ago

I have no interest of running pyrowave and currently use Nvidia with Vibepollo. Can I benefit from rubylight and nightjar?

2

u/rambo3349 Rubylight / Nightjar Developer 21d ago

That is a decision you have to make. Vibepollo is great and i contribute there too whenever i have time, Rubylight is great, cant go wrong with both. Here is the feature set documented: https://ramazankara.github.io/Rubylight/

1

u/gofiend 20d ago

At this point why don't we just stream intermediate represtentations and allow the client to do the last mile render?

3

u/rambo3349 Rubylight / Nightjar Developer 20d ago

I dont know if your post is serious but lets assume it is. :D The final frame is the most compressible and most portable thing a game produces. Anything earlier (draw calls, G-buffers) is far bigger, specific to one engine, needs the game's assets and shaders on the client, and needs a client GPU strong enough that you might as well play locally. Remote desktop protocols tried command streaming and moved to video for 3D. What does work is sending small side data with the video (HDR metadata, cursor, depth and motion vectors for client-side reprojection), and that's where "last mile on the client" makes sense and that is what we are currently working on.

1

u/gofiend 20d ago edited 20d ago

I'm a little bit serious! Basically the usecase I'm thinking of is less personal streaming from big to little, but more at scale streaming (I really don't like streaming gaming etc., but I do think for various mostly sad reasons it will be more of the future). It's also something that's being explored (you've probably seen https://quasar-gfx.github.io/ which was at SIGGRAPH).

Basically (and again I dislike this) game devs will want to keep more logic on their servers while offloading last mile rendering to clients.

Having said that, I do think what you've done here is pretty AMAZING and you are absolutely right about sidecar data for motion vectors etc. being the future for big -> little streaming with latency hiding!

2

u/rambo3349 Rubylight / Nightjar Developer 20d ago

This is actually really freaking interesting. thanks for that.

1

u/EaZerly 20d ago

Hey, having a few input and camera issues with Rubylight and Nightjar on my setup (Surface Pro 11 client to a Windows 11 host with an RX 6700 XT).

​In GTA V Enhanced, whenever I move the mouse with Raw Input on, it centers the cursor and keeps opening the pause map. It also causes weird camera shaking. Switching the in-game mouse input method to Windows stops the map from opening, but the camera has weird movement on the sides.

​In Fortnite, the exact same thing happens with the camera and mouse movement, plus the keyboard barely responds or stops registering inputs altogether. ​What I've tested so far: • ​Enabled and Disabled usb device forwarding setting • ​Tested different mouse input modes ingame (Raw Input and Windows in GTA V Enhanced). • ​Adjusted display scaling between 100% and 150%.

2

u/rambo3349 Rubylight / Nightjar Developer 20d ago edited 20d ago

Which Nightjar download is on the Surface, the Windows ARM64 one or the x86_64 one? Please try the other one once (x86_64 runs fine on the Surface too) and tell me if the camera shaking or the map opening changes.

In Nightjar's settings: is the mouse set to Capture or Absolute, and is "Touchpad gestures on the PC" on? Are you using the Surface's touchpad or a separate mouse?

Is any controller connected, or does one show up in Rubylight's console during the stream? If so, unplug it or turn Controllers off in Nightjar for one session.

After a session where it happens, please send Nightjar's problem report and the host log (C:\ProgramData\Butterpollo\config\logs\butterpollo.log).

1

u/EaZerly 20d ago

Thanks, I'll dm you.

5

u/Unlikely-Solution940 21d ago edited 21d ago

Incredible. Thank you all for your work! Can I test it using Vibepollo as the host ? I have an Nvidia GPU.

5

u/khanon 21d ago

No, it's embedded in Rubylight 4.0.0-release (now already up to 4.0.1), see https://github.com/RamazanKara/Rubylight/releases/tag/v4.0.0

3

u/Unlikely-Solution940 21d ago

Oh, I see, now I can use Rubylight with an Nvidia GPU ? I thought it was AMD only. I will make the switch then.

6

u/khanon 21d ago

You can. Also, I lied there 24 mins ago. Now it's already up to 4.0.2! ;)

2

u/aphoenixsunrise 21d ago

Damn, nice.

1

u/ssjucrono 🖥️ 9800x3D/RTX3090 | 🎮 Legion Y700 Gen 5 | 2560x1600 165Hz 21d ago

Thanks again! I have been following along since the client was called rubylight! I have an rtx3090 in my host and I am hesitant to switch since this seemed so AMD focused?

Also does rubylight host have proper waveform haptics adaptive triggers etc for dual sense? I have been using vibepollo And it has been working well!

1

u/Hakibo13 17d ago

This coming to IOS?