ValveSoftware / steam-for-linux

Issue tracking for the Steam for Linux beta client
4.22k stars 174 forks source link

Use hardware encoding on AMD RX480 for In-Home Streaming. #4890

Closed toojays closed 2 years ago

toojays commented 7 years ago

My GPU is an RX 480. When streaming to the steam link from Linux, my streaming_log.txt shows:

[2017-03-09 22:54:10] >>> Capture method set to Desktop OpenGL NV12 + scale + libx264 main (3 threads)
[2017-03-09 22:54:10] >>> Capture resolution set to 1280x720

Whereas from Windows, I get:

[2017-01-12 06:55:24] >>> Capture method set to Steam D3D10 NV12 + AMF H264
[2017-01-12 06:55:24] >>> Capture resolution set to 1920x1080

Unsurprisingly, I get a better picture, and smoother performance when streaming from Windows.

Recent versions of Mesa support hardware encoding of H264 on this GPU:

┌(toojays@kano)─(9993)─(0)─(2017 03 10 20:16:12)
└─(~)─> vainfo | grep Entry
libva info: VA-API version 0.39.4
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_0_39
libva info: va_openDriver() returns 0
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      <unknown profile>               : VAEntrypointVLD
      <unknown profile>               : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc

Please enhance the Steam Linux client to take advantage of this for streaming to the Steam Link.

ibrokemypie commented 5 years ago

so still only support for nvidia for encoding. software encoding KILLS game performance, and is such a waste of gpu or quicksync acceleration support on the hardware

daniel-j commented 5 years ago

With Steam Link Anywhere, this issue becomes even more relevant. Would be nice with hardware encoding support!

edenist commented 5 years ago

@kisak-valve or anyone else able to comment on if this is being worked on or not?

Software encoding is such a huge drain of my resources [currently using 4/8 cores for it] which are better used to run the game itself. There is also the extra latency which software encoding adds which arguably is the bigger issue for many games.

Also, is there any way we can help? Is there an API or something in steam we can use to hack our own solution together?

BlazeKl commented 5 years ago

I would love to have hardware encoding for amd, currently losing a lot of performance when streaming to my laptop

veikk0 commented 5 years ago

I recently tried out hardware encoding on an RX 470 via FFmpeg and tried recording gameplay using OBS (which uses VAAPI via FFmpeg). TL;DR: AMD's hardware encoder is not very useful on Linux because when the GPU is near 100% utilisation, the encoder chokes and drops 99% of frames, resulting in a slideshow recording. The cause is most likely that the ability to control the speed/compression tradeoff is either not implemented or not functional on Linux and the encoder defaults to the maximum compression ratio, which for whatever reason craps out when other parts of the GPU are under intense load.

This has also been documented to happen on Windows in a hardware encoder investigation done by GameSpot's Tim Schiessert:

AMD’s encoder is even worse in that when your GPU utilization is up near 100%, the encoder completely craps its dacks and can’t render more than about 1 frame per second, which wasn’t an issue with the Nvidia cards.

I was able to get the encoder working with a frame limiter enabled, which brought GPU utilization down to around 60% in Forza Horizon 4, but even with the ‘Quality’ encoding preset, the quality Vega 64 produced was worse than with even Nvidia’s Pascal cards.

I also saw a user report about this on Reddit. Apparently OBS has an option on Windows to change the compression efficiency from "best quality" (which is the default) to "balanced" which fixes the framedrop issue, so the feature definitely does exist. It's just not available on Linux for whatever reason. Not even FFmpeg is able to use the feature: it would evoked with the -compression_level switch, but this shows the error [h264_vaapi @ 0x5642618e45c0] Quality attribute is not supported: will use default quality level.

This is probably why AMD's hardware encoding isn't yet supported for In-Home Streaming on Linux. It's not very useful to add even preliminary support when you can't guarantee it's going to work properly.

If anyone knows or has suggestion as to where the root cause of this bug should be reported to (or if it has been already), please tell so we can track it.

toojays commented 5 years ago

[h264_vaapi @ 0x5642618e45c0] Quality attribute is not supported: will use default quality level.

