playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] can't get webgl hardware acceleration working using official docker image

Open denisbrondy opened this issue 2 years ago • 19 comments

Context:

  • Playwright Version: 1.27.1
  • Operating System: Linux RH8
  • Node.js version: 16.14.2 (on hosting machine)
  • Browser: Chromium
  • Extra: Docker version 20.10.21
  • nvidia Quadro T1000

Describe the bug

Hi,

T trying to run playwright tests using webgl hardware acceleration inside the official Microsoft docker image. Here is the way I tried to make it work and I currently out of new idea to make it work.

1/ Using my hosting machine (see hereafter description), and WITHOUT docker, I created a classic project using the npx playwright command scafolding tool. I created a basic test that assert the chromium url chrome://gpu to check the two tags "WebGL" and "WebGL2".

Using this setup, I succeed in having the correct setup. screenshot

2/ Using the same scafolded project, i tried to run the same test inside the latest docker official image, which should be : mcr.microsoft.com/playwright:v1.27.0-focal. GPU and associated libraries seems correctly configured, as far as I known. I run the docker image using --gpus all. I can call nvidia-smi inside the docker.

First time I ran the test, I get the test failed. The two flags are setup to "Software only, hardware acceleration unavailable" (see screenshot). Which is not what we want because our UI massively use WebGL (threejs app) and the test will be definitively slow.

screenshot2

So I googled I find additional chrome parameters to be injected via the playwright.config.js file. I tried : --use-gl=egl

And this time the flags are now "Unavailable". screenshot3

I finally tried to also export the display of the docker image running to have direct access the chrome UI but I cannot get the hardware acceleration working fine.

Do you folks have any idea to make it working ?

Commands used:

npx playwright test --project=chromium (for both inside docker and on the hosting machine)

docker run --rm -e DISPLAY=${DISPLAY} -v /tmp/.X11-unix:/tmp/.X11-unix --gpus all -it -v /home/user/Documents/test-playwright:/tmp/denis mcr.microsoft.com/playwright:latest

In playwright.config.js launchOptions: { args: ["--use-gl=egl"] }

denisbrondy avatar Nov 15 '22 07:11 denisbrondy

+1

teslyaua avatar Jan 10 '23 07:01 teslyaua

Hello Tks for the pull up ! Any idea to solve this issue ? Tks

denisbrondy avatar Jan 11 '23 19:01 denisbrondy

Hello there! Same issue, looking forward to any workarounds/fixes.

olivandesign avatar Jan 16 '23 08:01 olivandesign

Have you tried --use-gl=angle? Works here in the official docker image with mapbox GL.

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        launchOptions: { args: ['--use-gl=angle']  }
      }
    }
  ]
});

Manduro avatar Jan 27 '23 10:01 Manduro

Have you tried --use-gl=angle? Works here in the official docker image with mapbox GL.

{
	projects: [
		{
			name: 'chromium',
			use: {
				...devices['Desktop Chrome'],
				launchOptions: {
					args: ['--use-gl=angle']
				}
			}
		}
	]
}

I have tried couple of options, this one as well. Didn't work for me: image

With image: mcr.microsoft.com/playwright:v1.30.0-focal

teslyaua avatar Jan 27 '23 11:01 teslyaua

Hello Same issue here. Confirmed does not fix the problem.

denisbrondy avatar Jan 30 '23 17:01 denisbrondy

+1

maxuai avatar Feb 27 '23 15:02 maxuai

+1

artkuznetsov avatar Mar 09 '23 04:03 artkuznetsov

I am experiencing the same issues. Are there any workarounds to get GPU running?

crllnsmnn avatar Mar 15 '23 06:03 crllnsmnn

same

Napolitain avatar Jun 09 '23 18:06 Napolitain

Hi all Could it be possible to have support on this issue ? We plan having a lot of tests using webgl soon and we do not know how to fix this problem... Please .. Tks again ! Denis

denisbrondy avatar Jun 11 '23 18:06 denisbrondy

