NVlabs / nvdiffrast

Nvdiffrast - Modular Primitives for High-Performance Differentiable Rendering
Other
1.31k stars 139 forks source link

First image black with Open3D #59

Closed wpalfi closed 2 years ago

wpalfi commented 2 years ago

I create an Open3D window. rasterize() returns only zeros in the very first invocation. After that, everything works fine. Example:

import open3d.visualization.gui as gui
import torch
import nvdiffrast.torch as dr

gui.Application.instance.initialize()
gui.Application.instance.create_window().close() #problem disappears when I remove this line

def tensor(*args, **kwargs):
    return torch.tensor(*args, device='cuda', **kwargs)

pos = tensor([[[-0.8, -0.8, 0, 1], [0.8, -0.8, 0, 1], [-0.8, 0.8, 0, 1]]], dtype=torch.float32)
tri = tensor([[0, 1, 2]], dtype=torch.int32)

glctx = dr.RasterizeGLContext()

for i in range(2):
    rast, _ = dr.rasterize(glctx, pos, tri, resolution=[256, 256])
    print(rast[0].max().item())

Output:

0.0
1.0

I can use a warmup rasterize() as a workaround, so it is not a big problem for me.

nvdiffrast https://github.com/NVlabs/nvdiffrast/commit/e44c9a29867addc8b98982deeec1f66c4a7d8b54 Open3D 0.13.0 Windows 11 GeForce GTX 1050 Ti Nvidia Driver 30.0.14.9676 11/9/2021 Cuda 11.3.1 Pytorch 1.10.0 python 3.8.12

s-laine commented 2 years ago

This is an annoying but known issue and mentioned in the documentation of rasterize(). I've never had a reliable test case to reproduce it, so I couldn't hunt it down properly or even identify if the bug is on my side or something in the driver stack that needs to be worked around. If your example code causes the bug to happen consistently, I should be able to dig deeper.

wpalfi commented 2 years ago

I tested the example on two different machines. The output is always the same.

s-laine commented 2 years ago

v0.2.8 includes a workaround that fixes this particular repro, so closing the issue. With any luck this also fixed the nondeterministic blank buffer bug.