Coder Social home page Coder Social logo

Headless OpenGL rendering about open3d HOT 35 CLOSED

qianyizh avatar qianyizh commented on May 6, 2024 1
Headless OpenGL rendering

from open3d.

Comments (35)

qianyizh avatar qianyizh commented on May 6, 2024 2

Recently I have the needs for glfw rendering on headless server and have gain some success.
See this:
glfw/glfw#1004

In short, Alexey's email is absolute correct.

First, you need to setup Xorg correctly.
You can check /etc/X11/xorg.conf to see if it is configured headlessly (usually via sudo nvidia-xconfig -a --use-display-device=none).
Stop lightdm and restart Xorg to make sure the correct configuration is running.

Then, if you don't want to specify a GPU, you can just setup the environment variable DISPLAY to :0 and test the OpenGL setup.

export DISPLAY=:0
glxinfo | grep OpenGL

You should see something like:

OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: TITAN Xp/PCIe/SSE2
OpenGL core profile version string: 4.5.0 NVIDIA 384.90
OpenGL core profile shading language version string: 4.50 NVIDIA
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 384.90
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 NVIDIA 384.90
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

If your server has multiple GPUs, you will be able to see multiple copies of the above information.

If you have passed this test, setup the DISPLAY environment variable and try some program with glfwInit(), say

export DISPLAY=:0
./some_program_that_has_glfwinit

There is a risk that you will have this error

glfw.GLFWError: (65544) b'X11: RandR gamma ramp support seems broken'

This is an error of version 3.2 and older. They don't support headless rendering. Since 3.3 (current master) it is supported.
Then everything should be fine.

In addition, if you want to specify GPU, you can use VirtualGL and TurboVNC to mock a display. This is done with the following steps.

First, install VirtualGL and TurboVNC, something like:

sudo dpkg -i virtualgl_xxx.deb
sudo dpkg -i turbovnc_xxx.deb

Then launch vnc server to run glfw.

// These two steps make sure that the right headless Xorg is configured
sudo service lightdm stop
sudo nohup Xorg :0 &

// Launch a vncserver to mock display on :1
// You can change it to :2, :3, ...
/opt/TurboVNC/bin/vncserver :1

// Launch program on :1
export DISPLAY=:1
vglrun -d :0.0 glxinfo
vglrun -d :0.0 <a script that calls glfw>

from open3d.

takanokage avatar takanokage commented on May 6, 2024 1

Another approach is to use Docker to create a headless environment for Open3D.
I already have a docker image based on ubuntu 16.04 with xvfb and x11vnc that works. I've also tested one light window manager (ratpoison) but I'm not too happy with it and want to test others. Next I need to test building/running Open3D inside it.

If we need access to the host GPU (NVIDIA) there are already good solutions to get that: NVIDIA-docker and NVIDIA docker images with CUDA and cuDNN.

I've also been looking into using Alpine as the base if the image size is a concern. The Ubuntu image with xvfb and x1vnc gets to about 450MB while the Alpine image to just about 70MB.

from open3d.

syncle avatar syncle commented on May 6, 2024

I am looking into this issue and read some documents.
According to this glfw 3.3 support headless rendering using OSMesa.
The glfw version included in Open3D seems to be 3.1. Can we upgrade glfw for this?

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

Yes.

from open3d.

syncle avatar syncle commented on May 6, 2024

As we discussed today, glfw 3.3 is not available yet. So we need to find the detour.
I tested following code with one of GCP virtual machine

glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);

but got the error.

GLFW Error: X11: The DISPLAY environment variable is missing
Failed to initialize GLFW
Failed creating OpenGL window.

Basically glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); hides existing window. This method does not working in the environment GLFW cannot make a window.

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

Another option is to mimic libigl's tcpviewer.
See this for reference:
https://github.com/libigl/libigl/blob/master/python/tcpviewer.py

Lower priority. Close for now.

from open3d.

vkoltun avatar vkoltun commented on May 6, 2024

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

Reopen per request.

from open3d.

bhack avatar bhack commented on May 6, 2024

Other than VNC there is also xpra https://xpra.org/trac/wiki/Usage/OpenGL

from open3d.

rukie avatar rukie commented on May 6, 2024

As another user, this would be an excellent feature! ๐Ÿ‘

from open3d.

syncle avatar syncle commented on May 6, 2024

Working on this. I am using glfw3.3_dev to avoid hassles.

Edit: my working branch with glfw3.3_dev.

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

The purpose is to make Open3D rendering part running on cloud (AWS/GCloud). @syncle can you help test the solution on GCloud?

from open3d.

syncle avatar syncle commented on May 6, 2024

Sure. I can use a fresh Ubuntu machine running on GCloud. @takanokage, can you elaborate your steps for me? That will be used for documents too.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

I will post more once I have it working.
I'm at the point where I can build Open3D inside the docker container. However the verification step after the build fails, for this reason I added issue 241.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

I got Open3D built and working inside a Docker container.
However I'm getting the same X11: RandR gamma ramp support seems broken error.
Next: I'll check the VirtualGL suggestion by Qianyi.

$ cd ~/Open3D/build/lib/Tutorial/Basic
$ python3 rgbd_redwood.py
press q

Read Redwood dataset
RGBDImage of size 
Color image : 640x480, with 1 channels.
Depth image : 640x480, with 1 channels.
Use numpy.asarray to access buffer data.
GLFW Error: X11: RandR gamma ramp support seems broken
GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory

from open3d.

syncle avatar syncle commented on May 6, 2024

From @qianyizh's post

There is a risk that you will have this error

glfw.GLFWError: (65544) b'X11: RandR gamma ramp support seems broken'

This is an error of version 3.2 and older. They don't support headless rendering. Since 3.3 (current master) it is supported. Then everything should be fine.

It might be good to try Open3D + GLFW3.3_dev solution via

git clone -b headless_rendering https://github.com/syncle/Open3D.git

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Jaesik, I just tried your branch with glfw 3.3 inside my docker container.
Somehow I'm still getting the same X11: RandR gamma ramp support seems broken error.
I seem to remember you mentioned I need to build with a particular flag, can you tell me what that was again? tx!

from open3d.

syncle avatar syncle commented on May 6, 2024

Yes. Try it with

cmake -DOpen3D_USE_NATIVE_DEPENDENCY_BUILD=OFF ../src

Edit:
Check out what cmake says. It should say like building glfw from source.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Thanks!
So that did something:
GLFW Error: OSMesa: Library not found
Failed to create window
[DrawGeometries] Failed creating OpenGL window.

Did you install a special package for this?

from open3d.

syncle avatar syncle commented on May 6, 2024

I think this should work

sudo apt-get install libgl1-mesa-dev -y 
sudo apt-get install libosmesa6-dev -y

from open3d.

takanokage avatar takanokage commented on May 6, 2024

This is the output of glxinfo: OpenGL version string: 3.0 Mesa 17.2.8

libgl1-mesa-dev was already installed.
I installed libosmesa6-dev and the previous glfw error dissapeared.

Now I'm getting a segmentation fault when running Tutorial/Basic/rgbd-redwood.py or Tutorial/Advanced/customized_visualization.py. I'll troubleshoot and let you know what I'll find.

$ python3 customized_visualization.py
Reading PLY: [========================================] 100%

  1. Customized visualization to mimic DrawGeometry
    Segmentation fault (core dumped)

from open3d.

takanokage avatar takanokage commented on May 6, 2024

After going trough lots of resources it would seem the segmentation fault is likely an issue introduced by the use of docker.
Among the things I have tried:

  • use an NVIDIA driver+CUDA based image
  • use nvidia-docker to run the containers

Others have seen the same error however there's no consensus on how to address it.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

The Segmentation fault went away. I successfully ran Tutorial/Basic/rgbd_redwood.py and
Tutorial/Advanced/customize_visualization.py.

I cloned and tested using the master branch rather than the headless_rendering branch with glfw3.3.

I'm still getting the X11: RandR gamma ramp support seems broken error but that shows that this error has a different cause/meaning than we previously thought.

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

You are not linking to the dev branch of glfw (3.3).
In dev branch this message has been removed X11: RandR gamma ramp support seems broken. If you are using the correct version, you should not be able to see it.
Read the code of glfw, you will see.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

In other words this is more like a warning instead of an error and will go away once we move to glfw 3.3?

from open3d.

qianyizh avatar qianyizh commented on May 6, 2024

https://github.com/glfw/glfw/blame/6e69f63ffa4059d0f16344e6b038285c1ca78c16/src/x11_init.c
glfw/glfw@b025880#diff-9c6aefaea564bfbb5f29c9b9026e1b34
glfw/glfw@5fe4dfb

from open3d.

takanokage avatar takanokage commented on May 6, 2024
  1. If I clone/build/run the headless_rendering branch I get the segmentation fault.
    $ cd ~/Open3D/build/lib/Tutorial/Advanced
    $ python3 customized_visualization.py

Reading PLY: [========================================] 100%

  1. Customized visualization to mimic DrawGeometry
    Segmentation fault (core dumped)
  1. If I clone/build/run the master branch I get the RandR and joystick errors but the tutorials run fine.
    $ cd ~/Open3D/build/lib/Tutorial/Advanced
    $ python3 customized_visualization.py

Reading PLY: [========================================] 100%

  1. Customized visualization to mimic DrawGeometry
    GLFW Error: X11: RandR gamma ramp support seems broken
    GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
    GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory
  2. Customized visualization with a rotating view
    GLFW Error: X11: RandR gamma ramp support seems broken
    GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
    GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory
  3. Customized visualization showing normal rendering
    GLFW Error: X11: RandR gamma ramp support seems broken
    GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
    GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory
  4. Customized visualization with key press callbacks
    Press 'K' to change background color to black
    Press 'R' to load a customized render option, showing normals
    Press ',' to capture the depth buffer and show it
    Press '.' to capture the screen and show it
    GLFW Error: X11: RandR gamma ramp support seems broken
    GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
    GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory
  5. Customized visualization playing a camera trajectory
    GLFW Error: X11: RandR gamma ramp support seems broken
    GLFW Error: Linux: Failed to watch for joystick connections in /dev/input: No such file or directory
    GLFW Error: Linux: Failed to open joystick device directory /dev/input: No such file or directory
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00000
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00001
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00002
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00003
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00004
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00005
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00006
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.
    Capture image 00007
    [ViewControl] ConvertFromPinholeCameraParameters() failed because window height and width do not match.

from open3d.

syncle avatar syncle commented on May 6, 2024

After going trough lots of resources it would seem the segmentation fault is likely an issue introduced by the use of docker.

If the issue is due to docker, how about not using docker? You can make virtual machine instead. As @qianyizh have tested on Ubuntu systems, we just want to finalize this issue with GLFW3.3, instead of blocked by new issues regarding the docker.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Actually that was a speculation on my part.
A later experiment showed a correlation between glfw 3.3 and the presence of the segmentation fault. The master branch works fine with docker.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

I have headless rendering working inside docker with the master branch of Open3D.
Next I'll be working on the documentation before submitting a pull request.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Bind mounts (#254)
I propose we make the whole Open3D folder available both inside the docker container and on the host side. In this way we not only gain direct access to the images generated but we also enable developing Open3D on the host side and testing on both host side and docker side of things.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Because we moved #254 under #17 I need to postpone the pull request until after I implement/test it.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

I got headless working together with bind mounting.
Bind mounting was a ton of work and should've been an independent pull request.

from open3d.

takanokage avatar takanokage commented on May 6, 2024

Usage notes:

  1. clone my branch
  2. $ cd <Open3D path>/utilities/docker/ubuntu-xvfb/tools
  3. $ ./build.sh to build the image
  4. $ ./attach.sh to clone/build the master Open3D repo and start the Open3D container
  5. $ ./headless_sample.sh to run the sample that renders some images and saves them to disk.
    The sample will render some images which can be accessed on the host at ~/Open3D_docker. These files don't go away if the container is stopped.

Notes:

  • the sample will not return. Ctrl+c to exit. Need to update the sample to exit on it's own.
  • the cloning is done for now to ~/Open3D_docker. We have options: find a way to let the user specify the destination or just reuse the current location of Open3D.
  • TODO: uncomment entries in the dependencies section inside the Dockerfile.

from open3d.

syncle avatar syncle commented on May 6, 2024

Addressed in #273.

from open3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.