Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless rendering EGL (without GLX) #7

Closed
bhack opened this issue Feb 24, 2019 · 31 comments
Closed

Headless rendering EGL (without GLX) #7

bhack opened this issue Feb 24, 2019 · 31 comments
Labels
enhancement New feature or request

Comments

@bhack
Copy link

bhack commented Feb 24, 2019

If you are interested in EGL headless check https://bitbucket.org/pyglet/pyglet/issues/219/egl-support-headless-rendering

@mmatl mmatl added the enhancement New feature or request label Feb 24, 2019
@mmatl
Copy link
Owner

mmatl commented Feb 24, 2019

@bhack Great link, thanks so much! Pyglet already had an EGL backend (I had a sample platform for it here), but it hasn't worked very stably as of yet. I'll be keeping an eye on this thread, and I'll add in support for hardware-accelerated headless rendering with EGL as soon as Pyglet supports it cleanly.

Best,
Matt

@bhack
Copy link
Author

bhack commented Feb 24, 2019

@bhack
Copy link
Author

bhack commented Feb 24, 2019

Cause:

OpenGL 3.3 and above, the corresponding GLSL version matches the OpenGL version

But here i see 3.2:
https://github.com/mmatl/pyrender/blob/master/pyrender/platforms.py#L120

And shaders
#version 330 core

@mmatl
Copy link
Owner

mmatl commented Feb 25, 2019

Hi @bhack,

Thanks for the suggestion. After messing around a lot, I realized that I just had an NVIDIA driver issue with EGL on Ubuntu 16.04. I tried my EGL platform on Google CoLab and it works on newer Ubuntu versions (or if you install your drivers from a runfile). Check it out here. Does that work for you?

@bhack
Copy link
Author

bhack commented Feb 25, 2019

This require email notification. Can you share in the repo or on gist?
I have a machine to test it.

@mmatl
Copy link
Owner

mmatl commented Feb 25, 2019

Oops so sorry, forgot to share the link! You should be able to access it now.

Here's the code:

# Render offscreen -- make sure to set the PyOpenGL platform
import os
os.environ["PYOPENGL_PLATFORM"] = "egl"
import numpy as np
import trimesh
import pyrender

# Load the FUZE bottle trimesh and put it in a scene
fuze_trimesh = trimesh.load('pyrender/examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)

# Set up the camera -- z-axis away from the scene, x-axis right, y-axis up
camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0)
s = np.sqrt(2)/2
camera_pose = np.array([
       [0.0, -s,   s,   0.3],
       [1.0,  0.0, 0.0, 0.0],
       [0.0,  s,   s,   0.35],
       [0.0,  0.0, 0.0, 1.0],
    ])
scene.add(camera, pose=camera_pose)

# Set up the light -- a single spot light in the same spot as the camera
light = pyrender.SpotLight(color=np.ones(3), intensity=3.0,
                               innerConeAngle=np.pi/16.0)
scene.add(light, pose=camera_pose)

# Render the scene
r = pyrender.OffscreenRenderer(640, 480)
color, depth = r.render(scene)

# Show the images
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(1,2,1)
plt.axis('off')
plt.imshow(color)
plt.subplot(1,2,2)
plt.axis('off')
plt.imshow(depth, cmap=plt.cm.gray_r)
plt.show()

image

@bhack
Copy link
Author

bhack commented Feb 25, 2019

Yes it is working correctly.
Of course I need to use savefig in a headless context.

@mmatl
Copy link
Owner

mmatl commented Feb 25, 2019 via email

@bhack
Copy link
Author

bhack commented Feb 25, 2019

I've tested on Ubuntu 16.04

@bhack
Copy link
Author

bhack commented Feb 25, 2019

If you are interested for the readme:
EGL 1.5 on r600, radeonsi, nv50, nvc0 from https://www.mesa3d.org/relnotes/11.0.0.html
So we are talking about 2015 release.
I don't know the updated Intel status.