sadly, I faced it but that bug is in Firefox browwser, not Chromium. do you know any ideal to fixed this problem ?

quan-nm-nexlesoft avatar Jul 29 '23 05:07 quan-nm-nexlesoft

@quan-nm-nexlesoft Firefox does not support WebGL in headless mode. Make sure that you run in headed mode, and you will need a virtual framebuffer for that (xvfb). Prepend your test run command with xvfb-run, e.g like this: xvfb-run npx playwright test ... or whatever.

@denisbrondy Maybe also check in Chromium whether headed vs headless mode makes a difference.

jhyot avatar Aug 23 '23 11:08 jhyot

We've had HWA working in docker with playwright + headless chrome by building a custom image from the base nvcr.io/nvidia/cudagl:11.4.2-runtime-ubuntu20.04.

Found this issue while investigating as our setup stopped working with chromium after playwright 1.31.

It would be much nicer to have HWA support in the blessed microsoft playwright images

kmannislands avatar Nov 14 '23 02:11 kmannislands

@kmannislands Did you make this image publicly available? It'd be nice if you could.

vcardins avatar Nov 15 '23 01:11 vcardins

any updates?

DoonPort0422 avatar Dec 20 '23 06:12 DoonPort0422

This combination worked for me

const browser = await chromium.launch({
        headless: true,
        args: [
                '--use-gl=egl',
                '--ignore-gpu-blocklist',
                '--use-gl=angle',
        ],
    }

along with using xvfb to run it

xvfb-run node src/index.js

Logged settings

[
 'Canvas: Hardware accelerated\n' +
   'Canvas out-of-process rasterization: Disabled\n' +
   'Direct Rendering Display Compositor: Disabled\n' +
   'Compositing: Hardware accelerated\n' +
   'Multiple Raster Threads: Enabled\n' +
   'OpenGL: Enabled\n' +
   'Rasterization: Hardware accelerated\n' +
   'Raw Draw: Disabled\n' +
   'Video Decode: Hardware accelerated\n' +
   'Video Encode: Software only. Hardware acceleration disabled\n' +
   'Vulkan: Disabled\n' +
   'WebGL: Hardware accelerated\n' +
   'WebGL2: Hardware accelerated\n' +
   'WebGPU: Disabled'
]

ipatka avatar Jan 07 '24 18:01 ipatka

I think I'm facing a similar issue, however what's different in my case is I have two different machines with identical setups (same packages etc) building the same dockerfile. When I test the resulting images one will have hardware acceleration enabled and the other won't, it's as if there's some contextual difference when building that I can't find.

homerjam avatar Jan 26 '24 00:01 homerjam

This combination worked for me

const browser = await chromium.launch({
        headless: true,
        args: [
                '--use-gl=egl',
                '--ignore-gpu-blocklist',
                '--use-gl=angle',
        ],
    }

along with using xvfb to run it

xvfb-run node src/index.js

Thanks for sharing @ipatka. I can confirm this also worked for me.

StebanDev avatar Feb 01 '24 00:02 StebanDev

@ipatka @StebanDev Could you please share more details, if possible? Perhaps snippets of your dockerfile?

We can't get passed xvfb-run. It hangs the docker container, regardless of what args or options passed.

aidinabedi avatar Feb 19 '24 22:02 aidinabedi

@ipatka @StebanDev Could you please share more details, if possible? Perhaps snippets of your dockerfile?

We can't get passed xvfb-run. It hangs the docker container, regardless of what args or options passed.

@aidinabedi Doesn't work for you locally or on the CI? In my case it was working fine on github actions but to make it work locally I needed to add the --init option to the docker run command. https://docs.docker.com/engine/reference/commandline/container_run/#init Hope it helps!

StebanDev avatar Feb 20 '24 17:02 StebanDev

Thank you @StebanDev! I was indeed running locally. Using --init resolved xvfb-run hanging.

aidinabedi avatar Feb 20 '24 17:02 aidinabedi