pol-rivero / DiscordAudioStream

Windows utility for streaming (with audio!) in Discord. Easily share the the audio of entire screen, or even use OBS for streaming!
GNU General Public License v3.0
184 stars 7 forks source link

GPU Acceleration Issue #54

Open Piglerr opened 2 weeks ago

Piglerr commented 2 weeks ago

I use Discord Audio stream since version 1.2.3 but for some reason it stopped working a few days ago. I now updated to the latest version and the issue is still there.

The video (and the preview) are very laggy all of a sudden. Even if i drag the window the window itself lags behind.

I dont know if the app did use my gpu or cpu before this issue happened but it does use my cpu now (at 20%ish utilization) which doesnt have integrated graphics.

I have already set my 2070s as a rendering device in the Windows and Nvidia settings but that didnt help either.

Any ideas how to resolve this?

pol-rivero commented 2 weeks ago

That's strange. I'll have a look tomorrow and try to reproduce it.

pol-rivero commented 2 weeks ago

I haven't seen anything strange in my computer, it's using the GPU as expected. Let's see if we can find something on the logs. Please follow these steps:

  1. Download the latest version (1.4.2) if you haven't already
  2. Go to Settings > Debug and enable "Output log file". Restart the program.
  3. Go to Settings > Capture and change the capture method for fullscreen or window (depending on what you are going to capture) to BitBlt.
  4. Open the Windows Task Manager and make sure the capture is being done on the CPU (if you have a fast CPU, you might want to increase the capture framerate to 60 FPS to make it more noticeable).
  5. Without closing the program, change the capture method back to Windows 10 or DXGI Duplication, both of which are GPU-accelerated.
  6. Check the Task Manager to see if the CPU usage has dropped.
  7. Close the program and send me the log file (DiscordAudioStream_log.txt, created next to your DiscordAudioStream.exe executable).
Piglerr commented 2 weeks ago

So I have done all of that.

When I set the capture method to Windows 10, the CPU dropped to around 15% and the GPU was at 4%. But it still stutters.

DiscordAudioStream_log.txt

Should i try to wipe the gpu drivers with DDU (DisplayDriverUninstaller) and install the latest one?

pol-rivero commented 2 weeks ago

I see no errors in the log, and the fact that the CPU usage drops when changing to Windows 10 seems to indicate that the GPU acceleration is also working.

You say that the error started randomly without making any change to DiscordAudioStream, so something external must have caused it. As you said, you could try reinstalling the drivers, maybe it somehow fixes the issue.

This part of your original message seems very strange:

Even if i drag the window the window itself lags behind.

Can you try the following?

  1. Ensure the Window capture method is Windows 10.
  2. Capture a window and move that window around. The captured video should not lag behind. If it does, something strange has happened (send me the log).
  3. Restart the program.
  4. Check that the same window is remembered and re-captured automatically when the program opens.
  5. Open settings and check that the capture method is still Windows 10 (has not changed to BitBlt).
  6. Move the captured window and ensure that the captured video doesn't lag behind.
Piglerr commented 2 weeks ago

To clarify whats happening i recorded it heres a link to the video:

https://youtu.be/0R4qCIEtkNM

And the log file:

DiscordAudioStream_log.txt

I will now completely wipe the video drivers. I will update you on how that turns out.

Piglerr commented 2 weeks ago

I now wiped and reinstalled the video drivers but the issue is still there.

pol-rivero commented 2 weeks ago

I see I misunderstood what you meant. The issue you are seeing can be caused when the UI thread has too much work and can't keep up. Usually, the heaviest task in the UI thread is drawing the captured image. Can you check if capturing a smaller area (for example, a small window) also causes this stuttering?

The ways to mitigate this performance issue are:

Still, what seems really strange to me is that it just started happening randomly. Do you remember doing any change on your system that could have caused it? (like a Windows or driver update, connecting a 4k monitor, etc.)

Piglerr commented 2 weeks ago

Im not shure but there could have been a Windows update before this happened.

BUT i just found something weird as i tried to capture a small window. Here is a video again:

https://youtu.be/mj6DRScGW44?si=a2I4xOSReNh3oQ8_

And the log file again:

DiscordAudioStream_log.txt

Okay so before i press the start stream button the window itself is what feels like 60 ish fps. Or at least choppier than everything else (i use a 144hz monitor). It's hard to see, but if you compare the cursor and the window with each other, you can see even in the video that the cursor is smoother than the window. If the scale setting is not at 100%, the window and the capture stutter. At 100% it no longer stutters. But it doesn't stutter no matter what scale setting I have set if I select a very small window for Area.

pol-rivero commented 2 weeks ago

Oh! That's a great find! I forgot that rescaling the image is done on the CPU, so maybe that has somehow become very slow on your PC. Rescaling the image on the GPU should be possible, but it's been a long time since I wrote this program, so it will take some time to find out how. Also, I don't have nearly as much free time as I did back then.

For now you can keep using the 100% scale as a workaround.

Piglerr commented 2 weeks ago

Will do. Thank you for your time.

pol-rivero commented 1 week ago

I managed to free up some time and I think I got it working. Thank you for your patience. The latest build scales down the image using the GPU, please try it and let me know if it fixes your performance issue (also tell me if you find any bugs). Make sure to use the Windows 10 capture method for the best results

I'm still not 100% happy with the image quality, sometimes it has a bit of aliasing. I might try to implement a better sampling algorithm before publishing the release version, if I find the time.