@mmatl
Copy link
Owner

mmatl commented Feb 25, 2019

Thanks so much! I'll close the issue for now.

@mmatl mmatl closed this as completed Feb 25, 2019
@arsalan-mousavian
Copy link

arsalan-mousavian commented May 11, 2019

I am trying to use pyrender inside a docker image. I get the following error when I try to just import. If I try to import for the second time it goes through and then fails when creating offscreenrenderer. Any suggestions?

import os
>>> os.environ["PYOPENGL_PLATFORM"] = "egl"
>>> os.environ["PYOPENGL_PLATFORM"] = "egl"
>>> import pyrender
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 351, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Window'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 351, in __getattr__
    return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute '_create_shadow_window'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pyrender/__init__.py", line 12, in <module>
    from .viewer import Viewer
  File "/usr/local/lib/python3.5/dist-packages/pyrender/viewer.py", line 36, in <module>
    class Viewer(pyglet.window.Window):
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 357, in __getattr__
    __import__(import_name)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/window/__init__.py", line 1872, in <module>
    gl._create_shadow_window()
  File "/usr/local/lib/python3.5/dist-packages/pyglet/__init__.py", line 357, in __getattr__
    __import__(import_name)
  File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/__init__.py", line 100, in <module>
    from pyglet.gl.lib import GLException
  File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/lib.py", line 143, in <module>
    from pyglet.gl.lib_glx import link_GL, link_GLU, link_GLX
  File "/usr/local/lib/python3.5/dist-packages/pyglet/gl/lib_glx.py", line 50, in <module>
    gl_lib = pyglet.lib.load_library('GL')
  File "/usr/local/lib/python3.5/dist-packages/pyglet/lib.py", line 168, in load_library
    raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "GL" not found.
>>> os.environ["PYOPENGL_PLATFORM"] = "egl"
>>> import pyrender
>>> pyrender.OffscreenRenderer(400, 400)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pyrender/offscreen.py", line 32, in __init__
    self._create()
  File "/usr/local/lib/python3.5/dist-packages/pyrender/offscreen.py", line 129, in _create
    self._platform.init_context()
  File "/usr/local/lib/python3.5/dist-packages/pyrender/platforms.py", line 137, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "/usr/local/lib/python3.5/dist-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/usr/local/lib/python3.5/dist-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
	err = 12289,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7f1fe2a4c158>,
		c_long(0),
		c_long(0),
	),
	result = 0
)

@Ushk
Copy link

Ushk commented Jul 14, 2019

@arsalan-mousavian - I am having the same issue. Did you resolve it somehow, or open a new issue? (I am aware this one is closed).

I have seen this post:
https://github.com/NVIDIA/libglvnd/issues/174
but the solution given did not work for me.

@arsalan-mousavian
Copy link

I ended up creating my docker image based of https://hub.docker.com/r/nvidia/cudagl and fixed the issue.

@Ushk
Copy link

Ushk commented Jul 14, 2019

Thanks for the speedy reply, especially given that the last comment was over two months ago!

Mine is also based on cudagl (have tried 10.0-devel and 10.0-base, to be specific). Could I ask which image you used? And, if possible (I realise time has passed) what apt install packages you used in the run file, in case this is ultimately some sort of missing library issue.

@arsalan-mousavian
Copy link

nvidia/cudagl:10.0-devel-ubuntu16.04

@Ushk
Copy link

Ushk commented Jul 17, 2019

For the benefit of anyone who reads this at a later date (relevant) - I gave up and switched to a different python package. I couldn't get any of the listed docker images to work for me.

@mikedh
Copy link

mikedh commented Jul 17, 2019

Haha I have no idea if it works with pyrender, but I use LLVMpipe software rasterization and XVFB to do simple renders in containers to avoid the pain of CUDA/EGL/etc. I just pushed a minimal example which should render a sphere inside a container.

@wangg12
Copy link
Contributor

