FreeTube
FreeTube copied to clipboard
[Feature Request]: Ability to toggle hardware acceleration off
Guidelines
- [X] I have searched the issue tracker for a feature request that matches the one I want to file, without success.
- [X] I have searched the documentation for information that matches the description of the feature request I want to file, without success.
Problem Description
my PC for whatever reason does not like hardware acceleration on some apps, freetube included, it will make the screen all glitchy and spastic, sometimes go fully black in the app. I know it's caused by hardware acceleration because my browser did the same thing on youtube's website until I disabled hardware acceleration in the settings.
Proposed Solution
Simple toggle in the Player Settings
Alternatives Considered
I could not find any other solution to this issue
Issue Labels
improvement to existing feature, new optional setting
Additional Information
I have a 3060 GPU
(Not my post, just an example) https://community.brave.com/t/hardware-acceleration-broken-youtube-videos-flickering-anti-aliasing-broken/319307
The app works fine on my laptop but does the above listed issues on my main PC.
I think this is reasonable, looks like you'll need to be able to at least access settings and restart the app but easily doable.
Reference link for whoever attempts: https://www.electronjs.org/docs/latest/api/app#appdisablehardwareacceleration
I am giving a shot at adding a setting for this, however I have stumbled upon a couple issues, any help from the contributors would be appreciated. Here is a PR on my own fork for reference of where I'm at:
https://github.com/gtsop/FreeTube/pull/1/files
As you can see, I have added UI code using disableSmoothScrolling
as my guide
Problem 1: Contrary to disableSmoothScrolling
, the new disableHardwareAcceleration
option needs to be accessible before the app is ready. In order to do this i added the _findAppPreReadyRelatedSettings()
method on the base handler but unfortunately when I am trying to call this method with await
in index.js
, the electron app won't start at all.
https://github.com/gtsop/FreeTube/pull/1/files#diff-f4ca67281c6be819c2166841d7631ffd5316d4c3a3b40e01a512c4113a537b2cR56
I also don't see any crash errors anywhere which is making it harder for me to solve this issue
Problem 2: I am not sure how to validate that hardware acceleration has been disabled. I tried doing
app.getGPUInfo('basic').then(basicObj => {
console.dir(basicObj);
});
But nothing would appear on my console.
About logging, I added these
src/renderer/main.js
ipcRenderer.on('log', (event, data) => {
console.log(data)
})
src/main/index.js
app.getGPUInfo('basic').then(info => {
mainWindow.webContents.send('log', info)
})
and got
{
"auxAttributes": {
"amdSwitchable": false,
"canSupportThreadedTextureMailbox": false,
"dx12FeatureLevel": "Not supported"
...
in devtools
Thanks to @hockerschwan I have validated that the code actually has an impact on disabling hardware acceleration, I updated my linked PR. Now the first problem remains, getting the setting value from the database at the initialization stage
https://github.com/gtsop/FreeTube/pull/1/files
Update: I realized the my problem was not with calling the await
keyword (needed to declare runApp
as async
) but with the actual call to the base handler.
https://github.com/gtsop/FreeTube/pull/1/files#diff-f4ca67281c6be819c2166841d7631ffd5316d4c3a3b40e01a512c4113a537b2cR57
I have a hard time debugging this because I do not see error logs anywhere. The application crashes before the window comes up and I don't see any error logs in my terminal. Can someone help me with figuring out how to see the crash logs?
It's tedious but npm run build
then freetube
will log to shell.
It seems basehandlers
is empty before app is ready
I've been meaning to do a more in-depth reply but I keep running short on time, you can debug the app using chrome remote debugging to see all the main process messages. There are a few bits of info online and I think we need to write up a better development.md section on it. Cheers for the work on this.
@hockerschwan
It seems basehandlers is empty before app is ready
The problem is with the call to the database. I replaced the implementation of the basehandler function I was calling with return Promise.resolve(1)
and everything worked fine. Replacing that with the query call to database causes the application to never show the window.
Also, I noticed that this process is delay-sensitive. I tried waiting for a timeout of 100ms return new Promise((r) => setTimeout(r, 100));
and the application came up properly. Replacing this timeout with 200ms or higher cause the application to crash. From that, I make the hypothesis that the call to the database takes more than 100ms to resolve and this delay (for some reason) makes the app crash. Will need to validate though through logs.
@vallode I saw some related information online but it seemed to troublesome and I assumed there must be an easier way, thus I didn't bother. Since you're telling me that's the actuall way to debug the main thread, I'll go ahead and do it. Would be very helpful to have your write-up on how to debug it though.
Update: I updated my PR with a fixture to demonstrate the code works if the database is not called https://github.com/gtsop/FreeTube/pull/1/files#diff-00d732993695386319f793fc4fe19dd1aacf8d9519390634eebc3bc1c5d78438R36
@hockerschwan
It's tedious but
npm run build
thenfreetube
will log to shell.
Tried it and got this, then nothing happened:
johndoe@laptop1:~/Projects/FreeTube/build/linux-unpacked$ ./freetube
mesa: for the --simplifycfg-sink-common option: may only occur zero or one times!
mesa: for the --global-isel-abort option: may only occur zero or one times!
mesa: for the --amdgpu-atomic-optimizations option: may only occur zero or one times!
[38003:0619/204833.026726:ERROR:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process.
This issue is stale because it has been open 28 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Is this still being worked on or is it not possible with the code? I'd just like to voice the continuing need for this feature. In GPU heavy games, having freetube on a second monitor requires disabling hardware acceleration to have a non-stuttery experience.
@mokahless This issue is still relevant :)
This issue is stale because it has been open 28 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Sorry for the lack of updates, they come with lack of progress. Unfortunately I don't have the knowledge to progress with this issue, a contributor with better knowledge of Electron and how the App is structure should follow up and give guidance. All my code is up in the linked PR, I am glad to carry on if given guidance, else someone else has to do the job.
This problem boils down to storing and retrieving the configuration option properly. The UI was implemented already and the electron command to disable hardware acceleration seems to be working fine.
if you want to do stuff before the ready event is fired, it has to be entirely synchronous, as the database library only supports callbacks and async (which is good for everything else in FreeTube), you can't access this setting in the database before the ready event fires.
What's happening at the moment:
- you access the settings database asynchronously
- the ready event fires
- your asynchronous database access finishes
The order will be the same most times, but of course there is a tiny chance that the database access finishes before the ready event fires, but this is extremely rare.
I was the one who made this post originally, I deleted my account for privacy and a lack of use for the account.
Has there been any progress on this? I am unable to use this app without resetting my GPU settings every time I want to use it.
@absidue I believe we cannot store this option in the database because of what you described. So the question is: Where should we store it?
- One simple solution would be to modify the lunch parameters of the program. Then we would add some instructions for users to add a command line argument at the startup file (not very user friendly for non-technical people)
- Are there any conventions for electron apps to store configuration like that? Do we know of any other Electron applications that disable hardware acceleration and how they store this setting?
@Lagomorpheus there has been some progress but not all the way: We have built the UI for toggling the setting and we have identified the appropriate command to turn off hardware acceleration. However we have not figured out how to properly store this setting due to some technicalities of the how the platform works
Sorry @gtsop, I did not notice this thread. Maybe you can do something similar to how the imageCache setting is set and retrieved?
It creates a file when it's set and removes it when it is unset. At startup, it checks for the existance of the file synchronously instead of doing any calls to check app settings.
You can see the code for this change here: https://github.com/FreeTubeApp/FreeTube/pull/2498/files
Maybe @absidue has more input on this idea?