serverless-chrome
serverless-chrome copied to clipboard
Add WebGL Support
Hello,
I spent all day experimenting and got WebGL working with headless shell. See the thumbnails here: https://www.reddit.com/r/pplay/ - they are rendered by lambda function from webgl scene.
To enable WebGL:
- I built osmesa using this script: https://github.com/devernay/osmesa-install . I changed
disable_shared
toenable_shared
(line 534) to create libOSMesa32.so file). On EC2 instance, then final file was called libMangledOSMesa32 - just copy it next to the headless chrome binary aslibosmesa.so
. - Remove
disable-gpu
flag, and tweak serverless-plugin-chrome, so thatlibosmesa.so
is included into distribution.
PS: I don't remember whether I used headless_shell
from this repository.It might be from https://github.com/universalbasket/aws-lambda-chrome But still - the WebGL in AWS lambda is possible, and I'm very happy to share it :).
Hi @anvaka — That's interesting. When building chromium from source, it also produces a libosmesa.so
shared library. I just don't include it as it was my understanding that WebGL wasn't yet supported by the headless_shell
. But, perhaps this is no longer the case!
@anvaka do you have a repo containing a working setup for running webgl on AWS lambda? I'm trying to do the same thing without luck :(
I just got this running using the steps @anvaka provided. Not sure if it's enough to just include a libosmesa.so
binary in the repo or if you'd want to build that at the same time as the Chrome binary, but I'm happy to try and put together a pull request with a little guidance.
Yep, I can confirm, I got it working as well. The best option is to get the headless_shell binary and the libOSMesa.so in the AWS redHat distro and ship them together to the lambda. Note that all data paths needs to point to /tmp, otherwise it will crash because of write permissions. The webgl version Mesa provides is wegbl1 but it does the work, pretty slow but works.
Hi Guys,
I'm still having trouble, so I'm hoping someone could point me in the right direction.
- I installed the mesa-libOSMesa package on an Amazon Linux platform
- Obtained the .so file, and copied this into the /node_modules/serverless-chrome/lambda/dist folder as libosmesa.so
- I modified the bundle dist file and hobbled out the --disable-gpu
- I added to the flags; --use-gl=osmesa
Deploying it I still can't see rendered webgl content. Is there a step I am missing?
Cheers Cam
To anyone looking for a working combination of Mesa and Headless shell for AWS, these are the binaries, it provides pretty slow webgl V1, but it works. Hope it helps!
Headless Shell Mesa AWS Lambda
Remember to put in your flags:
[ '--use-gl=osmesa', '--enable-webgl', '--ignore-gpu-blacklist', '--homedir=/tmp', '--single-process', '--data-path=/tmp/data-path', '--disk-cache-dir=/tmp/cache-dir' ]
Otherwise it will crash due to write permissions.
Hello, @vsantosu can you please share binaries again (the link is 404 at the moment)? Also after playing around I think I got chromium to render webgl content with screenshot function, but when printing to PDF WebGL areas appears to be blank (found a similar issue https://github.com/GoogleChrome/puppeteer/issues/1731 but nothing helps), does anyone faced this issue? Thanks.
If anyone had the same PDF issue, rolling back to 64.0.3282.167
(instead of latest stable 67.0.3396.79
or dev 69.0.3452.0
) solved it for me.
Has anyone had experience using swiftshader
instead of mesa
when no GPU available?
@vsantosu
I was hoping you still had that build somewhere. @mvoropaiev pointed out the link doesn't work.
I tried what @anvaka suggested without any luck. I have a zip with both headless_shell
and libosmesa.so
in there. The headless_shell works, but things fail with webgl.
Here are my CLI args:
args: [
'--use-gl=osmesa',
'--enable-webgl',
'--hide-scrollbars',
'--mute-audio',
'--no-sandbox',
'--single-process',
'--disable-breakpad',
'--ignore-gpu-blacklist',
'--homedir=/tmp',
'--data-path=/tmp/data-path',
'--disk-cache-dir=/tmp/cache-dir'
]
I'm actually firing this up with Puppeteer. The same command works locally, but I get errors on the lambda. My lambda works fine for non-webgl stuff.
Sorry for the broken link guys. I re-uploaded the zip here:
It has the libosmesa.so already in the directory, just point Puppeteer to it and everything should work fine.
Disclaimer: I ended up using Software Based Rendering using array buffers(Threejs) because Mesa rendering is slow as a asphalt serum. Lambda CPU is pretty fast, so my rendering time went down from minutes to seconds(30 or less).
@vsantosu
Thanks!. This is helpful
On a sidenote, do you have any idea how to get swiftshader-webgl on a lambda? Or if it's possible?
I'm trying to render a mapbox map on a lambda, and I'm really not having luck.
@rthomps7 I haven't deal with swiftshader yet, but if you get it working let me know! What I do is launch a Lambda EC2 image instance, compile everything there with static linking, and then try to get a screenshot of some Webgl render. To double check I try to use the static compiled library in a fresh CentOS VM locally.
@rthomps7 did you had any luck trying swift shader? I'm searching online but without luck. I think it is possible to build headless chrome with swiftshader enabled.
What about adding the following line after: build flags?
echo 'enable_swiftshader = true' >> out/Headless/args.gn && \
Afterwards a quick test can be done by adding:
--use-gl=swiftshader
In chromium command line arguments.
I have not been able to dedicate the time to it, but I'd love to have it figured out.
On Mon, Aug 20, 2018 at 8:48 AM Victor O. Santos Uceta < [email protected]> wrote:
What about adding the following line after: build flags https://github.com/adieuadieu/serverless-chrome/blob/master/packages/lambda/builds/chromium/build/build.sh#L90 ?
echo 'enable_swiftshader = true' >> out/Headless/args.gn && \
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/adieuadieu/serverless-chrome/issues/108#issuecomment-414322407, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOMZKC8R7Q92IPwbZQhBq4-j8SyoHBUks5uSr4pgaJpZM4R5F2- .
--
Bobby Thompson / Co-Founder 913.314.2520 javascript:void(0); / [email protected] www.uhray.com
I can try doing a build with enable_swiftshader
if someone else can help test the resulting binary on aws lambda.
if someone else can help test the resulting binary on aws lambda
@adieuadieu I could easily to do it tomorrow morning my time
@adieuadieu I volunteer to that. I already have some experiments setup there, I just need the binary to replace.
Thank you! I've started a build. If it builds successfully, I'll provide a link to the binary in the morning (UTC+2).
OK; binary is available here. It's also available in a Docker image: adieuadieu/headless-chromium-for-aws-lambda:experimental-swiftshader
@adieuadieu it seems WebGL doesn't work with the provided binary in my case.
@adieuadieu it does not seems like it is working for me either... I have not build headless chrome for Unix yet, but in Windows, chromium comes with a directory called swiftshader with two binaries:
- libEGL.dll
- libGLESv2.dll
I guess that for a lambda build will be something like:
- libEGL.o
- libGLESv2.o
If you can find some files like those in the build directory, we need to provide those in the same directory as headless_chrome binary at the time of launching with:
--use-gl=swiftshader
Which is the case with MESA lib.
@vsantosu ah shoot. you're right. I'll get you those library binaries, as well. Need to do another build, though. The EC2 instance I built on was terminated.
i've built Chromium using this instruction
Here are the output files: headless_shell swiftshader/libEGL.so swiftshader/libGLESv2.so
They works for me and WebGL renders on the page. Unfortunately I didn't notice any benefits in comparison with osmesa
- almost the same rendering time.
Look forward to seeing this in action. On Wed, 22 Aug 2018 at 7:16 am, Andrei [email protected] wrote:
i've built Chromium using this instruction https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md
Here are the output files: headless_shell https://s3-eu-west-1.amazonaws.com/apalchys-public/headless_shell swiftshader/libEGL.so https://s3-eu-west-1.amazonaws.com/apalchys-public/swiftshader/libEGL.so swiftshader/libGLESv2.so https://s3-eu-west-1.amazonaws.com/apalchys-public/swiftshader/libGLESv2.so
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/adieuadieu/serverless-chrome/issues/108#issuecomment-414824452, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjVHvuPP_fhORSGC5gtCYYO77eMl6hrks5uTHiogaJpZM4R5F2- .
Great! Thanks,
I will try some benchmarks tonight as well. Last time I tried MESA it took about 3 minutes to render some Threejs scene with lights. We also need to check if swiftshader takes advantage of parallelism, if so in AWS lambda 1 core environment there will be not much difference.
@vsantosu - any luck?
@rthomps7 unfortunately not :(... I tried to setup the provided build by @apalchys but it does not seems to work for me in AWS Lambda...
@apalchys , did you got to tried in an actual AWS lambda function or just docker? If so, what is your directory organization(do you leave the .o files for swiftshader in the /swiftshader directory or next to the headless chrome binary?). Also, can you provide your command line flags?
Whenever I try to launch it, it does not even load the page. The build provided by @adieuadieu works for me and is pretty lightweight but I don't have the swiftshader binaries, I don't dare to mix them with the ones provided by @apalchys. I'm curious what version of WebGL is reported when using swiftshader....
@vsantosu actual AWS lambda. I will try to create a simple working repo for AWS Lambda by tomorrow