This is probably why AMD's hardware encoding isn't yet supported for In-Home Streaming on Linux. It's not very useful to add even preliminary support when you can't guarantee it's going to work properly.

If anyone knows or has suggestion as to where the root cause of this bug should be reported to (or if it has been already), please tell so we can track it.

The AMD va-api driver is part of Mesa. Maybe start with the Mesa users mailing list.

This is probably why AMD's hardware encoding isn't yet supported for In-Home Streaming on Linux. It's not very useful to add even preliminary support when you can't guarantee it's going to work properly.

Since when was everything in Steam guaranteed to work properly? ;) There's already a check-box for hardware encoding in the GUI, just leave it disabled by default if it's flakey.

It's been widely reported that Google's new game streaming service is running AMD GPUs on Linux, so the capability exists in some form, somewhere.

Valve has AMD driver developers on staff. They have made other improvements in AMD drivers, and I expect they could implement the necessary quality preset code as well if it were a blocker to getting hardware encoding working.

IMO AMD has more to gain than Valve from Steam supporting their GPUs for hardware encoding (how many people on this thread will buy Nvidia next time?) and should work together with Valve to get this feature implemented.

HorstBaerbel commented 5 years ago

@veikk0 and @toojays : Apparently it works through gstreamer, but not through FFmpeg.
The test didn't bother testing more than one game on AMD, plus someone in the comments mentioned it: Why not use the Vendor-specific tools to test this too? I'd blame it on driver issues or OBS not doing the right thing. That aside: That was Windows, not Linux, so almost entirely a different thing.
It might be that on Linux the driver, MESA or VAAPI is not yet up to snuff, but I'd just call it a beta, add a disclaimer and be done with it.

coldhand7 commented 5 years ago

@kisak-valve Any news on this ?

toojays commented 5 years ago

After over two years with no action on this bug, I've finally gone with the expensive workaround of swapping out my RX480 for an Nvidia card (GTX 2060). I'm now comfortably streaming the Witcher 3 (under Proton) to my Steam Link at 1080p, with the streaming frame rate between 45-60 FPS, and my i5 CPU showing about 30% idle. I would much prefer using an AMD card due to the free drivers, but in this one area it just can't meet my requirements. Hopefully the situation is different by the next time I need to buy or recommend a GPU.

As far as I can tell, even with Nvidia, Steam's in-home streaming still copies each frame from the card over the PCI bus to the CPU, then sends it back to the card for encoding. I.e. the Nvidia technologies which are supposed to avoid this (NVFBC and NVIFR) aren't wired up to Steam on Linux. This suggests to me that there should be no disadvantage to @HorstBaerbel's suggestion of dropping in an older Nvidia card and doing the rendering on the AMD card but the encoding on the Nvidia card. Assuming it works. Sorry, I've already packed up my RX480 to sell, so will not be trying this experiment.

mellon85 commented 5 years ago

@slouken any update?

DistantThunder commented 5 years ago

@kisak-valve Hi guys, thanks for all your work.

I'm a new AMD GPU owner and would like to know if VAAPI hardware encoding is anything to hope for sooner rather than later?

parkerlreed commented 5 years ago

Oh look now I can remote stream and yet I still can't encode or decode with VAAPI. Hurts performance on both ends.

image

Seriously, is this never going to be fixed?

ryester19 commented 5 years ago

I'm fortunate enough as to where I only need video decoding from amdgpu since I'm using a Windows host, and my CPU can easily decode a 1080p stream for now. I'll add myself to the list of people wanting this since it has helped my display latency in the past

HorstBaerbel commented 5 years ago

Kudos to Valves commitment to OS OSes <3. Why not celebrate that by implementing an VA-API hardware encoding backend? ;P

moritz31 commented 5 years ago

Very annoying that the do not support this! Come on Valve!

spychodelics commented 5 years ago

Pretty please!

fallenguru commented 5 years ago

Is there an ETA, is it at least on the roadmap? I'd like to get an AMD card for my new build, not least because Valve has done so much work on them (ACO etc.), but I don't want to risk a hit on in-home streaming performance, as I play most games on the projector.

ryad-eldajani commented 4 years ago

The Android Steamlink App seems to have problems with libx264 encoded streams on certain devices. On my device connected to the TV, I have an unusable experience when streaming from AMD based Linux host using libx264 ("slow decoding" errors). Hardware accelerated h264 or h265 streams are working fine. Thus I would be extremely happy, if Valve could implement VAAPI :)

Stkrx commented 4 years ago

+1 for VAAPI encoding support

At least support AMF on amdgpu-pro for play games with encoding in linux

maxtorete commented 4 years ago

So we are few days ahead of the third birthday of this issue, it would be a great gift if we get a fix for hardware encoding in AMD hardware 😃

parkerlreed commented 4 years ago

My CPU is still crying image

tullo-x86 commented 4 years ago

TFW VA-API is 12 years old, but you backed the wrong horse

image

venomousZealot commented 4 years ago

I can confirm that sticking in an additional, nvidia-based gpu enables NVENC right out of the box. Quality is awesome and latency seems fine for a phone.

Obviously, I support this issue and would rather not do this... However, this is pretty much the last thing I need Windows for. If I was desperate to make the switch this would be a solution, but I will probably stick with Windows for now as running another gpu seems absurd.

Screenshot_20200422-160713_Steam_Link

Stkrx commented 4 years ago

Continue to using Windows as primary desktop by this issue, pls support vaapi on amd encoding.

cRaZy-bisCuiT commented 4 years ago

Any updates on that topic? Hardware encoding works very well as you could see by trying either ffmpeg manually to convert videos or use recent versions of OBS. Quality is fine and CPU load is very low. Any updates on that topic?

For some games my 3570K@4,4Ghz + RX480 8GB is very fine playing directly on the desktop but the performance gets abysmal while using inhome streaming due to missing hw encoding.

PS: Is it possible to use the HD4000 of the processor for encoding and the RX 480 to render the game?

torokati44 commented 4 years ago

+1 from me too to please support this. OBS, for example, can use the hardware encoder on my RX580 on Linux just fine.

torokati44 commented 4 years ago

I mean, isn't Steam already using ffmpeg/libav for this? If so, then... How is it much more code than this, for example? https://github.com/obsproject/obs-studio/blob/master/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c Someone, please, just shovel this in there somewhere, and let us be finally happy... I personally wouldn't even mind if it wouldn't be adaptive, or configurable, or anything like that, I'd like to just have it work in any way at all...

cRaZy-bisCuiT commented 4 years ago

Fun fact: Valve is pushing the FOSS Mesa driver stack for AMD/Intel but does not make us of it's capabilities aka hardware encoding.

HorstBaerbel commented 4 years ago

Maybe you can snatch some implementation details from Mozilla / Firefox. They finally have decoding running on X11. Yay.

torokati44 commented 4 years ago

The decoding is already accelerated by VA-API in Steam, as far as I can tell. But that's only one half (and the less useful one If you ask me) of the story...

HorstBaerbel commented 4 years ago

The decoding is already accelerated by VA-API in Steam, as far as I can tell. But that's only one half (and the less useful one If you ask me) of the story...

Yes, I know. It was more of a tounge-in-cheek comment. Else than that it is probably the more useful half, because more people use it.

cRaZy-bisCuiT commented 4 years ago

The decoding is already accelerated by VA-API in Steam, as far as I can tell. But that's only one half (and the less useful one If you ask me) of the story...

Yes, I know. It was more of a tounge-in-cheek comment. Else than that it is probably the more useful half, because more people use it.

Not sure about the "more useful", since if a system is only decoding it will most likely not be limited by the CPU. If you play a game and encode some stream having 50% CPU usage just for encoding is too much.

darksaboteur commented 4 years ago

This is the only thing keeping me on Windows for my gaming PC. I often stream to my loungeroom tv and my old quad core CPU can't handle it. On Windows my Radeon 7970 handles the encoding and it works perfectly. Valve, what can we do to help bump up the priority of this? With all of the great Linux work you have done this is a critical feature to overlook for so long

tullo-x86 commented 4 years ago

@Plagman

We don't currently support VA-API for encoding, but it's a valid feature request, thanks.