wangg12 commented Jul 20, 2019

@mmatl I ran your EGL example, but get this error:

Traceback (most recent call last):
  File "lib/python3.6/site-packages/OpenGL/latebind.py", line 41, in __call__
    return self._finalCall( *args, **named )
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "examples/egl_example.py", line 36, in <module>
    color, depth = r.render(scene)
  File "pyrender/examples/../pyrender/offscreen.py", line 100, in render
    return self._renderer.render(scene, flags)
  File "pyrender/examples/../pyrender/renderer.py", line 121, in render
    self._update_context(scene, flags)
  File "pyrender/examples/../pyrender/renderer.py", line 709, in _update_context
    p._add_to_context()
  File "pyrender/examples/../pyrender/primitive.py", line 324, in _add_to_context
    self._vaid = glGenVertexArrays(1)
  File "lib/python3.6/site-packages/OpenGL/latebind.py", line 45, in __call__
    return self._finalCall( *args, **named )
  File "lib/python3.6/site-packages/OpenGL/wrapper.py", line 657, in wrapperCall
    result = wrappedOperation( *cArguments )
  File "lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 401, in __call__
    if self.load():
  File "lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 390, in load
    error_checker = self.error_checker,
  File "lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 148, in constructFunction
    if (not is_core) and not self.checkExtension( extension ):
  File "lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 270, in checkExtension
    result = extensions.ExtensionQuerier.hasExtension( name )
  File "lib/python3.6/site-packages/OpenGL/extensions.py", line 98, in hasExtension
    result = registered( specifier )
  File "lib/python3.6/site-packages/OpenGL/extensions.py", line 105, in __call__
    if not specifier.startswith( self.prefix ):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Do you know how to solve this problem?

@oarriaga
Copy link

I have the same problem as @wangg12 :<

@wangg12
Copy link
Contributor

wangg12 commented Aug 3, 2019

My problem was gone by this.

@LaiQE
Copy link

LaiQE commented Dec 16, 2019

I ended up creating my docker image based of https://hub.docker.com/r/nvidia/cudagl and fixed the issue.

thak you very much , solve my problem

@wookayin
Copy link

For anyone who might run into this issue and find this issue from Googling: make sure you have libegl1 (or libegl-dev) packages installed.

@wine3603
Copy link

wine3603 commented Sep 26, 2020

I get the same error on ubuntu 18, cuda 10, pyrender 0.1.36 with pyopengl 1.30, any helps?

libEGL warning: DRI2: failed to create dri screen
libEGL warning: Not allowed to force software rendering when API explicitly selects a hardware device.
libEGL warning: DRI2: failed to create dri screen
Traceback (most recent call last):
  File "demo.py", line 382, in <module>
    main(args)
  File "demo.py", line 256, in main
    renderer = Renderer(resolution=(orig_width, orig_height), orig_img=True, wireframe=args.wireframe)
  File "/home/zhang-u16/VIBE/lib/utils/renderer.py", line 60, in __init__
    point_size=1.0
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/platforms/egl.py", line 177, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
	err = 12289,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7fefdc14ecb0>,
		c_long(0),
		c_long(0),
	),
	result = 0
)
```
`

@bestgodok
Copy link

I get the same error on ubuntu 18, cuda 10, pyrender 0.1.36 with pyopengl 1.30, any helps?

libEGL warning: DRI2: failed to create dri screen
libEGL warning: Not allowed to force software rendering when API explicitly selects a hardware device.
libEGL warning: DRI2: failed to create dri screen
Traceback (most recent call last):
  File "demo.py", line 382, in <module>
    main(args)
  File "demo.py", line 256, in main
    renderer = Renderer(resolution=(orig_width, orig_height), orig_img=True, wireframe=args.wireframe)
  File "/home/zhang-u16/VIBE/lib/utils/renderer.py", line 60, in __init__
    point_size=1.0
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/platforms/egl.py", line 177, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
	err = 12289,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7fefdc14ecb0>,
		c_long(0),
		c_long(0),
	),
	result = 0
)

