kaolin icon indicating copy to clipboard operation
kaolin copied to clipboard

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

Open walsvid opened this issue 1 year ago • 2 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 https://github.com/sicxu/Deep3DFaceRecon_pytorch/issues/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.

https://github.com/NVIDIAGameWorks/kaolin/blob/5406915c3a020596384b1a36679ff68afd04d455/kaolin/render/mesh/rasterization.py#L35-L39

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.

walsvid avatar May 14 '24 06:05 walsvid

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>

shumash avatar Jul 19 '24 13:07 shumash