deterministic rasterization

Summary: Attempt to fix #659, an observation that the rasterizer is nondeterministic, by resolving tied faces by picking those with lower index.

Reviewed By: nikhilaravi, patricklabatut

Differential Revision: D30699039

fbshipit-source-id: 39ed797eb7e9ce7370ae71259ad6b757f9449923
This commit is contained in:
Jeremy Reizenstein
2021-09-23 06:57:11 -07:00
committed by Facebook GitHub Bot
parent cb170ac024
commit 860b742a02
3 changed files with 24 additions and 9 deletions

View File

@@ -1151,6 +1151,28 @@ class TestRasterizeMeshes(TestCaseMixin, unittest.TestCase):
bin_faces_same = (bin_faces.squeeze() == bin_faces_expected).all()
self.assertTrue(bin_faces_same.item() == 1)
def test_order_of_ties(self):
# Tied faces are rasterized in index order
# We rasterize a mesh with many faces.
device = torch.device("cuda:0")
verts = -5 * torch.eye(3, dtype=torch.float32, device=device)[None]
faces = torch.arange(3, device=device, dtype=torch.int64).expand(1, 100, 3)
mesh = Meshes(verts=verts, faces=faces)
R, T = look_at_view_transform(2.7, 0.0, 0.0)
cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
raster_settings = RasterizationSettings(
image_size=28, faces_per_pixel=100, bin_size=0
)
rasterizer = MeshRasterizer(raster_settings=raster_settings)
out = rasterizer(mesh, cameras=cameras)
self.assertClose(
out.pix_to_face[0, 14:, :14],
torch.arange(100, device=device).expand(14, 14, 100),
)
@staticmethod
def rasterize_meshes_python_with_init(
num_meshes: int,