looks around nervously soooo... does this GitHub issue count as said feature request, or is there somewhere more formal that it should be submitted?

Just wanna make sure we're on the same page here.

venomousZealot commented 4 years ago

Make sure you give the first post a thumbs-up.

lhindir commented 4 years ago

From the latest beta update:

pressure-vessel: bring host VDPAU and VA-API drivers into the container

pressure-vessel is an opt-in containerization system for Steam games with advantages for host isolation and dependency management.

This must just be for VA-API's decoding features, then?

parkerlreed commented 4 years ago

Yeah, that's just for games running in the Steam Linux Runtime. It's for keeping older games running on modern systems.

derlaft commented 4 years ago

I think the biggest problem here, is that libav h264_vaapi encoder does not support the same set of option as the libx264 encoder. It might be extremely tricky to adapt existing code to such a radical change. That being said, I would not expect this to happen at all.

torokati44 commented 4 years ago

I disagree, but obviously none of us outsiders sees what's really the issue, since all this is closed-source. :)

derlaft commented 4 years ago

I disagree

... because?

kparal commented 4 years ago

Stop spamming, you're not helping. If you care about this issue, subscribe and vote with a thumbs up on the first post. This is not a discussion forum, stop the chat.

Rimits commented 3 years ago

I have a RX5700XT, and hw encoding still doesn't work. If i enable it in steam, my phone shows nothing but a black screen for a few seconds and exits. Now I'm forced to use cpu encoding, and it hurts a lot when playing proton games. vote for HW encoding

ieyi4ooPAig1ui5U commented 3 years ago

I have a RX 5500 XT 8GB and hw encoding isn't working for me here, either. It was working fine for some years with the old 2GB NVidia GTX 650 Ti "BOOST" that I was using prior, so I must confess to being greatly disappointed by this as well. So disappointed in fact, that I signed up to github just to report this.

KristijanZic commented 3 years ago

How is 2021 looking for this issue? Is VA-API on the roadmap?

l3iggs commented 3 years ago

Crazy that they're rolling out new features like remote play together: invite anyone which pretty much requires this bug to be fixed to work properly for many of us, but they do seemingly nothing on this bug and give us radio silence here for literally years now.

rventers commented 3 years ago

Looks like they've been working on using VA-API decoding on Linux clients, I'm really hoping they also are working on the Linux host encoding as well.

https://steamcommunity.com/groups/SteamClientBeta/announcements/detail/3050602228716269850

Stkrx commented 3 years ago

https://www.phoronix.com/scan.php?page=news_item&px=H264-SVC-Mesa-AMD-VCN

Good times to implement AMD linux encoding? :)

Mushoz commented 3 years ago

The issue was brought up back in 2017 (!). Valve's silence on this deafening. Would it be possible to get at least some form of communication on this issue? I think the most important questions are:

  1. Is implementation of this being considered or do we simply have to accept the fact this is never going to be implemented?
  2. If the answer to the previous question is yes, what would a rough timeline be? Are we talking months or years? Something else?

Any sort of information regarding this issue would be much appreciated, so we don't have to go by hope.

ripper81 commented 3 years ago

Yes it would be nice to get some feedback here. Nvidia owners could rely on NVENC since forever for hosting games over steam remoteplay. Not everyone owns a CPU that has the performance needed for hosting a game via steam remoteplay in way that results in a stable performance and decent quality. H.264 encoding is supported by a huge amount of AMD GPU's. Every GPU utilizing the AMDGPU kernelmodule should be able to make use of it. I have used VAAPI encoding for H.264 with OBS and Shotcut for a while now and it works great. Since steam uses ffmpeg just like these two apps, it should be doable with steam remoteplay too.

falk4243 commented 2 years ago

It is really quite unbelievable that this feature has not been implemented yet. Take a look at https://github.com/loki-47-6F-64/sunshine for example, which makes Gamestream possible via VAAPI for AMD GPUs. With the Steamdeck coming, this issue is probably going to be fixed sooner or later - or should Steam rely on CPU encoding for Valve's own console as well? It makes absolutely no sense to leave this issue open, if only for that.