`

I have the same problem. Have you solved it?

@azuryl
Copy link

azuryl commented Feb 6, 2022

Hi @bhack,

Thanks for the suggestion. After messing around a lot, I realized that I just had an NVIDIA driver issue with EGL on Ubuntu 16.04. I tried my EGL platform on Google CoLab and it works on newer Ubuntu versions (or if you install your drivers from a runfile). Check it out here. Does that work for you?

@mmatl Dear the link not exit do you solved in ubuntu 18.04

@azuryl
Copy link

azuryl commented Feb 6, 2022

I get the same error on ubuntu 18, cuda 10, pyrender 0.1.36 with pyopengl 1.30, any helps?

libEGL warning: DRI2: failed to create dri screen
libEGL warning: Not allowed to force software rendering when API explicitly selects a hardware device.
libEGL warning: DRI2: failed to create dri screen
Traceback (most recent call last):
  File "demo.py", line 382, in <module>
    main(args)
  File "demo.py", line 256, in main
    renderer = Renderer(resolution=(orig_width, orig_height), orig_img=True, wireframe=args.wireframe)
  File "/home/zhang-u16/VIBE/lib/utils/renderer.py", line 60, in __init__
    point_size=1.0
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/offscreen.py", line 134, in _create
    self._platform.init_context()
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/pyrender/platforms/egl.py", line 177, in init_context
    assert eglInitialize(self._egl_display, major, minor)
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/home/zhang-u16/VIBE/vibe-env/lib/python3.7/site-packages/OpenGL/error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
	err = 12289,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7fefdc14ecb0>,
		c_long(0),
		c_long(0),
	),
	result = 0
)

`

I have the same problem. Have you solved it?

same issue

@JZhao12
Copy link

JZhao12 commented Mar 3, 2022

Hello guys I met a similar issue with 'OpenGL.error.GLError: GLError( err = 12289', I was doing the offscreen rendering based on Pyrender. Now I solved this problem by calling render.delete(), so every time it will rebuild the rendering again and this issue disappeared. Hope it helps.

@lingtengqiu
Copy link

Hello guys I met a similar issue with 'OpenGL.error.GLError: GLError( err = 12289', I was doing the offscreen rendering based on Pyrender. Now I solved this problem by calling render.delete(), so every time it will rebuild the rendering again and this issue disappeared. Hope it helps.

where I add this code? could you please give us a example?

@JZhao12
Copy link

JZhao12 commented Mar 12, 2022

Hi @lingtengqiu , I used the Pyrender example code from here https://pyrender.readthedocs.io/en/latest/examples/quickstart.html , and I added the render.delete() in the end of the script.

import numpy as np
import trimesh
import pyrender
import matplotlib.pyplot as plt
fuze_trimesh = trimesh.load('examples/models/fuze.obj')
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
scene = pyrender.Scene()
scene.add(mesh)
camera = pyrender.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=1.0)
s = np.sqrt(2)/2
camera_pose = np.array([
... [0.0, -s, s, 0.3],
... [1.0, 0.0, 0.0, 0.0],
... [0.0, s, s, 0.35],
... [0.0, 0.0, 0.0, 1.0],
... ])
scene.add(camera, pose=camera_pose)
light = pyrender.SpotLight(color=np.ones(3), intensity=3.0,
... innerConeAngle=np.pi/16.0,
... outerConeAngle=np.pi/6.0)
scene.add(light, pose=camera_pose)
r = pyrender.OffscreenRenderer(400, 400)
color, depth = r.render(scene)
r.delete()

Hope it helps

@reconlabs-sergio
Copy link

I ended up creating my docker image based of https://hub.docker.com/r/nvidia/cudagl and fixed the issue.

I confirm that this solved my problem. I used 11.3.0-devel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests