NVIDIAGameWorks/kaolin

[F glutil.cpp:338] eglInitialize() failed Aborted (core dumped) when render with kaolin and nvdiffrast

walsvid opened this issue · 1 comments

I have discovered that under certain NVIDIA driver versions and OpenGL versions, using nvdiffrast within kaolin to render causes errors. As mentioned in this issue sicxu/Deep3DFaceRecon_pytorch#2, the problem is related to the use of nvdiff.RasterizeGLContext instead of nvdiff.RasterizeCudaContext. I noticed that in the kaolin code, the Context is initialized and fixed to always be GLContext.

def _get_nvdiff_glctx(device):
if device not in _device2glctx:
_device2glctx[device] = nvdiff.RasterizeGLContext(
output_db=False, device=device)
return _device2glctx[device]

After changing this to nvdiff.RasterizeCudaContext and recompiling kaolin, I used kal.render.mesh.rasterize and selected 'nvdiffrast' as the backend for rendering. The result was normal, with the only issue being that the output must be a multiple of 8.

I would like to know if there are plans in future versions to make the Context type a selectable parameter. Additionally, I would like to inquire if there is a need to contribute a pull request.

Hello, thanks for your detailed note!

In fact, there is an option to set the default context without recompiling the code with: kal.render.mesh.nvdiffrast_context.nvdiffrast_use_cuda(). However, it looks like there is a bug in that function (thank you for alerting us to it).

You can still bypass that bug and set your preferred context using:

import kaolin as kal
import nvdiffrast.torch

kal.render.mesh.nvdiffrast_context.set_default_nvdiffrast_context(
    nvdiffrast.torch.RasterizeCudaContext("cuda"), "cuda")

print(kal.render.mesh.nvdiffrast_context.default_nvdiffrast_context(device="cuda"))

# Prints: <nvdiffrast.torch.ops.RasterizeCudaContext object at 0x7fc42c2164c0>